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 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 UNREACHABLE(); | 857 UNREACHABLE(); |
858 } | 858 } |
859 | 859 |
860 if (!HasReturnNode(node_sequence)) { | 860 if (!HasReturnNode(node_sequence)) { |
861 // Add implicit return node. | 861 // Add implicit return node. |
862 node_sequence->Add(new ReturnNode(func.end_token_pos())); | 862 node_sequence->Add(new ReturnNode(func.end_token_pos())); |
863 } | 863 } |
864 if (parsed_function->has_expression_temp_var()) { | 864 if (parsed_function->has_expression_temp_var()) { |
865 node_sequence->scope()->AddVariable(parsed_function->expression_temp_var()); | 865 node_sequence->scope()->AddVariable(parsed_function->expression_temp_var()); |
866 } | 866 } |
867 if (parsed_function->has_saved_current_context_var()) { | 867 node_sequence->scope()->AddVariable( |
868 node_sequence->scope()->AddVariable( | 868 parsed_function->current_context_var()); |
869 parsed_function->saved_current_context_var()); | |
870 } | |
871 if (parsed_function->has_finally_return_temp_var()) { | 869 if (parsed_function->has_finally_return_temp_var()) { |
872 node_sequence->scope()->AddVariable( | 870 node_sequence->scope()->AddVariable( |
873 parsed_function->finally_return_temp_var()); | 871 parsed_function->finally_return_temp_var()); |
874 } | 872 } |
875 parsed_function->SetNodeSequence(node_sequence); | 873 parsed_function->SetNodeSequence(node_sequence); |
876 | 874 |
877 // The instantiator may be required at run time for generic type checks or | 875 // The instantiator may be required at run time for generic type checks or |
878 // allocation of generic types. | 876 // allocation of generic types. |
879 if (parser.IsInstantiatorRequired()) { | 877 if (parser.IsInstantiatorRequired()) { |
880 // In the case of a local function, only set the instantiator if the | 878 // In the case of a local function, only set the instantiator if the |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 ParsedFunction* parsed_function = new ParsedFunction(isolate, initializer); | 1059 ParsedFunction* parsed_function = new ParsedFunction(isolate, initializer); |
1062 Parser parser(script, parsed_function, field.token_pos()); | 1060 Parser parser(script, parsed_function, field.token_pos()); |
1063 | 1061 |
1064 SequenceNode* body = parser.ParseStaticInitializer(); | 1062 SequenceNode* body = parser.ParseStaticInitializer(); |
1065 parsed_function->SetNodeSequence(body); | 1063 parsed_function->SetNodeSequence(body); |
1066 parsed_function->set_default_parameter_values(Object::null_array()); | 1064 parsed_function->set_default_parameter_values(Object::null_array()); |
1067 | 1065 |
1068 if (parsed_function->has_expression_temp_var()) { | 1066 if (parsed_function->has_expression_temp_var()) { |
1069 body->scope()->AddVariable(parsed_function->expression_temp_var()); | 1067 body->scope()->AddVariable(parsed_function->expression_temp_var()); |
1070 } | 1068 } |
1071 if (parsed_function->has_saved_current_context_var()) { | 1069 body->scope()->AddVariable(parsed_function->current_context_var()); |
1072 body->scope()->AddVariable(parsed_function->saved_current_context_var()); | |
1073 } | |
1074 if (parsed_function->has_finally_return_temp_var()) { | 1070 if (parsed_function->has_finally_return_temp_var()) { |
1075 body->scope()->AddVariable(parsed_function->finally_return_temp_var()); | 1071 body->scope()->AddVariable(parsed_function->finally_return_temp_var()); |
1076 } | 1072 } |
1077 // The instantiator is not required in a static expression. | 1073 // The instantiator is not required in a static expression. |
1078 ASSERT(!parser.IsInstantiatorRequired()); | 1074 ASSERT(!parser.IsInstantiatorRequired()); |
1079 | 1075 |
1080 return parsed_function; | 1076 return parsed_function; |
1081 } | 1077 } |
1082 | 1078 |
1083 | 1079 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1380 args->Add(new(I) LoadLocalNode(token_pos, scope->VariableAt(i))); | 1376 args->Add(new(I) LoadLocalNode(token_pos, scope->VariableAt(i))); |
1381 intptr_t index = i - desc.PositionalCount(); | 1377 intptr_t index = i - desc.PositionalCount(); |
1382 names.SetAt(index, String::Handle(I, desc.NameAt(index))); | 1378 names.SetAt(index, String::Handle(I, desc.NameAt(index))); |
1383 } | 1379 } |
1384 args->set_names(names); | 1380 args->set_names(names); |
1385 | 1381 |
1386 const Class& owner = Class::Handle(I, func.Owner()); | 1382 const Class& owner = Class::Handle(I, func.Owner()); |
1387 ASSERT(!owner.IsNull()); | 1383 ASSERT(!owner.IsNull()); |
1388 AstNode* result = NULL; | 1384 AstNode* result = NULL; |
1389 if (owner.IsSignatureClass() && name.Equals(Symbols::Call())) { | 1385 if (owner.IsSignatureClass() && name.Equals(Symbols::Call())) { |
1390 EnsureSavedCurrentContext(); | |
1391 result = new ClosureCallNode(token_pos, getter_call, args); | 1386 result = new ClosureCallNode(token_pos, getter_call, args); |
1392 } else { | 1387 } else { |
1393 result = BuildClosureCall(token_pos, getter_call, args); | 1388 result = BuildClosureCall(token_pos, getter_call, args); |
1394 } | 1389 } |
1395 | 1390 |
1396 ReturnNode* return_node = new ReturnNode(token_pos, result); | 1391 ReturnNode* return_node = new ReturnNode(token_pos, result); |
1397 current_block_->statements->Add(return_node); | 1392 current_block_->statements->Add(return_node); |
1398 return CloseBlock(); | 1393 return CloseBlock(); |
1399 } | 1394 } |
1400 | 1395 |
(...skipping 7287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8688 return expressions; | 8683 return expressions; |
8689 } | 8684 } |
8690 | 8685 |
8691 | 8686 |
8692 void Parser::EnsureExpressionTemp() { | 8687 void Parser::EnsureExpressionTemp() { |
8693 // Temporary used later by the flow_graph_builder. | 8688 // Temporary used later by the flow_graph_builder. |
8694 parsed_function()->EnsureExpressionTemp(); | 8689 parsed_function()->EnsureExpressionTemp(); |
8695 } | 8690 } |
8696 | 8691 |
8697 | 8692 |
8698 void Parser::EnsureSavedCurrentContext() { | |
8699 // Used later by the flow_graph_builder to save current context. | |
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 } | |
8709 | |
8710 | |
8711 LocalVariable* Parser::CreateTempConstVariable(intptr_t token_pos, | 8693 LocalVariable* Parser::CreateTempConstVariable(intptr_t token_pos, |
8712 const char* s) { | 8694 const char* s) { |
8713 char name[64]; | 8695 char name[64]; |
8714 OS::SNPrint(name, 64, ":%s%" Pd, s, token_pos); | 8696 OS::SNPrint(name, 64, ":%s%" Pd, s, token_pos); |
8715 LocalVariable* temp = new(I) LocalVariable( | 8697 LocalVariable* temp = new(I) LocalVariable( |
8716 token_pos, | 8698 token_pos, |
8717 String::ZoneHandle(I, Symbols::New(name)), | 8699 String::ZoneHandle(I, Symbols::New(name)), |
8718 Type::ZoneHandle(I, Type::DynamicType())); | 8700 Type::ZoneHandle(I, Type::DynamicType())); |
8719 temp->set_is_final(); | 8701 temp->set_is_final(); |
8720 current_block_->scope->AddVariable(temp); | 8702 current_block_->scope->AddVariable(temp); |
(...skipping 3225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11946 void Parser::SkipQualIdent() { | 11928 void Parser::SkipQualIdent() { |
11947 ASSERT(IsIdentifier()); | 11929 ASSERT(IsIdentifier()); |
11948 ConsumeToken(); | 11930 ConsumeToken(); |
11949 if (CurrentToken() == Token::kPERIOD) { | 11931 if (CurrentToken() == Token::kPERIOD) { |
11950 ConsumeToken(); // Consume the kPERIOD token. | 11932 ConsumeToken(); // Consume the kPERIOD token. |
11951 ExpectIdentifier("identifier expected after '.'"); | 11933 ExpectIdentifier("identifier expected after '.'"); |
11952 } | 11934 } |
11953 } | 11935 } |
11954 | 11936 |
11955 } // namespace dart | 11937 } // namespace dart |
OLD | NEW |