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 "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 const AbstractType* type) { | 418 const AbstractType* type) { |
| 419 this->num_fixed_parameters++; | 419 this->num_fixed_parameters++; |
| 420 ParamDesc param; | 420 ParamDesc param; |
| 421 param.name_pos = name_pos; | 421 param.name_pos = name_pos; |
| 422 param.name = name; | 422 param.name = name; |
| 423 param.is_final = true; | 423 param.is_final = true; |
| 424 param.type = type; | 424 param.type = type; |
| 425 this->parameters->Add(param); | 425 this->parameters->Add(param); |
| 426 } | 426 } |
| 427 | 427 |
| 428 void AddReceiver(intptr_t name_pos) { | 428 void AddReceiver(const Type* receiver_type) { |
| 429 ASSERT(this->parameters->is_empty()); | 429 ASSERT(this->parameters->is_empty()); |
| 430 // The receiver does not need to be type checked. | 430 AddFinalParameter(receiver_type->token_pos(), |
|
hausner
2012/08/02 23:25:00
Why are you using the token position of the type,
regis
2012/08/02 23:58:37
The token position is now passed to ReceiverType t
| |
| 431 AddFinalParameter(name_pos, | |
| 432 &String::ZoneHandle(Symbols::This()), | 431 &String::ZoneHandle(Symbols::This()), |
| 433 &Type::ZoneHandle(Type::DynamicType())); | 432 receiver_type); |
| 434 } | 433 } |
| 435 | 434 |
| 436 void SetImplicitlyFinal() { | 435 void SetImplicitlyFinal() { |
| 437 implicitly_final = true; | 436 implicitly_final = true; |
| 438 } | 437 } |
| 439 | 438 |
| 440 int num_fixed_parameters; | 439 int num_fixed_parameters; |
| 441 int num_optional_parameters; | 440 int num_optional_parameters; |
| 442 bool has_named_optional_parameters; // Indicates use of the new syntax. | 441 bool has_named_optional_parameters; // Indicates use of the new syntax. |
| 443 bool has_field_initializer; | 442 bool has_field_initializer; |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 705 } | 704 } |
| 706 if (parsed_function->has_expression_temp_var()) { | 705 if (parsed_function->has_expression_temp_var()) { |
| 707 node_sequence->scope()->AddVariable(parsed_function->expression_temp_var()); | 706 node_sequence->scope()->AddVariable(parsed_function->expression_temp_var()); |
| 708 } | 707 } |
| 709 parsed_function->SetNodeSequence(node_sequence); | 708 parsed_function->SetNodeSequence(node_sequence); |
| 710 | 709 |
| 711 // The instantiator may be required at run time for generic type checks or | 710 // The instantiator may be required at run time for generic type checks or |
| 712 // allocation of generic types. | 711 // allocation of generic types. |
| 713 if (parser.IsInstantiatorRequired()) { | 712 if (parser.IsInstantiatorRequired()) { |
| 714 // In the case of a local function, only set the instantiator if the | 713 // In the case of a local function, only set the instantiator if the |
| 715 // receiver was captured. | 714 // receiver (or type arguments parameter of a factory) was captured. |
| 715 LocalVariable* instantiator = NULL; | |
| 716 const bool kTestOnly = true; | 716 const bool kTestOnly = true; |
| 717 LocalVariable* receiver = | 717 if (parser.current_function().IsInFactoryScope()) { |
| 718 parser.LookupReceiver(node_sequence->scope(), kTestOnly); | 718 instantiator = parser.LookupTypeArgumentsParameter(node_sequence->scope(), |
| 719 kTestOnly); | |
| 720 } else { | |
| 721 instantiator = parser.LookupReceiver(node_sequence->scope(), kTestOnly); | |
| 722 } | |
| 719 if (!parser.current_function().IsLocalFunction() || | 723 if (!parser.current_function().IsLocalFunction() || |
| 720 ((receiver != NULL) && receiver->is_captured())) { | 724 ((instantiator != NULL) && instantiator->is_captured())) { |
| 721 parsed_function->set_instantiator( | 725 parsed_function->set_instantiator( |
| 722 new LoadLocalNode(node_sequence->token_pos(), *receiver)); | 726 new LoadLocalNode(node_sequence->token_pos(), *instantiator)); |
| 723 } | 727 } |
| 724 } | 728 } |
| 725 | 729 |
| 726 parsed_function->set_default_parameter_values(default_parameter_values); | 730 parsed_function->set_default_parameter_values(default_parameter_values); |
| 727 isolate->set_ast_node_id(prev_ast_node_id); | 731 isolate->set_ast_node_id(prev_ast_node_id); |
| 728 } | 732 } |
| 729 | 733 |
| 730 | 734 |
| 731 // TODO(regis): Implement support for non-const final static fields (currently | 735 // TODO(regis): Implement support for non-const final static fields (currently |
| 732 // supported "final" fields are actually const fields). | 736 // supported "final" fields are actually const fields). |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 843 } | 847 } |
| 844 | 848 |
| 845 | 849 |
| 846 // Create AstNodes for an implicit instance getter method: | 850 // Create AstNodes for an implicit instance getter method: |
| 847 // LoadLocalNode 0 ('this'); | 851 // LoadLocalNode 0 ('this'); |
| 848 // LoadInstanceFieldNode (field_name); | 852 // LoadInstanceFieldNode (field_name); |
| 849 // ReturnNode (field's value); | 853 // ReturnNode (field's value); |
| 850 SequenceNode* Parser::ParseInstanceGetter(const Function& func) { | 854 SequenceNode* Parser::ParseInstanceGetter(const Function& func) { |
| 851 TRACE_PARSER("ParseInstanceGetter"); | 855 TRACE_PARSER("ParseInstanceGetter"); |
| 852 ParamList params; | 856 ParamList params; |
| 853 params.AddReceiver(TokenPos()); | 857 ASSERT(current_class().raw() == func.owner()); |
| 858 params.AddReceiver(ReceiverType(TokenPos())); | |
| 854 ASSERT(func.num_fixed_parameters() == 1); // receiver. | 859 ASSERT(func.num_fixed_parameters() == 1); // receiver. |
| 855 ASSERT(func.num_optional_parameters() == 0); | 860 ASSERT(func.num_optional_parameters() == 0); |
| 856 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 861 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 857 | 862 |
| 858 // Build local scope for function and populate with the formal parameters. | 863 // Build local scope for function and populate with the formal parameters. |
| 859 OpenFunctionBlock(func); | 864 OpenFunctionBlock(func); |
| 860 AddFormalParamsToScope(¶ms, current_block_->scope); | 865 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 861 | 866 |
| 862 // Receiver is local 0. | 867 // Receiver is local 0. |
| 863 LocalVariable* receiver = current_block_->scope->VariableAt(0); | 868 LocalVariable* receiver = current_block_->scope->VariableAt(0); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 888 TRACE_PARSER("ParseInstanceSetter"); | 893 TRACE_PARSER("ParseInstanceSetter"); |
| 889 // TokenPos() returns the function's token position which points to | 894 // TokenPos() returns the function's token position which points to |
| 890 // the name of the field; we can use it to form the field_name. | 895 // the name of the field; we can use it to form the field_name. |
| 891 const String& field_name = *CurrentLiteral(); | 896 const String& field_name = *CurrentLiteral(); |
| 892 const Class& field_class = Class::ZoneHandle(func.owner()); | 897 const Class& field_class = Class::ZoneHandle(func.owner()); |
| 893 const Field& field = | 898 const Field& field = |
| 894 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); | 899 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); |
| 895 const AbstractType& field_type = AbstractType::ZoneHandle(field.type()); | 900 const AbstractType& field_type = AbstractType::ZoneHandle(field.type()); |
| 896 | 901 |
| 897 ParamList params; | 902 ParamList params; |
| 898 params.AddReceiver(TokenPos()); | 903 ASSERT(current_class().raw() == func.owner()); |
| 904 params.AddReceiver(ReceiverType(TokenPos())); | |
| 899 params.AddFinalParameter(TokenPos(), | 905 params.AddFinalParameter(TokenPos(), |
| 900 &String::ZoneHandle(Symbols::Value()), | 906 &String::ZoneHandle(Symbols::Value()), |
| 901 &field_type); | 907 &field_type); |
| 902 ASSERT(func.num_fixed_parameters() == 2); // receiver, value. | 908 ASSERT(func.num_fixed_parameters() == 2); // receiver, value. |
| 903 ASSERT(func.num_optional_parameters() == 0); | 909 ASSERT(func.num_optional_parameters() == 0); |
| 904 ASSERT(AbstractType::Handle(func.result_type()).IsVoidType()); | 910 ASSERT(AbstractType::Handle(func.result_type()).IsVoidType()); |
| 905 | 911 |
| 906 // Build local scope for function and populate with the formal parameters. | 912 // Build local scope for function and populate with the formal parameters. |
| 907 OpenFunctionBlock(func); | 913 OpenFunctionBlock(func); |
| 908 AddFormalParamsToScope(¶ms, current_block_->scope); | 914 AddFormalParamsToScope(¶ms, current_block_->scope); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1064 ParseFormalParameterList(no_explicit_default_values, &func_params); | 1070 ParseFormalParameterList(no_explicit_default_values, &func_params); |
| 1065 | 1071 |
| 1066 // The field 'is_static' has no meaning for signature functions. | 1072 // The field 'is_static' has no meaning for signature functions. |
| 1067 const Function& signature_function = Function::Handle( | 1073 const Function& signature_function = Function::Handle( |
| 1068 Function::New(*parameter.name, | 1074 Function::New(*parameter.name, |
| 1069 RawFunction::kSignatureFunction, | 1075 RawFunction::kSignatureFunction, |
| 1070 /* is_static = */ false, | 1076 /* is_static = */ false, |
| 1071 /* is_const = */ false, | 1077 /* is_const = */ false, |
| 1072 /* is_abstract = */ false, | 1078 /* is_abstract = */ false, |
| 1073 /* is_external = */ false, | 1079 /* is_external = */ false, |
| 1080 current_class(), | |
| 1074 parameter.name_pos)); | 1081 parameter.name_pos)); |
| 1075 signature_function.set_owner(current_class()); | |
| 1076 signature_function.set_result_type(result_type); | 1082 signature_function.set_result_type(result_type); |
| 1077 AddFormalParamsToFunction(&func_params, signature_function); | 1083 AddFormalParamsToFunction(&func_params, signature_function); |
| 1078 const String& signature = String::Handle(signature_function.Signature()); | 1084 const String& signature = String::Handle(signature_function.Signature()); |
| 1079 // Lookup the signature class, i.e. the class whose name is the signature. | 1085 // Lookup the signature class, i.e. the class whose name is the signature. |
| 1080 // We only lookup in the current library, but not in its imports, and only | 1086 // We only lookup in the current library, but not in its imports, and only |
| 1081 // create a new canonical signature class if it does not exist yet. | 1087 // create a new canonical signature class if it does not exist yet. |
| 1082 Class& signature_class = Class::ZoneHandle( | 1088 Class& signature_class = Class::ZoneHandle( |
| 1083 library_.LookupLocalClass(signature)); | 1089 library_.LookupLocalClass(signature)); |
| 1084 if (signature_class.IsNull()) { | 1090 if (signature_class.IsNull()) { |
| 1085 signature_class = Class::NewSignatureClass(signature, | 1091 signature_class = Class::NewSignatureClass(signature, |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1428 AstNode* receiver) { | 1434 AstNode* receiver) { |
| 1429 Function& implicit_closure_function = | 1435 Function& implicit_closure_function = |
| 1430 Function::ZoneHandle(func.ImplicitClosureFunction()); | 1436 Function::ZoneHandle(func.ImplicitClosureFunction()); |
| 1431 if (receiver != NULL) { | 1437 if (receiver != NULL) { |
| 1432 // If we create an implicit instance closure from inside a closure of a | 1438 // If we create an implicit instance closure from inside a closure of a |
| 1433 // parameterized class, make sure that the receiver is captured as | 1439 // parameterized class, make sure that the receiver is captured as |
| 1434 // instantiator. | 1440 // instantiator. |
| 1435 if (current_block_->scope->function_level() > 0) { | 1441 if (current_block_->scope->function_level() > 0) { |
| 1436 const Class& signature_class = Class::Handle(func.signature_class()); | 1442 const Class& signature_class = Class::Handle(func.signature_class()); |
| 1437 if (signature_class.NumTypeParameters() > 0) { | 1443 if (signature_class.NumTypeParameters() > 0) { |
| 1438 CaptureReceiver(); | 1444 CaptureInstantiator(); |
| 1439 } | 1445 } |
| 1440 } | 1446 } |
| 1441 } | 1447 } |
| 1442 return new ClosureNode(token_pos, implicit_closure_function, receiver, NULL); | 1448 return new ClosureNode(token_pos, implicit_closure_function, receiver, NULL); |
| 1443 } | 1449 } |
| 1444 | 1450 |
| 1445 | 1451 |
| 1446 AstNode* Parser::ParseSuperFieldAccess(const String& field_name) { | 1452 AstNode* Parser::ParseSuperFieldAccess(const String& field_name) { |
| 1447 TRACE_PARSER("ParseSuperFieldAccess"); | 1453 TRACE_PARSER("ParseSuperFieldAccess"); |
| 1448 const intptr_t field_pos = TokenPos(); | 1454 const intptr_t field_pos = TokenPos(); |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1834 | 1840 |
| 1835 LocalVariable* receiver = new LocalVariable( | 1841 LocalVariable* receiver = new LocalVariable( |
| 1836 ctor_pos, | 1842 ctor_pos, |
| 1837 String::ZoneHandle(Symbols::This()), | 1843 String::ZoneHandle(Symbols::This()), |
| 1838 Type::ZoneHandle(Type::DynamicType())); | 1844 Type::ZoneHandle(Type::DynamicType())); |
| 1839 current_block_->scope->AddVariable(receiver); | 1845 current_block_->scope->AddVariable(receiver); |
| 1840 | 1846 |
| 1841 LocalVariable* phase_parameter = new LocalVariable( | 1847 LocalVariable* phase_parameter = new LocalVariable( |
| 1842 ctor_pos, | 1848 ctor_pos, |
| 1843 String::ZoneHandle(Symbols::PhaseParameter()), | 1849 String::ZoneHandle(Symbols::PhaseParameter()), |
| 1844 Type::ZoneHandle(Type::DynamicType())); | 1850 Type::ZoneHandle(Type::IntInterface())); |
| 1845 current_block_->scope->AddVariable(phase_parameter); | 1851 current_block_->scope->AddVariable(phase_parameter); |
| 1846 | 1852 |
| 1847 // Now that the "this" parameter is in scope, we can generate the code | 1853 // Now that the "this" parameter is in scope, we can generate the code |
| 1848 // to strore the initializer expressions in the respective instance fields. | 1854 // to strore the initializer expressions in the respective instance fields. |
| 1849 for (int i = 0; i < initializers.length(); i++) { | 1855 for (int i = 0; i < initializers.length(); i++) { |
| 1850 const Field* field = initializers[i].inst_field; | 1856 const Field* field = initializers[i].inst_field; |
| 1851 AstNode* instance = new LoadLocalNode(field->token_pos(), *receiver); | 1857 AstNode* instance = new LoadLocalNode(field->token_pos(), *receiver); |
| 1852 AstNode* field_init = | 1858 AstNode* field_init = |
| 1853 new StoreInstanceFieldNode(field->token_pos(), | 1859 new StoreInstanceFieldNode(field->token_pos(), |
| 1854 instance, | 1860 instance, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1890 return MakeImplicitConstructor(func); | 1896 return MakeImplicitConstructor(func); |
| 1891 } | 1897 } |
| 1892 | 1898 |
| 1893 OpenFunctionBlock(func); | 1899 OpenFunctionBlock(func); |
| 1894 ParamList params; | 1900 ParamList params; |
| 1895 const bool allow_explicit_default_values = true; | 1901 const bool allow_explicit_default_values = true; |
| 1896 ASSERT(CurrentToken() == Token::kLPAREN); | 1902 ASSERT(CurrentToken() == Token::kLPAREN); |
| 1897 | 1903 |
| 1898 // Add implicit receiver parameter which is passed the allocated | 1904 // Add implicit receiver parameter which is passed the allocated |
| 1899 // but uninitialized instance to construct. | 1905 // but uninitialized instance to construct. |
| 1900 params.AddReceiver(TokenPos()); | 1906 ASSERT(current_class().raw() == func.owner()); |
| 1907 params.AddReceiver(ReceiverType(TokenPos())); | |
| 1901 | 1908 |
| 1902 // Add implicit parameter for construction phase. | 1909 // Add implicit parameter for construction phase. |
| 1903 params.AddFinalParameter( | 1910 params.AddFinalParameter( |
| 1904 TokenPos(), | 1911 TokenPos(), |
| 1905 &String::ZoneHandle(Symbols::PhaseParameter()), | 1912 &String::ZoneHandle(Symbols::PhaseParameter()), |
| 1906 &Type::ZoneHandle(Type::DynamicType())); | 1913 &Type::ZoneHandle(Type::IntInterface())); |
| 1907 | 1914 |
| 1908 if (func.is_const()) { | 1915 if (func.is_const()) { |
| 1909 params.SetImplicitlyFinal(); | 1916 params.SetImplicitlyFinal(); |
| 1910 } | 1917 } |
| 1911 ParseFormalParameterList(allow_explicit_default_values, ¶ms); | 1918 ParseFormalParameterList(allow_explicit_default_values, ¶ms); |
| 1912 | 1919 |
| 1913 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); | 1920 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); |
| 1914 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 1921 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 1915 ASSERT(func.NumberOfParameters() == params.parameters->length()); | 1922 ASSERT(func.NumberOfParameters() == params.parameters->length()); |
| 1916 | 1923 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2136 return statements; | 2143 return statements; |
| 2137 } | 2144 } |
| 2138 | 2145 |
| 2139 ASSERT(!func.IsConstructor()); | 2146 ASSERT(!func.IsConstructor()); |
| 2140 OpenFunctionBlock(func); // Build local scope for function. | 2147 OpenFunctionBlock(func); // Build local scope for function. |
| 2141 | 2148 |
| 2142 ParamList params; | 2149 ParamList params; |
| 2143 // Static functions do not have a receiver. | 2150 // Static functions do not have a receiver. |
| 2144 // An instance closure may capture and access the receiver, but via the | 2151 // An instance closure may capture and access the receiver, but via the |
| 2145 // context and not via the first formal parameter. | 2152 // context and not via the first formal parameter. |
| 2146 // The first parameter of a factory is the AbstractTypeArguments vector of the | 2153 // The first parameter of a factory is the AbstractTypeArguments vector of |
| 2147 // type of the instance to be allocated. We name this hidden parameter 'this'. | 2154 // the type of the instance to be allocated. |
| 2148 const bool has_receiver = !func.IsClosureFunction() && | 2155 if (!func.is_static() && !func.IsClosureFunction()) { |
| 2149 (!func.is_static() || func.IsFactory()); | 2156 ASSERT(current_class().raw() == func.owner()); |
| 2150 const bool allow_explicit_default_values = true; | 2157 params.AddReceiver(ReceiverType(TokenPos())); |
| 2151 if (has_receiver) { | 2158 } else if (func.IsFactory()) { |
| 2152 params.AddReceiver(TokenPos()); | 2159 params.AddFinalParameter( |
| 2160 TokenPos(), | |
| 2161 &String::ZoneHandle(Symbols::TypeArgumentsParameter()), | |
| 2162 &Type::ZoneHandle(Type::DynamicType())); | |
| 2153 } | 2163 } |
| 2154 ASSERT(CurrentToken() == Token::kLPAREN); | 2164 ASSERT(CurrentToken() == Token::kLPAREN); |
| 2165 const bool allow_explicit_default_values = true; | |
| 2155 ParseFormalParameterList(allow_explicit_default_values, ¶ms); | 2166 ParseFormalParameterList(allow_explicit_default_values, ¶ms); |
| 2156 | 2167 |
| 2157 // The number of parameters and their type are not yet set in local functions, | 2168 // The number of parameters and their type are not yet set in local functions, |
| 2158 // since they are not 'top-level' parsed. | 2169 // since they are not 'top-level' parsed. |
| 2159 if (func.IsLocalFunction()) { | 2170 if (func.IsLocalFunction()) { |
| 2160 AddFormalParamsToFunction(¶ms, func); | 2171 AddFormalParamsToFunction(¶ms, func); |
| 2161 } | 2172 } |
| 2162 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); | 2173 SetupDefaultsForOptionalParams(¶ms, default_parameter_values); |
| 2163 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 2174 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 2164 ASSERT(func.NumberOfParameters() == params.parameters->length()); | 2175 ASSERT(func.NumberOfParameters() == params.parameters->length()); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2177 // Populate function scope with the formal parameters. | 2188 // Populate function scope with the formal parameters. |
| 2178 AddFormalParamsToScope(¶ms, current_block_->scope); | 2189 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 2179 | 2190 |
| 2180 if (FLAG_enable_type_checks && | 2191 if (FLAG_enable_type_checks && |
| 2181 (current_block_->scope->function_level() > 0)) { | 2192 (current_block_->scope->function_level() > 0)) { |
| 2182 // We are parsing, but not compiling, a local function. | 2193 // We are parsing, but not compiling, a local function. |
| 2183 // The instantiator may be required at run time for generic type checks. | 2194 // The instantiator may be required at run time for generic type checks. |
| 2184 if (IsInstantiatorRequired()) { | 2195 if (IsInstantiatorRequired()) { |
| 2185 // Make sure that the receiver of the enclosing instance function | 2196 // Make sure that the receiver of the enclosing instance function |
| 2186 // (or implicit first parameter of an enclosing factory) is marked as | 2197 // (or implicit first parameter of an enclosing factory) is marked as |
| 2187 // captured if type checks are enabled, because they may access the | 2198 // captured if type checks are enabled, because they may access it to |
| 2188 // receiver to instantiate types. | 2199 // instantiate types. |
| 2189 CaptureReceiver(); | 2200 CaptureInstantiator(); |
| 2190 } | 2201 } |
| 2191 } | 2202 } |
| 2192 | 2203 |
| 2193 OpenBlock(); // Open a nested scope for the outermost function block. | 2204 OpenBlock(); // Open a nested scope for the outermost function block. |
| 2194 if (CurrentToken() == Token::kLBRACE) { | 2205 if (CurrentToken() == Token::kLBRACE) { |
| 2195 ConsumeToken(); | 2206 ConsumeToken(); |
| 2196 ParseStatementSequence(); | 2207 ParseStatementSequence(); |
| 2197 ExpectToken(Token::kRBRACE); | 2208 ExpectToken(Token::kRBRACE); |
| 2198 } else if (CurrentToken() == Token::kARROW) { | 2209 } else if (CurrentToken() == Token::kARROW) { |
| 2199 ConsumeToken(); | 2210 ConsumeToken(); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2342 ErrorMsg(method->name_pos, | 2353 ErrorMsg(method->name_pos, |
| 2343 "'external' method only allowed in class definition"); | 2354 "'external' method only allowed in class definition"); |
| 2344 } | 2355 } |
| 2345 | 2356 |
| 2346 if (members->FunctionNameExists(*method->name, method->kind)) { | 2357 if (members->FunctionNameExists(*method->name, method->kind)) { |
| 2347 ErrorMsg(method->name_pos, | 2358 ErrorMsg(method->name_pos, |
| 2348 "field or method '%s' already defined", method->name->ToCString()); | 2359 "field or method '%s' already defined", method->name->ToCString()); |
| 2349 } | 2360 } |
| 2350 | 2361 |
| 2351 // Parse the formal parameters. | 2362 // Parse the formal parameters. |
| 2352 // The first parameter of factory methods is an implicit parameter called | |
| 2353 // 'this' of type AbstractTypeArguments. | |
| 2354 const bool has_this_param = | |
| 2355 !method->has_static || method->IsConstructor() || method->has_factory; | |
| 2356 const bool are_implicitly_final = method->has_const; | 2363 const bool are_implicitly_final = method->has_const; |
| 2357 const bool allow_explicit_default_values = true; | 2364 const bool allow_explicit_default_values = true; |
| 2358 const intptr_t formal_param_pos = TokenPos(); | 2365 const intptr_t formal_param_pos = TokenPos(); |
| 2359 method->params.Clear(); | 2366 method->params.Clear(); |
| 2360 if (has_this_param) { | 2367 // Static functions do not have a receiver. |
| 2361 method->params.AddReceiver(formal_param_pos); | 2368 // The first parameter of a factory is the AbstractTypeArguments vector of |
| 2369 // the type of the instance to be allocated. | |
| 2370 if (!method->has_static || method->IsConstructor()) { | |
| 2371 method->params.AddReceiver(ReceiverType(formal_param_pos)); | |
| 2372 } else if (method->has_factory) { | |
| 2373 method->params.AddFinalParameter( | |
| 2374 formal_param_pos, | |
| 2375 &String::ZoneHandle(Symbols::TypeArgumentsParameter()), | |
| 2376 &Type::ZoneHandle(Type::DynamicType())); | |
| 2362 } | 2377 } |
| 2363 // Constructors have an implicit parameter for the construction phase. | 2378 // Constructors have an implicit parameter for the construction phase. |
| 2364 if (method->IsConstructor()) { | 2379 if (method->IsConstructor()) { |
| 2365 method->params.AddFinalParameter( | 2380 method->params.AddFinalParameter( |
| 2366 TokenPos(), | 2381 TokenPos(), |
| 2367 &String::ZoneHandle(Symbols::PhaseParameter()), | 2382 &String::ZoneHandle(Symbols::PhaseParameter()), |
| 2368 &Type::ZoneHandle(Type::DynamicType())); | 2383 &Type::ZoneHandle(Type::IntInterface())); |
| 2369 } | 2384 } |
| 2370 if (are_implicitly_final) { | 2385 if (are_implicitly_final) { |
| 2371 method->params.SetImplicitlyFinal(); | 2386 method->params.SetImplicitlyFinal(); |
| 2372 } | 2387 } |
| 2373 ParseFormalParameterList(allow_explicit_default_values, &method->params); | 2388 ParseFormalParameterList(allow_explicit_default_values, &method->params); |
| 2374 if (method->IsGetter() || method->IsSetter()) { | 2389 if (method->IsGetter() || method->IsSetter()) { |
| 2375 int expected_num_parameters = 0; | 2390 int expected_num_parameters = 0; |
| 2376 if (method->IsGetter()) { | 2391 if (method->IsGetter()) { |
| 2377 expected_num_parameters = (method->has_static) ? 0 : 1; | 2392 expected_num_parameters = (method->has_static) ? 0 : 1; |
| 2378 method->name = &String::ZoneHandle(Field::GetterSymbol(*method->name)); | 2393 method->name = &String::ZoneHandle(Field::GetterSymbol(*method->name)); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2515 } else { | 2530 } else { |
| 2516 function_kind = RawFunction::kRegularFunction; | 2531 function_kind = RawFunction::kRegularFunction; |
| 2517 } | 2532 } |
| 2518 Function& func = Function::Handle( | 2533 Function& func = Function::Handle( |
| 2519 Function::New(*method->name, | 2534 Function::New(*method->name, |
| 2520 function_kind, | 2535 function_kind, |
| 2521 method->has_static, | 2536 method->has_static, |
| 2522 method->has_const, | 2537 method->has_const, |
| 2523 method->has_abstract, | 2538 method->has_abstract, |
| 2524 method->has_external, | 2539 method->has_external, |
| 2540 current_class(), | |
| 2525 method_pos)); | 2541 method_pos)); |
| 2526 func.set_result_type(*method->type); | 2542 func.set_result_type(*method->type); |
| 2527 func.set_end_token_pos(method_end_pos); | 2543 func.set_end_token_pos(method_end_pos); |
| 2528 | 2544 |
| 2529 // No need to resolve parameter types yet, or add parameters to local scope. | 2545 // No need to resolve parameter types yet, or add parameters to local scope. |
| 2530 ASSERT(is_top_level_); | 2546 ASSERT(is_top_level_); |
| 2531 AddFormalParamsToFunction(&method->params, func); | 2547 AddFormalParamsToFunction(&method->params, func); |
| 2532 members->AddFunction(func); | 2548 members->AddFunction(func); |
| 2533 } | 2549 } |
| 2534 | 2550 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2592 } | 2608 } |
| 2593 } | 2609 } |
| 2594 | 2610 |
| 2595 // Create the field object. | 2611 // Create the field object. |
| 2596 // TODO(hausner): For now, all static final fields are constant. Remove | 2612 // TODO(hausner): For now, all static final fields are constant. Remove |
| 2597 // this when lazy init of static variables is implemented. | 2613 // this when lazy init of static variables is implemented. |
| 2598 class_field = Field::New(*field->name, | 2614 class_field = Field::New(*field->name, |
| 2599 field->has_static, | 2615 field->has_static, |
| 2600 field->has_final, | 2616 field->has_final, |
| 2601 field->has_const || field->has_final, | 2617 field->has_const || field->has_final, |
| 2618 current_class(), | |
| 2602 field->name_pos); | 2619 field->name_pos); |
| 2603 class_field.set_type(*field->type); | 2620 class_field.set_type(*field->type); |
| 2604 class_field.set_has_initializer(has_initializer); | 2621 class_field.set_has_initializer(has_initializer); |
| 2605 members->AddField(class_field); | 2622 members->AddField(class_field); |
| 2606 | 2623 |
| 2607 // For static final fields, set value to "uninitialized" and | 2624 // For static final fields, set value to "uninitialized" and |
| 2608 // create a kConstImplicitGetter getter method. | 2625 // create a kConstImplicitGetter getter method. |
| 2609 if (field->has_static && has_initializer) { | 2626 if (field->has_static && has_initializer) { |
| 2610 class_field.set_value(init_value); | 2627 class_field.set_value(init_value); |
| 2611 if (!has_simple_literal) { | 2628 if (!has_simple_literal) { |
| 2612 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); | 2629 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); |
| 2613 getter = Function::New(getter_name, RawFunction::kConstImplicitGetter, | 2630 getter = Function::New(getter_name, |
| 2614 field->has_static, field->has_final, | 2631 RawFunction::kConstImplicitGetter, |
| 2615 /* is_abstract */ false, | 2632 field->has_static, |
| 2616 /* is_external */ false, | 2633 field->has_final, |
| 2634 /* is_abstract = */ false, | |
| 2635 /* is_external = */ false, | |
| 2636 current_class(), | |
| 2617 field->name_pos); | 2637 field->name_pos); |
| 2618 getter.set_result_type(*field->type); | 2638 getter.set_result_type(*field->type); |
| 2619 members->AddFunction(getter); | 2639 members->AddFunction(getter); |
| 2620 } | 2640 } |
| 2621 } | 2641 } |
| 2622 | 2642 |
| 2623 // For instance fields, we create implicit getter and setter methods. | 2643 // For instance fields, we create implicit getter and setter methods. |
| 2624 if (!field->has_static) { | 2644 if (!field->has_static) { |
| 2625 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); | 2645 String& getter_name = String::Handle(Field::GetterSymbol(*field->name)); |
| 2626 getter = Function::New(getter_name, RawFunction::kImplicitGetter, | 2646 getter = Function::New(getter_name, RawFunction::kImplicitGetter, |
| 2627 field->has_static, field->has_final, false, | 2647 field->has_static, |
| 2628 /* is_abstract */ false, | 2648 field->has_final, |
| 2649 /* is_abstract = */ false, | |
| 2650 /* is_external = */ false, | |
| 2651 current_class(), | |
| 2629 field->name_pos); | 2652 field->name_pos); |
| 2630 ParamList params; | 2653 ParamList params; |
| 2631 params.AddReceiver(TokenPos()); | 2654 ASSERT(current_class().raw() == getter.owner()); |
| 2655 params.AddReceiver(ReceiverType(TokenPos())); | |
| 2632 getter.set_result_type(*field->type); | 2656 getter.set_result_type(*field->type); |
| 2633 AddFormalParamsToFunction(¶ms, getter); | 2657 AddFormalParamsToFunction(¶ms, getter); |
| 2634 members->AddFunction(getter); | 2658 members->AddFunction(getter); |
| 2635 if (!field->has_final) { | 2659 if (!field->has_final) { |
| 2636 // Build a setter accessor for non-const fields. | 2660 // Build a setter accessor for non-const fields. |
| 2637 String& setter_name = String::Handle(Field::SetterSymbol(*field->name)); | 2661 String& setter_name = String::Handle(Field::SetterSymbol(*field->name)); |
| 2638 setter = Function::New(setter_name, RawFunction::kImplicitSetter, | 2662 setter = Function::New(setter_name, RawFunction::kImplicitSetter, |
| 2639 field->has_static, field->has_final, false, | 2663 field->has_static, |
| 2640 /* is_abstract */ false, | 2664 field->has_final, |
| 2665 /* is_abstract = */ false, | |
| 2666 /* is_external = */ false, | |
| 2667 current_class(), | |
| 2641 field->name_pos); | 2668 field->name_pos); |
| 2642 ParamList params; | 2669 ParamList params; |
| 2643 params.AddReceiver(TokenPos()); | 2670 ASSERT(current_class().raw() == setter.owner()); |
| 2671 params.AddReceiver(ReceiverType(TokenPos())); | |
| 2644 params.AddFinalParameter(TokenPos(), | 2672 params.AddFinalParameter(TokenPos(), |
| 2645 &String::ZoneHandle(Symbols::Value()), | 2673 &String::ZoneHandle(Symbols::Value()), |
| 2646 field->type); | 2674 field->type); |
| 2647 setter.set_result_type(Type::Handle(Type::VoidType())); | 2675 setter.set_result_type(Type::Handle(Type::VoidType())); |
| 2648 AddFormalParamsToFunction(¶ms, setter); | 2676 AddFormalParamsToFunction(¶ms, setter); |
| 2649 members->AddFunction(setter); | 2677 members->AddFunction(setter); |
| 2650 } | 2678 } |
| 2651 } | 2679 } |
| 2652 | 2680 |
| 2653 if (CurrentToken() != Token::kCOMMA) { | 2681 if (CurrentToken() != Token::kCOMMA) { |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3012 ctor_name = Symbols::New(ctor_name); | 3040 ctor_name = Symbols::New(ctor_name); |
| 3013 // The token position for the implicit constructor is the 'class' | 3041 // The token position for the implicit constructor is the 'class' |
| 3014 // keyword of the constructor's class. | 3042 // keyword of the constructor's class. |
| 3015 Function& ctor = Function::Handle( | 3043 Function& ctor = Function::Handle( |
| 3016 Function::New(ctor_name, | 3044 Function::New(ctor_name, |
| 3017 RawFunction::kConstructor, | 3045 RawFunction::kConstructor, |
| 3018 /* is_static = */ false, | 3046 /* is_static = */ false, |
| 3019 /* is_const = */ false, | 3047 /* is_const = */ false, |
| 3020 /* is_abstract = */ false, | 3048 /* is_abstract = */ false, |
| 3021 /* is_external = */ false, | 3049 /* is_external = */ false, |
| 3050 current_class(), | |
| 3022 class_desc->token_pos())); | 3051 class_desc->token_pos())); |
| 3023 ParamList params; | 3052 ParamList params; |
| 3024 // Add implicit 'this' parameter. | 3053 // Add implicit 'this' parameter. |
| 3025 params.AddReceiver(TokenPos()); | 3054 ASSERT(current_class().raw() == ctor.owner()); |
| 3055 params.AddReceiver(ReceiverType(TokenPos())); | |
| 3026 // Add implicit parameter for construction phase. | 3056 // Add implicit parameter for construction phase. |
| 3027 params.AddFinalParameter( | 3057 params.AddFinalParameter( |
| 3028 TokenPos(), | 3058 TokenPos(), |
| 3029 &String::ZoneHandle(Symbols::PhaseParameter()), | 3059 &String::ZoneHandle(Symbols::PhaseParameter()), |
| 3030 &Type::ZoneHandle(Type::DynamicType())); | 3060 &Type::ZoneHandle(Type::IntInterface())); |
| 3031 | 3061 |
| 3032 AddFormalParamsToFunction(¶ms, ctor); | 3062 AddFormalParamsToFunction(¶ms, ctor); |
| 3033 // The body of the constructor cannot modify the type arguments of the | 3063 // The body of the constructor cannot modify the type of the constructed |
| 3034 // constructed instance, which is passed in as a hidden parameter. | 3064 // instance, which is passed in as the receiver. |
| 3035 // Therefore, there is no need to set the result type to be checked. | 3065 ctor.set_result_type(*((*params.parameters)[0].type)); |
| 3036 const AbstractType& result_type = Type::ZoneHandle(Type::DynamicType()); | |
| 3037 ctor.set_result_type(result_type); | |
| 3038 class_desc->AddFunction(ctor); | 3066 class_desc->AddFunction(ctor); |
| 3039 } | 3067 } |
| 3040 | 3068 |
| 3041 // Check for cycles in constructor redirection. | 3069 // Check for cycles in constructor redirection. |
| 3042 const GrowableArray<MemberDesc>& members = class_desc->members(); | 3070 const GrowableArray<MemberDesc>& members = class_desc->members(); |
| 3043 for (int i = 0; i < members.length(); i++) { | 3071 for (int i = 0; i < members.length(); i++) { |
| 3044 MemberDesc* member = &members[i]; | 3072 MemberDesc* member = &members[i]; |
| 3045 GrowableArray<MemberDesc*> ctors; | 3073 GrowableArray<MemberDesc*> ctors; |
| 3046 while ((member != NULL) && (member->redirect_name != NULL)) { | 3074 while ((member != NULL) && (member->redirect_name != NULL)) { |
| 3047 ASSERT(member->IsConstructor()); | 3075 ASSERT(member->IsConstructor()); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3132 const bool no_explicit_default_values = false; | 3160 const bool no_explicit_default_values = false; |
| 3133 ParseFormalParameterList(no_explicit_default_values, &func_params); | 3161 ParseFormalParameterList(no_explicit_default_values, &func_params); |
| 3134 // The field 'is_static' has no meaning for signature functions. | 3162 // The field 'is_static' has no meaning for signature functions. |
| 3135 Function& signature_function = Function::Handle( | 3163 Function& signature_function = Function::Handle( |
| 3136 Function::New(*alias_name, | 3164 Function::New(*alias_name, |
| 3137 RawFunction::kSignatureFunction, | 3165 RawFunction::kSignatureFunction, |
| 3138 /* is_static = */ false, | 3166 /* is_static = */ false, |
| 3139 /* is_const = */ false, | 3167 /* is_const = */ false, |
| 3140 /* is_abstract = */ false, | 3168 /* is_abstract = */ false, |
| 3141 /* is_external = */ false, | 3169 /* is_external = */ false, |
| 3170 alias_owner, | |
| 3142 alias_name_pos)); | 3171 alias_name_pos)); |
| 3143 signature_function.set_owner(alias_owner); | |
| 3144 signature_function.set_result_type(result_type); | 3172 signature_function.set_result_type(result_type); |
| 3145 AddFormalParamsToFunction(&func_params, signature_function); | 3173 AddFormalParamsToFunction(&func_params, signature_function); |
| 3146 const String& signature = String::Handle(signature_function.Signature()); | 3174 const String& signature = String::Handle(signature_function.Signature()); |
| 3147 if (FLAG_trace_parser) { | 3175 if (FLAG_trace_parser) { |
| 3148 OS::Print("TopLevel parsing function type alias '%s'\n", | 3176 OS::Print("TopLevel parsing function type alias '%s'\n", |
| 3149 signature.ToCString()); | 3177 signature.ToCString()); |
| 3150 } | 3178 } |
| 3151 // Lookup the signature class, i.e. the class whose name is the signature. | 3179 // Lookup the signature class, i.e. the class whose name is the signature. |
| 3152 // We only lookup in the current library, but not in its imports, and only | 3180 // We only lookup in the current library, but not in its imports, and only |
| 3153 // create a new canonical signature class if it does not exist yet. | 3181 // create a new canonical signature class if it does not exist yet. |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3551 if (library_.LookupObject(accessor_name) != Object::null()) { | 3579 if (library_.LookupObject(accessor_name) != Object::null()) { |
| 3552 ErrorMsg(name_pos, "getter for '%s' is already defined", | 3580 ErrorMsg(name_pos, "getter for '%s' is already defined", |
| 3553 var_name.ToCString()); | 3581 var_name.ToCString()); |
| 3554 } | 3582 } |
| 3555 accessor_name = Field::SetterName(var_name); | 3583 accessor_name = Field::SetterName(var_name); |
| 3556 if (library_.LookupObject(accessor_name) != Object::null()) { | 3584 if (library_.LookupObject(accessor_name) != Object::null()) { |
| 3557 ErrorMsg(name_pos, "setter for '%s' is already defined", | 3585 ErrorMsg(name_pos, "setter for '%s' is already defined", |
| 3558 var_name.ToCString()); | 3586 var_name.ToCString()); |
| 3559 } | 3587 } |
| 3560 | 3588 |
| 3561 field = Field::New(var_name, is_static, is_final, is_const, name_pos); | 3589 field = Field::New( |
| 3590 var_name, is_static, is_final, is_const, current_class(), name_pos); | |
| 3562 field.set_type(type); | 3591 field.set_type(type); |
| 3563 field.set_value(Instance::Handle(Instance::null())); | 3592 field.set_value(Instance::Handle(Instance::null())); |
| 3564 top_level->fields.Add(field); | 3593 top_level->fields.Add(field); |
| 3565 library_.AddObject(field, var_name); | 3594 library_.AddObject(field, var_name); |
| 3566 if (CurrentToken() == Token::kASSIGN) { | 3595 if (CurrentToken() == Token::kASSIGN) { |
| 3567 ConsumeToken(); | 3596 ConsumeToken(); |
| 3568 Instance& field_value = Instance::Handle(Object::sentinel()); | 3597 Instance& field_value = Instance::Handle(Object::sentinel()); |
| 3569 bool has_simple_literal = false; | 3598 bool has_simple_literal = false; |
| 3570 if ((is_final || is_const) && (LookaheadToken(1) == Token::kSEMICOLON)) { | 3599 if ((is_final || is_const) && (LookaheadToken(1) == Token::kSEMICOLON)) { |
| 3571 has_simple_literal = IsSimpleLiteral(type, &field_value); | 3600 has_simple_literal = IsSimpleLiteral(type, &field_value); |
| 3572 } | 3601 } |
| 3573 SkipExpr(); | 3602 SkipExpr(); |
| 3574 field.set_value(field_value); | 3603 field.set_value(field_value); |
| 3575 if (!has_simple_literal) { | 3604 if (!has_simple_literal) { |
| 3576 // Create a static const getter. | 3605 // Create a static const getter. |
| 3577 String& getter_name = String::ZoneHandle(Field::GetterSymbol(var_name)); | 3606 String& getter_name = String::ZoneHandle(Field::GetterSymbol(var_name)); |
| 3578 getter = Function::New(getter_name, RawFunction::kConstImplicitGetter, | 3607 getter = Function::New(getter_name, |
| 3579 is_static, is_final, false, false, name_pos); | 3608 RawFunction::kConstImplicitGetter, |
| 3609 is_static, | |
| 3610 is_final, | |
| 3611 /* is_abstract = */ false, | |
| 3612 /* is_external = */ false, | |
| 3613 current_class(), | |
| 3614 name_pos); | |
| 3580 getter.set_result_type(type); | 3615 getter.set_result_type(type); |
| 3581 top_level->functions.Add(getter); | 3616 top_level->functions.Add(getter); |
| 3582 } | 3617 } |
| 3583 | 3618 |
| 3584 } else if (is_final || is_const) { | 3619 } else if (is_final || is_const) { |
| 3585 ErrorMsg(name_pos, "missing initializer for final or const variable"); | 3620 ErrorMsg(name_pos, "missing initializer for final or const variable"); |
| 3586 } | 3621 } |
| 3587 | 3622 |
| 3588 if (CurrentToken() == Token::kCOMMA) { | 3623 if (CurrentToken() == Token::kCOMMA) { |
| 3589 ConsumeToken(); | 3624 ConsumeToken(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3651 ConsumeToken(); | 3686 ConsumeToken(); |
| 3652 SkipExpr(); | 3687 SkipExpr(); |
| 3653 ExpectSemicolon(); | 3688 ExpectSemicolon(); |
| 3654 function_end_pos = TokenPos(); | 3689 function_end_pos = TokenPos(); |
| 3655 } else if (IsLiteral("native")) { | 3690 } else if (IsLiteral("native")) { |
| 3656 ParseNativeDeclaration(); | 3691 ParseNativeDeclaration(); |
| 3657 } else { | 3692 } else { |
| 3658 ErrorMsg("function block expected"); | 3693 ErrorMsg("function block expected"); |
| 3659 } | 3694 } |
| 3660 Function& func = Function::Handle( | 3695 Function& func = Function::Handle( |
| 3661 Function::New(func_name, RawFunction::kRegularFunction, | 3696 Function::New(func_name, |
| 3662 is_static, false, false, is_external, function_pos)); | 3697 RawFunction::kRegularFunction, |
| 3698 is_static, | |
| 3699 /* is_const = */ false, | |
| 3700 /* is_abstract = */ false, | |
| 3701 is_external, | |
| 3702 current_class(), | |
| 3703 function_pos)); | |
| 3663 func.set_result_type(result_type); | 3704 func.set_result_type(result_type); |
| 3664 func.set_end_token_pos(function_end_pos); | 3705 func.set_end_token_pos(function_end_pos); |
| 3665 AddFormalParamsToFunction(¶ms, func); | 3706 AddFormalParamsToFunction(¶ms, func); |
| 3666 top_level->functions.Add(func); | 3707 top_level->functions.Add(func); |
| 3667 library_.AddObject(func, func_name); | 3708 library_.AddObject(func, func_name); |
| 3668 } | 3709 } |
| 3669 | 3710 |
| 3670 | 3711 |
| 3671 void Parser::ParseTopLevelAccessor(TopLevel* top_level) { | 3712 void Parser::ParseTopLevelAccessor(TopLevel* top_level) { |
| 3672 TRACE_PARSER("ParseTopLevelAccessor"); | 3713 TRACE_PARSER("ParseTopLevelAccessor"); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3734 ExpectSemicolon(); | 3775 ExpectSemicolon(); |
| 3735 } else if (IsLiteral("native")) { | 3776 } else if (IsLiteral("native")) { |
| 3736 ParseNativeDeclaration(); | 3777 ParseNativeDeclaration(); |
| 3737 } else { | 3778 } else { |
| 3738 ErrorMsg("function block expected"); | 3779 ErrorMsg("function block expected"); |
| 3739 } | 3780 } |
| 3740 Function& func = Function::Handle( | 3781 Function& func = Function::Handle( |
| 3741 Function::New(accessor_name, | 3782 Function::New(accessor_name, |
| 3742 is_getter? RawFunction::kGetterFunction : | 3783 is_getter? RawFunction::kGetterFunction : |
| 3743 RawFunction::kSetterFunction, | 3784 RawFunction::kSetterFunction, |
| 3744 is_static, false, false, false, accessor_pos)); | 3785 is_static, |
| 3786 /* is_const = */ false, | |
| 3787 /* is_abstract = */ false, | |
| 3788 /* is_external = */ false, | |
| 3789 current_class(), | |
| 3790 accessor_pos)); | |
| 3745 func.set_result_type(result_type); | 3791 func.set_result_type(result_type); |
| 3746 AddFormalParamsToFunction(¶ms, func); | 3792 AddFormalParamsToFunction(¶ms, func); |
| 3747 top_level->functions.Add(func); | 3793 top_level->functions.Add(func); |
| 3748 library_.AddObject(func, accessor_name); | 3794 library_.AddObject(func, accessor_name); |
| 3749 } | 3795 } |
| 3750 | 3796 |
| 3751 | 3797 |
| 3752 void Parser::ParseLibraryName() { | 3798 void Parser::ParseLibraryName() { |
| 3753 TRACE_PARSER("ParseLibraryName"); | 3799 TRACE_PARSER("ParseLibraryName"); |
| 3754 if ((script_.kind() == RawScript::kLibraryTag) && | 3800 if ((script_.kind() == RawScript::kLibraryTag) && |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4130 new ReturnNode(TokenPos(), new NativeBodyNode(TokenPos(), | 4176 new ReturnNode(TokenPos(), new NativeBodyNode(TokenPos(), |
| 4131 native_name, | 4177 native_name, |
| 4132 native_function, | 4178 native_function, |
| 4133 num_parameters, | 4179 num_parameters, |
| 4134 has_opt_params, | 4180 has_opt_params, |
| 4135 is_instance_closure))); | 4181 is_instance_closure))); |
| 4136 } | 4182 } |
| 4137 | 4183 |
| 4138 | 4184 |
| 4139 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) { | 4185 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) { |
| 4186 ASSERT(!current_function().is_static()); | |
| 4140 const String& this_name = String::Handle(Symbols::This()); | 4187 const String& this_name = String::Handle(Symbols::This()); |
| 4141 return from_scope->LookupVariable(this_name, test_only); | 4188 return from_scope->LookupVariable(this_name, test_only); |
| 4142 } | 4189 } |
| 4143 | 4190 |
| 4144 | 4191 |
| 4192 LocalVariable* Parser::LookupTypeArgumentsParameter(LocalScope* from_scope, | |
| 4193 bool test_only) { | |
| 4194 ASSERT(current_function().IsInFactoryScope()); | |
| 4195 const String& param_name = String::Handle(Symbols::TypeArgumentsParameter()); | |
| 4196 return from_scope->LookupVariable(param_name, test_only); | |
| 4197 } | |
| 4145 LocalVariable* Parser::LookupPhaseParameter() { | 4198 LocalVariable* Parser::LookupPhaseParameter() { |
| 4146 const String& phase_name = | 4199 const String& phase_name = |
| 4147 String::Handle(Symbols::PhaseParameter()); | 4200 String::Handle(Symbols::PhaseParameter()); |
| 4148 const bool kTestOnly = false; | 4201 const bool kTestOnly = false; |
| 4149 return current_block_->scope->LookupVariable(phase_name, kTestOnly); | 4202 return current_block_->scope->LookupVariable(phase_name, kTestOnly); |
| 4150 } | 4203 } |
| 4151 | 4204 |
| 4152 | 4205 |
| 4153 void Parser::CaptureReceiver() { | 4206 void Parser::CaptureInstantiator() { |
| 4154 ASSERT(current_block_->scope->function_level() > 0); | 4207 ASSERT(current_block_->scope->function_level() > 0); |
| 4155 const bool kTestOnly = false; | 4208 const bool kTestOnly = false; |
| 4156 // Side effect of lookup captures the receiver variable. | 4209 // Side effect of lookup captures the instantiator variable. |
| 4157 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); | 4210 LocalVariable* instantiator = NULL; |
| 4158 ASSERT(receiver != NULL); | 4211 if (current_function().IsInFactoryScope()) { |
| 4212 instantiator = LookupTypeArgumentsParameter(current_block_->scope, | |
| 4213 kTestOnly); | |
| 4214 } else { | |
| 4215 instantiator = LookupReceiver(current_block_->scope, kTestOnly); | |
| 4216 } | |
| 4217 ASSERT(instantiator != NULL); | |
| 4159 } | 4218 } |
| 4160 | 4219 |
| 4161 | 4220 |
| 4162 AstNode* Parser::LoadReceiver(intptr_t token_pos) { | 4221 AstNode* Parser::LoadReceiver(intptr_t token_pos) { |
| 4163 // A nested function may access 'this', referring to the receiver of the | 4222 // A nested function may access 'this', referring to the receiver of the |
| 4164 // outermost enclosing function. | 4223 // outermost enclosing function. |
| 4165 // We should not be loading the receiver from a static scope. | |
| 4166 ASSERT(!current_function().is_static() || | |
| 4167 current_function().IsInFactoryScope()); | |
| 4168 const bool kTestOnly = false; | 4224 const bool kTestOnly = false; |
| 4169 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); | 4225 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); |
| 4170 if (receiver == NULL) { | 4226 if (receiver == NULL) { |
| 4171 ErrorMsg(token_pos, "illegal implicit access to receiver 'this'"); | 4227 ErrorMsg(token_pos, "illegal implicit access to receiver 'this'"); |
| 4172 } | 4228 } |
| 4173 return new LoadLocalNode(TokenPos(), *receiver); | 4229 return new LoadLocalNode(TokenPos(), *receiver); |
| 4174 } | 4230 } |
| 4175 | 4231 |
| 4176 | 4232 |
| 4233 AstNode* Parser::LoadTypeArgumentsParameter(intptr_t token_pos) { | |
| 4234 // A nested function may access ':type_arguments' to use as instantiator, | |
| 4235 // referring to the implicit first parameter of the outermost enclosing | |
| 4236 // factory function. | |
| 4237 const bool kTestOnly = false; | |
| 4238 LocalVariable* param = LookupTypeArgumentsParameter(current_block_->scope, | |
| 4239 kTestOnly); | |
| 4240 ASSERT(param != NULL); | |
| 4241 return new LoadLocalNode(TokenPos(), *param); | |
| 4242 } | |
| 4243 | |
| 4244 | |
| 4177 AstNode* Parser::CallGetter(intptr_t token_pos, | 4245 AstNode* Parser::CallGetter(intptr_t token_pos, |
| 4178 AstNode* object, | 4246 AstNode* object, |
| 4179 const String& name) { | 4247 const String& name) { |
| 4180 return new InstanceGetterNode(TokenPos(), object, name); | 4248 return new InstanceGetterNode(TokenPos(), object, name); |
| 4181 } | 4249 } |
| 4182 | 4250 |
| 4183 | 4251 |
| 4184 // Returns ast nodes of the variable initialization. | 4252 // Returns ast nodes of the variable initialization. |
| 4185 AstNode* Parser::ParseVariableDeclaration(const AbstractType& type, | 4253 AstNode* Parser::ParseVariableDeclaration(const AbstractType& type, |
| 4186 bool is_final, | 4254 bool is_final, |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4406 ASSERT(function.signature_class() == signature_class.raw()); | 4474 ASSERT(function.signature_class() == signature_class.raw()); |
| 4407 | 4475 |
| 4408 // Local functions are registered in the enclosing class, but | 4476 // Local functions are registered in the enclosing class, but |
| 4409 // ignored during class finalization. The enclosing class has | 4477 // ignored during class finalization. The enclosing class has |
| 4410 // already been finalized. | 4478 // already been finalized. |
| 4411 ASSERT(current_class().is_finalized()); | 4479 ASSERT(current_class().is_finalized()); |
| 4412 | 4480 |
| 4413 // Make sure that the instantiator is captured. | 4481 // Make sure that the instantiator is captured. |
| 4414 if ((signature_class.NumTypeParameters() > 0) && | 4482 if ((signature_class.NumTypeParameters() > 0) && |
| 4415 (current_block_->scope->function_level() > 0)) { | 4483 (current_block_->scope->function_level() > 0)) { |
| 4416 CaptureReceiver(); | 4484 CaptureInstantiator(); |
| 4417 } | 4485 } |
| 4418 | 4486 |
| 4419 // Since the signature type is cached by the signature class, it may have | 4487 // Since the signature type is cached by the signature class, it may have |
| 4420 // been finalized already. | 4488 // been finalized already. |
| 4421 Type& signature_type = Type::Handle(signature_class.SignatureType()); | 4489 Type& signature_type = Type::Handle(signature_class.SignatureType()); |
| 4422 AbstractTypeArguments& signature_type_arguments = | 4490 AbstractTypeArguments& signature_type_arguments = |
| 4423 AbstractTypeArguments::Handle(signature_type.arguments()); | 4491 AbstractTypeArguments::Handle(signature_type.arguments()); |
| 4424 | 4492 |
| 4425 if (!signature_type.IsFinalized()) { | 4493 if (!signature_type.IsFinalized()) { |
| 4426 signature_type ^= ClassFinalizer::FinalizeType( | 4494 signature_type ^= ClassFinalizer::FinalizeType( |
| (...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5560 new JumpNode(catch_pos, Token::kCONTINUE, end_catch_label)); | 5628 new JumpNode(catch_pos, Token::kCONTINUE, end_catch_label)); |
| 5561 SequenceNode* catch_handler = CloseBlock(); | 5629 SequenceNode* catch_handler = CloseBlock(); |
| 5562 ExpectToken(Token::kRBRACE); | 5630 ExpectToken(Token::kRBRACE); |
| 5563 | 5631 |
| 5564 if (!exception_param.type->IsDynamicType()) { // Has a type specification. | 5632 if (!exception_param.type->IsDynamicType()) { // Has a type specification. |
| 5565 // Now form an 'if type check' as an exception type exists in | 5633 // Now form an 'if type check' as an exception type exists in |
| 5566 // the catch specifier. | 5634 // the catch specifier. |
| 5567 if (!exception_param.type->IsInstantiated() && | 5635 if (!exception_param.type->IsInstantiated() && |
| 5568 (current_block_->scope->function_level() > 0)) { | 5636 (current_block_->scope->function_level() > 0)) { |
| 5569 // Make sure that the instantiator is captured. | 5637 // Make sure that the instantiator is captured. |
| 5570 CaptureReceiver(); | 5638 CaptureInstantiator(); |
| 5571 } | 5639 } |
| 5572 TypeNode* exception_type = new TypeNode(catch_pos, *exception_param.type); | 5640 TypeNode* exception_type = new TypeNode(catch_pos, *exception_param.type); |
| 5573 AstNode* exception_var = new LoadLocalNode(catch_pos, *catch_excp_var); | 5641 AstNode* exception_var = new LoadLocalNode(catch_pos, *catch_excp_var); |
| 5574 if (!exception_type->type().IsInstantiated()) { | 5642 if (!exception_type->type().IsInstantiated()) { |
| 5575 EnsureExpressionTemp(); | 5643 EnsureExpressionTemp(); |
| 5576 } | 5644 } |
| 5577 AstNode* type_cond_expr = new ComparisonNode( | 5645 AstNode* type_cond_expr = new ComparisonNode( |
| 5578 catch_pos, Token::kIS, exception_var, exception_type); | 5646 catch_pos, Token::kIS, exception_var, exception_type); |
| 5579 current_block_->statements->Add( | 5647 current_block_->statements->Add( |
| 5580 new IfNode(catch_pos, type_cond_expr, catch_handler, NULL)); | 5648 new IfNode(catch_pos, type_cond_expr, catch_handler, NULL)); |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6156 if ((op_kind == Token::kIS) && (CurrentToken() == Token::kNOT)) { | 6224 if ((op_kind == Token::kIS) && (CurrentToken() == Token::kNOT)) { |
| 6157 ConsumeToken(); | 6225 ConsumeToken(); |
| 6158 op_kind = Token::kISNOT; | 6226 op_kind = Token::kISNOT; |
| 6159 } | 6227 } |
| 6160 const intptr_t type_pos = TokenPos(); | 6228 const intptr_t type_pos = TokenPos(); |
| 6161 const AbstractType& type = | 6229 const AbstractType& type = |
| 6162 AbstractType::ZoneHandle(ParseType(ClassFinalizer::kCanonicalize)); | 6230 AbstractType::ZoneHandle(ParseType(ClassFinalizer::kCanonicalize)); |
| 6163 if (!type.IsInstantiated() && | 6231 if (!type.IsInstantiated() && |
| 6164 (current_block_->scope->function_level() > 0)) { | 6232 (current_block_->scope->function_level() > 0)) { |
| 6165 // Make sure that the instantiator is captured. | 6233 // Make sure that the instantiator is captured. |
| 6166 CaptureReceiver(); | 6234 CaptureInstantiator(); |
| 6167 } | 6235 } |
| 6168 right_operand = new TypeNode(type_pos, type); | 6236 right_operand = new TypeNode(type_pos, type); |
| 6169 if ((op_kind == Token::kIS) && type.IsMalformed()) { | 6237 if ((op_kind == Token::kIS) && type.IsMalformed()) { |
| 6170 // Note that a type error is thrown even if the tested value is null | 6238 // Note that a type error is thrown even if the tested value is null |
| 6171 // in a type test. However, no cast exception is thrown if the value | 6239 // in a type test. However, no cast exception is thrown if the value |
| 6172 // is null in a type cast. | 6240 // is null in a type cast. |
| 6173 return ThrowTypeError(type_pos, type); | 6241 return ThrowTypeError(type_pos, type); |
| 6174 } | 6242 } |
| 6175 } | 6243 } |
| 6176 if (Token::IsRelationalOperator(op_kind) | 6244 if (Token::IsRelationalOperator(op_kind) |
| (...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7127 if (current_function().is_static()) { | 7195 if (current_function().is_static()) { |
| 7128 ErrorMsg(field_pos, | 7196 ErrorMsg(field_pos, |
| 7129 "cannot access instance field '%s' from a static function", | 7197 "cannot access instance field '%s' from a static function", |
| 7130 field_name.ToCString()); | 7198 field_name.ToCString()); |
| 7131 } | 7199 } |
| 7132 } | 7200 } |
| 7133 | 7201 |
| 7134 | 7202 |
| 7135 // If type parameters are currently in scope, return their declaring class, | 7203 // If type parameters are currently in scope, return their declaring class, |
| 7136 // otherwise return null. | 7204 // otherwise return null. |
| 7137 RawClass* Parser::TypeParametersScopeClass() { | 7205 RawClass* Parser::TypeParametersScopeClass() const { |
| 7138 // Type parameters cannot be referred to from a static function, except from | 7206 // Type parameters cannot be referred to from a static function, except from |
| 7139 // a constructor or from a factory. | 7207 // a constructor or from a factory. |
| 7140 // A constructor is considered as non-static by the compiler. | 7208 // A constructor is considered as non-static by the compiler. |
| 7141 if (is_top_level_) { | 7209 if (is_top_level_) { |
| 7142 if ((current_member_ == NULL) || | 7210 if ((current_member_ == NULL) || |
| 7143 (current_member_->has_factory || !current_member_->has_static)) { | 7211 (current_member_->has_factory || !current_member_->has_static)) { |
| 7144 return current_class().raw(); | 7212 return current_class().raw(); |
| 7145 } | 7213 } |
| 7146 } else { | 7214 } else { |
| 7147 if (!current_function().IsNull()) { | 7215 if (!current_function().IsNull()) { |
| 7148 Function& outer_function = Function::Handle(current_function().raw()); | 7216 Function& outer_function = Function::Handle(current_function().raw()); |
| 7149 while (outer_function.IsLocalFunction()) { | 7217 while (outer_function.IsLocalFunction()) { |
| 7150 outer_function = outer_function.parent_function(); | 7218 outer_function = outer_function.parent_function(); |
| 7151 } | 7219 } |
| 7152 if (outer_function.IsFactory() || !outer_function.is_static()) { | 7220 if (outer_function.IsFactory() || !outer_function.is_static()) { |
| 7153 return current_class().raw(); | 7221 return current_class().raw(); |
| 7154 } | 7222 } |
| 7155 } | 7223 } |
| 7156 } | 7224 } |
| 7157 return Class::null(); | 7225 return Class::null(); |
| 7158 } | 7226 } |
| 7159 | 7227 |
| 7160 | 7228 |
| 7229 const Type* Parser::ReceiverType(intptr_t type_pos) const { | |
| 7230 ASSERT(!current_class().IsNull()); | |
| 7231 TypeArguments& type_arguments = TypeArguments::Handle(); | |
| 7232 if (current_class().NumTypeParameters() > 0) { | |
| 7233 type_arguments = current_class().type_parameters(); | |
| 7234 } | |
| 7235 Type& type = Type::ZoneHandle( | |
| 7236 Type::New(current_class(), type_arguments, type_pos)); | |
|
hausner
2012/08/02 23:25:00
I don't understand why you have to allocate a new
regis
2012/08/02 23:58:37
We add this type to the formal parameter list, not
| |
| 7237 if (!is_top_level_) { | |
| 7238 type ^= ClassFinalizer::FinalizeType( | |
| 7239 current_class(), type, ClassFinalizer::kCanonicalizeWellFormed); | |
| 7240 } | |
| 7241 return &type; | |
| 7242 } | |
| 7243 | |
| 7244 | |
| 7161 bool Parser::IsInstantiatorRequired() const { | 7245 bool Parser::IsInstantiatorRequired() const { |
| 7162 ASSERT(!current_function().IsNull()); | 7246 ASSERT(!current_function().IsNull()); |
| 7163 Function& outer_function = Function::Handle(current_function().raw()); | 7247 Function& outer_function = Function::Handle(current_function().raw()); |
| 7164 while (outer_function.IsLocalFunction()) { | 7248 while (outer_function.IsLocalFunction()) { |
| 7165 outer_function = outer_function.parent_function(); | 7249 outer_function = outer_function.parent_function(); |
| 7166 } | 7250 } |
| 7167 if (outer_function.IsFactory() || !outer_function.is_static()) { | 7251 if (outer_function.IsFactory() || !outer_function.is_static()) { |
| 7168 return current_class().NumTypeParameters() > 0; | 7252 return current_class().NumTypeParameters() > 0; |
| 7169 } | 7253 } |
| 7170 return false; | 7254 return false; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7357 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 7441 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 7358 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | 7442 *node = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); |
| 7359 } | 7443 } |
| 7360 return true; | 7444 return true; |
| 7361 } else if (func.IsStaticFunction()) { | 7445 } else if (func.IsStaticFunction()) { |
| 7362 if (node != NULL) { | 7446 if (node != NULL) { |
| 7363 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 7447 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
| 7364 // The static getter may be changed later into an instance setter. | 7448 // The static getter may be changed later into an instance setter. |
| 7365 AstNode* receiver = NULL; | 7449 AstNode* receiver = NULL; |
| 7366 const bool kTestOnly = true; | 7450 const bool kTestOnly = true; |
| 7367 if ((!current_function().is_static() || | 7451 ASSERT(!current_function().IsInFactoryScope()); |
| 7368 current_function().IsInFactoryScope()) && | 7452 if (!current_function().is_static() && |
| 7369 (LookupReceiver(current_block_->scope, kTestOnly) != NULL)) { | 7453 (LookupReceiver(current_block_->scope, kTestOnly) != NULL)) { |
| 7370 receiver = LoadReceiver(ident_pos); | 7454 receiver = LoadReceiver(ident_pos); |
| 7371 } | 7455 } |
| 7372 *node = new StaticGetterNode(ident_pos, | 7456 *node = new StaticGetterNode(ident_pos, |
| 7373 receiver, | 7457 receiver, |
| 7374 Class::ZoneHandle(isolate, cls.raw()), | 7458 Class::ZoneHandle(isolate, cls.raw()), |
| 7375 ident); | 7459 ident); |
| 7376 } | 7460 } |
| 7377 return true; | 7461 return true; |
| 7378 } | 7462 } |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7781 ASSERT(!list_literal_factory_class.IsNull()); | 7865 ASSERT(!list_literal_factory_class.IsNull()); |
| 7782 const String& list_literal_factory_name = | 7866 const String& list_literal_factory_name = |
| 7783 String::Handle(Symbols::ListLiteralFactory()); | 7867 String::Handle(Symbols::ListLiteralFactory()); |
| 7784 const Function& list_literal_factory = Function::ZoneHandle( | 7868 const Function& list_literal_factory = Function::ZoneHandle( |
| 7785 list_literal_factory_class.LookupFactory(list_literal_factory_name)); | 7869 list_literal_factory_class.LookupFactory(list_literal_factory_name)); |
| 7786 ASSERT(!list_literal_factory.IsNull()); | 7870 ASSERT(!list_literal_factory.IsNull()); |
| 7787 if (!type_arguments.IsNull() && | 7871 if (!type_arguments.IsNull() && |
| 7788 !type_arguments.IsInstantiated() && | 7872 !type_arguments.IsInstantiated() && |
| 7789 (current_block_->scope->function_level() > 0)) { | 7873 (current_block_->scope->function_level() > 0)) { |
| 7790 // Make sure that the instantiator is captured. | 7874 // Make sure that the instantiator is captured. |
| 7791 CaptureReceiver(); | 7875 CaptureInstantiator(); |
| 7792 } | 7876 } |
| 7793 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); | 7877 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); |
| 7794 factory_param->Add(list); | 7878 factory_param->Add(list); |
| 7795 AbstractTypeArguments& canonical_type_arguments = | 7879 AbstractTypeArguments& canonical_type_arguments = |
| 7796 AbstractTypeArguments::ZoneHandle(type_arguments.Canonicalize()); | 7880 AbstractTypeArguments::ZoneHandle(type_arguments.Canonicalize()); |
| 7797 return CreateConstructorCallNode(literal_pos, | 7881 return CreateConstructorCallNode(literal_pos, |
| 7798 canonical_type_arguments, | 7882 canonical_type_arguments, |
| 7799 list_literal_factory, | 7883 list_literal_factory, |
| 7800 factory_param); | 7884 factory_param); |
| 7801 } | 7885 } |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8004 ASSERT(!map_literal_factory_class.IsNull()); | 8088 ASSERT(!map_literal_factory_class.IsNull()); |
| 8005 const String& map_literal_factory_name = | 8089 const String& map_literal_factory_name = |
| 8006 String::Handle(Symbols::MapLiteralFactory()); | 8090 String::Handle(Symbols::MapLiteralFactory()); |
| 8007 const Function& map_literal_factory = Function::ZoneHandle( | 8091 const Function& map_literal_factory = Function::ZoneHandle( |
| 8008 map_literal_factory_class.LookupFactory(map_literal_factory_name)); | 8092 map_literal_factory_class.LookupFactory(map_literal_factory_name)); |
| 8009 ASSERT(!map_literal_factory.IsNull()); | 8093 ASSERT(!map_literal_factory.IsNull()); |
| 8010 if (!map_type_arguments.IsNull() && | 8094 if (!map_type_arguments.IsNull() && |
| 8011 !map_type_arguments.IsInstantiated() && | 8095 !map_type_arguments.IsInstantiated() && |
| 8012 (current_block_->scope->function_level() > 0)) { | 8096 (current_block_->scope->function_level() > 0)) { |
| 8013 // Make sure that the instantiator is captured. | 8097 // Make sure that the instantiator is captured. |
| 8014 CaptureReceiver(); | 8098 CaptureInstantiator(); |
| 8015 } | 8099 } |
| 8016 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); | 8100 ArgumentListNode* factory_param = new ArgumentListNode(literal_pos); |
| 8017 factory_param->Add(kv_pairs); | 8101 factory_param->Add(kv_pairs); |
| 8018 return CreateConstructorCallNode(literal_pos, | 8102 return CreateConstructorCallNode(literal_pos, |
| 8019 map_type_arguments, | 8103 map_type_arguments, |
| 8020 map_literal_factory, | 8104 map_literal_factory, |
| 8021 factory_param); | 8105 factory_param); |
| 8022 } | 8106 } |
| 8023 } | 8107 } |
| 8024 | 8108 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8279 new_object = new LiteralNode(new_pos, | 8363 new_object = new LiteralNode(new_pos, |
| 8280 Instance::ZoneHandle(const_instance.raw())); | 8364 Instance::ZoneHandle(const_instance.raw())); |
| 8281 } | 8365 } |
| 8282 } else { | 8366 } else { |
| 8283 CheckFunctionIsCallable(new_pos, constructor); | 8367 CheckFunctionIsCallable(new_pos, constructor); |
| 8284 CheckConstructorCallTypeArguments(new_pos, constructor, type_arguments); | 8368 CheckConstructorCallTypeArguments(new_pos, constructor, type_arguments); |
| 8285 if (!type_arguments.IsNull() && | 8369 if (!type_arguments.IsNull() && |
| 8286 !type_arguments.IsInstantiated() && | 8370 !type_arguments.IsInstantiated() && |
| 8287 (current_block_->scope->function_level() > 0)) { | 8371 (current_block_->scope->function_level() > 0)) { |
| 8288 // Make sure that the instantiator is captured. | 8372 // Make sure that the instantiator is captured. |
| 8289 CaptureReceiver(); | 8373 CaptureInstantiator(); |
| 8290 } | 8374 } |
| 8291 if (type.IsMalformed()) { | 8375 if (type.IsMalformed()) { |
| 8292 // Compile the throw of a dynamic type error due to a bound error. | 8376 // Compile the throw of a dynamic type error due to a bound error. |
| 8293 return ThrowTypeError(type_pos, type); | 8377 return ThrowTypeError(type_pos, type); |
| 8294 } | 8378 } |
| 8295 // If the type argument vector is not instantiated, we verify in checked | 8379 // If the type argument vector is not instantiated, we verify in checked |
| 8296 // mode at runtime that it is within its declared bounds. | 8380 // mode at runtime that it is within its declared bounds. |
| 8297 new_object = CreateConstructorCallNode( | 8381 new_object = CreateConstructorCallNode( |
| 8298 new_pos, type_arguments, constructor, arguments); | 8382 new_pos, type_arguments, constructor, arguments); |
| 8299 } | 8383 } |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8876 void Parser::SkipQualIdent() { | 8960 void Parser::SkipQualIdent() { |
| 8877 ASSERT(IsIdentifier()); | 8961 ASSERT(IsIdentifier()); |
| 8878 ConsumeToken(); | 8962 ConsumeToken(); |
| 8879 if (CurrentToken() == Token::kPERIOD) { | 8963 if (CurrentToken() == Token::kPERIOD) { |
| 8880 ConsumeToken(); // Consume the kPERIOD token. | 8964 ConsumeToken(); // Consume the kPERIOD token. |
| 8881 ExpectIdentifier("identifier expected after '.'"); | 8965 ExpectIdentifier("identifier expected after '.'"); |
| 8882 } | 8966 } |
| 8883 } | 8967 } |
| 8884 | 8968 |
| 8885 } // namespace dart | 8969 } // namespace dart |
| OLD | NEW |