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 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer); | 851 TimerScope timer(FLAG_compiler_stats, &CompilerStats::parser_timer); |
852 CompilerStats::num_functions_compiled++; | 852 CompilerStats::num_functions_compiled++; |
853 ASSERT(isolate->long_jump_base()->IsSafeToJump()); | 853 ASSERT(isolate->long_jump_base()->IsSafeToJump()); |
854 ASSERT(parsed_function != NULL); | 854 ASSERT(parsed_function != NULL); |
855 const Function& func = parsed_function->function(); | 855 const Function& func = parsed_function->function(); |
856 const Script& script = Script::Handle(zone, func.script()); | 856 const Script& script = Script::Handle(zone, func.script()); |
857 Parser parser(script, parsed_function, func.token_pos()); | 857 Parser parser(script, parsed_function, func.token_pos()); |
858 SequenceNode* node_sequence = NULL; | 858 SequenceNode* node_sequence = NULL; |
859 Array& default_parameter_values = Array::ZoneHandle(zone, Array::null()); | 859 Array& default_parameter_values = Array::ZoneHandle(zone, Array::null()); |
860 switch (func.kind()) { | 860 switch (func.kind()) { |
| 861 case RawFunction::kClosureFunction: |
| 862 if (func.IsImplicitClosureFunction()) { |
| 863 parser.SkipFunctionPreamble(); |
| 864 node_sequence = |
| 865 parser.ParseImplicitClosure(func, &default_parameter_values); |
| 866 break; |
| 867 } |
| 868 // Fall-through: Handle non-implicit closures. |
861 case RawFunction::kRegularFunction: | 869 case RawFunction::kRegularFunction: |
862 case RawFunction::kClosureFunction: | |
863 case RawFunction::kGetterFunction: | 870 case RawFunction::kGetterFunction: |
864 case RawFunction::kSetterFunction: | 871 case RawFunction::kSetterFunction: |
865 case RawFunction::kConstructor: | 872 case RawFunction::kConstructor: |
866 // The call to a redirecting factory is redirected. | 873 // The call to a redirecting factory is redirected. |
867 ASSERT(!func.IsRedirectingFactory()); | 874 ASSERT(!func.IsRedirectingFactory()); |
868 if (!func.IsImplicitConstructor()) { | 875 if (!func.IsImplicitConstructor()) { |
869 parser.SkipFunctionPreamble(); | 876 parser.SkipFunctionPreamble(); |
870 } | 877 } |
871 node_sequence = parser.ParseFunc(func, &default_parameter_values); | 878 node_sequence = parser.ParseFunc(func, &default_parameter_values); |
872 break; | 879 break; |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1294 | 1301 |
1295 EnsureExpressionTemp(); | 1302 EnsureExpressionTemp(); |
1296 StoreInstanceFieldNode* store_field = | 1303 StoreInstanceFieldNode* store_field = |
1297 new StoreInstanceFieldNode(ident_pos, receiver, field, value); | 1304 new StoreInstanceFieldNode(ident_pos, receiver, field, value); |
1298 current_block_->statements->Add(store_field); | 1305 current_block_->statements->Add(store_field); |
1299 current_block_->statements->Add(new ReturnNode(Scanner::kNoSourcePos)); | 1306 current_block_->statements->Add(new ReturnNode(Scanner::kNoSourcePos)); |
1300 return CloseBlock(); | 1307 return CloseBlock(); |
1301 } | 1308 } |
1302 | 1309 |
1303 | 1310 |
| 1311 SequenceNode* Parser::ParseImplicitClosure(const Function& func, |
| 1312 Array* default_values) { |
| 1313 TRACE_PARSER("ParseImplicitClosure"); |
| 1314 |
| 1315 intptr_t token_pos = func.token_pos(); |
| 1316 |
| 1317 OpenFunctionBlock(func); |
| 1318 |
| 1319 ParamList params; |
| 1320 |
| 1321 params.AddFinalParameter( |
| 1322 token_pos, |
| 1323 &Symbols::ClosureParameter(), |
| 1324 &Type::ZoneHandle(Type::DynamicType())); |
| 1325 |
| 1326 const bool allow_explicit_default_values = true; |
| 1327 ParseFormalParameterList(allow_explicit_default_values, false, ¶ms); |
| 1328 SetupDefaultsForOptionalParams(¶ms, default_values); |
| 1329 |
| 1330 // Getters can't be closurized. If supported, they need special |
| 1331 // handling of the parameters as in ParseFunc. |
| 1332 const Function& parent = Function::ZoneHandle(func.parent_function()); |
| 1333 ASSERT(!parent.IsGetterFunction()); |
| 1334 |
| 1335 // Populate function scope with the formal parameters. |
| 1336 LocalScope* scope = current_block_->scope; |
| 1337 AddFormalParamsToScope(¶ms, scope); |
| 1338 |
| 1339 ArgumentListNode* func_args = new ArgumentListNode(token_pos); |
| 1340 if (!func.is_static()) { |
| 1341 func_args->Add(LoadReceiver(token_pos)); |
| 1342 } |
| 1343 // Skip implicit parameter at 0. |
| 1344 for (intptr_t i = 1; i < func.NumParameters(); ++i) { |
| 1345 func_args->Add(new LoadLocalNode(token_pos, scope->VariableAt(i))); |
| 1346 } |
| 1347 |
| 1348 if (func.HasOptionalNamedParameters()) { |
| 1349 const Array& arg_names = |
| 1350 Array::ZoneHandle(Array::New(func.NumOptionalParameters())); |
| 1351 for (intptr_t i = 0; i < arg_names.Length(); ++i) { |
| 1352 intptr_t index = func.num_fixed_parameters() + i; |
| 1353 arg_names.SetAt(i, String::Handle(func.ParameterNameAt(index))); |
| 1354 } |
| 1355 func_args->set_names(arg_names); |
| 1356 } |
| 1357 StaticCallNode* call = new StaticCallNode(token_pos, parent, func_args); |
| 1358 ReturnNode* return_node = new ReturnNode(token_pos, call); |
| 1359 current_block_->statements->Add(return_node); |
| 1360 return CloseBlock(); |
| 1361 } |
| 1362 |
| 1363 |
1304 SequenceNode* Parser::ParseMethodExtractor(const Function& func) { | 1364 SequenceNode* Parser::ParseMethodExtractor(const Function& func) { |
1305 TRACE_PARSER("ParseMethodExtractor"); | 1365 TRACE_PARSER("ParseMethodExtractor"); |
1306 ParamList params; | 1366 ParamList params; |
1307 | 1367 |
1308 const intptr_t ident_pos = func.token_pos(); | 1368 const intptr_t ident_pos = func.token_pos(); |
1309 ASSERT(func.token_pos() == 0); | 1369 ASSERT(func.token_pos() == 0); |
1310 ASSERT(current_class().raw() == func.Owner()); | 1370 ASSERT(current_class().raw() == func.Owner()); |
1311 params.AddReceiver(ReceiverType(current_class()), ident_pos); | 1371 params.AddReceiver(ReceiverType(current_class()), ident_pos); |
1312 ASSERT(func.num_fixed_parameters() == 1); // Receiver. | 1372 ASSERT(func.num_fixed_parameters() == 1); // Receiver. |
1313 ASSERT(!func.HasOptionalParameters()); | 1373 ASSERT(!func.HasOptionalParameters()); |
(...skipping 11907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13221 void Parser::SkipQualIdent() { | 13281 void Parser::SkipQualIdent() { |
13222 ASSERT(IsIdentifier()); | 13282 ASSERT(IsIdentifier()); |
13223 ConsumeToken(); | 13283 ConsumeToken(); |
13224 if (CurrentToken() == Token::kPERIOD) { | 13284 if (CurrentToken() == Token::kPERIOD) { |
13225 ConsumeToken(); // Consume the kPERIOD token. | 13285 ConsumeToken(); // Consume the kPERIOD token. |
13226 ExpectIdentifier("identifier expected after '.'"); | 13286 ExpectIdentifier("identifier expected after '.'"); |
13227 } | 13287 } |
13228 } | 13288 } |
13229 | 13289 |
13230 } // namespace dart | 13290 } // namespace dart |
OLD | NEW |