Chromium Code Reviews| Index: runtime/vm/parser.cc |
| =================================================================== |
| --- runtime/vm/parser.cc (revision 7463) |
| +++ runtime/vm/parser.cc (working copy) |
| @@ -112,6 +112,13 @@ |
| } |
| +LocalVariable* ParsedFunction::CreateExpressionTempVar(intptr_t token_index) { |
| + return new LocalVariable(token_index, |
| + String::ZoneHandle(String::NewSymbol(":expr_temp")), |
| + Type::ZoneHandle(Type::DynamicType())); |
| +} |
| + |
| + |
| void ParsedFunction::SetNodeSequence(SequenceNode* node_sequence) { |
| ASSERT(node_sequence_ == NULL); |
| ASSERT(node_sequence != NULL); |
| @@ -129,6 +136,7 @@ |
| node_sequence_->set_last_parameter_id(parameter_id); |
| } |
| + |
| void ParsedFunction::AllocateVariables() { |
| LocalScope* scope = node_sequence()->scope(); |
| const int fixed_parameter_count = function().num_fixed_parameters(); |
| @@ -228,7 +236,8 @@ |
| } |
| -Parser::Parser(const Script& script, const Library& library) |
| +Parser::Parser(const Script& script, |
| + const Library& library) |
| : script_(script), |
| tokens_(TokenStream::Handle(script.tokens())), |
| token_index_(0), |
| @@ -240,7 +249,7 @@ |
| current_class_(Class::Handle()), |
| library_(library), |
| try_blocks_list_(NULL), |
| - increment_temp_(NULL) { |
| + expression_temp_(NULL) { |
| ASSERT(!tokens_.IsNull()); |
| ASSERT(!library.IsNull()); |
| SetPosition(0); |
| @@ -261,7 +270,7 @@ |
| current_class_(Class::Handle(current_function_.owner())), |
| library_(Library::Handle(current_class_.library())), |
| try_blocks_list_(NULL), |
| - increment_temp_(NULL) { |
| + expression_temp_(NULL) { |
| ASSERT(!tokens_.IsNull()); |
| ASSERT(!function.IsNull()); |
| SetPosition(token_index); |
| @@ -685,9 +694,12 @@ |
| // Add implicit return node. |
| node_sequence->Add(new ReturnNode(parser.token_index_)); |
| } |
| - if (parser.increment_temp_ != NULL) { |
| - node_sequence->scope()->AddVariable(parser.increment_temp_); |
| + if (parser.expression_temp_ != NULL) { |
| + parsed_function->set_expression_temp_var(parser.expression_temp_); |
| } |
| + if (parsed_function->has_expression_temp_var()) { |
|
hausner
2012/05/09 20:52:08
This if statement is true iff the previous one was
srdjan
2012/05/09 21:25:45
Yes, but it can be true even if the previous one w
|
| + node_sequence->scope()->AddVariable(parsed_function->expression_temp_var()); |
| + } |
| parsed_function->SetNodeSequence(node_sequence); |
| // The instantiator may be required at run time for generic type checks or |
| @@ -5257,6 +5269,7 @@ |
| new LiteralNode(catch_pos, Instance::ZoneHandle(Instance::null())); |
| AstNode* null_cond_expr = new ComparisonNode( |
| catch_pos, Token::kEQ_STRICT, exception_var, null_literal); |
| + EnsureExpressionTemp(); |
| AstNode* or_node = new BinaryOpNode( |
| catch_pos, Token::kOR, null_cond_expr, type_cond_expr); |
| current_block_->statements->Add( |
| @@ -5904,15 +5917,20 @@ |
| const LocalVariable& Parser::GetIncrementTempLocal() { |
| - if (increment_temp_ == NULL) { |
| - increment_temp_ = |
| - new LocalVariable(current_function_.token_index(), |
| - String::ZoneHandle(String::NewSymbol(":incrtemp")), |
| - Type::ZoneHandle(Type::DynamicType())); |
| + if (expression_temp_ == NULL) { |
| + expression_temp_ = ParsedFunction::CreateExpressionTempVar( |
| + current_function().token_index()); |
| } |
| - return *increment_temp_; |
| + return *expression_temp_; |
| } |
| + |
| +void Parser::EnsureExpressionTemp() { |
| + // Temporary used later by the flow_graph_builder. |
| + GetIncrementTempLocal(); |
| +} |
| + |
| + |
| LocalVariable* Parser::CreateTempConstVariable(intptr_t token_index, |
| intptr_t token_id, |
| const char* s) { |
| @@ -5949,6 +5967,9 @@ |
| } |
| } |
| } |
| + if ((binary_op == Token::kAND) || (binary_op == Token::kOR)) { |
|
hausner
2012/05/09 20:52:08
I thought you wanted to do constant folding in the
srdjan
2012/05/09 21:25:45
It turns out that constant folding is not needed.
|
| + EnsureExpressionTemp(); |
| + } |
| return new BinaryOpNode(op_pos, binary_op, lhs, rhs); |
| } |
| @@ -6119,6 +6140,7 @@ |
| const intptr_t expr_pos = token_index_; |
| AstNode* expr = ParseBinaryExpr(Token::Precedence(Token::kOR)); |
| if (CurrentToken() == Token::kCONDITIONAL) { |
| + EnsureExpressionTemp(); |
| ConsumeToken(); |
| AstNode* expr1 = ParseExpr(kAllowConst); |
| ExpectToken(Token::kCOLON); |