| 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 "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/ast_transformer.h" | 9 #include "vm/ast_transformer.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1633 Isolate::Current()->object_store()->function_impl_type()).type_class()); | 1633 Isolate::Current()->object_store()->function_impl_type()).type_class()); |
| 1634 | 1634 |
| 1635 const Class& owner = Class::Handle(Z, func.Owner()); | 1635 const Class& owner = Class::Handle(Z, func.Owner()); |
| 1636 ASSERT(!owner.IsNull()); | 1636 ASSERT(!owner.IsNull()); |
| 1637 const String& name = String::Handle(Z, func.name()); | 1637 const String& name = String::Handle(Z, func.name()); |
| 1638 AstNode* function_object = NULL; | 1638 AstNode* function_object = NULL; |
| 1639 if (owner.raw() == function_impl.raw() && name.Equals(Symbols::Call())) { | 1639 if (owner.raw() == function_impl.raw() && name.Equals(Symbols::Call())) { |
| 1640 function_object = receiver; | 1640 function_object = receiver; |
| 1641 } else { | 1641 } else { |
| 1642 const String& getter_name = String::ZoneHandle(Z, | 1642 const String& getter_name = String::ZoneHandle(Z, |
| 1643 Symbols::New(String::Handle(Z, Field::GetterName(name)))); | 1643 Symbols::New(String::Handle(Z, Field::GetterSymbol(name)))); |
| 1644 function_object = new(Z) InstanceCallNode( | 1644 function_object = new(Z) InstanceCallNode( |
| 1645 token_pos, receiver, getter_name, no_args); | 1645 token_pos, receiver, getter_name, no_args); |
| 1646 } | 1646 } |
| 1647 | 1647 |
| 1648 // Pass arguments 1..n to the closure call. | 1648 // Pass arguments 1..n to the closure call. |
| 1649 ArgumentListNode* args = new(Z) ArgumentListNode(token_pos); | 1649 ArgumentListNode* args = new(Z) ArgumentListNode(token_pos); |
| 1650 const Array& names = Array::Handle( | 1650 const Array& names = Array::Handle( |
| 1651 Z, Array::New(desc.NamedCount(), Heap::kOld)); | 1651 Z, Array::New(desc.NamedCount(), Heap::kOld)); |
| 1652 // Positional parameters. | 1652 // Positional parameters. |
| 1653 intptr_t i = 1; | 1653 intptr_t i = 1; |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2323 intptr_t field_pos) { | 2323 intptr_t field_pos) { |
| 2324 TRACE_PARSER("ParseSuperFieldAccess"); | 2324 TRACE_PARSER("ParseSuperFieldAccess"); |
| 2325 const Class& super_class = Class::ZoneHandle(Z, current_class().SuperClass()); | 2325 const Class& super_class = Class::ZoneHandle(Z, current_class().SuperClass()); |
| 2326 if (super_class.IsNull()) { | 2326 if (super_class.IsNull()) { |
| 2327 ReportError("class '%s' does not have a superclass", | 2327 ReportError("class '%s' does not have a superclass", |
| 2328 String::Handle(Z, current_class().Name()).ToCString()); | 2328 String::Handle(Z, current_class().Name()).ToCString()); |
| 2329 } | 2329 } |
| 2330 AstNode* implicit_argument = LoadReceiver(field_pos); | 2330 AstNode* implicit_argument = LoadReceiver(field_pos); |
| 2331 | 2331 |
| 2332 const String& getter_name = | 2332 const String& getter_name = |
| 2333 String::ZoneHandle(Z, Field::GetterName(field_name)); | 2333 String::ZoneHandle(Z, Field::LookupGetterSymbol(field_name)); |
| 2334 const Function& super_getter = Function::ZoneHandle(Z, | 2334 Function& super_getter = Function::ZoneHandle(Z); |
| 2335 Resolver::ResolveDynamicAnyArgs(super_class, getter_name)); | 2335 if (!getter_name.IsNull()) { |
| 2336 super_getter = Resolver::ResolveDynamicAnyArgs(super_class, getter_name); |
| 2337 } |
| 2336 if (super_getter.IsNull()) { | 2338 if (super_getter.IsNull()) { |
| 2337 const String& setter_name = | 2339 const String& setter_name = |
| 2338 String::ZoneHandle(Z, Field::SetterName(field_name)); | 2340 String::ZoneHandle(Z, Field::LookupSetterSymbol(field_name)); |
| 2339 const Function& super_setter = Function::ZoneHandle(Z, | 2341 Function& super_setter = Function::ZoneHandle(Z); |
| 2340 Resolver::ResolveDynamicAnyArgs(super_class, setter_name)); | 2342 if (!setter_name.IsNull()) { |
| 2343 super_setter = Resolver::ResolveDynamicAnyArgs(super_class, setter_name); |
| 2344 } |
| 2341 if (super_setter.IsNull()) { | 2345 if (super_setter.IsNull()) { |
| 2342 // Check if this is an access to an implicit closure using 'super'. | 2346 // Check if this is an access to an implicit closure using 'super'. |
| 2343 // If a function exists of the specified field_name then try | 2347 // If a function exists of the specified field_name then try |
| 2344 // accessing it as a getter, at runtime we will handle this by | 2348 // accessing it as a getter, at runtime we will handle this by |
| 2345 // creating an implicit closure of the function and returning it. | 2349 // creating an implicit closure of the function and returning it. |
| 2346 const Function& super_function = Function::ZoneHandle(Z, | 2350 const Function& super_function = Function::ZoneHandle(Z, |
| 2347 Resolver::ResolveDynamicAnyArgs(super_class, field_name)); | 2351 Resolver::ResolveDynamicAnyArgs(super_class, field_name)); |
| 2348 if (!super_function.IsNull()) { | 2352 if (!super_function.IsNull()) { |
| 2349 // In case CreateAssignmentNode is called later on this | 2353 // In case CreateAssignmentNode is called later on this |
| 2350 // CreateImplicitClosureNode, it will be replaced by a StaticSetterNode. | 2354 // CreateImplicitClosureNode, it will be replaced by a StaticSetterNode. |
| (...skipping 3989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6340 AddFinallyClauseToNode(true, node_to_inline, node); | 6344 AddFinallyClauseToNode(true, node_to_inline, node); |
| 6341 node_index++; | 6345 node_index++; |
| 6342 } | 6346 } |
| 6343 } while (finally_clause == NULL); | 6347 } while (finally_clause == NULL); |
| 6344 | 6348 |
| 6345 if (try_stack_ != NULL) { | 6349 if (try_stack_ != NULL) { |
| 6346 try_stack_->exit_finally(); | 6350 try_stack_->exit_finally(); |
| 6347 } | 6351 } |
| 6348 | 6352 |
| 6349 const GrowableObjectArray& handler_types = | 6353 const GrowableObjectArray& handler_types = |
| 6350 GrowableObjectArray::Handle(Z, GrowableObjectArray::New()); | 6354 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); |
| 6351 handler_types.Add(dynamic_type); // Catch block handles all exceptions. | 6355 handler_types.Add(dynamic_type); // Catch block handles all exceptions. |
| 6352 | 6356 |
| 6353 CatchClauseNode* catch_clause = new(Z) CatchClauseNode( | 6357 CatchClauseNode* catch_clause = new(Z) CatchClauseNode( |
| 6354 Scanner::kNoSourcePos, | 6358 Scanner::kNoSourcePos, |
| 6355 catch_handler_list, | 6359 catch_handler_list, |
| 6356 Array::ZoneHandle(Z, Array::MakeArray(handler_types)), | 6360 Array::ZoneHandle(Z, Array::MakeArray(handler_types)), |
| 6357 context_var, | 6361 context_var, |
| 6358 exception_var, | 6362 exception_var, |
| 6359 stack_trace_var, | 6363 stack_trace_var, |
| 6360 saved_exception_var, | 6364 saved_exception_var, |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6457 completer_args)); | 6461 completer_args)); |
| 6458 ReturnNode* return_node = new (Z) ReturnNode(Scanner::kNoSourcePos); | 6462 ReturnNode* return_node = new (Z) ReturnNode(Scanner::kNoSourcePos); |
| 6459 // Behavior like a continuation return, i.e,. don't call a completer. | 6463 // Behavior like a continuation return, i.e,. don't call a completer. |
| 6460 return_node->set_return_type(ReturnNode::kContinuation); | 6464 return_node->set_return_type(ReturnNode::kContinuation); |
| 6461 current_block_->statements->Add(return_node); | 6465 current_block_->statements->Add(return_node); |
| 6462 AstNode* catch_block = CloseBlock(); | 6466 AstNode* catch_block = CloseBlock(); |
| 6463 current_block_->statements->Add(catch_block); | 6467 current_block_->statements->Add(catch_block); |
| 6464 SequenceNode* catch_handler_list = CloseBlock(); | 6468 SequenceNode* catch_handler_list = CloseBlock(); |
| 6465 | 6469 |
| 6466 const GrowableObjectArray& handler_types = | 6470 const GrowableObjectArray& handler_types = |
| 6467 GrowableObjectArray::Handle(Z, GrowableObjectArray::New()); | 6471 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); |
| 6468 handler_types.SetLength(0); | 6472 handler_types.SetLength(0); |
| 6469 handler_types.Add(*exception_param.type); | 6473 handler_types.Add(*exception_param.type); |
| 6470 | 6474 |
| 6471 TryStack* try_statement = PopTry(); | 6475 TryStack* try_statement = PopTry(); |
| 6472 const intptr_t try_index = try_statement->try_index(); | 6476 const intptr_t try_index = try_statement->try_index(); |
| 6473 | 6477 |
| 6474 CatchClauseNode* catch_clause = new (Z) CatchClauseNode( | 6478 CatchClauseNode* catch_clause = new (Z) CatchClauseNode( |
| 6475 Scanner::kNoSourcePos, | 6479 Scanner::kNoSourcePos, |
| 6476 catch_handler_list, | 6480 catch_handler_list, |
| 6477 Array::ZoneHandle(Z, Array::MakeArray(handler_types)), | 6481 Array::ZoneHandle(Z, Array::MakeArray(handler_types)), |
| (...skipping 3185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9663 | 9667 |
| 9664 if ((CurrentToken() != Token::kCATCH) && !IsSymbol(Symbols::On()) && | 9668 if ((CurrentToken() != Token::kCATCH) && !IsSymbol(Symbols::On()) && |
| 9665 (CurrentToken() != Token::kFINALLY)) { | 9669 (CurrentToken() != Token::kFINALLY)) { |
| 9666 ReportError("catch or finally clause expected"); | 9670 ReportError("catch or finally clause expected"); |
| 9667 } | 9671 } |
| 9668 | 9672 |
| 9669 // Now parse the 'catch' blocks if any. | 9673 // Now parse the 'catch' blocks if any. |
| 9670 try_stack_->enter_catch(); | 9674 try_stack_->enter_catch(); |
| 9671 const intptr_t handler_pos = TokenPos(); | 9675 const intptr_t handler_pos = TokenPos(); |
| 9672 const GrowableObjectArray& handler_types = | 9676 const GrowableObjectArray& handler_types = |
| 9673 GrowableObjectArray::Handle(Z, GrowableObjectArray::New()); | 9677 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); |
| 9674 bool needs_stack_trace = false; | 9678 bool needs_stack_trace = false; |
| 9675 SequenceNode* catch_handler_list = | 9679 SequenceNode* catch_handler_list = |
| 9676 ParseCatchClauses(handler_pos, | 9680 ParseCatchClauses(handler_pos, |
| 9677 is_async, | 9681 is_async, |
| 9678 exception_var, | 9682 exception_var, |
| 9679 stack_trace_var, | 9683 stack_trace_var, |
| 9680 is_async ? saved_exception_var : exception_var, | 9684 is_async ? saved_exception_var : exception_var, |
| 9681 is_async ? saved_stack_trace_var : stack_trace_var, | 9685 is_async ? saved_stack_trace_var : stack_trace_var, |
| 9682 handler_types, | 9686 handler_types, |
| 9683 &needs_stack_trace); | 9687 &needs_stack_trace); |
| (...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11154 AstNode* initializing_getter = RunStaticFieldInitializer(field, ident_pos); | 11158 AstNode* initializing_getter = RunStaticFieldInitializer(field, ident_pos); |
| 11155 if (initializing_getter != NULL) { | 11159 if (initializing_getter != NULL) { |
| 11156 // The field is not yet initialized and could not be initialized at compile | 11160 // The field is not yet initialized and could not be initialized at compile |
| 11157 // time. The getter will initialize the field. | 11161 // time. The getter will initialize the field. |
| 11158 return initializing_getter; | 11162 return initializing_getter; |
| 11159 } | 11163 } |
| 11160 // The field is initialized. | 11164 // The field is initialized. |
| 11161 ASSERT(field.is_static()); | 11165 ASSERT(field.is_static()); |
| 11162 const Class& field_owner = Class::ZoneHandle(Z, field.owner()); | 11166 const Class& field_owner = Class::ZoneHandle(Z, field.owner()); |
| 11163 const String& field_name = String::ZoneHandle(Z, field.name()); | 11167 const String& field_name = String::ZoneHandle(Z, field.name()); |
| 11164 const String& getter_name = String::Handle(Z, Field::GetterName(field_name)); | 11168 const String& getter_name = |
| 11169 String::Handle(Z, Field::GetterSymbol(field_name)); |
| 11165 const Function& getter = Function::Handle(Z, | 11170 const Function& getter = Function::Handle(Z, |
| 11166 field_owner.LookupStaticFunction(getter_name)); | 11171 field_owner.LookupStaticFunction(getter_name)); |
| 11167 // Never load field directly if there is a getter (deterministic AST). | 11172 // Never load field directly if there is a getter (deterministic AST). |
| 11168 if (getter.IsNull() || field.is_const()) { | 11173 if (getter.IsNull() || field.is_const()) { |
| 11169 return new(Z) LoadStaticFieldNode( | 11174 return new(Z) LoadStaticFieldNode( |
| 11170 ident_pos, Field::ZoneHandle(Z, field.raw())); | 11175 ident_pos, Field::ZoneHandle(Z, field.raw())); |
| 11171 } else { | 11176 } else { |
| 11172 ASSERT(getter.kind() == RawFunction::kImplicitStaticFinalGetter); | 11177 ASSERT(getter.kind() == RawFunction::kImplicitStaticFinalGetter); |
| 11173 return new(Z) StaticGetterNode(ident_pos, | 11178 return new(Z) StaticGetterNode(ident_pos, |
| 11174 NULL, // Receiver. | 11179 NULL, // Receiver. |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11549 | 11554 |
| 11550 String& extractor_name = String::ZoneHandle(Z); | 11555 String& extractor_name = String::ZoneHandle(Z); |
| 11551 if (IsIdentifier()) { | 11556 if (IsIdentifier()) { |
| 11552 extractor_name = CurrentLiteral()->raw(); | 11557 extractor_name = CurrentLiteral()->raw(); |
| 11553 ConsumeToken(); | 11558 ConsumeToken(); |
| 11554 if (CurrentToken() == Token::kASSIGN) { | 11559 if (CurrentToken() == Token::kASSIGN) { |
| 11555 ConsumeToken(); | 11560 ConsumeToken(); |
| 11556 is_setter_name = true; | 11561 is_setter_name = true; |
| 11557 } | 11562 } |
| 11558 } else if (Token::CanBeOverloaded(CurrentToken())) { | 11563 } else if (Token::CanBeOverloaded(CurrentToken())) { |
| 11559 extractor_name = String::New(Token::Str(CurrentToken())); | 11564 extractor_name = Symbols::New(Token::Str(CurrentToken())); |
| 11560 ConsumeToken(); | 11565 ConsumeToken(); |
| 11561 } else { | 11566 } else { |
| 11562 ReportError("identifier or operator expected"); | 11567 ReportError("identifier or operator expected"); |
| 11563 } | 11568 } |
| 11564 | 11569 |
| 11565 if (primary->IsPrimaryNode() && primary->AsPrimaryNode()->IsSuper()) { | 11570 if (primary->IsPrimaryNode() && primary->AsPrimaryNode()->IsSuper()) { |
| 11566 // TODO(hausner): implement super#m | 11571 // TODO(hausner): implement super#m |
| 11567 ReportError("closurization of super method not yet supported"); | 11572 ReportError("closurization of super method not yet supported"); |
| 11568 } | 11573 } |
| 11569 | 11574 |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11959 | 11964 |
| 11960 | 11965 |
| 11961 // If the field is already initialized, return no ast (NULL). | 11966 // If the field is already initialized, return no ast (NULL). |
| 11962 // Otherwise, if the field is constant, initialize the field and return no ast. | 11967 // Otherwise, if the field is constant, initialize the field and return no ast. |
| 11963 // If the field is not initialized and not const, return the ast for the getter. | 11968 // If the field is not initialized and not const, return the ast for the getter. |
| 11964 StaticGetterNode* Parser::RunStaticFieldInitializer(const Field& field, | 11969 StaticGetterNode* Parser::RunStaticFieldInitializer(const Field& field, |
| 11965 intptr_t field_ref_pos) { | 11970 intptr_t field_ref_pos) { |
| 11966 ASSERT(field.is_static()); | 11971 ASSERT(field.is_static()); |
| 11967 const Class& field_owner = Class::ZoneHandle(Z, field.owner()); | 11972 const Class& field_owner = Class::ZoneHandle(Z, field.owner()); |
| 11968 const String& field_name = String::ZoneHandle(Z, field.name()); | 11973 const String& field_name = String::ZoneHandle(Z, field.name()); |
| 11969 const String& getter_name = String::Handle(Z, Field::GetterName(field_name)); | 11974 const String& getter_name = |
| 11975 String::Handle(Z, Field::GetterSymbol(field_name)); |
| 11970 const Function& getter = Function::Handle(Z, | 11976 const Function& getter = Function::Handle(Z, |
| 11971 field_owner.LookupStaticFunction(getter_name)); | 11977 field_owner.LookupStaticFunction(getter_name)); |
| 11972 const Instance& value = Instance::Handle(Z, field.value()); | 11978 const Instance& value = Instance::Handle(Z, field.value()); |
| 11973 if (value.raw() == Object::transition_sentinel().raw()) { | 11979 if (value.raw() == Object::transition_sentinel().raw()) { |
| 11974 if (field.is_const()) { | 11980 if (field.is_const()) { |
| 11975 ReportError("circular dependency while initializing static field '%s'", | 11981 ReportError("circular dependency while initializing static field '%s'", |
| 11976 field_name.ToCString()); | 11982 field_name.ToCString()); |
| 11977 } else { | 11983 } else { |
| 11978 // The implicit static getter will throw the exception if necessary. | 11984 // The implicit static getter will throw the exception if necessary. |
| 11979 return new(Z) StaticGetterNode( | 11985 return new(Z) StaticGetterNode( |
| (...skipping 2283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14263 void Parser::SkipQualIdent() { | 14269 void Parser::SkipQualIdent() { |
| 14264 ASSERT(IsIdentifier()); | 14270 ASSERT(IsIdentifier()); |
| 14265 ConsumeToken(); | 14271 ConsumeToken(); |
| 14266 if (CurrentToken() == Token::kPERIOD) { | 14272 if (CurrentToken() == Token::kPERIOD) { |
| 14267 ConsumeToken(); // Consume the kPERIOD token. | 14273 ConsumeToken(); // Consume the kPERIOD token. |
| 14268 ExpectIdentifier("identifier expected after '.'"); | 14274 ExpectIdentifier("identifier expected after '.'"); |
| 14269 } | 14275 } |
| 14270 } | 14276 } |
| 14271 | 14277 |
| 14272 } // namespace dart | 14278 } // namespace dart |
| OLD | NEW |