| 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 #include "vm/flags.h" | 6 #include "vm/flags.h" |
| 7 | 7 |
| 8 #ifndef DART_PRECOMPILED_RUNTIME | 8 #ifndef DART_PRECOMPILED_RUNTIME |
| 9 | 9 |
| 10 #include "lib/invocation_mirror.h" | 10 #include "lib/invocation_mirror.h" |
| (...skipping 1539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1550 return CloseBlock(); | 1550 return CloseBlock(); |
| 1551 } | 1551 } |
| 1552 | 1552 |
| 1553 | 1553 |
| 1554 SequenceNode* Parser::ParseImplicitClosure(const Function& func) { | 1554 SequenceNode* Parser::ParseImplicitClosure(const Function& func) { |
| 1555 TRACE_PARSER("ParseImplicitClosure"); | 1555 TRACE_PARSER("ParseImplicitClosure"); |
| 1556 TokenPosition token_pos = func.token_pos(); | 1556 TokenPosition token_pos = func.token_pos(); |
| 1557 | 1557 |
| 1558 OpenFunctionBlock(func); | 1558 OpenFunctionBlock(func); |
| 1559 | 1559 |
| 1560 const Function& parent = Function::Handle(func.parent_function()); |
| 1561 intptr_t type_args_len = 0; // Length of type args vector passed to parent. |
| 1562 LocalVariable* type_args_var = NULL; |
| 1560 if (FLAG_reify_generic_functions) { | 1563 if (FLAG_reify_generic_functions) { |
| 1561 // The parent function of an implicit closure is the original function, i.e. | 1564 // The parent function of an implicit closure is the original function, i.e. |
| 1562 // non-closurized. It is not an enclosing function in the usual sense of a | 1565 // non-closurized. It is not an enclosing function in the usual sense of a |
| 1563 // parent function. Do not set parent_type_arguments() in parsed_function_. | 1566 // parent function. Do not set parent_type_arguments() in parsed_function_. |
| 1564 ASSERT(func.IsGeneric() == func.HasGenericParent()); | 1567 ASSERT(func.IsGeneric() == parent.IsGeneric()); |
| 1565 | 1568 |
| 1566 if (func.IsGeneric()) { | 1569 if (func.IsGeneric()) { |
| 1570 type_args_len = func.NumTypeParameters(); |
| 1567 // Insert function type arguments variable to scope. | 1571 // Insert function type arguments variable to scope. |
| 1568 LocalVariable* function_type_arguments = new (Z) LocalVariable( | 1572 type_args_var = new (Z) LocalVariable( |
| 1569 TokenPosition::kNoSource, TokenPosition::kNoSource, | 1573 TokenPosition::kNoSource, TokenPosition::kNoSource, |
| 1570 Symbols::FunctionTypeArgumentsVar(), Object::dynamic_type()); | 1574 Symbols::FunctionTypeArgumentsVar(), Object::dynamic_type()); |
| 1571 current_block_->scope->AddVariable(function_type_arguments); | 1575 current_block_->scope->AddVariable(type_args_var); |
| 1572 ASSERT(FunctionLevel() == 0); | 1576 ASSERT(FunctionLevel() == 0); |
| 1573 parsed_function_->set_function_type_arguments(function_type_arguments); | 1577 parsed_function_->set_function_type_arguments(type_args_var); |
| 1574 } | 1578 } |
| 1575 } | 1579 } |
| 1576 | 1580 |
| 1577 // TODO(regis): Pass the function type arguments if func is generic. | |
| 1578 ParamList params; | 1581 ParamList params; |
| 1579 params.AddFinalParameter(token_pos, &Symbols::ClosureParameter(), | 1582 params.AddFinalParameter(token_pos, &Symbols::ClosureParameter(), |
| 1580 &Object::dynamic_type()); | 1583 &Object::dynamic_type()); |
| 1581 | 1584 |
| 1582 const Function& parent = Function::Handle(func.parent_function()); | |
| 1583 if (parent.IsImplicitSetterFunction()) { | 1585 if (parent.IsImplicitSetterFunction()) { |
| 1584 const TokenPosition ident_pos = func.token_pos(); | 1586 const TokenPosition ident_pos = func.token_pos(); |
| 1585 ASSERT(IsIdentifier()); | 1587 ASSERT(IsIdentifier()); |
| 1586 params.AddFinalParameter(ident_pos, &Symbols::Value(), | 1588 params.AddFinalParameter(ident_pos, &Symbols::Value(), |
| 1587 &Object::dynamic_type()); | 1589 &Object::dynamic_type()); |
| 1588 ASSERT(func.num_fixed_parameters() == 2); // closure, value. | 1590 ASSERT(func.num_fixed_parameters() == 2); // closure, value. |
| 1589 } else if (!parent.IsGetterFunction() && !parent.IsImplicitGetterFunction()) { | 1591 } else if (!parent.IsGetterFunction() && !parent.IsImplicitGetterFunction()) { |
| 1590 // NOTE: For the `kernel -> flowgraph` we don't use the parser. | 1592 // NOTE: For the `kernel -> flowgraph` we don't use the parser. |
| 1591 if (parent.kernel_function() == NULL) { | 1593 if (parent.kernel_function() == NULL) { |
| 1592 SkipFunctionPreamble(); | 1594 SkipFunctionPreamble(); |
| 1593 const bool use_function_type_syntax = false; | 1595 const bool use_function_type_syntax = false; |
| 1594 const bool allow_explicit_default_values = true; | 1596 const bool allow_explicit_default_values = true; |
| 1595 const bool evaluate_metadata = false; | 1597 const bool evaluate_metadata = false; |
| 1596 ParseFormalParameterList(use_function_type_syntax, | 1598 ParseFormalParameterList(use_function_type_syntax, |
| 1597 allow_explicit_default_values, evaluate_metadata, | 1599 allow_explicit_default_values, evaluate_metadata, |
| 1598 ¶ms); | 1600 ¶ms); |
| 1599 FinalizeFormalParameterTypes(¶ms); | 1601 FinalizeFormalParameterTypes(¶ms); |
| 1600 SetupDefaultsForOptionalParams(params); | 1602 SetupDefaultsForOptionalParams(params); |
| 1601 } | 1603 } |
| 1602 } | 1604 } |
| 1603 | 1605 |
| 1604 // Populate function scope with the formal parameters. | 1606 // Populate function scope with the formal parameters. |
| 1605 LocalScope* scope = current_block_->scope; | 1607 LocalScope* scope = current_block_->scope; |
| 1606 AddFormalParamsToScope(¶ms, scope); | 1608 AddFormalParamsToScope(¶ms, scope); |
| 1607 | 1609 |
| 1608 ArgumentListNode* func_args = new ArgumentListNode(token_pos); | 1610 ArgumentListNode* func_args = |
| 1611 new ArgumentListNode(token_pos, type_args_var, type_args_len); |
| 1609 if (!func.is_static()) { | 1612 if (!func.is_static()) { |
| 1610 func_args->Add(LoadReceiver(token_pos)); | 1613 func_args->Add(LoadReceiver(token_pos)); |
| 1611 } | 1614 } |
| 1612 // Skip implicit parameter at 0. | 1615 // Skip implicit parameter at 0. |
| 1613 for (intptr_t i = 1; i < func.NumParameters(); ++i) { | 1616 for (intptr_t i = 1; i < func.NumParameters(); ++i) { |
| 1614 func_args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); | 1617 func_args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); |
| 1615 } | 1618 } |
| 1616 | 1619 |
| 1617 if (func.HasOptionalNamedParameters()) { | 1620 if (func.HasOptionalNamedParameters()) { |
| 1618 // TODO(srdjan): Must allocate array in old space, since it | 1621 // TODO(srdjan): Must allocate array in old space, since it |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1647 call = new StaticCallNode(token_pos, target, func_args); | 1650 call = new StaticCallNode(token_pos, target, func_args); |
| 1648 } else if (!parent.is_static()) { | 1651 } else if (!parent.is_static()) { |
| 1649 ASSERT(Isolate::Current()->HasAttemptedReload()); | 1652 ASSERT(Isolate::Current()->HasAttemptedReload()); |
| 1650 // If a subsequent reload reintroduces the target in the middle of the | 1653 // If a subsequent reload reintroduces the target in the middle of the |
| 1651 // Invocation object being constructed, we won't be able to successfully | 1654 // Invocation object being constructed, we won't be able to successfully |
| 1652 // deopt because the generated AST will change. | 1655 // deopt because the generated AST will change. |
| 1653 func.SetIsOptimizable(false); | 1656 func.SetIsOptimizable(false); |
| 1654 | 1657 |
| 1655 ArgumentListNode* arguments = BuildNoSuchMethodArguments( | 1658 ArgumentListNode* arguments = BuildNoSuchMethodArguments( |
| 1656 token_pos, func_name, *func_args, NULL, false); | 1659 token_pos, func_name, *func_args, NULL, false); |
| 1660 const intptr_t kTypeArgsLen = 0; |
| 1657 const intptr_t kNumArguments = 2; // Receiver, InvocationMirror. | 1661 const intptr_t kNumArguments = 2; // Receiver, InvocationMirror. |
| 1658 ArgumentsDescriptor args_desc( | 1662 ArgumentsDescriptor args_desc(Array::Handle( |
| 1659 Array::Handle(Z, ArgumentsDescriptor::New(kNumArguments))); | 1663 Z, ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments))); |
| 1660 Function& no_such_method = | 1664 Function& no_such_method = |
| 1661 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass( | 1665 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass( |
| 1662 owner, Symbols::NoSuchMethod(), args_desc)); | 1666 owner, Symbols::NoSuchMethod(), args_desc)); |
| 1663 if (no_such_method.IsNull()) { | 1667 if (no_such_method.IsNull()) { |
| 1664 // If noSuchMethod(i) is not found, call Object:noSuchMethod. | 1668 // If noSuchMethod(i) is not found, call Object:noSuchMethod. |
| 1665 no_such_method ^= Resolver::ResolveDynamicForReceiverClass( | 1669 no_such_method ^= Resolver::ResolveDynamicForReceiverClass( |
| 1666 Class::Handle(Z, I->object_store()->object_class()), | 1670 Class::Handle(Z, I->object_store()->object_class()), |
| 1667 Symbols::NoSuchMethod(), args_desc); | 1671 Symbols::NoSuchMethod(), args_desc); |
| 1668 } | 1672 } |
| 1669 call = new StaticCallNode(token_pos, no_such_method, arguments); | 1673 call = new StaticCallNode(token_pos, no_such_method, arguments); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1790 Array::ZoneHandle(Z, Array::New(desc.NamedCount(), Heap::kOld)); | 1794 Array::ZoneHandle(Z, Array::New(desc.NamedCount(), Heap::kOld)); |
| 1791 for (intptr_t i = 0; i < arg_names.Length(); ++i) { | 1795 for (intptr_t i = 0; i < arg_names.Length(); ++i) { |
| 1792 arg_names.SetAt(i, String::Handle(Z, desc.NameAt(i))); | 1796 arg_names.SetAt(i, String::Handle(Z, desc.NameAt(i))); |
| 1793 } | 1797 } |
| 1794 func_args->set_names(arg_names); | 1798 func_args->set_names(arg_names); |
| 1795 } | 1799 } |
| 1796 | 1800 |
| 1797 const String& func_name = String::ZoneHandle(Z, func.name()); | 1801 const String& func_name = String::ZoneHandle(Z, func.name()); |
| 1798 ArgumentListNode* arguments = | 1802 ArgumentListNode* arguments = |
| 1799 BuildNoSuchMethodArguments(token_pos, func_name, *func_args, NULL, false); | 1803 BuildNoSuchMethodArguments(token_pos, func_name, *func_args, NULL, false); |
| 1804 const intptr_t kTypeArgsLen = 0; |
| 1800 const intptr_t kNumArguments = 2; // Receiver, InvocationMirror. | 1805 const intptr_t kNumArguments = 2; // Receiver, InvocationMirror. |
| 1801 ArgumentsDescriptor args_desc( | 1806 ArgumentsDescriptor args_desc( |
| 1802 Array::Handle(Z, ArgumentsDescriptor::New(kNumArguments))); | 1807 Array::Handle(Z, ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments))); |
| 1803 Function& no_such_method = Function::ZoneHandle( | 1808 Function& no_such_method = Function::ZoneHandle( |
| 1804 Z, | 1809 Z, |
| 1805 Resolver::ResolveDynamicForReceiverClass( | 1810 Resolver::ResolveDynamicForReceiverClass( |
| 1806 Class::Handle(Z, func.Owner()), Symbols::NoSuchMethod(), args_desc)); | 1811 Class::Handle(Z, func.Owner()), Symbols::NoSuchMethod(), args_desc)); |
| 1807 if (no_such_method.IsNull()) { | 1812 if (no_such_method.IsNull()) { |
| 1808 // If noSuchMethod(i) is not found, call Object:noSuchMethod. | 1813 // If noSuchMethod(i) is not found, call Object:noSuchMethod. |
| 1809 no_such_method ^= Resolver::ResolveDynamicForReceiverClass( | 1814 no_such_method ^= Resolver::ResolveDynamicForReceiverClass( |
| 1810 Class::Handle(Z, I->object_store()->object_class()), | 1815 Class::Handle(Z, I->object_store()->object_class()), |
| 1811 Symbols::NoSuchMethod(), args_desc); | 1816 Symbols::NoSuchMethod(), args_desc); |
| 1812 } | 1817 } |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2371 bool resolve_getter, | 2376 bool resolve_getter, |
| 2372 bool* is_no_such_method) { | 2377 bool* is_no_such_method) { |
| 2373 const Class& super_class = Class::Handle(Z, current_class().SuperClass()); | 2378 const Class& super_class = Class::Handle(Z, current_class().SuperClass()); |
| 2374 if (super_class.IsNull()) { | 2379 if (super_class.IsNull()) { |
| 2375 ReportError(token_pos, "class '%s' does not have a superclass", | 2380 ReportError(token_pos, "class '%s' does not have a superclass", |
| 2376 String::Handle(Z, current_class().Name()).ToCString()); | 2381 String::Handle(Z, current_class().Name()).ToCString()); |
| 2377 } | 2382 } |
| 2378 Function& super_func = Function::Handle( | 2383 Function& super_func = Function::Handle( |
| 2379 Z, Resolver::ResolveDynamicAnyArgs(Z, super_class, name)); | 2384 Z, Resolver::ResolveDynamicAnyArgs(Z, super_class, name)); |
| 2380 if (!super_func.IsNull() && | 2385 if (!super_func.IsNull() && |
| 2381 !super_func.AreValidArguments(arguments->length(), arguments->names(), | 2386 !super_func.AreValidArguments(arguments->type_args_len(), |
| 2387 arguments->length(), arguments->names(), |
| 2382 NULL)) { | 2388 NULL)) { |
| 2383 super_func = Function::null(); | 2389 super_func = Function::null(); |
| 2384 } else if (super_func.IsNull() && resolve_getter) { | 2390 } else if (super_func.IsNull() && resolve_getter) { |
| 2385 const String& getter_name = | 2391 const String& getter_name = |
| 2386 String::ZoneHandle(Z, Field::LookupGetterSymbol(name)); | 2392 String::ZoneHandle(Z, Field::LookupGetterSymbol(name)); |
| 2387 if (!getter_name.IsNull()) { | 2393 if (!getter_name.IsNull()) { |
| 2388 super_func = Resolver::ResolveDynamicAnyArgs(Z, super_class, getter_name); | 2394 super_func = Resolver::ResolveDynamicAnyArgs(Z, super_class, getter_name); |
| 2389 ASSERT(super_func.IsNull() || | 2395 ASSERT(super_func.IsNull() || |
| 2390 (super_func.kind() != RawFunction::kImplicitStaticFinalGetter)); | 2396 (super_func.kind() != RawFunction::kImplicitStaticFinalGetter)); |
| 2391 } | 2397 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2409 const LocalVariable* temp_for_last_arg, | 2415 const LocalVariable* temp_for_last_arg, |
| 2410 bool is_super_invocation) { | 2416 bool is_super_invocation) { |
| 2411 const TokenPosition args_pos = function_args.token_pos(); | 2417 const TokenPosition args_pos = function_args.token_pos(); |
| 2412 // Build arguments to the call to the static | 2418 // Build arguments to the call to the static |
| 2413 // InvocationMirror._allocateInvocationMirror method. | 2419 // InvocationMirror._allocateInvocationMirror method. |
| 2414 ArgumentListNode* arguments = new ArgumentListNode(args_pos); | 2420 ArgumentListNode* arguments = new ArgumentListNode(args_pos); |
| 2415 // The first argument is the original function name. | 2421 // The first argument is the original function name. |
| 2416 arguments->Add(new LiteralNode(args_pos, function_name)); | 2422 arguments->Add(new LiteralNode(args_pos, function_name)); |
| 2417 // The second argument is the arguments descriptor of the original function. | 2423 // The second argument is the arguments descriptor of the original function. |
| 2418 const Array& args_descriptor = Array::ZoneHandle( | 2424 const Array& args_descriptor = Array::ZoneHandle( |
| 2419 ArgumentsDescriptor::New(function_args.length(), function_args.names())); | 2425 ArgumentsDescriptor::New(function_args.type_args_len(), |
| 2426 function_args.length(), function_args.names())); |
| 2420 arguments->Add(new LiteralNode(args_pos, args_descriptor)); | 2427 arguments->Add(new LiteralNode(args_pos, args_descriptor)); |
| 2421 // The third argument is an array containing the original function arguments, | 2428 // The third argument is an array containing the original function arguments, |
| 2422 // including the receiver. | 2429 // including the function type arguments and the receiver. |
| 2423 ArrayNode* args_array = | 2430 ArrayNode* args_array = |
| 2424 new ArrayNode(args_pos, Type::ZoneHandle(Type::ArrayType())); | 2431 new ArrayNode(args_pos, Type::ZoneHandle(Type::ArrayType())); |
| 2432 // The type_args_var is only used in the generated body of an implicit closure |
| 2433 // where noSuchMethod should never be called. |
| 2434 ASSERT(function_args.type_args_var() == NULL); |
| 2435 if (!function_args.type_arguments().IsNull()) { |
| 2436 // TODO(regis): Pass the original type arguments to the invocation mirror. |
| 2437 } |
| 2425 for (intptr_t i = 0; i < function_args.length(); i++) { | 2438 for (intptr_t i = 0; i < function_args.length(); i++) { |
| 2426 AstNode* arg = function_args.NodeAt(i); | 2439 AstNode* arg = function_args.NodeAt(i); |
| 2427 if ((temp_for_last_arg != NULL) && (i == function_args.length() - 1)) { | 2440 if ((temp_for_last_arg != NULL) && (i == function_args.length() - 1)) { |
| 2428 LetNode* store_arg = new LetNode(arg->token_pos()); | 2441 LetNode* store_arg = new LetNode(arg->token_pos()); |
| 2429 store_arg->AddNode( | 2442 store_arg->AddNode( |
| 2430 new StoreLocalNode(arg->token_pos(), temp_for_last_arg, arg)); | 2443 new StoreLocalNode(arg->token_pos(), temp_for_last_arg, arg)); |
| 2431 store_arg->AddNode( | 2444 store_arg->AddNode( |
| 2432 new LoadLocalNode(arg->token_pos(), temp_for_last_arg)); | 2445 new LoadLocalNode(arg->token_pos(), temp_for_last_arg)); |
| 2433 args_array->AddElement(store_arg); | 2446 args_array->AddElement(store_arg); |
| 2434 } else { | 2447 } else { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2460 ArgumentListNode* arguments = new ArgumentListNode(args_pos); | 2473 ArgumentListNode* arguments = new ArgumentListNode(args_pos); |
| 2461 arguments->Add(function_args.NodeAt(0)); | 2474 arguments->Add(function_args.NodeAt(0)); |
| 2462 // The second argument is the invocation mirror. | 2475 // The second argument is the invocation mirror. |
| 2463 arguments->Add( | 2476 arguments->Add( |
| 2464 BuildInvocationMirrorAllocation(call_pos, function_name, function_args, | 2477 BuildInvocationMirrorAllocation(call_pos, function_name, function_args, |
| 2465 temp_for_last_arg, is_super_invocation)); | 2478 temp_for_last_arg, is_super_invocation)); |
| 2466 return arguments; | 2479 return arguments; |
| 2467 } | 2480 } |
| 2468 | 2481 |
| 2469 | 2482 |
| 2470 AstNode* Parser::ParseSuperCall(const String& function_name) { | 2483 AstNode* Parser::ParseSuperCall(const String& function_name, |
| 2484 const TypeArguments& func_type_args) { |
| 2471 TRACE_PARSER("ParseSuperCall"); | 2485 TRACE_PARSER("ParseSuperCall"); |
| 2472 ASSERT(CurrentToken() == Token::kLPAREN); | 2486 ASSERT(CurrentToken() == Token::kLPAREN); |
| 2473 const TokenPosition supercall_pos = TokenPos(); | 2487 const TokenPosition supercall_pos = TokenPos(); |
| 2474 | 2488 |
| 2475 // 'this' parameter is the first argument to super call. | 2489 // 'this' parameter is the first argument to super call (after the type args). |
| 2476 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); | 2490 ArgumentListNode* arguments = |
| 2491 new ArgumentListNode(supercall_pos, func_type_args); |
| 2477 AstNode* receiver = LoadReceiver(supercall_pos); | 2492 AstNode* receiver = LoadReceiver(supercall_pos); |
| 2478 arguments->Add(receiver); | 2493 arguments->Add(receiver); |
| 2479 ParseActualParameters(arguments, kAllowConst); | 2494 ParseActualParameters(arguments, Object::null_type_arguments(), kAllowConst); |
| 2480 | 2495 |
| 2481 const bool kResolveGetter = true; | 2496 const bool kResolveGetter = true; |
| 2482 bool is_no_such_method = false; | 2497 bool is_no_such_method = false; |
| 2483 const Function& super_function = Function::ZoneHandle( | 2498 const Function& super_function = Function::ZoneHandle( |
| 2484 Z, GetSuperFunction(supercall_pos, function_name, arguments, | 2499 Z, GetSuperFunction(supercall_pos, function_name, arguments, |
| 2485 kResolveGetter, &is_no_such_method)); | 2500 kResolveGetter, &is_no_such_method)); |
| 2486 if (super_function.IsGetterFunction() || | 2501 if (super_function.IsGetterFunction() || |
| 2487 super_function.IsImplicitGetterFunction()) { | 2502 super_function.IsImplicitGetterFunction()) { |
| 2488 const Class& super_class = | 2503 const Class& super_class = |
| 2489 Class::ZoneHandle(Z, current_class().SuperClass()); | 2504 Class::ZoneHandle(Z, current_class().SuperClass()); |
| 2490 AstNode* closure = new StaticGetterNode( | 2505 AstNode* closure = new StaticGetterNode( |
| 2491 supercall_pos, LoadReceiver(supercall_pos), super_class, function_name); | 2506 supercall_pos, LoadReceiver(supercall_pos), super_class, function_name); |
| 2492 // 'this' is not passed as parameter to the closure. | 2507 // 'this' is not passed as parameter to the closure. |
| 2493 ArgumentListNode* closure_arguments = new ArgumentListNode(supercall_pos); | 2508 ArgumentListNode* closure_arguments = |
| 2509 new ArgumentListNode(supercall_pos, func_type_args); |
| 2494 for (int i = 1; i < arguments->length(); i++) { | 2510 for (int i = 1; i < arguments->length(); i++) { |
| 2495 closure_arguments->Add(arguments->NodeAt(i)); | 2511 closure_arguments->Add(arguments->NodeAt(i)); |
| 2496 } | 2512 } |
| 2497 return BuildClosureCall(supercall_pos, closure, closure_arguments); | 2513 return BuildClosureCall(supercall_pos, closure, closure_arguments); |
| 2498 } | 2514 } |
| 2499 if (is_no_such_method) { | 2515 if (is_no_such_method) { |
| 2500 arguments = BuildNoSuchMethodArguments(supercall_pos, function_name, | 2516 arguments = BuildNoSuchMethodArguments(supercall_pos, function_name, |
| 2501 *arguments, NULL, true); | 2517 *arguments, NULL, true); |
| 2502 } | 2518 } |
| 2503 return new StaticCallNode(supercall_pos, super_function, arguments); | 2519 return new StaticCallNode(supercall_pos, super_function, arguments); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2698 } | 2714 } |
| 2699 ReportError(supercall_pos, | 2715 ReportError(supercall_pos, |
| 2700 "unresolved implicit call to super constructor '%s()'", | 2716 "unresolved implicit call to super constructor '%s()'", |
| 2701 String::Handle(Z, super_class.Name()).ToCString()); | 2717 String::Handle(Z, super_class.Name()).ToCString()); |
| 2702 } | 2718 } |
| 2703 if (current_function().is_const() && !super_ctor.is_const()) { | 2719 if (current_function().is_const() && !super_ctor.is_const()) { |
| 2704 ReportError(supercall_pos, "implicit call to non-const super constructor"); | 2720 ReportError(supercall_pos, "implicit call to non-const super constructor"); |
| 2705 } | 2721 } |
| 2706 | 2722 |
| 2707 String& error_message = String::Handle(Z); | 2723 String& error_message = String::Handle(Z); |
| 2708 if (!super_ctor.AreValidArguments(arguments->length(), arguments->names(), | 2724 if (!super_ctor.AreValidArguments(arguments->type_args_len(), |
| 2725 arguments->length(), arguments->names(), |
| 2709 &error_message)) { | 2726 &error_message)) { |
| 2710 ReportError(supercall_pos, | 2727 ReportError(supercall_pos, |
| 2711 "invalid arguments passed to super constructor '%s()': %s", | 2728 "invalid arguments passed to super constructor '%s()': %s", |
| 2712 String::Handle(Z, super_class.Name()).ToCString(), | 2729 String::Handle(Z, super_class.Name()).ToCString(), |
| 2713 error_message.ToCString()); | 2730 error_message.ToCString()); |
| 2714 } | 2731 } |
| 2715 return new StaticCallNode(supercall_pos, super_ctor, arguments); | 2732 return new StaticCallNode(supercall_pos, super_ctor, arguments); |
| 2716 } | 2733 } |
| 2717 | 2734 |
| 2718 | 2735 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2733 } | 2750 } |
| 2734 CheckToken(Token::kLPAREN, "parameter list expected"); | 2751 CheckToken(Token::kLPAREN, "parameter list expected"); |
| 2735 | 2752 |
| 2736 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); | 2753 ArgumentListNode* arguments = new ArgumentListNode(supercall_pos); |
| 2737 // 'this' parameter is the first argument to super class constructor. | 2754 // 'this' parameter is the first argument to super class constructor. |
| 2738 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver); | 2755 AstNode* implicit_argument = new LoadLocalNode(supercall_pos, receiver); |
| 2739 arguments->Add(implicit_argument); | 2756 arguments->Add(implicit_argument); |
| 2740 | 2757 |
| 2741 // 'this' parameter must not be accessible to the other super call arguments. | 2758 // 'this' parameter must not be accessible to the other super call arguments. |
| 2742 receiver->set_invisible(true); | 2759 receiver->set_invisible(true); |
| 2743 ParseActualParameters(arguments, kAllowConst); | 2760 ParseActualParameters(arguments, Object::null_type_arguments(), kAllowConst); |
| 2744 receiver->set_invisible(false); | 2761 receiver->set_invisible(false); |
| 2745 | 2762 |
| 2746 // Resolve the constructor. | 2763 // Resolve the constructor. |
| 2747 const Function& super_ctor = | 2764 const Function& super_ctor = |
| 2748 Function::ZoneHandle(Z, super_class.LookupConstructor(ctor_name)); | 2765 Function::ZoneHandle(Z, super_class.LookupConstructor(ctor_name)); |
| 2749 if (super_ctor.IsNull()) { | 2766 if (super_ctor.IsNull()) { |
| 2750 if (super_class.LookupFactory(ctor_name) != Function::null()) { | 2767 if (super_class.LookupFactory(ctor_name) != Function::null()) { |
| 2751 ReportError(supercall_pos, | 2768 ReportError(supercall_pos, |
| 2752 "super class constructor '%s' " | 2769 "super class constructor '%s' " |
| 2753 "must not be a factory constructor", | 2770 "must not be a factory constructor", |
| 2754 ctor_name.ToCString()); | 2771 ctor_name.ToCString()); |
| 2755 } | 2772 } |
| 2756 ReportError(supercall_pos, "super class constructor '%s' not found", | 2773 ReportError(supercall_pos, "super class constructor '%s' not found", |
| 2757 ctor_name.ToCString()); | 2774 ctor_name.ToCString()); |
| 2758 } | 2775 } |
| 2759 if (current_function().is_const() && !super_ctor.is_const()) { | 2776 if (current_function().is_const() && !super_ctor.is_const()) { |
| 2760 ReportError(supercall_pos, "super constructor must be const"); | 2777 ReportError(supercall_pos, "super constructor must be const"); |
| 2761 } | 2778 } |
| 2762 String& error_message = String::Handle(Z); | 2779 String& error_message = String::Handle(Z); |
| 2763 if (!super_ctor.AreValidArguments(arguments->length(), arguments->names(), | 2780 if (!super_ctor.AreValidArguments(arguments->type_args_len(), |
| 2781 arguments->length(), arguments->names(), |
| 2764 &error_message)) { | 2782 &error_message)) { |
| 2765 ReportError(supercall_pos, | 2783 ReportError(supercall_pos, |
| 2766 "invalid arguments passed to super class constructor '%s': %s", | 2784 "invalid arguments passed to super class constructor '%s': %s", |
| 2767 ctor_name.ToCString(), error_message.ToCString()); | 2785 ctor_name.ToCString(), error_message.ToCString()); |
| 2768 } | 2786 } |
| 2769 return new StaticCallNode(supercall_pos, super_ctor, arguments); | 2787 return new StaticCallNode(supercall_pos, super_ctor, arguments); |
| 2770 } | 2788 } |
| 2771 | 2789 |
| 2772 | 2790 |
| 2773 AstNode* Parser::ParseInitializer(const Class& cls, | 2791 AstNode* Parser::ParseInitializer(const Class& cls, |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3125 } | 3143 } |
| 3126 ctor_name = Symbols::FromConcatAll(T, pieces); | 3144 ctor_name = Symbols::FromConcatAll(T, pieces); |
| 3127 CheckToken(Token::kLPAREN, "parameter list expected"); | 3145 CheckToken(Token::kLPAREN, "parameter list expected"); |
| 3128 | 3146 |
| 3129 ArgumentListNode* arguments = new ArgumentListNode(call_pos); | 3147 ArgumentListNode* arguments = new ArgumentListNode(call_pos); |
| 3130 // 'this' parameter is the first argument to constructor. | 3148 // 'this' parameter is the first argument to constructor. |
| 3131 AstNode* implicit_argument = new LoadLocalNode(call_pos, receiver); | 3149 AstNode* implicit_argument = new LoadLocalNode(call_pos, receiver); |
| 3132 arguments->Add(implicit_argument); | 3150 arguments->Add(implicit_argument); |
| 3133 | 3151 |
| 3134 receiver->set_invisible(true); | 3152 receiver->set_invisible(true); |
| 3135 ParseActualParameters(arguments, kAllowConst); | 3153 ParseActualParameters(arguments, Object::null_type_arguments(), kAllowConst); |
| 3136 receiver->set_invisible(false); | 3154 receiver->set_invisible(false); |
| 3137 // Resolve the constructor. | 3155 // Resolve the constructor. |
| 3138 const Function& redirect_ctor = | 3156 const Function& redirect_ctor = |
| 3139 Function::ZoneHandle(Z, cls.LookupConstructor(ctor_name)); | 3157 Function::ZoneHandle(Z, cls.LookupConstructor(ctor_name)); |
| 3140 if (redirect_ctor.IsNull()) { | 3158 if (redirect_ctor.IsNull()) { |
| 3141 if (cls.LookupFactory(ctor_name) != Function::null()) { | 3159 if (cls.LookupFactory(ctor_name) != Function::null()) { |
| 3142 ReportError(call_pos, | 3160 ReportError(call_pos, |
| 3143 "redirection constructor '%s' must not be a factory", | 3161 "redirection constructor '%s' must not be a factory", |
| 3144 String::Handle(Z, String::ScrubName(ctor_name)).ToCString()); | 3162 String::Handle(Z, String::ScrubName(ctor_name)).ToCString()); |
| 3145 } | 3163 } |
| 3146 ReportError(call_pos, "constructor '%s' not found", | 3164 ReportError(call_pos, "constructor '%s' not found", |
| 3147 String::Handle(Z, String::ScrubName(ctor_name)).ToCString()); | 3165 String::Handle(Z, String::ScrubName(ctor_name)).ToCString()); |
| 3148 } | 3166 } |
| 3149 if (current_function().is_const() && !redirect_ctor.is_const()) { | 3167 if (current_function().is_const() && !redirect_ctor.is_const()) { |
| 3150 ReportError(call_pos, "redirection constructor '%s' must be const", | 3168 ReportError(call_pos, "redirection constructor '%s' must be const", |
| 3151 String::Handle(Z, redirect_ctor.UserVisibleName()).ToCString()); | 3169 String::Handle(Z, redirect_ctor.UserVisibleName()).ToCString()); |
| 3152 } | 3170 } |
| 3153 String& error_message = String::Handle(Z); | 3171 String& error_message = String::Handle(Z); |
| 3154 if (!redirect_ctor.AreValidArguments(arguments->length(), arguments->names(), | 3172 if (!redirect_ctor.AreValidArguments(arguments->type_args_len(), |
| 3173 arguments->length(), arguments->names(), |
| 3155 &error_message)) { | 3174 &error_message)) { |
| 3156 ReportError(call_pos, "invalid arguments passed to constructor '%s': %s", | 3175 ReportError(call_pos, "invalid arguments passed to constructor '%s': %s", |
| 3157 String::Handle(Z, redirect_ctor.UserVisibleName()).ToCString(), | 3176 String::Handle(Z, redirect_ctor.UserVisibleName()).ToCString(), |
| 3158 error_message.ToCString()); | 3177 error_message.ToCString()); |
| 3159 } | 3178 } |
| 3160 current_block_->statements->Add( | 3179 current_block_->statements->Add( |
| 3161 new StaticCallNode(call_pos, redirect_ctor, arguments)); | 3180 new StaticCallNode(call_pos, redirect_ctor, arguments)); |
| 3162 } | 3181 } |
| 3163 | 3182 |
| 3164 | 3183 |
| (...skipping 6446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9611 return CloseBlock(); | 9630 return CloseBlock(); |
| 9612 } | 9631 } |
| 9613 | 9632 |
| 9614 | 9633 |
| 9615 // Calling VM-internal helpers, uses implementation core library. | 9634 // Calling VM-internal helpers, uses implementation core library. |
| 9616 AstNode* Parser::MakeStaticCall(const String& cls_name, | 9635 AstNode* Parser::MakeStaticCall(const String& cls_name, |
| 9617 const String& func_name, | 9636 const String& func_name, |
| 9618 ArgumentListNode* arguments) { | 9637 ArgumentListNode* arguments) { |
| 9619 const Class& cls = Class::Handle(Z, Library::LookupCoreClass(cls_name)); | 9638 const Class& cls = Class::Handle(Z, Library::LookupCoreClass(cls_name)); |
| 9620 ASSERT(!cls.IsNull()); | 9639 ASSERT(!cls.IsNull()); |
| 9640 const intptr_t kTypeArgsLen = 0; // Not passing type args to generic func. |
| 9621 const Function& func = Function::ZoneHandle( | 9641 const Function& func = Function::ZoneHandle( |
| 9622 Z, Resolver::ResolveStatic(cls, func_name, arguments->length(), | 9642 Z, Resolver::ResolveStatic(cls, func_name, kTypeArgsLen, |
| 9623 arguments->names())); | 9643 arguments->length(), arguments->names())); |
| 9624 ASSERT(!func.IsNull()); | 9644 ASSERT(!func.IsNull()); |
| 9625 return new (Z) StaticCallNode(arguments->token_pos(), func, arguments); | 9645 return new (Z) StaticCallNode(arguments->token_pos(), func, arguments); |
| 9626 } | 9646 } |
| 9627 | 9647 |
| 9628 | 9648 |
| 9629 AstNode* Parser::ParseAssertStatement(bool is_const) { | 9649 AstNode* Parser::ParseAssertStatement(bool is_const) { |
| 9630 TRACE_PARSER("ParseAssertStatement"); | 9650 TRACE_PARSER("ParseAssertStatement"); |
| 9631 ConsumeToken(); // Consume assert keyword. | 9651 ConsumeToken(); // Consume assert keyword. |
| 9632 ExpectToken(Token::kLPAREN); | 9652 ExpectToken(Token::kLPAREN); |
| 9633 const TokenPosition condition_pos = TokenPos(); | 9653 const TokenPosition condition_pos = TokenPos(); |
| (...skipping 1985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11619 expr = let_expr; | 11639 expr = let_expr; |
| 11620 } else { | 11640 } else { |
| 11621 expr = ParsePostfixExpr(); | 11641 expr = ParsePostfixExpr(); |
| 11622 } | 11642 } |
| 11623 return expr; | 11643 return expr; |
| 11624 } | 11644 } |
| 11625 | 11645 |
| 11626 | 11646 |
| 11627 ArgumentListNode* Parser::ParseActualParameters( | 11647 ArgumentListNode* Parser::ParseActualParameters( |
| 11628 ArgumentListNode* implicit_arguments, | 11648 ArgumentListNode* implicit_arguments, |
| 11649 const TypeArguments& func_type_args, |
| 11629 bool require_const) { | 11650 bool require_const) { |
| 11630 TRACE_PARSER("ParseActualParameters"); | 11651 TRACE_PARSER("ParseActualParameters"); |
| 11631 ASSERT(CurrentToken() == Token::kLPAREN); | 11652 ASSERT(CurrentToken() == Token::kLPAREN); |
| 11632 const bool saved_mode = SetAllowFunctionLiterals(true); | 11653 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 11633 ArgumentListNode* arguments; | 11654 ArgumentListNode* arguments; |
| 11634 if (implicit_arguments == NULL) { | 11655 if (implicit_arguments == NULL) { |
| 11635 arguments = new (Z) ArgumentListNode(TokenPos()); | 11656 // TODO(regis): When require_const is true, do we need to check that |
| 11657 // func_type_args are null or instantiated? |
| 11658 arguments = new (Z) ArgumentListNode(TokenPos(), func_type_args); |
| 11636 } else { | 11659 } else { |
| 11660 // If implicit arguments are provided, they include type arguments (if any). |
| 11661 ASSERT(func_type_args.IsNull()); |
| 11637 arguments = implicit_arguments; | 11662 arguments = implicit_arguments; |
| 11638 } | 11663 } |
| 11639 const GrowableObjectArray& names = | 11664 const GrowableObjectArray& names = |
| 11640 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); | 11665 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); |
| 11641 bool named_argument_seen = false; | 11666 bool named_argument_seen = false; |
| 11642 if (LookaheadToken(1) != Token::kRPAREN) { | 11667 if (LookaheadToken(1) != Token::kRPAREN) { |
| 11643 String& arg_name = String::Handle(Z); | 11668 String& arg_name = String::Handle(Z); |
| 11644 do { | 11669 do { |
| 11645 ASSERT((CurrentToken() == Token::kLPAREN) || | 11670 ASSERT((CurrentToken() == Token::kLPAREN) || |
| 11646 (CurrentToken() == Token::kCOMMA)); | 11671 (CurrentToken() == Token::kCOMMA)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 11677 if (named_argument_seen) { | 11702 if (named_argument_seen) { |
| 11678 arguments->set_names(Array::Handle(Z, Array::MakeArray(names))); | 11703 arguments->set_names(Array::Handle(Z, Array::MakeArray(names))); |
| 11679 } | 11704 } |
| 11680 return arguments; | 11705 return arguments; |
| 11681 } | 11706 } |
| 11682 | 11707 |
| 11683 | 11708 |
| 11684 AstNode* Parser::ParseStaticCall(const Class& cls, | 11709 AstNode* Parser::ParseStaticCall(const Class& cls, |
| 11685 const String& func_name, | 11710 const String& func_name, |
| 11686 TokenPosition ident_pos, | 11711 TokenPosition ident_pos, |
| 11712 const TypeArguments& func_type_args, |
| 11687 const LibraryPrefix* prefix) { | 11713 const LibraryPrefix* prefix) { |
| 11688 TRACE_PARSER("ParseStaticCall"); | 11714 TRACE_PARSER("ParseStaticCall"); |
| 11689 const TokenPosition call_pos = TokenPos(); | 11715 const TokenPosition call_pos = TokenPos(); |
| 11690 ASSERT(CurrentToken() == Token::kLPAREN); | 11716 ASSERT(CurrentToken() == Token::kLPAREN); |
| 11691 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); | 11717 ArgumentListNode* arguments = |
| 11718 ParseActualParameters(NULL, func_type_args, kAllowConst); |
| 11692 const int num_arguments = arguments->length(); | 11719 const int num_arguments = arguments->length(); |
| 11693 const Function& func = Function::ZoneHandle( | 11720 const Function& func = Function::ZoneHandle( |
| 11694 Z, Resolver::ResolveStatic(cls, func_name, num_arguments, | 11721 Z, Resolver::ResolveStatic(cls, func_name, func_type_args.Length(), |
| 11695 arguments->names())); | 11722 num_arguments, arguments->names())); |
| 11696 if (func.IsNull()) { | 11723 if (func.IsNull()) { |
| 11697 // Check if there is a static field of the same name, it could be a closure | 11724 // Check if there is a static field of the same name, it could be a closure |
| 11698 // and so we try and invoke the closure. | 11725 // and so we try and invoke the closure. |
| 11699 AstNode* closure = NULL; | 11726 AstNode* closure = NULL; |
| 11700 const Field& field = Field::ZoneHandle(Z, cls.LookupStaticField(func_name)); | 11727 const Field& field = Field::ZoneHandle(Z, cls.LookupStaticField(func_name)); |
| 11701 Function& func = Function::ZoneHandle(Z); | 11728 Function& func = Function::ZoneHandle(Z); |
| 11702 if (field.IsNull()) { | 11729 if (field.IsNull()) { |
| 11703 // No field, check if we have an explicit getter function. | 11730 // No field, check if we have an explicit getter function. |
| 11704 const String& getter_name = | 11731 const String& getter_name = |
| 11705 String::ZoneHandle(Z, Field::LookupGetterSymbol(func_name)); | 11732 String::ZoneHandle(Z, Field::LookupGetterSymbol(func_name)); |
| 11706 if (!getter_name.IsNull()) { | 11733 if (!getter_name.IsNull()) { |
| 11734 const int kTypeArgsLen = 0; // no type arguments. |
| 11707 const int kNumArguments = 0; // no arguments. | 11735 const int kNumArguments = 0; // no arguments. |
| 11708 func = Resolver::ResolveStatic(cls, getter_name, kNumArguments, | 11736 func = Resolver::ResolveStatic(cls, getter_name, kTypeArgsLen, |
| 11709 Object::empty_array()); | 11737 kNumArguments, Object::empty_array()); |
| 11710 if (!func.IsNull()) { | 11738 if (!func.IsNull()) { |
| 11711 ASSERT(func.kind() != RawFunction::kImplicitStaticFinalGetter); | 11739 ASSERT(func.kind() != RawFunction::kImplicitStaticFinalGetter); |
| 11712 closure = new (Z) StaticGetterNode( | 11740 closure = new (Z) StaticGetterNode( |
| 11713 call_pos, NULL, Class::ZoneHandle(Z, cls.raw()), func_name); | 11741 call_pos, NULL, Class::ZoneHandle(Z, cls.raw()), func_name); |
| 11714 return BuildClosureCall(call_pos, closure, arguments); | 11742 return BuildClosureCall(call_pos, closure, arguments); |
| 11715 } | 11743 } |
| 11716 } | 11744 } |
| 11717 } else { | 11745 } else { |
| 11718 closure = GenerateStaticFieldLookup(field, call_pos); | 11746 closure = GenerateStaticFieldLookup(field, call_pos); |
| 11719 return BuildClosureCall(call_pos, closure, arguments); | 11747 return BuildClosureCall(call_pos, closure, arguments); |
| 11720 } | 11748 } |
| 11721 // Could not resolve static method: throw a NoSuchMethodError. | 11749 // Could not resolve static method: throw a NoSuchMethodError. |
| 11722 return ThrowNoSuchMethodError(ident_pos, cls, func_name, arguments, | 11750 return ThrowNoSuchMethodError(ident_pos, cls, func_name, arguments, |
| 11723 InvocationMirror::kStatic, | 11751 InvocationMirror::kStatic, |
| 11724 InvocationMirror::kMethod, | 11752 InvocationMirror::kMethod, |
| 11725 NULL, // No existing function. | 11753 NULL, // No existing function. |
| 11726 prefix); | 11754 prefix); |
| 11727 } else if (cls.IsTopLevel() && (cls.library() == Library::CoreLibrary()) && | 11755 } else if (cls.IsTopLevel() && (cls.library() == Library::CoreLibrary()) && |
| 11728 (func.name() == Symbols::Identical().raw())) { | 11756 (func.name() == Symbols::Identical().raw()) && |
| 11757 func_type_args.IsNull()) { |
| 11729 // This is the predefined toplevel function identical(a,b). | 11758 // This is the predefined toplevel function identical(a,b). |
| 11730 // Create a comparison node instead of a static call to the function. | 11759 // Create a comparison node instead of a static call to the function. |
| 11731 ASSERT(num_arguments == 2); | 11760 ASSERT(num_arguments == 2); |
| 11732 | 11761 |
| 11733 // If both arguments are constant expressions of type string, | 11762 // If both arguments are constant expressions of type string, |
| 11734 // evaluate and canonicalize them. | 11763 // evaluate and canonicalize them. |
| 11735 // This guarantees that identical("ab", "a"+"b") is true. | 11764 // This guarantees that identical("ab", "a"+"b") is true. |
| 11736 // An alternative way to guarantee this would be to introduce | 11765 // An alternative way to guarantee this would be to introduce |
| 11737 // an AST node that canonicalizes a value. | 11766 // an AST node that canonicalizes a value. |
| 11738 AstNode* arg0 = arguments->NodeAt(0); | 11767 AstNode* arg0 = arguments->NodeAt(0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 11752 return new (Z) ComparisonNode(ident_pos, Token::kEQ_STRICT, | 11781 return new (Z) ComparisonNode(ident_pos, Token::kEQ_STRICT, |
| 11753 arguments->NodeAt(0), arguments->NodeAt(1)); | 11782 arguments->NodeAt(0), arguments->NodeAt(1)); |
| 11754 } | 11783 } |
| 11755 return new (Z) StaticCallNode(ident_pos, func, arguments); | 11784 return new (Z) StaticCallNode(ident_pos, func, arguments); |
| 11756 } | 11785 } |
| 11757 | 11786 |
| 11758 | 11787 |
| 11759 AstNode* Parser::ParseInstanceCall(AstNode* receiver, | 11788 AstNode* Parser::ParseInstanceCall(AstNode* receiver, |
| 11760 const String& func_name, | 11789 const String& func_name, |
| 11761 TokenPosition ident_pos, | 11790 TokenPosition ident_pos, |
| 11791 const TypeArguments& func_type_args, |
| 11762 bool is_conditional) { | 11792 bool is_conditional) { |
| 11763 TRACE_PARSER("ParseInstanceCall"); | 11793 TRACE_PARSER("ParseInstanceCall"); |
| 11764 CheckToken(Token::kLPAREN); | 11794 CheckToken(Token::kLPAREN); |
| 11765 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); | 11795 ArgumentListNode* arguments = |
| 11796 ParseActualParameters(NULL, func_type_args, kAllowConst); |
| 11766 return new (Z) InstanceCallNode(ident_pos, receiver, func_name, arguments, | 11797 return new (Z) InstanceCallNode(ident_pos, receiver, func_name, arguments, |
| 11767 is_conditional); | 11798 is_conditional); |
| 11768 } | 11799 } |
| 11769 | 11800 |
| 11770 | 11801 |
| 11771 AstNode* Parser::ParseClosureCall(AstNode* closure) { | 11802 AstNode* Parser::ParseClosureCall(AstNode* closure, |
| 11803 const TypeArguments& func_type_args) { |
| 11772 TRACE_PARSER("ParseClosureCall"); | 11804 TRACE_PARSER("ParseClosureCall"); |
| 11773 const TokenPosition call_pos = TokenPos(); | 11805 const TokenPosition call_pos = TokenPos(); |
| 11774 ASSERT(CurrentToken() == Token::kLPAREN); | 11806 ASSERT(CurrentToken() == Token::kLPAREN); |
| 11775 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); | 11807 ArgumentListNode* arguments = |
| 11808 ParseActualParameters(NULL, func_type_args, kAllowConst); |
| 11776 return BuildClosureCall(call_pos, closure, arguments); | 11809 return BuildClosureCall(call_pos, closure, arguments); |
| 11777 } | 11810 } |
| 11778 | 11811 |
| 11779 | 11812 |
| 11780 AstNode* Parser::GenerateStaticFieldLookup(const Field& field, | 11813 AstNode* Parser::GenerateStaticFieldLookup(const Field& field, |
| 11781 TokenPosition ident_pos) { | 11814 TokenPosition ident_pos) { |
| 11782 // If the static field has an initializer, initialize the field at compile | 11815 // If the static field has an initializer, initialize the field at compile |
| 11783 // time, which is only possible if the field is const. | 11816 // time, which is only possible if the field is const. |
| 11784 AstNode* initializing_getter = RunStaticFieldInitializer(field, ident_pos); | 11817 AstNode* initializing_getter = RunStaticFieldInitializer(field, ident_pos); |
| 11785 if (initializing_getter != NULL) { | 11818 if (initializing_getter != NULL) { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11965 // super calls handled in ParseSuperCall(). | 11998 // super calls handled in ParseSuperCall(). |
| 11966 ASSERT(!primary_node->IsSuper()); | 11999 ASSERT(!primary_node->IsSuper()); |
| 11967 left = LoadFieldIfUnresolved(left); | 12000 left = LoadFieldIfUnresolved(left); |
| 11968 } | 12001 } |
| 11969 } | 12002 } |
| 11970 const TokenPosition ident_pos = TokenPos(); | 12003 const TokenPosition ident_pos = TokenPos(); |
| 11971 String* ident = ExpectIdentifier("identifier expected"); | 12004 String* ident = ExpectIdentifier("identifier expected"); |
| 11972 if (IsArgumentPart()) { | 12005 if (IsArgumentPart()) { |
| 11973 // Identifier followed by optional type arguments and opening paren: | 12006 // Identifier followed by optional type arguments and opening paren: |
| 11974 // method call. | 12007 // method call. |
| 12008 TypeArguments& func_type_args = TypeArguments::ZoneHandle(Z); |
| 11975 if (CurrentToken() == Token::kLT) { | 12009 if (CurrentToken() == Token::kLT) { |
| 11976 // Type arguments. | 12010 // Type arguments. |
| 11977 if (!FLAG_generic_method_syntax) { | 12011 if (!FLAG_generic_method_syntax) { |
| 11978 ReportError("generic type arguments not supported."); | 12012 ReportError("generic type arguments not supported."); |
| 11979 } | 12013 } |
| 11980 // TODO(regis): Pass type arguments in generic call. | 12014 func_type_args = ParseTypeArguments(ClassFinalizer::kCanonicalize); |
| 11981 // For now, resolve type arguments and ignore. | 12015 if (!FLAG_reify_generic_functions) { |
| 11982 ParseTypeArguments(ClassFinalizer::kCanonicalize); | 12016 func_type_args = TypeArguments::null(); |
| 12017 } |
| 11983 } | 12018 } |
| 11984 PrimaryNode* primary_node = left->AsPrimaryNode(); | 12019 PrimaryNode* primary_node = left->AsPrimaryNode(); |
| 11985 if ((primary_node != NULL) && primary_node->primary().IsClass()) { | 12020 if ((primary_node != NULL) && primary_node->primary().IsClass()) { |
| 11986 // Static method call prefixed with class name. | 12021 // Static method call prefixed with class name. |
| 11987 const Class& cls = Class::Cast(primary_node->primary()); | 12022 const Class& cls = Class::Cast(primary_node->primary()); |
| 11988 selector = | 12023 selector = ParseStaticCall(cls, *ident, ident_pos, func_type_args, |
| 11989 ParseStaticCall(cls, *ident, ident_pos, primary_node->prefix()); | 12024 primary_node->prefix()); |
| 11990 } else { | 12025 } else { |
| 11991 if ((primary_node != NULL) && primary_node->is_deferred_reference()) { | 12026 if ((primary_node != NULL) && primary_node->is_deferred_reference()) { |
| 11992 const Class& cls = Class::Handle(library_.toplevel_class()); | 12027 const Class& cls = Class::Handle(library_.toplevel_class()); |
| 11993 selector = | 12028 selector = ParseStaticCall(cls, *ident, ident_pos, func_type_args, |
| 11994 ParseStaticCall(cls, *ident, ident_pos, primary_node->prefix()); | 12029 primary_node->prefix()); |
| 11995 } else { | 12030 } else { |
| 11996 selector = | 12031 selector = ParseInstanceCall(left, *ident, ident_pos, |
| 11997 ParseInstanceCall(left, *ident, ident_pos, is_conditional); | 12032 func_type_args, is_conditional); |
| 11998 } | 12033 } |
| 11999 } | 12034 } |
| 12000 } else { | 12035 } else { |
| 12001 // Field access. | 12036 // Field access. |
| 12002 Class& cls = Class::Handle(Z); | 12037 Class& cls = Class::Handle(Z); |
| 12003 bool is_deferred = false; | 12038 bool is_deferred = false; |
| 12004 if (left->IsPrimaryNode()) { | 12039 if (left->IsPrimaryNode()) { |
| 12005 PrimaryNode* primary_node = left->AsPrimaryNode(); | 12040 PrimaryNode* primary_node = left->AsPrimaryNode(); |
| 12006 is_deferred = primary_node->is_deferred_reference(); | 12041 is_deferred = primary_node->is_deferred_reference(); |
| 12007 if (primary_node->primary().IsClass()) { | 12042 if (primary_node->primary().IsClass()) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12056 primary_node->is_deferred_reference()); | 12091 primary_node->is_deferred_reference()); |
| 12057 } else if (primary_node->primary().IsTypeParameter()) { | 12092 } else if (primary_node->primary().IsTypeParameter()) { |
| 12058 array = LoadTypeParameter(primary_node); | 12093 array = LoadTypeParameter(primary_node); |
| 12059 } else { | 12094 } else { |
| 12060 UNREACHABLE(); // Internal parser error. | 12095 UNREACHABLE(); // Internal parser error. |
| 12061 } | 12096 } |
| 12062 } | 12097 } |
| 12063 selector = new (Z) | 12098 selector = new (Z) |
| 12064 LoadIndexedNode(bracket_pos, array, index, Class::ZoneHandle(Z)); | 12099 LoadIndexedNode(bracket_pos, array, index, Class::ZoneHandle(Z)); |
| 12065 } else if (IsArgumentPart()) { | 12100 } else if (IsArgumentPart()) { |
| 12101 TypeArguments& func_type_args = TypeArguments::ZoneHandle(Z); |
| 12066 if (CurrentToken() == Token::kLT) { | 12102 if (CurrentToken() == Token::kLT) { |
| 12067 // Type arguments. | 12103 // Type arguments. |
| 12068 if (!FLAG_generic_method_syntax) { | 12104 if (!FLAG_generic_method_syntax) { |
| 12069 ReportError("generic type arguments not supported."); | 12105 ReportError("generic type arguments not supported."); |
| 12070 } | 12106 } |
| 12071 // TODO(regis): Pass type arguments in generic call. | 12107 func_type_args = ParseTypeArguments(ClassFinalizer::kCanonicalize); |
| 12072 // For now, resolve type arguments and ignore. | 12108 if (!FLAG_reify_generic_functions) { |
| 12073 ParseTypeArguments(ClassFinalizer::kCanonicalize); | 12109 func_type_args = TypeArguments::null(); |
| 12110 } |
| 12074 } | 12111 } |
| 12075 if (left->IsPrimaryNode()) { | 12112 if (left->IsPrimaryNode()) { |
| 12076 PrimaryNode* primary_node = left->AsPrimaryNode(); | 12113 PrimaryNode* primary_node = left->AsPrimaryNode(); |
| 12077 const TokenPosition primary_pos = primary_node->token_pos(); | 12114 const TokenPosition primary_pos = primary_node->token_pos(); |
| 12078 if (primary_node->primary().IsFunction()) { | 12115 if (primary_node->primary().IsFunction()) { |
| 12079 const Function& func = Function::Cast(primary_node->primary()); | 12116 const Function& func = Function::Cast(primary_node->primary()); |
| 12080 const String& func_name = String::ZoneHandle(Z, func.name()); | 12117 const String& func_name = String::ZoneHandle(Z, func.name()); |
| 12081 if (func.is_static()) { | 12118 if (func.is_static()) { |
| 12082 // Parse static function call. | 12119 // Parse static function call. |
| 12083 Class& cls = Class::Handle(Z, func.Owner()); | 12120 Class& cls = Class::Handle(Z, func.Owner()); |
| 12084 selector = ParseStaticCall(cls, func_name, primary_pos); | 12121 selector = |
| 12122 ParseStaticCall(cls, func_name, primary_pos, func_type_args); |
| 12085 } else { | 12123 } else { |
| 12086 // Dynamic function call on implicit "this" parameter. | 12124 // Dynamic function call on implicit "this" parameter. |
| 12087 if (current_function().is_static()) { | 12125 if (current_function().is_static()) { |
| 12088 ReportError(primary_pos, | 12126 ReportError(primary_pos, |
| 12089 "cannot access instance method '%s' " | 12127 "cannot access instance method '%s' " |
| 12090 "from static function", | 12128 "from static function", |
| 12091 func_name.ToCString()); | 12129 func_name.ToCString()); |
| 12092 } | 12130 } |
| 12093 selector = | 12131 selector = ParseInstanceCall(LoadReceiver(primary_pos), func_name, |
| 12094 ParseInstanceCall(LoadReceiver(primary_pos), func_name, | 12132 primary_pos, func_type_args, |
| 12095 primary_pos, false /* is_conditional */); | 12133 false /* is_conditional */); |
| 12096 } | 12134 } |
| 12097 } else if (primary_node->primary().IsString()) { | 12135 } else if (primary_node->primary().IsString()) { |
| 12098 // Primary is an unresolved name. | 12136 // Primary is an unresolved name. |
| 12099 if (primary_node->IsSuper()) { | 12137 if (primary_node->IsSuper()) { |
| 12100 ReportError(primary_pos, "illegal use of super"); | 12138 ReportError(primary_pos, "illegal use of super"); |
| 12101 } | 12139 } |
| 12102 const String& name = | 12140 const String& name = |
| 12103 String::Cast(Object::ZoneHandle(primary_node->primary().raw())); | 12141 String::Cast(Object::ZoneHandle(primary_node->primary().raw())); |
| 12104 if (primary_node->is_deferred_reference()) { | 12142 if (primary_node->is_deferred_reference()) { |
| 12105 // The static call will be converted to throwing a NSM error. | 12143 // The static call will be converted to throwing a NSM error. |
| 12106 const Class& cls = Class::Handle(library_.toplevel_class()); | 12144 const Class& cls = Class::Handle(library_.toplevel_class()); |
| 12107 selector = | 12145 selector = ParseStaticCall(cls, name, primary_pos, func_type_args, |
| 12108 ParseStaticCall(cls, name, primary_pos, primary_node->prefix()); | 12146 primary_node->prefix()); |
| 12109 } else if (current_function().is_static()) { | 12147 } else if (current_function().is_static()) { |
| 12110 // The static call will be converted to throwing a NSM error. | 12148 // The static call will be converted to throwing a NSM error. |
| 12111 selector = ParseStaticCall(current_class(), name, primary_pos); | 12149 selector = ParseStaticCall(current_class(), name, primary_pos, |
| 12150 func_type_args); |
| 12112 } else { | 12151 } else { |
| 12113 // Treat as call to unresolved (instance) method. | 12152 // Treat as call to unresolved (instance) method. |
| 12114 selector = | 12153 selector = |
| 12115 ParseInstanceCall(LoadReceiver(primary_pos), name, primary_pos, | 12154 ParseInstanceCall(LoadReceiver(primary_pos), name, primary_pos, |
| 12116 false /* is_conditional */); | 12155 func_type_args, false /* is_conditional */); |
| 12117 } | 12156 } |
| 12118 } else if (primary_node->primary().IsTypeParameter()) { | 12157 } else if (primary_node->primary().IsTypeParameter()) { |
| 12158 // TODO(regis): What about the parsed type arguments? |
| 12119 selector = LoadTypeParameter(primary_node); | 12159 selector = LoadTypeParameter(primary_node); |
| 12120 } else if (primary_node->primary().IsClass()) { | 12160 } else if (primary_node->primary().IsClass()) { |
| 12161 // TODO(regis): What about the parsed type arguments? |
| 12121 const Class& type_class = Class::Cast(primary_node->primary()); | 12162 const Class& type_class = Class::Cast(primary_node->primary()); |
| 12122 AbstractType& type = Type::ZoneHandle( | 12163 AbstractType& type = Type::ZoneHandle( |
| 12123 Z, Type::New(type_class, Object::null_type_arguments(), | 12164 Z, Type::New(type_class, Object::null_type_arguments(), |
| 12124 primary_pos, Heap::kOld)); | 12165 primary_pos, Heap::kOld)); |
| 12125 type ^= CanonicalizeType(type); | 12166 type ^= CanonicalizeType(type); |
| 12126 // Type may be malbounded, but not malformed. | 12167 // Type may be malbounded, but not malformed. |
| 12127 ASSERT(!type.IsMalformed()); | 12168 ASSERT(!type.IsMalformed()); |
| 12128 selector = new (Z) TypeNode(primary_pos, type, | 12169 selector = new (Z) TypeNode(primary_pos, type, |
| 12129 primary_node->is_deferred_reference()); | 12170 primary_node->is_deferred_reference()); |
| 12130 } else { | 12171 } else { |
| 12131 UNREACHABLE(); // Internal parser error. | 12172 UNREACHABLE(); // Internal parser error. |
| 12132 } | 12173 } |
| 12133 } else { | 12174 } else { |
| 12134 // Left is not a primary node; this must be a closure call. | 12175 // Left is not a primary node; this must be a closure call. |
| 12135 AstNode* closure = left; | 12176 AstNode* closure = left; |
| 12136 selector = ParseClosureCall(closure); | 12177 selector = ParseClosureCall(closure, func_type_args); |
| 12137 } | 12178 } |
| 12138 } else { | 12179 } else { |
| 12139 // No (more) selectors to parse. | 12180 // No (more) selectors to parse. |
| 12140 left = LoadFieldIfUnresolved(left); | 12181 left = LoadFieldIfUnresolved(left); |
| 12141 if (left->IsPrimaryNode()) { | 12182 if (left->IsPrimaryNode()) { |
| 12142 PrimaryNode* primary_node = left->AsPrimaryNode(); | 12183 PrimaryNode* primary_node = left->AsPrimaryNode(); |
| 12143 const TokenPosition primary_pos = primary->token_pos(); | 12184 const TokenPosition primary_pos = primary->token_pos(); |
| 12144 if (primary_node->primary().IsFunction()) { | 12185 if (primary_node->primary().IsFunction()) { |
| 12145 // Treat as implicit closure. | 12186 // Treat as implicit closure. |
| 12146 left = LoadClosure(primary_node); | 12187 left = LoadClosure(primary_node); |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12676 StaticGetterNode(field_ref_pos, NULL, field_owner, field_name); | 12717 StaticGetterNode(field_ref_pos, NULL, field_owner, field_name); |
| 12677 } | 12718 } |
| 12678 } else if (value.raw() == Object::sentinel().raw()) { | 12719 } else if (value.raw() == Object::sentinel().raw()) { |
| 12679 // This field has not been referenced yet and thus the value has | 12720 // This field has not been referenced yet and thus the value has |
| 12680 // not been evaluated. If the field is const, call the static getter method | 12721 // not been evaluated. If the field is const, call the static getter method |
| 12681 // to evaluate the expression and canonicalize the value. | 12722 // to evaluate the expression and canonicalize the value. |
| 12682 if (field.is_const()) { | 12723 if (field.is_const()) { |
| 12683 NoReloadScope no_reload_scope(isolate(), thread()); | 12724 NoReloadScope no_reload_scope(isolate(), thread()); |
| 12684 NoOOBMessageScope no_msg_scope(thread()); | 12725 NoOOBMessageScope no_msg_scope(thread()); |
| 12685 field.SetStaticValue(Object::transition_sentinel()); | 12726 field.SetStaticValue(Object::transition_sentinel()); |
| 12686 const int kNumArguments = 0; // no arguments. | 12727 const int kTypeArgsLen = 0; // No type argument vector. |
| 12728 const int kNumArguments = 0; // No arguments. |
| 12687 const Function& func = Function::Handle( | 12729 const Function& func = Function::Handle( |
| 12688 Z, Resolver::ResolveStatic(field_owner, getter_name, kNumArguments, | 12730 Z, Resolver::ResolveStatic(field_owner, getter_name, kTypeArgsLen, |
| 12689 Object::empty_array())); | 12731 kNumArguments, Object::empty_array())); |
| 12690 ASSERT(!func.IsNull()); | 12732 ASSERT(!func.IsNull()); |
| 12691 ASSERT(func.kind() == RawFunction::kImplicitStaticFinalGetter); | 12733 ASSERT(func.kind() == RawFunction::kImplicitStaticFinalGetter); |
| 12692 Object& const_value = Object::Handle(Z); | 12734 Object& const_value = Object::Handle(Z); |
| 12693 const_value = DartEntry::InvokeFunction(func, Object::empty_array()); | 12735 const_value = DartEntry::InvokeFunction(func, Object::empty_array()); |
| 12694 if (const_value.IsError()) { | 12736 if (const_value.IsError()) { |
| 12695 const Error& error = Error::Cast(const_value); | 12737 const Error& error = Error::Cast(const_value); |
| 12696 if (error.IsUnhandledException()) { | 12738 if (error.IsUnhandledException()) { |
| 12697 // An exception may not occur in every parse attempt, i.e., the | 12739 // An exception may not occur in every parse attempt, i.e., the |
| 12698 // generated AST is not deterministic. Therefore mark the function as | 12740 // generated AST is not deterministic. Therefore mark the function as |
| 12699 // not optimizable. | 12741 // not optimizable. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 12730 } | 12772 } |
| 12731 | 12773 |
| 12732 | 12774 |
| 12733 RawObject* Parser::EvaluateConstConstructorCall( | 12775 RawObject* Parser::EvaluateConstConstructorCall( |
| 12734 const Class& type_class, | 12776 const Class& type_class, |
| 12735 const TypeArguments& type_arguments, | 12777 const TypeArguments& type_arguments, |
| 12736 const Function& constructor, | 12778 const Function& constructor, |
| 12737 ArgumentListNode* arguments) { | 12779 ArgumentListNode* arguments) { |
| 12738 NoReloadScope no_reload_scope(isolate(), thread()); | 12780 NoReloadScope no_reload_scope(isolate(), thread()); |
| 12739 NoOOBMessageScope no_msg_scope(thread()); | 12781 NoOOBMessageScope no_msg_scope(thread()); |
| 12782 // Factories and constructors are not generic functions. |
| 12783 const int kTypeArgsLen = 0; |
| 12740 // Factories have one extra argument: the type arguments. | 12784 // Factories have one extra argument: the type arguments. |
| 12741 // Constructors have 1 extra arguments: receiver. | 12785 // Constructors have one extra arguments: receiver. |
| 12742 const int kNumExtraArgs = 1; | 12786 const int kNumExtraArgs = 1; |
| 12743 const int num_arguments = arguments->length() + kNumExtraArgs; | 12787 const int num_arguments = arguments->length() + kNumExtraArgs; |
| 12744 const Array& arg_values = | 12788 const Array& arg_values = |
| 12745 Array::Handle(Z, Array::New(num_arguments, Heap::kOld)); | 12789 Array::Handle(Z, Array::New(num_arguments, Heap::kOld)); |
| 12746 Instance& instance = Instance::Handle(Z); | 12790 Instance& instance = Instance::Handle(Z); |
| 12747 if (!constructor.IsFactory()) { | 12791 if (!constructor.IsFactory()) { |
| 12748 instance = Instance::New(type_class, Heap::kOld); | 12792 instance = Instance::New(type_class, Heap::kOld); |
| 12749 if (!type_arguments.IsNull()) { | 12793 if (!type_arguments.IsNull()) { |
| 12750 if (!type_arguments.IsInstantiated()) { | 12794 if (!type_arguments.IsInstantiated()) { |
| 12751 ReportError("type must be constant in const constructor"); | 12795 ReportError("type must be constant in const constructor"); |
| 12752 } | 12796 } |
| 12753 instance.SetTypeArguments( | 12797 instance.SetTypeArguments( |
| 12754 TypeArguments::Handle(Z, type_arguments.Canonicalize())); | 12798 TypeArguments::Handle(Z, type_arguments.Canonicalize())); |
| 12755 } | 12799 } |
| 12756 arg_values.SetAt(0, instance); | 12800 arg_values.SetAt(0, instance); |
| 12757 } else { | 12801 } else { |
| 12758 // Prepend type_arguments to list of arguments to factory. | 12802 // Prepend type_arguments to list of arguments to factory. |
| 12759 ASSERT(type_arguments.IsZoneHandle()); | 12803 ASSERT(type_arguments.IsZoneHandle()); |
| 12760 arg_values.SetAt(0, type_arguments); | 12804 arg_values.SetAt(0, type_arguments); |
| 12761 } | 12805 } |
| 12762 for (int i = 0; i < arguments->length(); i++) { | 12806 for (int i = 0; i < arguments->length(); i++) { |
| 12763 AstNode* arg = arguments->NodeAt(i); | 12807 AstNode* arg = arguments->NodeAt(i); |
| 12764 // Arguments have been evaluated to a literal value already. | 12808 // Arguments have been evaluated to a literal value already. |
| 12765 ASSERT(arg->IsLiteralNode()); | 12809 ASSERT(arg->IsLiteralNode()); |
| 12766 arg_values.SetAt((i + kNumExtraArgs), arg->AsLiteralNode()->literal()); | 12810 arg_values.SetAt((i + kNumExtraArgs), arg->AsLiteralNode()->literal()); |
| 12767 } | 12811 } |
| 12768 const Array& args_descriptor = Array::Handle( | 12812 const Array& args_descriptor = |
| 12769 Z, ArgumentsDescriptor::New(num_arguments, arguments->names())); | 12813 Array::Handle(Z, ArgumentsDescriptor::New(kTypeArgsLen, num_arguments, |
| 12814 arguments->names())); |
| 12770 const Object& result = Object::Handle( | 12815 const Object& result = Object::Handle( |
| 12771 Z, DartEntry::InvokeFunction(constructor, arg_values, args_descriptor)); | 12816 Z, DartEntry::InvokeFunction(constructor, arg_values, args_descriptor)); |
| 12772 if (result.IsError()) { | 12817 if (result.IsError()) { |
| 12773 // An exception may not occur in every parse attempt, i.e., the | 12818 // An exception may not occur in every parse attempt, i.e., the |
| 12774 // generated AST is not deterministic. Therefore mark the function as | 12819 // generated AST is not deterministic. Therefore mark the function as |
| 12775 // not optimizable. | 12820 // not optimizable. |
| 12776 current_function().SetIsOptimizable(false); | 12821 current_function().SetIsOptimizable(false); |
| 12777 if (result.IsUnhandledException()) { | 12822 if (result.IsUnhandledException()) { |
| 12778 return result.raw(); | 12823 return result.raw(); |
| 12779 } else { | 12824 } else { |
| (...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14063 ConsumeToken(); | 14108 ConsumeToken(); |
| 14064 named_constructor = ExpectIdentifier("name of constructor expected"); | 14109 named_constructor = ExpectIdentifier("name of constructor expected"); |
| 14065 } | 14110 } |
| 14066 | 14111 |
| 14067 // Parse constructor parameters. | 14112 // Parse constructor parameters. |
| 14068 TokenPosition call_pos = TokenPos(); | 14113 TokenPosition call_pos = TokenPos(); |
| 14069 ArgumentListNode* arguments = NULL; | 14114 ArgumentListNode* arguments = NULL; |
| 14070 if (!is_tearoff_expression) { | 14115 if (!is_tearoff_expression) { |
| 14071 CheckToken(Token::kLPAREN); | 14116 CheckToken(Token::kLPAREN); |
| 14072 call_pos = TokenPos(); | 14117 call_pos = TokenPos(); |
| 14073 arguments = ParseActualParameters(NULL, is_const); | 14118 arguments = |
| 14119 ParseActualParameters(NULL, TypeArguments::ZoneHandle(Z), is_const); |
| 14074 } else { | 14120 } else { |
| 14075 // Allocate dummy node with no arguments so we don't have to deal | 14121 // Allocate dummy node with no arguments so we don't have to deal |
| 14076 // with the NULL corner case below. | 14122 // with the NULL corner case below. |
| 14077 arguments = new (Z) ArgumentListNode(TokenPos()); | 14123 arguments = new (Z) ArgumentListNode(TokenPos()); |
| 14078 } | 14124 } |
| 14079 | 14125 |
| 14080 // Parsing is complete, so we can return a throw in case of a malformed or | 14126 // Parsing is complete, so we can return a throw in case of a malformed or |
| 14081 // malbounded type or report a compile-time error if the constructor is const. | 14127 // malbounded type or report a compile-time error if the constructor is const. |
| 14082 if (type.IsMalformedOrMalbounded()) { | 14128 if (type.IsMalformedOrMalbounded()) { |
| 14083 if (is_const) { | 14129 if (is_const) { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14242 if (!type_arguments.IsNull() && !type_arguments.IsInstantiated()) { | 14288 if (!type_arguments.IsNull() && !type_arguments.IsInstantiated()) { |
| 14243 CaptureAllInstantiators(); | 14289 CaptureAllInstantiators(); |
| 14244 } | 14290 } |
| 14245 SequenceNode* tearoff_body = CloseBlock(); | 14291 SequenceNode* tearoff_body = CloseBlock(); |
| 14246 ClosureNode* closure_obj = | 14292 ClosureNode* closure_obj = |
| 14247 new (Z) ClosureNode(new_pos, tearoff_func, NULL, tearoff_body->scope()); | 14293 new (Z) ClosureNode(new_pos, tearoff_func, NULL, tearoff_body->scope()); |
| 14248 return closure_obj; | 14294 return closure_obj; |
| 14249 } | 14295 } |
| 14250 | 14296 |
| 14251 ASSERT(!is_tearoff_expression); | 14297 ASSERT(!is_tearoff_expression); |
| 14298 const int kTypeArgsLen = 0; |
| 14252 String& error_message = String::Handle(Z); | 14299 String& error_message = String::Handle(Z); |
| 14253 if (!constructor.AreValidArguments(arguments_length, arguments->names(), | 14300 if (!constructor.AreValidArguments(kTypeArgsLen, arguments_length, |
| 14254 &error_message)) { | 14301 arguments->names(), &error_message)) { |
| 14255 const String& external_constructor_name = | 14302 const String& external_constructor_name = |
| 14256 (named_constructor ? constructor_name : type_class_name); | 14303 (named_constructor ? constructor_name : type_class_name); |
| 14257 if (is_const) { | 14304 if (is_const) { |
| 14258 ReportError(call_pos, | 14305 ReportError(call_pos, |
| 14259 "invalid arguments passed to constructor '%s' " | 14306 "invalid arguments passed to constructor '%s' " |
| 14260 "for class '%s': %s", | 14307 "for class '%s': %s", |
| 14261 external_constructor_name.ToCString(), | 14308 external_constructor_name.ToCString(), |
| 14262 String::Handle(Z, type_class.Name()).ToCString(), | 14309 String::Handle(Z, type_class.Name()).ToCString(), |
| 14263 error_message.ToCString()); | 14310 error_message.ToCString()); |
| 14264 } | 14311 } |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14650 if (current_class().SuperClass() == Class::null()) { | 14697 if (current_class().SuperClass() == Class::null()) { |
| 14651 ReportError("class '%s' does not have a superclass", | 14698 ReportError("class '%s' does not have a superclass", |
| 14652 String::Handle(Z, current_class().Name()).ToCString()); | 14699 String::Handle(Z, current_class().Name()).ToCString()); |
| 14653 } | 14700 } |
| 14654 const TokenPosition super_pos = TokenPos(); | 14701 const TokenPosition super_pos = TokenPos(); |
| 14655 ConsumeToken(); | 14702 ConsumeToken(); |
| 14656 if (CurrentToken() == Token::kPERIOD) { | 14703 if (CurrentToken() == Token::kPERIOD) { |
| 14657 ConsumeToken(); | 14704 ConsumeToken(); |
| 14658 const TokenPosition ident_pos = TokenPos(); | 14705 const TokenPosition ident_pos = TokenPos(); |
| 14659 const String& ident = *ExpectIdentifier("identifier expected"); | 14706 const String& ident = *ExpectIdentifier("identifier expected"); |
| 14660 if (CurrentToken() == Token::kLPAREN) { | 14707 if (IsArgumentPart()) { |
| 14661 primary = ParseSuperCall(ident); | 14708 TypeArguments& func_type_args = TypeArguments::ZoneHandle(Z); |
| 14709 if (CurrentToken() == Token::kLT) { |
| 14710 // Type arguments. |
| 14711 if (!FLAG_generic_method_syntax) { |
| 14712 ReportError("generic type arguments not supported."); |
| 14713 } |
| 14714 func_type_args = ParseTypeArguments(ClassFinalizer::kCanonicalize); |
| 14715 if (!FLAG_reify_generic_functions) { |
| 14716 func_type_args = TypeArguments::null(); |
| 14717 } |
| 14718 } |
| 14719 primary = ParseSuperCall(ident, func_type_args); |
| 14662 } else { | 14720 } else { |
| 14663 primary = ParseSuperFieldAccess(ident, ident_pos); | 14721 primary = ParseSuperFieldAccess(ident, ident_pos); |
| 14664 } | 14722 } |
| 14665 } else if ((CurrentToken() == Token::kLBRACK) || | 14723 } else if ((CurrentToken() == Token::kLBRACK) || |
| 14666 Token::CanBeOverloaded(CurrentToken()) || | 14724 Token::CanBeOverloaded(CurrentToken()) || |
| 14667 (CurrentToken() == Token::kNE)) { | 14725 (CurrentToken() == Token::kNE)) { |
| 14668 primary = ParseSuperOperator(); | 14726 primary = ParseSuperOperator(); |
| 14669 } else if (CurrentToken() == Token::kQM_PERIOD) { | 14727 } else if (CurrentToken() == Token::kQM_PERIOD) { |
| 14670 ReportError("super call or super getter may not use ?."); | 14728 ReportError("super call or super getter may not use ?."); |
| 14671 } else { | 14729 } else { |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15197 const ArgumentListNode& function_args, | 15255 const ArgumentListNode& function_args, |
| 15198 const LocalVariable* temp_for_last_arg, | 15256 const LocalVariable* temp_for_last_arg, |
| 15199 bool is_super_invocation) { | 15257 bool is_super_invocation) { |
| 15200 UNREACHABLE(); | 15258 UNREACHABLE(); |
| 15201 return NULL; | 15259 return NULL; |
| 15202 } | 15260 } |
| 15203 | 15261 |
| 15204 } // namespace dart | 15262 } // namespace dart |
| 15205 | 15263 |
| 15206 #endif // DART_PRECOMPILED_RUNTIME | 15264 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |