| 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 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 INC_STAT(isolate, num_functions_compiled, 1); | 883 INC_STAT(isolate, num_functions_compiled, 1); |
| 884 VMTagScope tagScope(thread, VMTag::kCompileParseFunctionTagId, | 884 VMTagScope tagScope(thread, VMTag::kCompileParseFunctionTagId, |
| 885 FLAG_profile_vm); | 885 FLAG_profile_vm); |
| 886 | 886 |
| 887 ASSERT(thread->long_jump_base()->IsSafeToJump()); | 887 ASSERT(thread->long_jump_base()->IsSafeToJump()); |
| 888 ASSERT(parsed_function != NULL); | 888 ASSERT(parsed_function != NULL); |
| 889 const Function& func = parsed_function->function(); | 889 const Function& func = parsed_function->function(); |
| 890 const Script& script = Script::Handle(zone, func.script()); | 890 const Script& script = Script::Handle(zone, func.script()); |
| 891 Parser parser(script, parsed_function, func.token_pos()); | 891 Parser parser(script, parsed_function, func.token_pos()); |
| 892 SequenceNode* node_sequence = NULL; | 892 SequenceNode* node_sequence = NULL; |
| 893 Array& default_parameter_values = Array::ZoneHandle(zone, Array::null()); | 893 ZoneGrowableArray<const Instance*>* default_parameter_values = |
| 894 new ZoneGrowableArray<const Instance*>(zone, 2); |
| 894 switch (func.kind()) { | 895 switch (func.kind()) { |
| 895 case RawFunction::kClosureFunction: | 896 case RawFunction::kClosureFunction: |
| 896 if (func.IsImplicitClosureFunction()) { | 897 if (func.IsImplicitClosureFunction()) { |
| 897 node_sequence = | 898 node_sequence = |
| 898 parser.ParseImplicitClosure(func, &default_parameter_values); | 899 parser.ParseImplicitClosure(func, default_parameter_values); |
| 899 break; | 900 break; |
| 900 } | 901 } |
| 901 if (func.IsConstructorClosureFunction()) { | 902 if (func.IsConstructorClosureFunction()) { |
| 902 node_sequence = | 903 node_sequence = |
| 903 parser.ParseConstructorClosure(func, &default_parameter_values); | 904 parser.ParseConstructorClosure(func, default_parameter_values); |
| 904 break; | 905 break; |
| 905 } | 906 } |
| 906 // Fall-through: Handle non-implicit closures. | 907 // Fall-through: Handle non-implicit closures. |
| 907 case RawFunction::kRegularFunction: | 908 case RawFunction::kRegularFunction: |
| 908 case RawFunction::kGetterFunction: | 909 case RawFunction::kGetterFunction: |
| 909 case RawFunction::kSetterFunction: | 910 case RawFunction::kSetterFunction: |
| 910 case RawFunction::kConstructor: | 911 case RawFunction::kConstructor: |
| 911 // The call to a redirecting factory is redirected. | 912 // The call to a redirecting factory is redirected. |
| 912 ASSERT(!func.IsRedirectingFactory()); | 913 ASSERT(!func.IsRedirectingFactory()); |
| 913 if (!func.IsImplicitConstructor()) { | 914 if (!func.IsImplicitConstructor()) { |
| 914 parser.SkipFunctionPreamble(); | 915 parser.SkipFunctionPreamble(); |
| 915 } | 916 } |
| 916 node_sequence = parser.ParseFunc(func, &default_parameter_values); | 917 node_sequence = parser.ParseFunc(func, default_parameter_values); |
| 917 break; | 918 break; |
| 918 case RawFunction::kImplicitGetter: | 919 case RawFunction::kImplicitGetter: |
| 919 ASSERT(!func.is_static()); | 920 ASSERT(!func.is_static()); |
| 920 node_sequence = parser.ParseInstanceGetter(func); | 921 node_sequence = parser.ParseInstanceGetter(func); |
| 921 break; | 922 break; |
| 922 case RawFunction::kImplicitSetter: | 923 case RawFunction::kImplicitSetter: |
| 923 ASSERT(!func.is_static()); | 924 ASSERT(!func.is_static()); |
| 924 node_sequence = parser.ParseInstanceSetter(func); | 925 node_sequence = parser.ParseInstanceSetter(func); |
| 925 break; | 926 break; |
| 926 case RawFunction::kImplicitStaticFinalGetter: | 927 case RawFunction::kImplicitStaticFinalGetter: |
| 927 node_sequence = parser.ParseStaticFinalGetter(func); | 928 node_sequence = parser.ParseStaticFinalGetter(func); |
| 928 INC_STAT(isolate, num_implicit_final_getters, 1); | 929 INC_STAT(isolate, num_implicit_final_getters, 1); |
| 929 break; | 930 break; |
| 930 case RawFunction::kMethodExtractor: | 931 case RawFunction::kMethodExtractor: |
| 931 node_sequence = parser.ParseMethodExtractor(func); | 932 node_sequence = parser.ParseMethodExtractor(func); |
| 932 break; | 933 break; |
| 933 case RawFunction::kNoSuchMethodDispatcher: | 934 case RawFunction::kNoSuchMethodDispatcher: |
| 934 node_sequence = | 935 node_sequence = |
| 935 parser.ParseNoSuchMethodDispatcher(func, &default_parameter_values); | 936 parser.ParseNoSuchMethodDispatcher(func, default_parameter_values); |
| 936 break; | 937 break; |
| 937 case RawFunction::kInvokeFieldDispatcher: | 938 case RawFunction::kInvokeFieldDispatcher: |
| 938 node_sequence = | 939 node_sequence = |
| 939 parser.ParseInvokeFieldDispatcher(func, &default_parameter_values); | 940 parser.ParseInvokeFieldDispatcher(func, default_parameter_values); |
| 940 break; | 941 break; |
| 941 case RawFunction::kIrregexpFunction: | 942 case RawFunction::kIrregexpFunction: |
| 942 UNREACHABLE(); // Irregexp functions have their own parser. | 943 UNREACHABLE(); // Irregexp functions have their own parser. |
| 943 default: | 944 default: |
| 944 UNREACHABLE(); | 945 UNREACHABLE(); |
| 945 } | 946 } |
| 946 | 947 |
| 947 if (parsed_function->has_expression_temp_var()) { | 948 if (parsed_function->has_expression_temp_var()) { |
| 948 node_sequence->scope()->AddVariable(parsed_function->expression_temp_var()); | 949 node_sequence->scope()->AddVariable(parsed_function->expression_temp_var()); |
| 949 } | 950 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 initializer.set_is_reflectable(false); | 1142 initializer.set_is_reflectable(false); |
| 1142 initializer.set_is_debuggable(false); | 1143 initializer.set_is_debuggable(false); |
| 1143 initializer.SetIsOptimizable(false); | 1144 initializer.SetIsOptimizable(false); |
| 1144 initializer.set_is_inlinable(false); | 1145 initializer.set_is_inlinable(false); |
| 1145 | 1146 |
| 1146 ParsedFunction* parsed_function = new ParsedFunction(thread, initializer); | 1147 ParsedFunction* parsed_function = new ParsedFunction(thread, initializer); |
| 1147 Parser parser(script, parsed_function, field.token_pos()); | 1148 Parser parser(script, parsed_function, field.token_pos()); |
| 1148 | 1149 |
| 1149 SequenceNode* body = parser.ParseStaticInitializer(); | 1150 SequenceNode* body = parser.ParseStaticInitializer(); |
| 1150 parsed_function->SetNodeSequence(body); | 1151 parsed_function->SetNodeSequence(body); |
| 1151 parsed_function->set_default_parameter_values(Object::null_array()); | |
| 1152 | 1152 |
| 1153 if (parsed_function->has_expression_temp_var()) { | 1153 if (parsed_function->has_expression_temp_var()) { |
| 1154 body->scope()->AddVariable(parsed_function->expression_temp_var()); | 1154 body->scope()->AddVariable(parsed_function->expression_temp_var()); |
| 1155 } | 1155 } |
| 1156 body->scope()->AddVariable(parsed_function->current_context_var()); | 1156 body->scope()->AddVariable(parsed_function->current_context_var()); |
| 1157 if (parsed_function->has_finally_return_temp_var()) { | 1157 if (parsed_function->has_finally_return_temp_var()) { |
| 1158 body->scope()->AddVariable(parsed_function->finally_return_temp_var()); | 1158 body->scope()->AddVariable(parsed_function->finally_return_temp_var()); |
| 1159 } | 1159 } |
| 1160 // The instantiator is not required in a static expression. | 1160 // The instantiator is not required in a static expression. |
| 1161 ASSERT(!parser.IsInstantiatorRequired()); | 1161 ASSERT(!parser.IsInstantiatorRequired()); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 | 1327 |
| 1328 EnsureExpressionTemp(); | 1328 EnsureExpressionTemp(); |
| 1329 StoreInstanceFieldNode* store_field = | 1329 StoreInstanceFieldNode* store_field = |
| 1330 new StoreInstanceFieldNode(ident_pos, receiver, field, value); | 1330 new StoreInstanceFieldNode(ident_pos, receiver, field, value); |
| 1331 current_block_->statements->Add(store_field); | 1331 current_block_->statements->Add(store_field); |
| 1332 current_block_->statements->Add(new ReturnNode(Scanner::kNoSourcePos)); | 1332 current_block_->statements->Add(new ReturnNode(Scanner::kNoSourcePos)); |
| 1333 return CloseBlock(); | 1333 return CloseBlock(); |
| 1334 } | 1334 } |
| 1335 | 1335 |
| 1336 | 1336 |
| 1337 SequenceNode* Parser::ParseConstructorClosure(const Function& func, | 1337 SequenceNode* Parser::ParseConstructorClosure( |
| 1338 Array* default_values) { | 1338 const Function& func, |
| 1339 ZoneGrowableArray<const Instance*>* default_values) { |
| 1339 TRACE_PARSER("ParseConstructorClosure"); | 1340 TRACE_PARSER("ParseConstructorClosure"); |
| 1340 const intptr_t token_pos = func.token_pos(); | 1341 const intptr_t token_pos = func.token_pos(); |
| 1341 | 1342 |
| 1342 Function& constructor = Function::ZoneHandle(Z); | 1343 Function& constructor = Function::ZoneHandle(Z); |
| 1343 TypeArguments& type_args = TypeArguments::ZoneHandle(Z); | 1344 TypeArguments& type_args = TypeArguments::ZoneHandle(Z); |
| 1344 ParseConstructorClosurization(&constructor, &type_args); | 1345 ParseConstructorClosurization(&constructor, &type_args); |
| 1345 ASSERT(!constructor.IsNull()); | 1346 ASSERT(!constructor.IsNull()); |
| 1346 | 1347 |
| 1347 ParamList params; | 1348 ParamList params; |
| 1348 // The first parameter of the closure function is the implicit closure | 1349 // The first parameter of the closure function is the implicit closure |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1382 } | 1383 } |
| 1383 | 1384 |
| 1384 AstNode* new_object = | 1385 AstNode* new_object = |
| 1385 CreateConstructorCallNode(token_pos, type_args, constructor, ctor_args); | 1386 CreateConstructorCallNode(token_pos, type_args, constructor, ctor_args); |
| 1386 ReturnNode* return_node = new ReturnNode(token_pos, new_object); | 1387 ReturnNode* return_node = new ReturnNode(token_pos, new_object); |
| 1387 current_block_->statements->Add(return_node); | 1388 current_block_->statements->Add(return_node); |
| 1388 return CloseBlock(); | 1389 return CloseBlock(); |
| 1389 } | 1390 } |
| 1390 | 1391 |
| 1391 | 1392 |
| 1392 SequenceNode* Parser::ParseImplicitClosure(const Function& func, | 1393 SequenceNode* Parser::ParseImplicitClosure( |
| 1393 Array* default_values) { | 1394 const Function& func, ZoneGrowableArray<const Instance*>* default_values) { |
| 1394 TRACE_PARSER("ParseImplicitClosure"); | 1395 TRACE_PARSER("ParseImplicitClosure"); |
| 1395 intptr_t token_pos = func.token_pos(); | 1396 intptr_t token_pos = func.token_pos(); |
| 1396 | 1397 |
| 1397 OpenFunctionBlock(func); | 1398 OpenFunctionBlock(func); |
| 1398 | 1399 |
| 1399 ParamList params; | 1400 ParamList params; |
| 1400 params.AddFinalParameter( | 1401 params.AddFinalParameter( |
| 1401 token_pos, | 1402 token_pos, |
| 1402 &Symbols::ClosureParameter(), | 1403 &Symbols::ClosureParameter(), |
| 1403 &Type::ZoneHandle(Type::DynamicType())); | 1404 &Type::ZoneHandle(Type::DynamicType())); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1477 Function::ZoneHandle(Z, func.extracted_method_closure()), | 1478 Function::ZoneHandle(Z, func.extracted_method_closure()), |
| 1478 load_receiver, | 1479 load_receiver, |
| 1479 NULL); | 1480 NULL); |
| 1480 | 1481 |
| 1481 ReturnNode* return_node = new ReturnNode(Scanner::kNoSourcePos, closure); | 1482 ReturnNode* return_node = new ReturnNode(Scanner::kNoSourcePos, closure); |
| 1482 current_block_->statements->Add(return_node); | 1483 current_block_->statements->Add(return_node); |
| 1483 return CloseBlock(); | 1484 return CloseBlock(); |
| 1484 } | 1485 } |
| 1485 | 1486 |
| 1486 | 1487 |
| 1487 void Parser::BuildDispatcherScope(const Function& func, | 1488 void Parser::BuildDispatcherScope( |
| 1488 const ArgumentsDescriptor& desc, | 1489 const Function& func, |
| 1489 Array* default_values) { | 1490 const ArgumentsDescriptor& desc, |
| 1491 ZoneGrowableArray<const Instance*>* default_values) { |
| 1490 ParamList params; | 1492 ParamList params; |
| 1491 // Receiver first. | 1493 // Receiver first. |
| 1492 intptr_t token_pos = func.token_pos(); | 1494 intptr_t token_pos = func.token_pos(); |
| 1493 params.AddReceiver(ReceiverType(current_class()), token_pos); | 1495 params.AddReceiver(ReceiverType(current_class()), token_pos); |
| 1494 // Remaining positional parameters. | 1496 // Remaining positional parameters. |
| 1495 intptr_t i = 1; | 1497 intptr_t i = 1; |
| 1496 for (; i < desc.PositionalCount(); ++i) { | 1498 for (; i < desc.PositionalCount(); ++i) { |
| 1497 ParamDesc p; | 1499 ParamDesc p; |
| 1498 char name[64]; | 1500 char name[64]; |
| 1499 OS::SNPrint(name, 64, ":p%" Pd, i); | 1501 OS::SNPrint(name, 64, ":p%" Pd, i); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1517 } | 1519 } |
| 1518 ASSERT(desc.NamedCount() == params.num_optional_parameters); | 1520 ASSERT(desc.NamedCount() == params.num_optional_parameters); |
| 1519 | 1521 |
| 1520 SetupDefaultsForOptionalParams(params, default_values); | 1522 SetupDefaultsForOptionalParams(params, default_values); |
| 1521 | 1523 |
| 1522 // Build local scope for function and populate with the formal parameters. | 1524 // Build local scope for function and populate with the formal parameters. |
| 1523 OpenFunctionBlock(func); | 1525 OpenFunctionBlock(func); |
| 1524 AddFormalParamsToScope(¶ms, current_block_->scope); | 1526 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 1525 } | 1527 } |
| 1526 | 1528 |
| 1527 SequenceNode* Parser::ParseNoSuchMethodDispatcher(const Function& func, | 1529 SequenceNode* Parser::ParseNoSuchMethodDispatcher( |
| 1528 Array* default_values) { | 1530 const Function& func, |
| 1531 ZoneGrowableArray<const Instance*>* default_values) { |
| 1529 TRACE_PARSER("ParseNoSuchMethodDispatcher"); | 1532 TRACE_PARSER("ParseNoSuchMethodDispatcher"); |
| 1530 ASSERT(FLAG_lazy_dispatchers); | 1533 ASSERT(FLAG_lazy_dispatchers); |
| 1531 | 1534 |
| 1532 ASSERT(func.IsNoSuchMethodDispatcher()); | 1535 ASSERT(func.IsNoSuchMethodDispatcher()); |
| 1533 intptr_t token_pos = func.token_pos(); | 1536 intptr_t token_pos = func.token_pos(); |
| 1534 ASSERT(func.token_pos() == 0); | 1537 ASSERT(func.token_pos() == 0); |
| 1535 ASSERT(current_class().raw() == func.Owner()); | 1538 ASSERT(current_class().raw() == func.Owner()); |
| 1536 | 1539 |
| 1537 ArgumentsDescriptor desc(Array::Handle(Z, func.saved_args_desc())); | 1540 ArgumentsDescriptor desc(Array::Handle(Z, func.saved_args_desc())); |
| 1538 ASSERT(desc.Count() > 0); | 1541 ASSERT(desc.Count() > 0); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1575 } | 1578 } |
| 1576 StaticCallNode* call = | 1579 StaticCallNode* call = |
| 1577 new StaticCallNode(token_pos, no_such_method, arguments); | 1580 new StaticCallNode(token_pos, no_such_method, arguments); |
| 1578 | 1581 |
| 1579 ReturnNode* return_node = new ReturnNode(token_pos, call); | 1582 ReturnNode* return_node = new ReturnNode(token_pos, call); |
| 1580 current_block_->statements->Add(return_node); | 1583 current_block_->statements->Add(return_node); |
| 1581 return CloseBlock(); | 1584 return CloseBlock(); |
| 1582 } | 1585 } |
| 1583 | 1586 |
| 1584 | 1587 |
| 1585 SequenceNode* Parser::ParseInvokeFieldDispatcher(const Function& func, | 1588 SequenceNode* Parser::ParseInvokeFieldDispatcher( |
| 1586 Array* default_values) { | 1589 const Function& func, |
| 1590 ZoneGrowableArray<const Instance*>* default_values) { |
| 1587 TRACE_PARSER("ParseInvokeFieldDispatcher"); | 1591 TRACE_PARSER("ParseInvokeFieldDispatcher"); |
| 1588 ASSERT(FLAG_lazy_dispatchers); | 1592 ASSERT(FLAG_lazy_dispatchers); |
| 1589 | 1593 |
| 1590 ASSERT(func.IsInvokeFieldDispatcher()); | 1594 ASSERT(func.IsInvokeFieldDispatcher()); |
| 1591 intptr_t token_pos = func.token_pos(); | 1595 intptr_t token_pos = func.token_pos(); |
| 1592 ASSERT(func.token_pos() == 0); | 1596 ASSERT(func.token_pos() == 0); |
| 1593 ASSERT(current_class().raw() == func.Owner()); | 1597 ASSERT(current_class().raw() == func.Owner()); |
| 1594 | 1598 |
| 1595 const Array& args_desc = Array::Handle(Z, func.saved_args_desc()); | 1599 const Array& args_desc = Array::Handle(Z, func.saved_args_desc()); |
| 1596 ArgumentsDescriptor desc(args_desc); | 1600 ArgumentsDescriptor desc(args_desc); |
| (...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2900 } | 2904 } |
| 2901 } | 2905 } |
| 2902 ASSERT(!unregister_pending_function_); | 2906 ASSERT(!unregister_pending_function_); |
| 2903 pending_functions.Add(current_function()); | 2907 pending_functions.Add(current_function()); |
| 2904 unregister_pending_function_ = true; | 2908 unregister_pending_function_ = true; |
| 2905 } | 2909 } |
| 2906 | 2910 |
| 2907 | 2911 |
| 2908 // Parser is at the opening parenthesis of the formal parameter declaration | 2912 // Parser is at the opening parenthesis of the formal parameter declaration |
| 2909 // of function. Parse the formal parameters, initializers and code. | 2913 // of function. Parse the formal parameters, initializers and code. |
| 2910 SequenceNode* Parser::ParseConstructor(const Function& func, | 2914 SequenceNode* Parser::ParseConstructor( |
| 2911 Array* default_parameter_values) { | 2915 const Function& func, |
| 2916 ZoneGrowableArray<const Instance*>* default_parameter_values) { |
| 2912 TRACE_PARSER("ParseConstructor"); | 2917 TRACE_PARSER("ParseConstructor"); |
| 2913 ASSERT(func.IsGenerativeConstructor()); | 2918 ASSERT(func.IsGenerativeConstructor()); |
| 2914 ASSERT(!func.IsFactory()); | 2919 ASSERT(!func.IsFactory()); |
| 2915 ASSERT(!func.is_static()); | 2920 ASSERT(!func.is_static()); |
| 2916 ASSERT(!func.IsLocalFunction()); | 2921 ASSERT(!func.IsLocalFunction()); |
| 2917 const Class& cls = Class::Handle(Z, func.Owner()); | 2922 const Class& cls = Class::Handle(Z, func.Owner()); |
| 2918 ASSERT(!cls.IsNull()); | 2923 ASSERT(!cls.IsNull()); |
| 2919 | 2924 |
| 2920 CheckRecursiveInvocation(); | 2925 CheckRecursiveInvocation(); |
| 2921 | 2926 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3209 } | 3214 } |
| 3210 current_block_->statements->Add(new ReturnNode(func.end_token_pos())); | 3215 current_block_->statements->Add(new ReturnNode(func.end_token_pos())); |
| 3211 SequenceNode* statements = CloseBlock(); | 3216 SequenceNode* statements = CloseBlock(); |
| 3212 return statements; | 3217 return statements; |
| 3213 } | 3218 } |
| 3214 | 3219 |
| 3215 | 3220 |
| 3216 // Parser is at the opening parenthesis of the formal parameter | 3221 // Parser is at the opening parenthesis of the formal parameter |
| 3217 // declaration of the function or constructor. | 3222 // declaration of the function or constructor. |
| 3218 // Parse the formal parameters and code. | 3223 // Parse the formal parameters and code. |
| 3219 SequenceNode* Parser::ParseFunc(const Function& func, | 3224 SequenceNode* Parser::ParseFunc( |
| 3220 Array* default_parameter_values) { | 3225 const Function& func, |
| 3226 ZoneGrowableArray<const Instance*>* default_parameter_values) { |
| 3221 TRACE_PARSER("ParseFunc"); | 3227 TRACE_PARSER("ParseFunc"); |
| 3222 Function& saved_innermost_function = | 3228 Function& saved_innermost_function = |
| 3223 Function::Handle(Z, innermost_function().raw()); | 3229 Function::Handle(Z, innermost_function().raw()); |
| 3224 innermost_function_ = func.raw(); | 3230 innermost_function_ = func.raw(); |
| 3225 | 3231 |
| 3226 // Save current try index. Try index starts at zero for each function. | 3232 // Save current try index. Try index starts at zero for each function. |
| 3227 intptr_t saved_try_index = last_used_try_index_; | 3233 intptr_t saved_try_index = last_used_try_index_; |
| 3228 last_used_try_index_ = 0; | 3234 last_used_try_index_ = 0; |
| 3229 | 3235 |
| 3230 // In case of nested async functions we also need to save the scope where | 3236 // In case of nested async functions we also need to save the scope where |
| (...skipping 3987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7218 ASSERT(new_body->scope() != NULL); | 7224 ASSERT(new_body->scope() != NULL); |
| 7219 new_body->scope()->LookupVariable(Symbols::AwaitJumpVar(), false); | 7225 new_body->scope()->LookupVariable(Symbols::AwaitJumpVar(), false); |
| 7220 new_body->scope()->LookupVariable(Symbols::AwaitContextVar(), false); | 7226 new_body->scope()->LookupVariable(Symbols::AwaitContextVar(), false); |
| 7221 new_body->scope()->LookupVariable(Symbols::AsyncCompleter(), false); | 7227 new_body->scope()->LookupVariable(Symbols::AsyncCompleter(), false); |
| 7222 new_body->scope()->RecursivelyCaptureAllVariables(); | 7228 new_body->scope()->RecursivelyCaptureAllVariables(); |
| 7223 return new_body; | 7229 return new_body; |
| 7224 } | 7230 } |
| 7225 | 7231 |
| 7226 | 7232 |
| 7227 // Set up default values for all optional parameters to the function. | 7233 // Set up default values for all optional parameters to the function. |
| 7228 void Parser::SetupDefaultsForOptionalParams(const ParamList& params, | 7234 void Parser::SetupDefaultsForOptionalParams( |
| 7229 Array* default_values) { | 7235 const ParamList& params, |
| 7236 ZoneGrowableArray<const Instance*>* default_values) { |
| 7230 if (params.num_optional_parameters > 0) { | 7237 if (params.num_optional_parameters > 0) { |
| 7231 // Build array of default parameter values. | 7238 // Build array of default parameter values. |
| 7232 *default_values = Array::New(params.num_optional_parameters); | |
| 7233 const ZoneGrowableArray<ParamDesc>& parameters = *params.parameters; | 7239 const ZoneGrowableArray<ParamDesc>& parameters = *params.parameters; |
| 7234 const int first_opt_param_offset = params.num_fixed_parameters; | 7240 const int first_opt_param_offset = params.num_fixed_parameters; |
| 7235 for (int i = 0; i < params.num_optional_parameters; i++) { | 7241 for (int i = 0; i < params.num_optional_parameters; i++) { |
| 7236 const Object* default_value = | 7242 const Instance* default_value = |
| 7237 parameters[i + first_opt_param_offset].default_value; | 7243 parameters[i + first_opt_param_offset].default_value; |
| 7238 default_values->SetAt(i, *default_value); | 7244 default_values->Add(default_value); |
| 7239 } | 7245 } |
| 7240 } | 7246 } |
| 7241 } | 7247 } |
| 7242 | 7248 |
| 7243 | 7249 |
| 7244 // Populate the parameter type array and parameter name array of the function | 7250 // Populate the parameter type array and parameter name array of the function |
| 7245 // with the formal parameter types and names. | 7251 // with the formal parameter types and names. |
| 7246 void Parser::AddFormalParamsToFunction(const ParamList* params, | 7252 void Parser::AddFormalParamsToFunction(const ParamList* params, |
| 7247 const Function& func) { | 7253 const Function& func) { |
| 7248 ASSERT((params != NULL) && (params->parameters != NULL)); | 7254 ASSERT((params != NULL) && (params->parameters != NULL)); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7665 } else { | 7671 } else { |
| 7666 ReportError(function_pos, | 7672 ReportError(function_pos, |
| 7667 "'%s' from outer scope has already been used, " | 7673 "'%s' from outer scope has already been used, " |
| 7668 "cannot redefine", | 7674 "cannot redefine", |
| 7669 function_variable->name().ToCString()); | 7675 function_variable->name().ToCString()); |
| 7670 } | 7676 } |
| 7671 } | 7677 } |
| 7672 } | 7678 } |
| 7673 | 7679 |
| 7674 // Parse the local function. | 7680 // Parse the local function. |
| 7675 Array& default_parameter_values = Array::Handle(Z); | 7681 ZoneGrowableArray<const Instance*>* default_parameter_values = |
| 7682 new ZoneGrowableArray<const Instance*>(Z, 2); |
| 7676 SequenceNode* statements = Parser::ParseFunc(function, | 7683 SequenceNode* statements = Parser::ParseFunc(function, |
| 7677 &default_parameter_values); | 7684 default_parameter_values); |
| 7678 | 7685 |
| 7679 // Now that the local function has formal parameters, lookup the signature | 7686 // Now that the local function has formal parameters, lookup the signature |
| 7680 // class in the current library (but not in its imports) and only create a new | 7687 // class in the current library (but not in its imports) and only create a new |
| 7681 // canonical signature class if it does not exist yet. | 7688 // canonical signature class if it does not exist yet. |
| 7682 const String& signature = String::Handle(Z, function.Signature()); | 7689 const String& signature = String::Handle(Z, function.Signature()); |
| 7683 Class& signature_class = Class::ZoneHandle(Z); | 7690 Class& signature_class = Class::ZoneHandle(Z); |
| 7684 if (!is_new_closure) { | 7691 if (!is_new_closure) { |
| 7685 signature_class = function.signature_class(); | 7692 signature_class = function.signature_class(); |
| 7686 } | 7693 } |
| 7687 if (signature_class.IsNull()) { | 7694 if (signature_class.IsNull()) { |
| (...skipping 6485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14173 void Parser::SkipQualIdent() { | 14180 void Parser::SkipQualIdent() { |
| 14174 ASSERT(IsIdentifier()); | 14181 ASSERT(IsIdentifier()); |
| 14175 ConsumeToken(); | 14182 ConsumeToken(); |
| 14176 if (CurrentToken() == Token::kPERIOD) { | 14183 if (CurrentToken() == Token::kPERIOD) { |
| 14177 ConsumeToken(); // Consume the kPERIOD token. | 14184 ConsumeToken(); // Consume the kPERIOD token. |
| 14178 ExpectIdentifier("identifier expected after '.'"); | 14185 ExpectIdentifier("identifier expected after '.'"); |
| 14179 } | 14186 } |
| 14180 } | 14187 } |
| 14181 | 14188 |
| 14182 } // namespace dart | 14189 } // namespace dart |
| OLD | NEW |