Chromium Code Reviews| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 Symbols::ExprTemp(), | 120 Symbols::ExprTemp(), |
| 121 Type::ZoneHandle(Type::DynamicType())); | 121 Type::ZoneHandle(Type::DynamicType())); |
| 122 ASSERT(temp != NULL); | 122 ASSERT(temp != NULL); |
| 123 set_expression_temp_var(temp); | 123 set_expression_temp_var(temp); |
| 124 } | 124 } |
| 125 ASSERT(has_expression_temp_var()); | 125 ASSERT(has_expression_temp_var()); |
| 126 return expression_temp_var(); | 126 return expression_temp_var(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 | 129 |
| 130 LocalVariable* ParsedFunction::EnsureSavedCurrentContext() { | |
|
hausner
2014/10/29 16:44:34
Now that every function has a local variable to st
Florian Schneider
2014/10/29 17:50:45
Done. Yes, I can now remove this function.
| |
| 131 if (!has_current_context_var()) { | |
| 132 LocalVariable* temp = new(I) LocalVariable( | |
| 133 function().token_pos(), | |
| 134 Symbols::CurrentContextVar(), | |
| 135 Type::ZoneHandle(I, Type::DynamicType())); | |
| 136 ASSERT(temp != NULL); | |
| 137 set_current_context_var(temp); | |
| 138 } | |
| 139 return current_context_var(); | |
| 140 } | |
| 141 | |
| 142 | |
| 130 void ParsedFunction::EnsureFinallyReturnTemp() { | 143 void ParsedFunction::EnsureFinallyReturnTemp() { |
| 131 if (!has_finally_return_temp_var()) { | 144 if (!has_finally_return_temp_var()) { |
| 132 LocalVariable* temp = new(I) LocalVariable( | 145 LocalVariable* temp = new(I) LocalVariable( |
| 133 function_.token_pos(), | 146 function_.token_pos(), |
| 134 String::ZoneHandle(I, Symbols::New(":finally_ret_val")), | 147 String::ZoneHandle(I, Symbols::New(":finally_ret_val")), |
| 135 Type::ZoneHandle(I, Type::DynamicType())); | 148 Type::ZoneHandle(I, Type::DynamicType())); |
| 136 ASSERT(temp != NULL); | 149 ASSERT(temp != NULL); |
| 137 temp->set_is_final(); | 150 temp->set_is_final(); |
| 138 set_finally_return_temp_var(temp); | 151 set_finally_return_temp_var(temp); |
| 139 } | 152 } |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 parsed_function->function().origin()).library())), | 351 parsed_function->function().origin()).library())), |
| 339 try_blocks_list_(NULL), | 352 try_blocks_list_(NULL), |
| 340 last_used_try_index_(0), | 353 last_used_try_index_(0), |
| 341 unregister_pending_function_(false), | 354 unregister_pending_function_(false), |
| 342 async_temp_scope_(NULL) { | 355 async_temp_scope_(NULL) { |
| 343 ASSERT(tokens_iterator_.IsValid()); | 356 ASSERT(tokens_iterator_.IsValid()); |
| 344 ASSERT(!current_function().IsNull()); | 357 ASSERT(!current_function().IsNull()); |
| 345 if (FLAG_enable_type_checks) { | 358 if (FLAG_enable_type_checks) { |
| 346 EnsureExpressionTemp(); | 359 EnsureExpressionTemp(); |
| 347 } | 360 } |
| 361 EnsureSavedCurrentContext(); | |
| 348 } | 362 } |
| 349 | 363 |
| 350 | 364 |
| 351 Parser::~Parser() { | 365 Parser::~Parser() { |
| 352 if (unregister_pending_function_) { | 366 if (unregister_pending_function_) { |
| 353 const GrowableObjectArray& pending_functions = | 367 const GrowableObjectArray& pending_functions = |
| 354 GrowableObjectArray::Handle(I->object_store()->pending_functions()); | 368 GrowableObjectArray::Handle(I->object_store()->pending_functions()); |
| 355 ASSERT(pending_functions.Length() > 0); | 369 ASSERT(pending_functions.Length() > 0); |
| 356 ASSERT(pending_functions.At(pending_functions.Length()-1) == | 370 ASSERT(pending_functions.At(pending_functions.Length()-1) == |
| 357 current_function().raw()); | 371 current_function().raw()); |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 857 UNREACHABLE(); | 871 UNREACHABLE(); |
| 858 } | 872 } |
| 859 | 873 |
| 860 if (!HasReturnNode(node_sequence)) { | 874 if (!HasReturnNode(node_sequence)) { |
| 861 // Add implicit return node. | 875 // Add implicit return node. |
| 862 node_sequence->Add(new ReturnNode(func.end_token_pos())); | 876 node_sequence->Add(new ReturnNode(func.end_token_pos())); |
| 863 } | 877 } |
| 864 if (parsed_function->has_expression_temp_var()) { | 878 if (parsed_function->has_expression_temp_var()) { |
| 865 node_sequence->scope()->AddVariable(parsed_function->expression_temp_var()); | 879 node_sequence->scope()->AddVariable(parsed_function->expression_temp_var()); |
| 866 } | 880 } |
| 867 if (parsed_function->has_saved_current_context_var()) { | 881 if (parsed_function->has_current_context_var()) { |
|
hausner
2014/10/29 16:44:34
This is always true now, correct?
Florian Schneider
2014/10/29 17:50:45
Done.
| |
| 868 node_sequence->scope()->AddVariable( | 882 node_sequence->scope()->AddVariable( |
| 869 parsed_function->saved_current_context_var()); | 883 parsed_function->current_context_var()); |
| 870 } | 884 } |
| 871 if (parsed_function->has_finally_return_temp_var()) { | 885 if (parsed_function->has_finally_return_temp_var()) { |
| 872 node_sequence->scope()->AddVariable( | 886 node_sequence->scope()->AddVariable( |
| 873 parsed_function->finally_return_temp_var()); | 887 parsed_function->finally_return_temp_var()); |
| 874 } | 888 } |
| 875 parsed_function->SetNodeSequence(node_sequence); | 889 parsed_function->SetNodeSequence(node_sequence); |
| 876 | 890 |
| 877 // The instantiator may be required at run time for generic type checks or | 891 // The instantiator may be required at run time for generic type checks or |
| 878 // allocation of generic types. | 892 // allocation of generic types. |
| 879 if (parser.IsInstantiatorRequired()) { | 893 if (parser.IsInstantiatorRequired()) { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1061 ParsedFunction* parsed_function = new ParsedFunction(isolate, initializer); | 1075 ParsedFunction* parsed_function = new ParsedFunction(isolate, initializer); |
| 1062 Parser parser(script, parsed_function, field.token_pos()); | 1076 Parser parser(script, parsed_function, field.token_pos()); |
| 1063 | 1077 |
| 1064 SequenceNode* body = parser.ParseStaticInitializer(); | 1078 SequenceNode* body = parser.ParseStaticInitializer(); |
| 1065 parsed_function->SetNodeSequence(body); | 1079 parsed_function->SetNodeSequence(body); |
| 1066 parsed_function->set_default_parameter_values(Object::null_array()); | 1080 parsed_function->set_default_parameter_values(Object::null_array()); |
| 1067 | 1081 |
| 1068 if (parsed_function->has_expression_temp_var()) { | 1082 if (parsed_function->has_expression_temp_var()) { |
| 1069 body->scope()->AddVariable(parsed_function->expression_temp_var()); | 1083 body->scope()->AddVariable(parsed_function->expression_temp_var()); |
| 1070 } | 1084 } |
| 1071 if (parsed_function->has_saved_current_context_var()) { | 1085 if (parsed_function->has_current_context_var()) { |
|
hausner
2014/10/29 16:44:34
ditto
Florian Schneider
2014/10/29 17:50:45
Done.
| |
| 1072 body->scope()->AddVariable(parsed_function->saved_current_context_var()); | 1086 body->scope()->AddVariable(parsed_function->current_context_var()); |
| 1073 } | 1087 } |
| 1074 if (parsed_function->has_finally_return_temp_var()) { | 1088 if (parsed_function->has_finally_return_temp_var()) { |
| 1075 body->scope()->AddVariable(parsed_function->finally_return_temp_var()); | 1089 body->scope()->AddVariable(parsed_function->finally_return_temp_var()); |
| 1076 } | 1090 } |
| 1077 // The instantiator is not required in a static expression. | 1091 // The instantiator is not required in a static expression. |
| 1078 ASSERT(!parser.IsInstantiatorRequired()); | 1092 ASSERT(!parser.IsInstantiatorRequired()); |
| 1079 | 1093 |
| 1080 return parsed_function; | 1094 return parsed_function; |
| 1081 } | 1095 } |
| 1082 | 1096 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1380 args->Add(new(I) LoadLocalNode(token_pos, scope->VariableAt(i))); | 1394 args->Add(new(I) LoadLocalNode(token_pos, scope->VariableAt(i))); |
| 1381 intptr_t index = i - desc.PositionalCount(); | 1395 intptr_t index = i - desc.PositionalCount(); |
| 1382 names.SetAt(index, String::Handle(I, desc.NameAt(index))); | 1396 names.SetAt(index, String::Handle(I, desc.NameAt(index))); |
| 1383 } | 1397 } |
| 1384 args->set_names(names); | 1398 args->set_names(names); |
| 1385 | 1399 |
| 1386 const Class& owner = Class::Handle(I, func.Owner()); | 1400 const Class& owner = Class::Handle(I, func.Owner()); |
| 1387 ASSERT(!owner.IsNull()); | 1401 ASSERT(!owner.IsNull()); |
| 1388 AstNode* result = NULL; | 1402 AstNode* result = NULL; |
| 1389 if (owner.IsSignatureClass() && name.Equals(Symbols::Call())) { | 1403 if (owner.IsSignatureClass() && name.Equals(Symbols::Call())) { |
| 1390 EnsureSavedCurrentContext(); | |
| 1391 result = new ClosureCallNode(token_pos, getter_call, args); | 1404 result = new ClosureCallNode(token_pos, getter_call, args); |
| 1392 } else { | 1405 } else { |
| 1393 result = BuildClosureCall(token_pos, getter_call, args); | 1406 result = BuildClosureCall(token_pos, getter_call, args); |
| 1394 } | 1407 } |
| 1395 | 1408 |
| 1396 ReturnNode* return_node = new ReturnNode(token_pos, result); | 1409 ReturnNode* return_node = new ReturnNode(token_pos, result); |
| 1397 current_block_->statements->Add(return_node); | 1410 current_block_->statements->Add(return_node); |
| 1398 return CloseBlock(); | 1411 return CloseBlock(); |
| 1399 } | 1412 } |
| 1400 | 1413 |
| (...skipping 7288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8689 } | 8702 } |
| 8690 | 8703 |
| 8691 | 8704 |
| 8692 void Parser::EnsureExpressionTemp() { | 8705 void Parser::EnsureExpressionTemp() { |
| 8693 // Temporary used later by the flow_graph_builder. | 8706 // Temporary used later by the flow_graph_builder. |
| 8694 parsed_function()->EnsureExpressionTemp(); | 8707 parsed_function()->EnsureExpressionTemp(); |
| 8695 } | 8708 } |
| 8696 | 8709 |
| 8697 | 8710 |
| 8698 void Parser::EnsureSavedCurrentContext() { | 8711 void Parser::EnsureSavedCurrentContext() { |
| 8699 // Used later by the flow_graph_builder to save current context. | 8712 parsed_function()->EnsureSavedCurrentContext(); |
| 8700 if (!parsed_function()->has_saved_current_context_var()) { | |
| 8701 LocalVariable* temp = new(I) LocalVariable( | |
| 8702 current_function().token_pos(), | |
| 8703 Symbols::SavedCurrentContextVar(), | |
| 8704 Type::ZoneHandle(I, Type::DynamicType())); | |
| 8705 ASSERT(temp != NULL); | |
| 8706 parsed_function()->set_saved_current_context_var(temp); | |
| 8707 } | |
| 8708 } | 8713 } |
| 8709 | 8714 |
| 8710 | 8715 |
| 8711 LocalVariable* Parser::CreateTempConstVariable(intptr_t token_pos, | 8716 LocalVariable* Parser::CreateTempConstVariable(intptr_t token_pos, |
| 8712 const char* s) { | 8717 const char* s) { |
| 8713 char name[64]; | 8718 char name[64]; |
| 8714 OS::SNPrint(name, 64, ":%s%" Pd, s, token_pos); | 8719 OS::SNPrint(name, 64, ":%s%" Pd, s, token_pos); |
| 8715 LocalVariable* temp = new(I) LocalVariable( | 8720 LocalVariable* temp = new(I) LocalVariable( |
| 8716 token_pos, | 8721 token_pos, |
| 8717 String::ZoneHandle(I, Symbols::New(name)), | 8722 String::ZoneHandle(I, Symbols::New(name)), |
| (...skipping 3228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11946 void Parser::SkipQualIdent() { | 11951 void Parser::SkipQualIdent() { |
| 11947 ASSERT(IsIdentifier()); | 11952 ASSERT(IsIdentifier()); |
| 11948 ConsumeToken(); | 11953 ConsumeToken(); |
| 11949 if (CurrentToken() == Token::kPERIOD) { | 11954 if (CurrentToken() == Token::kPERIOD) { |
| 11950 ConsumeToken(); // Consume the kPERIOD token. | 11955 ConsumeToken(); // Consume the kPERIOD token. |
| 11951 ExpectIdentifier("identifier expected after '.'"); | 11956 ExpectIdentifier("identifier expected after '.'"); |
| 11952 } | 11957 } |
| 11953 } | 11958 } |
| 11954 | 11959 |
| 11955 } // namespace dart | 11960 } // namespace dart |
| OLD | NEW |