| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/parser.h" | 5 #include "vm/parser.h" |
| 6 | 6 |
| 7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 1417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1428 Array::ZoneHandle(ArgumentsDescriptor::New(function_args.length(), | 1428 Array::ZoneHandle(ArgumentsDescriptor::New(function_args.length(), |
| 1429 function_args.names())); | 1429 function_args.names())); |
| 1430 arguments->Add(new LiteralNode(args_pos, args_descriptor)); | 1430 arguments->Add(new LiteralNode(args_pos, args_descriptor)); |
| 1431 // The third argument is an array containing the original function arguments, | 1431 // The third argument is an array containing the original function arguments, |
| 1432 // including the receiver. | 1432 // including the receiver. |
| 1433 ArrayNode* args_array = | 1433 ArrayNode* args_array = |
| 1434 new ArrayNode(args_pos, Type::ZoneHandle(Type::ArrayType())); | 1434 new ArrayNode(args_pos, Type::ZoneHandle(Type::ArrayType())); |
| 1435 for (intptr_t i = 0; i < function_args.length(); i++) { | 1435 for (intptr_t i = 0; i < function_args.length(); i++) { |
| 1436 AstNode* arg = function_args.NodeAt(i); | 1436 AstNode* arg = function_args.NodeAt(i); |
| 1437 if ((temp_for_last_arg != NULL) && (i == function_args.length() - 1)) { | 1437 if ((temp_for_last_arg != NULL) && (i == function_args.length() - 1)) { |
| 1438 args_array->AddElement( | 1438 LetNode* store_arg = new LetNode(arg->token_pos()); |
| 1439 new CommaNode(arg->token_pos(), | 1439 store_arg->AddNode(new StoreLocalNode(arg->token_pos(), |
| 1440 new StoreLocalNode(arg->token_pos(), | |
| 1441 temp_for_last_arg, | 1440 temp_for_last_arg, |
| 1442 arg), | 1441 arg)); |
| 1443 new LoadLocalNode(arg->token_pos(), | 1442 store_arg->AddNode(new LoadLocalNode(arg->token_pos(), |
| 1444 temp_for_last_arg))); | 1443 temp_for_last_arg)); |
| 1444 args_array->AddElement(store_arg); |
| 1445 } else { | 1445 } else { |
| 1446 args_array->AddElement(function_args.NodeAt(i)); | 1446 args_array->AddElement(arg); |
| 1447 } | 1447 } |
| 1448 } | 1448 } |
| 1449 arguments->Add(args_array); | 1449 arguments->Add(args_array); |
| 1450 // Lookup the static InvocationMirror._allocateInvocationMirror method. | 1450 // Lookup the static InvocationMirror._allocateInvocationMirror method. |
| 1451 const Class& mirror_class = | 1451 const Class& mirror_class = |
| 1452 Class::Handle(LookupCoreClass(Symbols::InvocationMirror())); | 1452 Class::Handle(LookupCoreClass(Symbols::InvocationMirror())); |
| 1453 ASSERT(!mirror_class.IsNull()); | 1453 ASSERT(!mirror_class.IsNull()); |
| 1454 const Function& allocation_function = Function::ZoneHandle( | 1454 const Function& allocation_function = Function::ZoneHandle( |
| 1455 mirror_class.LookupStaticFunction( | 1455 mirror_class.LookupStaticFunction( |
| 1456 PrivateCoreLibName(Symbols::AllocateInvocationMirror()))); | 1456 PrivateCoreLibName(Symbols::AllocateInvocationMirror()))); |
| (...skipping 5617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7074 result->IsStoreStaticFieldNode() || | 7074 result->IsStoreStaticFieldNode() || |
| 7075 result->IsStoreLocalNode())) { | 7075 result->IsStoreLocalNode())) { |
| 7076 EnsureExpressionTemp(); | 7076 EnsureExpressionTemp(); |
| 7077 } | 7077 } |
| 7078 return result; | 7078 return result; |
| 7079 } | 7079 } |
| 7080 | 7080 |
| 7081 | 7081 |
| 7082 AstNode* Parser::ParseCascades(AstNode* expr) { | 7082 AstNode* Parser::ParseCascades(AstNode* expr) { |
| 7083 intptr_t cascade_pos = TokenPos(); | 7083 intptr_t cascade_pos = TokenPos(); |
| 7084 LetNode* result = new LetNode(cascade_pos); | 7084 LetNode* cascade = new LetNode(cascade_pos); |
| 7085 LocalVariable* cascade_receiver_var = result->AddInitializer(expr); | 7085 LocalVariable* cascade_receiver_var = cascade->AddInitializer(expr); |
| 7086 // TODO(fschneider): Make LetNode support more than one body node and | |
| 7087 // replace the SequenceNode here and CommaNode here and in postfix | |
| 7088 // expressions. | |
| 7089 SequenceNode* cascade = new SequenceNode(cascade_pos, NULL); | |
| 7090 while (CurrentToken() == Token::kCASCADE) { | 7086 while (CurrentToken() == Token::kCASCADE) { |
| 7091 cascade_pos = TokenPos(); | 7087 cascade_pos = TokenPos(); |
| 7092 LoadLocalNode* load_cascade_receiver = | 7088 LoadLocalNode* load_cascade_receiver = |
| 7093 new LoadLocalNode(cascade_pos, cascade_receiver_var); | 7089 new LoadLocalNode(cascade_pos, cascade_receiver_var); |
| 7094 if (Token::IsIdentifier(LookaheadToken(1))) { | 7090 if (Token::IsIdentifier(LookaheadToken(1))) { |
| 7095 // Replace .. with . for ParseSelectors(). | 7091 // Replace .. with . for ParseSelectors(). |
| 7096 token_kind_ = Token::kPERIOD; | 7092 token_kind_ = Token::kPERIOD; |
| 7097 } else if (LookaheadToken(1) == Token::kLBRACK) { | 7093 } else if (LookaheadToken(1) == Token::kLBRACK) { |
| 7098 ConsumeToken(); | 7094 ConsumeToken(); |
| 7099 } else { | 7095 } else { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 7113 // temporary locals. | 7109 // temporary locals. |
| 7114 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr); | 7110 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr); |
| 7115 right_expr = | 7111 right_expr = |
| 7116 ExpandAssignableOp(assignment_pos, assignment_op, expr, right_expr); | 7112 ExpandAssignableOp(assignment_pos, assignment_op, expr, right_expr); |
| 7117 AstNode* assign_expr = CreateAssignmentNode(expr, right_expr); | 7113 AstNode* assign_expr = CreateAssignmentNode(expr, right_expr); |
| 7118 if (assign_expr == NULL) { | 7114 if (assign_expr == NULL) { |
| 7119 ErrorMsg(assignment_pos, | 7115 ErrorMsg(assignment_pos, |
| 7120 "left hand side of '%s' is not assignable", | 7116 "left hand side of '%s' is not assignable", |
| 7121 Token::Str(assignment_op)); | 7117 Token::Str(assignment_op)); |
| 7122 } | 7118 } |
| 7123 let_expr->set_body(assign_expr); | 7119 let_expr->AddNode(assign_expr); |
| 7124 expr = let_expr; | 7120 expr = let_expr; |
| 7125 } else { | 7121 } else { |
| 7126 right_expr = | 7122 right_expr = |
| 7127 ExpandAssignableOp(assignment_pos, assignment_op, expr, right_expr); | 7123 ExpandAssignableOp(assignment_pos, assignment_op, expr, right_expr); |
| 7128 AstNode* assign_expr = CreateAssignmentNode(expr, right_expr); | 7124 AstNode* assign_expr = CreateAssignmentNode(expr, right_expr); |
| 7129 if (assign_expr == NULL) { | 7125 if (assign_expr == NULL) { |
| 7130 ErrorMsg(assignment_pos, | 7126 ErrorMsg(assignment_pos, |
| 7131 "left hand side of '%s' is not assignable", | 7127 "left hand side of '%s' is not assignable", |
| 7132 Token::Str(assignment_op)); | 7128 Token::Str(assignment_op)); |
| 7133 } | 7129 } |
| 7134 expr = assign_expr; | 7130 expr = assign_expr; |
| 7135 } | 7131 } |
| 7136 } | 7132 } |
| 7137 cascade->Add(expr); | 7133 cascade->AddNode(expr); |
| 7138 } | 7134 } |
| 7139 // The result is a pair of the (side effects of the) cascade sequence | 7135 // The result is an expression with the (side effects of the) cascade |
| 7140 // followed by the (value of the) receiver temp variable load. | 7136 // sequence followed by the (value of the) receiver temp variable load. |
| 7141 CommaNode* body = new CommaNode( | 7137 cascade->AddNode(new LoadLocalNode(cascade_pos, cascade_receiver_var)); |
| 7142 cascade_pos, | 7138 return cascade; |
| 7143 cascade, | |
| 7144 new LoadLocalNode(cascade_pos, cascade_receiver_var)); | |
| 7145 result->set_body(body); | |
| 7146 return result; | |
| 7147 } | 7139 } |
| 7148 | 7140 |
| 7149 | 7141 |
| 7150 AstNode* Parser::ParseExpr(bool require_compiletime_const, | 7142 AstNode* Parser::ParseExpr(bool require_compiletime_const, |
| 7151 bool consume_cascades) { | 7143 bool consume_cascades) { |
| 7152 TRACE_PARSER("ParseExpr"); | 7144 TRACE_PARSER("ParseExpr"); |
| 7153 const intptr_t expr_pos = TokenPos(); | 7145 const intptr_t expr_pos = TokenPos(); |
| 7154 | 7146 |
| 7155 if (CurrentToken() == Token::kTHROW) { | 7147 if (CurrentToken() == Token::kTHROW) { |
| 7156 ConsumeToken(); | 7148 ConsumeToken(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 7181 // Compound assignment: store inputs with side effects into temp. locals. | 7173 // Compound assignment: store inputs with side effects into temp. locals. |
| 7182 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr); | 7174 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr); |
| 7183 AstNode* assigned_value = | 7175 AstNode* assigned_value = |
| 7184 ExpandAssignableOp(assignment_pos, assignment_op, expr, right_expr); | 7176 ExpandAssignableOp(assignment_pos, assignment_op, expr, right_expr); |
| 7185 AstNode* assign_expr = CreateAssignmentNode(expr, assigned_value); | 7177 AstNode* assign_expr = CreateAssignmentNode(expr, assigned_value); |
| 7186 if (assign_expr == NULL) { | 7178 if (assign_expr == NULL) { |
| 7187 ErrorMsg(assignment_pos, | 7179 ErrorMsg(assignment_pos, |
| 7188 "left hand side of '%s' is not assignable", | 7180 "left hand side of '%s' is not assignable", |
| 7189 Token::Str(assignment_op)); | 7181 Token::Str(assignment_op)); |
| 7190 } | 7182 } |
| 7191 let_expr->set_body(assign_expr); | 7183 let_expr->AddNode(assign_expr); |
| 7192 return let_expr; | 7184 return let_expr; |
| 7193 } else { | 7185 } else { |
| 7194 AstNode* assigned_value = | 7186 AstNode* assigned_value = |
| 7195 ExpandAssignableOp(assignment_pos, assignment_op, expr, right_expr); | 7187 ExpandAssignableOp(assignment_pos, assignment_op, expr, right_expr); |
| 7196 AstNode* assign_expr = CreateAssignmentNode(expr, assigned_value); | 7188 AstNode* assign_expr = CreateAssignmentNode(expr, assigned_value); |
| 7197 if (assign_expr == NULL) { | 7189 if (assign_expr == NULL) { |
| 7198 ErrorMsg(assignment_pos, | 7190 ErrorMsg(assignment_pos, |
| 7199 "left hand side of '%s' is not assignable", | 7191 "left hand side of '%s' is not assignable", |
| 7200 Token::Str(assignment_op)); | 7192 Token::Str(assignment_op)); |
| 7201 } | 7193 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7261 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr); | 7253 LetNode* let_expr = PrepareCompoundAssignmentNodes(&expr); |
| 7262 Token::Kind binary_op = | 7254 Token::Kind binary_op = |
| 7263 (incr_op == Token::kINCR) ? Token::kADD : Token::kSUB; | 7255 (incr_op == Token::kINCR) ? Token::kADD : Token::kSUB; |
| 7264 BinaryOpNode* add = new BinaryOpNode( | 7256 BinaryOpNode* add = new BinaryOpNode( |
| 7265 op_pos, | 7257 op_pos, |
| 7266 binary_op, | 7258 binary_op, |
| 7267 expr, | 7259 expr, |
| 7268 new LiteralNode(op_pos, Smi::ZoneHandle(Smi::New(1)))); | 7260 new LiteralNode(op_pos, Smi::ZoneHandle(Smi::New(1)))); |
| 7269 AstNode* store = CreateAssignmentNode(expr, add); | 7261 AstNode* store = CreateAssignmentNode(expr, add); |
| 7270 ASSERT(store != NULL); | 7262 ASSERT(store != NULL); |
| 7271 let_expr->set_body(store); | 7263 let_expr->AddNode(store); |
| 7272 expr = let_expr; | 7264 expr = let_expr; |
| 7273 } else { | 7265 } else { |
| 7274 expr = ParsePostfixExpr(); | 7266 expr = ParsePostfixExpr(); |
| 7275 } | 7267 } |
| 7276 return expr; | 7268 return expr; |
| 7277 } | 7269 } |
| 7278 | 7270 |
| 7279 | 7271 |
| 7280 ArgumentListNode* Parser::ParseActualParameters( | 7272 ArgumentListNode* Parser::ParseActualParameters( |
| 7281 ArgumentListNode* implicit_arguments, | 7273 ArgumentListNode* implicit_arguments, |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7757 (incr_op == Token::kINCR) ? Token::kADD : Token::kSUB; | 7749 (incr_op == Token::kINCR) ? Token::kADD : Token::kSUB; |
| 7758 BinaryOpNode* add = new BinaryOpNode( | 7750 BinaryOpNode* add = new BinaryOpNode( |
| 7759 postfix_expr_pos, | 7751 postfix_expr_pos, |
| 7760 binary_op, | 7752 binary_op, |
| 7761 new LoadLocalNode(postfix_expr_pos, temp), | 7753 new LoadLocalNode(postfix_expr_pos, temp), |
| 7762 new LiteralNode(postfix_expr_pos, Smi::ZoneHandle(Smi::New(1)))); | 7754 new LiteralNode(postfix_expr_pos, Smi::ZoneHandle(Smi::New(1)))); |
| 7763 AstNode* store = CreateAssignmentNode(postfix_expr, add); | 7755 AstNode* store = CreateAssignmentNode(postfix_expr, add); |
| 7764 ASSERT(store != NULL); | 7756 ASSERT(store != NULL); |
| 7765 // The result is a pair of the (side effects of the) store followed by | 7757 // The result is a pair of the (side effects of the) store followed by |
| 7766 // the (value of the) initial value temp variable load. | 7758 // the (value of the) initial value temp variable load. |
| 7767 let_expr->set_body(new CommaNode( | 7759 let_expr->AddNode(store); |
| 7768 postfix_expr_pos, | 7760 let_expr->AddNode(new LoadLocalNode(postfix_expr_pos, temp)); |
| 7769 store, | |
| 7770 new LoadLocalNode(postfix_expr_pos, temp))); | |
| 7771 return let_expr; | 7761 return let_expr; |
| 7772 } | 7762 } |
| 7773 return postfix_expr; | 7763 return postfix_expr; |
| 7774 } | 7764 } |
| 7775 | 7765 |
| 7776 | 7766 |
| 7777 // Resolve the given type and its type arguments from the given scope class | 7767 // Resolve the given type and its type arguments from the given scope class |
| 7778 // according to the given type finalization mode. | 7768 // according to the given type finalization mode. |
| 7779 // If the given scope class is null, use the current library, but do not try to | 7769 // If the given scope class is null, use the current library, but do not try to |
| 7780 // resolve type parameters. | 7770 // resolve type parameters. |
| (...skipping 2200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9981 void Parser::SkipQualIdent() { | 9971 void Parser::SkipQualIdent() { |
| 9982 ASSERT(IsIdentifier()); | 9972 ASSERT(IsIdentifier()); |
| 9983 ConsumeToken(); | 9973 ConsumeToken(); |
| 9984 if (CurrentToken() == Token::kPERIOD) { | 9974 if (CurrentToken() == Token::kPERIOD) { |
| 9985 ConsumeToken(); // Consume the kPERIOD token. | 9975 ConsumeToken(); // Consume the kPERIOD token. |
| 9986 ExpectIdentifier("identifier expected after '.'"); | 9976 ExpectIdentifier("identifier expected after '.'"); |
| 9987 } | 9977 } |
| 9988 } | 9978 } |
| 9989 | 9979 |
| 9990 } // namespace dart | 9980 } // namespace dart |
| OLD | NEW |