| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "src/v8.h" | 7 #include "src/v8.h" |
| 8 #include "test/cctest/cctest.h" | 8 #include "test/cctest/cctest.h" |
| 9 | 9 |
| 10 #include "src/base/utils/random-number-generator.h" | 10 #include "src/base/utils/random-number-generator.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 root_(new (zone_) Node(NULL)), | 37 root_(new (zone_) Node(NULL)), |
| 38 current_node_(root_), | 38 current_node_(root_), |
| 39 current_expression_(NULL) {} | 39 current_expression_(NULL) {} |
| 40 | 40 |
| 41 void If() { | 41 void If() { |
| 42 if (current_node_->else_node != NULL) { | 42 if (current_node_->else_node != NULL) { |
| 43 current_node_ = current_node_->else_node; | 43 current_node_ = current_node_->else_node; |
| 44 } else if (current_node_->then_node != NULL) { | 44 } else if (current_node_->then_node != NULL) { |
| 45 current_node_ = current_node_->then_node; | 45 current_node_ = current_node_->then_node; |
| 46 } | 46 } |
| 47 ASSERT(current_expression_ == NULL); | 47 DCHECK(current_expression_ == NULL); |
| 48 current_expression_ = new (zone_) Expression(zone_, NULL); | 48 current_expression_ = new (zone_) Expression(zone_, NULL); |
| 49 current_node_->condition = current_expression_; | 49 current_node_->condition = current_expression_; |
| 50 } | 50 } |
| 51 void IfNode() { LastChild()->variable_offset = variable_offset_++; } | 51 void IfNode() { LastChild()->variable_offset = variable_offset_++; } |
| 52 | 52 |
| 53 void OpenParen() { current_expression_ = LastChild(); } | 53 void OpenParen() { current_expression_ = LastChild(); } |
| 54 void CloseParen() { current_expression_ = current_expression_->parent; } | 54 void CloseParen() { current_expression_ = current_expression_->parent; } |
| 55 | 55 |
| 56 void And() { NewChild()->conjunction = true; } | 56 void And() { NewChild()->conjunction = true; } |
| 57 void Or() { NewChild()->disjunction = true; } | 57 void Or() { NewChild()->disjunction = true; } |
| 58 | 58 |
| 59 void Then() { | 59 void Then() { |
| 60 ASSERT(current_expression_ == NULL || current_expression_->parent == NULL); | 60 DCHECK(current_expression_ == NULL || current_expression_->parent == NULL); |
| 61 current_expression_ = NULL; | 61 current_expression_ = NULL; |
| 62 ASSERT(current_node_->then_node == NULL); | 62 DCHECK(current_node_->then_node == NULL); |
| 63 current_node_->then_node = new (zone_) Node(current_node_); | 63 current_node_->then_node = new (zone_) Node(current_node_); |
| 64 } | 64 } |
| 65 void Else() { | 65 void Else() { |
| 66 ASSERT(current_expression_ == NULL || current_expression_->parent == NULL); | 66 DCHECK(current_expression_ == NULL || current_expression_->parent == NULL); |
| 67 current_expression_ = NULL; | 67 current_expression_ = NULL; |
| 68 ASSERT(current_node_->else_node == NULL); | 68 DCHECK(current_node_->else_node == NULL); |
| 69 current_node_->else_node = new (zone_) Node(current_node_); | 69 current_node_->else_node = new (zone_) Node(current_node_); |
| 70 } | 70 } |
| 71 void Return() { | 71 void Return() { |
| 72 if (current_node_->else_node != NULL) { | 72 if (current_node_->else_node != NULL) { |
| 73 current_node_->else_node->returns = true; | 73 current_node_->else_node->returns = true; |
| 74 } else if (current_node_->then_node != NULL) { | 74 } else if (current_node_->then_node != NULL) { |
| 75 current_node_->then_node->returns = true; | 75 current_node_->then_node->returns = true; |
| 76 } else { | 76 } else { |
| 77 CHECK(false); | 77 CHECK(false); |
| 78 } | 78 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 Expression* NewChild() { | 157 Expression* NewChild() { |
| 158 Expression* child = new (zone_) Expression(zone_, current_expression_); | 158 Expression* child = new (zone_) Expression(zone_, current_expression_); |
| 159 current_expression_->children.push_back(child); | 159 current_expression_->children.push_back(child); |
| 160 return child; | 160 return child; |
| 161 } | 161 } |
| 162 | 162 |
| 163 static void PrintRecursive(std::vector<char>* v, Expression* expression) { | 163 static void PrintRecursive(std::vector<char>* v, Expression* expression) { |
| 164 CHECK(expression != NULL); | 164 CHECK(expression != NULL); |
| 165 if (expression->conjunction) { | 165 if (expression->conjunction) { |
| 166 ASSERT(!expression->disjunction); | 166 DCHECK(!expression->disjunction); |
| 167 v->push_back('&'); | 167 v->push_back('&'); |
| 168 } else if (expression->disjunction) { | 168 } else if (expression->disjunction) { |
| 169 v->push_back('|'); | 169 v->push_back('|'); |
| 170 } | 170 } |
| 171 if (expression->variable_offset != kUninitializedVariableOffset) { | 171 if (expression->variable_offset != kUninitializedVariableOffset) { |
| 172 v->push_back('v'); | 172 v->push_back('v'); |
| 173 } | 173 } |
| 174 Expressions& children = expression->children; | 174 Expressions& children = expression->children; |
| 175 if (children.empty()) return; | 175 if (children.empty()) return; |
| 176 v->push_back('('); | 176 v->push_back('('); |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 for (int i = 0; i < n_ifs * n_vars + 10; i++) { | 658 for (int i = 0; i < n_ifs * n_vars + 10; i++) { |
| 659 IfBuilderGenerator m; | 659 IfBuilderGenerator m; |
| 660 m.ParseRandomIfThenElse(&rng, n_ifs, n_vars); | 660 m.ParseRandomIfThenElse(&rng, n_ifs, n_vars); |
| 661 m.RunRandom(&rng); | 661 m.RunRandom(&rng); |
| 662 } | 662 } |
| 663 } | 663 } |
| 664 } | 664 } |
| 665 } | 665 } |
| 666 | 666 |
| 667 #endif | 667 #endif |
| OLD | NEW |