| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 if ((node_sequence->length() == 0) || | 573 if ((node_sequence->length() == 0) || |
| 574 !node_sequence->NodeAt(node_sequence->length() - 1)->IsReturnNode()) { | 574 !node_sequence->NodeAt(node_sequence->length() - 1)->IsReturnNode()) { |
| 575 // Add implicit return node. | 575 // Add implicit return node. |
| 576 node_sequence->Add(new ReturnNode(parser.token_index_)); | 576 node_sequence->Add(new ReturnNode(parser.token_index_)); |
| 577 } | 577 } |
| 578 parsed_function->set_node_sequence(node_sequence); | 578 parsed_function->set_node_sequence(node_sequence); |
| 579 | 579 |
| 580 // The instantiator may be required at run time for generic type checks or | 580 // The instantiator may be required at run time for generic type checks or |
| 581 // allocation of generic types. | 581 // allocation of generic types. |
| 582 if (parser.current_class().IsParameterized() && | 582 if (parser.current_class().IsParameterized() && |
| 583 (!parser.current_function().IsInStaticScope() || | 583 (!parser.current_function().is_static() || |
| 584 parser.current_function().IsInFactoryScope())) { | 584 parser.current_function().IsInFactoryScope())) { |
| 585 // In the case of a local function, only set the instantiator if the | 585 // In the case of a local function, only set the instantiator if the |
| 586 // receiver was captured. | 586 // receiver was captured. |
| 587 const bool kTestOnly = true; | 587 const bool kTestOnly = true; |
| 588 LocalVariable* receiver = | 588 LocalVariable* receiver = |
| 589 parser.LookupReceiver(node_sequence->scope(), | 589 parser.LookupReceiver(node_sequence->scope(), |
| 590 kTestOnly); | 590 kTestOnly); |
| 591 if (!parser.current_function().IsLocalFunction() || | 591 if (!parser.current_function().IsLocalFunction() || |
| 592 ((receiver != NULL) && receiver->is_captured())) { | 592 ((receiver != NULL) && receiver->is_captured())) { |
| 593 parsed_function->set_instantiator( | 593 parsed_function->set_instantiator( |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 ParamList func_params; | 836 ParamList func_params; |
| 837 const bool no_explicit_default_values = false; | 837 const bool no_explicit_default_values = false; |
| 838 ParseFormalParameterList(no_explicit_default_values, &func_params); | 838 ParseFormalParameterList(no_explicit_default_values, &func_params); |
| 839 // Change the name of the parameter type to be the signature of the | 839 // Change the name of the parameter type to be the signature of the |
| 840 // function type. | 840 // function type. |
| 841 // Note that the function type signature may involve parameters of a type | 841 // Note that the function type signature may involve parameters of a type |
| 842 // that is a type parameter of the enclosing class, so we parameterize the | 842 // that is a type parameter of the enclosing class, so we parameterize the |
| 843 // signature with the type parameters of the enclosing class, if any. | 843 // signature with the type parameters of the enclosing class, if any. |
| 844 // TODO(regis): Revisit if this is not the right thing to do. | 844 // TODO(regis): Revisit if this is not the right thing to do. |
| 845 const bool is_static = | 845 const bool is_static = |
| 846 current_function().IsNull() || current_function().IsInStaticScope(); | 846 current_function().IsNull() || current_function().is_static(); |
| 847 const Function& signature_function = Function::Handle( | 847 const Function& signature_function = Function::Handle( |
| 848 Function::New(*parameter.name, | 848 Function::New(*parameter.name, |
| 849 RawFunction::kSignatureFunction, | 849 RawFunction::kSignatureFunction, |
| 850 is_static, | 850 is_static, |
| 851 /* is_const = */ false, | 851 /* is_const = */ false, |
| 852 parameter.name_pos)); | 852 parameter.name_pos)); |
| 853 signature_function.set_owner(current_class()); | 853 signature_function.set_owner(current_class()); |
| 854 signature_function.set_result_type(result_type); | 854 signature_function.set_result_type(result_type); |
| 855 AddFormalParamsToFunction(&func_params, signature_function); | 855 AddFormalParamsToFunction(&func_params, signature_function); |
| 856 const String& signature = String::Handle(signature_function.Signature()); | 856 const String& signature = String::Handle(signature_function.Signature()); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1066 } | 1066 } |
| 1067 return super_op; | 1067 return super_op; |
| 1068 } | 1068 } |
| 1069 | 1069 |
| 1070 | 1070 |
| 1071 AstNode* Parser::CreateImplicitClosureNode(const Function& func, | 1071 AstNode* Parser::CreateImplicitClosureNode(const Function& func, |
| 1072 intptr_t token_pos, | 1072 intptr_t token_pos, |
| 1073 AstNode* receiver) { | 1073 AstNode* receiver) { |
| 1074 Function& implicit_closure_function = | 1074 Function& implicit_closure_function = |
| 1075 Function::ZoneHandle(func.ImplicitClosureFunction()); | 1075 Function::ZoneHandle(func.ImplicitClosureFunction()); |
| 1076 ASSERT(!implicit_closure_function.IsNull()); | |
| 1077 ASSERT(implicit_closure_function.is_static()); // TODO(regis): For now. | |
| 1078 AstNode* node; | |
| 1079 if (receiver == NULL) { | 1076 if (receiver == NULL) { |
| 1080 ASSERT(func.is_static()); | 1077 return new ImplicitStaticClosureNode(token_pos, implicit_closure_function); |
| 1081 node = new StaticImplicitClosureNode(token_pos, implicit_closure_function); | |
| 1082 } else { | 1078 } else { |
| 1083 ASSERT(!func.is_static()); | 1079 return new ImplicitInstanceClosureNode(token_pos, |
| 1084 node = new ImplicitClosureNode(token_pos, | 1080 implicit_closure_function, |
| 1085 implicit_closure_function, | 1081 receiver); |
| 1086 receiver); | |
| 1087 } | 1082 } |
| 1088 return node; | |
| 1089 } | 1083 } |
| 1090 | 1084 |
| 1091 | 1085 |
| 1092 AstNode* Parser::ParseSuperFieldAccess(const String& field_name) { | 1086 AstNode* Parser::ParseSuperFieldAccess(const String& field_name) { |
| 1093 const intptr_t field_pos = token_index_; | 1087 const intptr_t field_pos = token_index_; |
| 1094 const Class& super_class = Class::Handle(current_class().SuperClass()); | 1088 const Class& super_class = Class::Handle(current_class().SuperClass()); |
| 1095 if (super_class.IsNull()) { | 1089 if (super_class.IsNull()) { |
| 1096 ErrorMsg("class '%s' does not have a superclass", | 1090 ErrorMsg("class '%s' does not have a superclass", |
| 1097 String::Handle(current_class().Name()).ToCString()); | 1091 String::Handle(current_class().Name()).ToCString()); |
| 1098 } | 1092 } |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1410 if (IsLiteral("class")) { | 1404 if (IsLiteral("class")) { |
| 1411 // Special case: implicit constructor. There is no source text to | 1405 // Special case: implicit constructor. There is no source text to |
| 1412 // parse. We just build the sequence node by hand. | 1406 // parse. We just build the sequence node by hand. |
| 1413 return MakeImplicitConstructor(func); | 1407 return MakeImplicitConstructor(func); |
| 1414 } | 1408 } |
| 1415 | 1409 |
| 1416 // Build local scope for function. | 1410 // Build local scope for function. |
| 1417 OpenFunctionBlock(func); | 1411 OpenFunctionBlock(func); |
| 1418 | 1412 |
| 1419 ParamList params; | 1413 ParamList params; |
| 1414 // Static functions do not have a receiver, except constructors, which are |
| 1415 // passed the allocated but uninitialized instance to construct. |
| 1416 // An instance closure may capture and access the receiver, but via the |
| 1417 // context and not via the first formal parameter. |
| 1420 // The first parameter of a factory is the TypeArguments vector of the type | 1418 // The first parameter of a factory is the TypeArguments vector of the type |
| 1421 // of the instance to be allocated. We name this hidden parameter 'this'. | 1419 // of the instance to be allocated. We name this hidden parameter 'this'. |
| 1422 const bool has_receiver = | 1420 const bool has_receiver = !func.IsClosureFunction() && |
| 1423 !func.is_static() || func.IsConstructor() || func.IsFactory(); | 1421 (!func.is_static() || func.IsConstructor() || func.IsFactory()); |
| 1424 const bool are_implicitly_final = func.is_const() && func.IsConstructor(); | 1422 const bool are_implicitly_final = func.is_const() && func.IsConstructor(); |
| 1425 const bool allow_explicit_default_values = true; | 1423 const bool allow_explicit_default_values = true; |
| 1426 ASSERT(CurrentToken() == Token::kLPAREN); | 1424 ASSERT(CurrentToken() == Token::kLPAREN); |
| 1427 if (has_receiver) { | 1425 if (has_receiver) { |
| 1428 params.AddReceiver(token_index_); | 1426 params.AddReceiver(token_index_); |
| 1429 } | 1427 } |
| 1430 if (are_implicitly_final) { | 1428 if (are_implicitly_final) { |
| 1431 params.SetImplicitlyFinal(); | 1429 params.SetImplicitlyFinal(); |
| 1432 } | 1430 } |
| 1433 ParseFormalParameterList(allow_explicit_default_values, ¶ms); | 1431 ParseFormalParameterList(allow_explicit_default_values, ¶ms); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1533 if (initialized_check_needed) { | 1531 if (initialized_check_needed) { |
| 1534 CheckConstFieldsInitialized(cls); | 1532 CheckConstFieldsInitialized(cls); |
| 1535 } | 1533 } |
| 1536 } | 1534 } |
| 1537 | 1535 |
| 1538 if (current_block_->scope->function_level() > 0) { | 1536 if (current_block_->scope->function_level() > 0) { |
| 1539 // We are parsing, but not compiling, a local function. | 1537 // We are parsing, but not compiling, a local function. |
| 1540 // The instantiator may be required at run time for generic type checks or | 1538 // The instantiator may be required at run time for generic type checks or |
| 1541 // allocation of generic types. | 1539 // allocation of generic types. |
| 1542 if (current_class().IsParameterized() && | 1540 if (current_class().IsParameterized() && |
| 1543 (!current_function().IsInStaticScope() || | 1541 (!current_function().is_static() || |
| 1544 current_function().IsInFactoryScope())) { | 1542 current_function().IsInFactoryScope())) { |
| 1545 // Make sure that the receiver of the enclosing instance function | 1543 // Make sure that the receiver of the enclosing instance function |
| 1546 // (or implicit first parameter of an enclosing factory) is marked as | 1544 // (or implicit first parameter of an enclosing factory) is marked as |
| 1547 // captured if type checks are enabled, because they may access the | 1545 // captured if type checks are enabled, because they may access the |
| 1548 // receiver to instantiate types. | 1546 // receiver to instantiate types. |
| 1549 if (FLAG_enable_type_checks) { | 1547 if (FLAG_enable_type_checks) { |
| 1550 CaptureReceiver(); | 1548 CaptureReceiver(); |
| 1551 } | 1549 } |
| 1552 } | 1550 } |
| 1553 } | 1551 } |
| (...skipping 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3143 // Side effect of lookup captures the receiver variable. | 3141 // Side effect of lookup captures the receiver variable. |
| 3144 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); | 3142 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); |
| 3145 ASSERT(receiver != NULL); | 3143 ASSERT(receiver != NULL); |
| 3146 } | 3144 } |
| 3147 | 3145 |
| 3148 | 3146 |
| 3149 AstNode* Parser::LoadReceiver(intptr_t token_pos) { | 3147 AstNode* Parser::LoadReceiver(intptr_t token_pos) { |
| 3150 // A nested function may access 'this', referring to the receiver of the | 3148 // A nested function may access 'this', referring to the receiver of the |
| 3151 // outermost enclosing function. | 3149 // outermost enclosing function. |
| 3152 // We should not be loading the receiver from a static scope. | 3150 // We should not be loading the receiver from a static scope. |
| 3153 ASSERT(!current_function().IsInStaticScope() || | 3151 ASSERT(!current_function().is_static() || |
| 3154 current_function().IsInFactoryScope()); | 3152 current_function().IsInFactoryScope()); |
| 3155 const bool kTestOnly = false; | 3153 const bool kTestOnly = false; |
| 3156 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); | 3154 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); |
| 3157 if (receiver == NULL) { | 3155 if (receiver == NULL) { |
| 3158 ErrorMsg(token_pos, "illegal access to 'this'"); | 3156 ErrorMsg(token_pos, "illegal access to 'this'"); |
| 3159 } | 3157 } |
| 3160 return new LoadLocalNode(token_index_, *receiver); | 3158 return new LoadLocalNode(token_index_, *receiver); |
| 3161 } | 3159 } |
| 3162 | 3160 |
| 3163 | 3161 |
| (...skipping 2210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5374 AstNode* array = left; | 5372 AstNode* array = left; |
| 5375 if (left->IsPrimaryNode()) { | 5373 if (left->IsPrimaryNode()) { |
| 5376 PrimaryNode* primary = left->AsPrimaryNode(); | 5374 PrimaryNode* primary = left->AsPrimaryNode(); |
| 5377 if (primary->primary().IsFunction()) { | 5375 if (primary->primary().IsFunction()) { |
| 5378 ErrorMsg(bracket_pos, "cannot apply index operator to function"); | 5376 ErrorMsg(bracket_pos, "cannot apply index operator to function"); |
| 5379 } else if (primary->primary().IsClass()) { | 5377 } else if (primary->primary().IsClass()) { |
| 5380 ErrorMsg(bracket_pos, "cannot apply index operator to class"); | 5378 ErrorMsg(bracket_pos, "cannot apply index operator to class"); |
| 5381 } else if (primary->primary().IsString()) { | 5379 } else if (primary->primary().IsString()) { |
| 5382 // Primary is an unresolved name. | 5380 // Primary is an unresolved name. |
| 5383 String& name = String::CheckedZoneHandle(primary->primary().raw()); | 5381 String& name = String::CheckedZoneHandle(primary->primary().raw()); |
| 5384 if (current_function().IsInStaticScope()) { | 5382 if (current_function().is_static()) { |
| 5385 ErrorMsg(primary->token_index(), | 5383 ErrorMsg(primary->token_index(), |
| 5386 "identifier '%s' is not declared in this scope", | 5384 "identifier '%s' is not declared in this scope", |
| 5387 name.ToCString()); | 5385 name.ToCString()); |
| 5388 } else { | 5386 } else { |
| 5389 // Treat as call to unresolved (instance) method. | 5387 // Treat as call to unresolved (instance) method. |
| 5390 AstNode* receiver = LoadReceiver(primary->token_index()); | 5388 AstNode* receiver = LoadReceiver(primary->token_index()); |
| 5391 selector = ParseInstanceCall(receiver, name); | 5389 selector = ParseInstanceCall(receiver, name); |
| 5392 } | 5390 } |
| 5393 } else { | 5391 } else { |
| 5394 // Internal parser error. | 5392 // Internal parser error. |
| 5395 UNREACHABLE(); | 5393 UNREACHABLE(); |
| 5396 } | 5394 } |
| 5397 } | 5395 } |
| 5398 selector = new LoadIndexedNode(bracket_pos, array, index); | 5396 selector = new LoadIndexedNode(bracket_pos, array, index); |
| 5399 } else if (CurrentToken() == Token::kLPAREN) { | 5397 } else if (CurrentToken() == Token::kLPAREN) { |
| 5400 if (left->IsPrimaryNode()) { | 5398 if (left->IsPrimaryNode()) { |
| 5401 PrimaryNode* primary = left->AsPrimaryNode(); | 5399 PrimaryNode* primary = left->AsPrimaryNode(); |
| 5402 const intptr_t primary_pos = primary->token_index(); | 5400 const intptr_t primary_pos = primary->token_index(); |
| 5403 if (primary->primary().IsFunction()) { | 5401 if (primary->primary().IsFunction()) { |
| 5404 Function& func = Function::CheckedHandle(primary->primary().raw()); | 5402 Function& func = Function::CheckedHandle(primary->primary().raw()); |
| 5405 String& func_name = String::ZoneHandle(func.name()); | 5403 String& func_name = String::ZoneHandle(func.name()); |
| 5406 if (func.is_static()) { | 5404 if (func.is_static()) { |
| 5407 // Parse static function call. | 5405 // Parse static function call. |
| 5408 Class& cls = Class::Handle(func.owner()); | 5406 Class& cls = Class::Handle(func.owner()); |
| 5409 selector = ParseStaticCall(cls, func_name, primary_pos); | 5407 selector = ParseStaticCall(cls, func_name, primary_pos); |
| 5410 } else { | 5408 } else { |
| 5411 // Dynamic function call on implicit "this" parameter. | 5409 // Dynamic function call on implicit "this" parameter. |
| 5412 if (current_function().IsInStaticScope()) { | 5410 if (current_function().is_static()) { |
| 5413 ErrorMsg(primary_pos, | 5411 ErrorMsg(primary_pos, |
| 5414 "Cannot access instance method '%s' " | 5412 "Cannot access instance method '%s' " |
| 5415 "from static function", | 5413 "from static function", |
| 5416 func_name.ToCString()); | 5414 func_name.ToCString()); |
| 5417 } | 5415 } |
| 5418 selector = ParseInstanceCall(LoadReceiver(primary_pos), func_name); | 5416 selector = ParseInstanceCall(LoadReceiver(primary_pos), func_name); |
| 5419 } | 5417 } |
| 5420 } else if (primary->primary().IsString()) { | 5418 } else if (primary->primary().IsString()) { |
| 5421 // Primary is an unresolved name. | 5419 // Primary is an unresolved name. |
| 5422 String& name = String::CheckedZoneHandle(primary->primary().raw()); | 5420 String& name = String::CheckedZoneHandle(primary->primary().raw()); |
| 5423 if (current_function().IsInStaticScope()) { | 5421 if (current_function().is_static()) { |
| 5424 ErrorMsg(primary->token_index(), | 5422 ErrorMsg(primary->token_index(), |
| 5425 "identifier '%s' is not declared in this scope", | 5423 "identifier '%s' is not declared in this scope", |
| 5426 name.ToCString()); | 5424 name.ToCString()); |
| 5427 } else { | 5425 } else { |
| 5428 // Treat as call to unresolved (instance) method. | 5426 // Treat as call to unresolved (instance) method. |
| 5429 AstNode* receiver = LoadReceiver(primary->token_index()); | 5427 AstNode* receiver = LoadReceiver(primary->token_index()); |
| 5430 selector = ParseInstanceCall(receiver, name); | 5428 selector = ParseInstanceCall(receiver, name); |
| 5431 } | 5429 } |
| 5432 } else if (primary->primary().IsClass()) { | 5430 } else if (primary->primary().IsClass()) { |
| 5433 ErrorMsg(left->token_index(), | 5431 ErrorMsg(left->token_index(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 5447 if (left->AsPrimaryNode()->primary().IsString()) { | 5445 if (left->AsPrimaryNode()->primary().IsString()) { |
| 5448 PrimaryNode* primary = left->AsPrimaryNode(); | 5446 PrimaryNode* primary = left->AsPrimaryNode(); |
| 5449 const String& ident = | 5447 const String& ident = |
| 5450 String::CheckedZoneHandle(primary->primary().raw()); | 5448 String::CheckedZoneHandle(primary->primary().raw()); |
| 5451 // An unresolved identifier that is not followed by a selector token | 5449 // An unresolved identifier that is not followed by a selector token |
| 5452 // . or [ or (. | 5450 // . or [ or (. |
| 5453 // If we are in a static method, this is an error. | 5451 // If we are in a static method, this is an error. |
| 5454 // If we are compiling an instance method, convert this into | 5452 // If we are compiling an instance method, convert this into |
| 5455 // a runtime lookup for a field (which may be defined in a | 5453 // a runtime lookup for a field (which may be defined in a |
| 5456 // subclass.) | 5454 // subclass.) |
| 5457 if (current_function().IsInStaticScope()) { | 5455 if (current_function().is_static()) { |
| 5458 ErrorMsg(primary->token_index(), | 5456 ErrorMsg(primary->token_index(), |
| 5459 "identifier '%s' is not declared in this scope", | 5457 "identifier '%s' is not declared in this scope", |
| 5460 ident.ToCString()); | 5458 ident.ToCString()); |
| 5461 } else { | 5459 } else { |
| 5462 // Treat as call to unresolved (instance) field. | 5460 // Treat as call to unresolved (instance) field. |
| 5463 AstNode* receiver = LoadReceiver(primary->token_index()); | 5461 AstNode* receiver = LoadReceiver(primary->token_index()); |
| 5464 postfix_expr = ParseInstanceFieldAccess(receiver, ident); | 5462 postfix_expr = ParseInstanceFieldAccess(receiver, ident); |
| 5465 } | 5463 } |
| 5466 } else if (left->AsPrimaryNode()->primary().IsFunction()) { | 5464 } else if (left->AsPrimaryNode()->primary().IsFunction()) { |
| 5467 // Treat as implicit closure. | 5465 // Treat as implicit closure. |
| 5468 PrimaryNode* primary = left->AsPrimaryNode(); | 5466 PrimaryNode* primary = left->AsPrimaryNode(); |
| 5469 const Function& func = | 5467 const Function& func = |
| 5470 Function::CheckedZoneHandle(primary->primary().raw()); | 5468 Function::CheckedZoneHandle(primary->primary().raw()); |
| 5471 const String& funcname = String::ZoneHandle(func.name()); | 5469 const String& funcname = String::ZoneHandle(func.name()); |
| 5472 if (func.is_static()) { | 5470 if (func.is_static()) { |
| 5473 // Static function access. | 5471 // Static function access. |
| 5474 postfix_expr = CreateImplicitClosureNode(func, | 5472 postfix_expr = CreateImplicitClosureNode(func, |
| 5475 primary->token_index(), | 5473 primary->token_index(), |
| 5476 NULL); | 5474 NULL); |
| 5477 } else { | 5475 } else { |
| 5478 // Instance function access. | 5476 // Instance function access. |
| 5479 if (current_function().IsInStaticScope() || | 5477 if (current_function().is_static() || |
| 5480 current_function().IsInFactoryScope()) { | 5478 current_function().IsInFactoryScope()) { |
| 5481 ErrorMsg(primary->token_index(), | 5479 ErrorMsg(primary->token_index(), |
| 5482 "illegal use of method '%s'", | 5480 "illegal use of method '%s'", |
| 5483 funcname.ToCString()); | 5481 funcname.ToCString()); |
| 5484 } | 5482 } |
| 5485 AstNode* receiver = LoadReceiver(primary->token_index()); | 5483 AstNode* receiver = LoadReceiver(primary->token_index()); |
| 5486 postfix_expr = ParseInstanceFieldAccess(receiver, funcname); | 5484 postfix_expr = ParseInstanceFieldAccess(receiver, funcname); |
| 5487 } | 5485 } |
| 5488 } | 5486 } |
| 5489 } | 5487 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5596 // A found name is treated as accessed and possibly marked as captured. | 5594 // A found name is treated as accessed and possibly marked as captured. |
| 5597 const bool kTestOnly = false; | 5595 const bool kTestOnly = false; |
| 5598 return current_block_->scope->LookupVariable(ident, kTestOnly); | 5596 return current_block_->scope->LookupVariable(ident, kTestOnly); |
| 5599 } | 5597 } |
| 5600 | 5598 |
| 5601 | 5599 |
| 5602 void Parser::CheckInstanceFieldAccess(intptr_t field_pos, | 5600 void Parser::CheckInstanceFieldAccess(intptr_t field_pos, |
| 5603 const String& field_name) { | 5601 const String& field_name) { |
| 5604 // Fields are not accessible from a static function, except from a | 5602 // Fields are not accessible from a static function, except from a |
| 5605 // constructor, which is considered as non-static by the compiler. | 5603 // constructor, which is considered as non-static by the compiler. |
| 5606 if (current_function().IsInStaticScope()) { | 5604 if (current_function().is_static()) { |
| 5607 ErrorMsg(field_pos, | 5605 ErrorMsg(field_pos, |
| 5608 "cannot access instance field '%s' from a static function", | 5606 "cannot access instance field '%s' from a static function", |
| 5609 field_name.ToCString()); | 5607 field_name.ToCString()); |
| 5610 } | 5608 } |
| 5611 } | 5609 } |
| 5612 | 5610 |
| 5613 | 5611 |
| 5614 void Parser::CheckTypeParameterReference(intptr_t type_parameter_pos, | 5612 void Parser::CheckTypeParameterReference(intptr_t type_parameter_pos, |
| 5615 const String& type_parameter_name) { | 5613 const String& type_parameter_name) { |
| 5616 // Type parameters cannot be referred to from a static function, except from | 5614 // Type parameters cannot be referred to from a static function, except from |
| 5617 // a constructor or from a factory. | 5615 // a constructor or from a factory. |
| 5618 // A constructor is considered as non-static by the compiler. | 5616 // A constructor is considered as non-static by the compiler. |
| 5619 if ((is_top_level_ && | 5617 if ((is_top_level_ && |
| 5620 (current_member_ != NULL) && | 5618 (current_member_ != NULL) && |
| 5621 current_member_->has_static && | 5619 current_member_->has_static && |
| 5622 !current_member_->has_factory) || | 5620 !current_member_->has_factory) || |
| 5623 (!current_function().IsNull() && | 5621 (!current_function().IsNull() && |
| 5624 current_function().IsInStaticScope() && | 5622 current_function().is_static() && |
| 5625 !current_function().IsInFactoryScope())) { | 5623 !current_function().IsInFactoryScope())) { |
| 5626 ErrorMsg(type_parameter_pos, | 5624 ErrorMsg(type_parameter_pos, |
| 5627 "cannot refer to type parameter '%s' from a static function", | 5625 "cannot refer to type parameter '%s' from a static function", |
| 5628 type_parameter_name.ToCString()); | 5626 type_parameter_name.ToCString()); |
| 5629 } | 5627 } |
| 5630 } | 5628 } |
| 5631 | 5629 |
| 5632 | 5630 |
| 5633 void Parser::RunStaticFieldInitializer(const Field& field) { | 5631 void Parser::RunStaticFieldInitializer(const Field& field) { |
| 5634 ASSERT(field.is_static()); | 5632 ASSERT(field.is_static()); |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5921 qual_ident, | 5919 qual_ident, |
| 5922 kResolveIncludingImports); | 5920 kResolveIncludingImports); |
| 5923 } | 5921 } |
| 5924 if (var_or_field->IsPrimaryNode()) { | 5922 if (var_or_field->IsPrimaryNode()) { |
| 5925 PrimaryNode* primary = var_or_field->AsPrimaryNode(); | 5923 PrimaryNode* primary = var_or_field->AsPrimaryNode(); |
| 5926 if (primary->primary().IsString()) { | 5924 if (primary->primary().IsString()) { |
| 5927 // We got an unresolved name. If we are compiling a static | 5925 // We got an unresolved name. If we are compiling a static |
| 5928 // method, this is an error. In an instance method, we convert | 5926 // method, this is an error. In an instance method, we convert |
| 5929 // the unresolved name to an instance field access, since a | 5927 // the unresolved name to an instance field access, since a |
| 5930 // subclass might define a field with this name. | 5928 // subclass might define a field with this name. |
| 5931 if (current_function().IsInStaticScope()) { | 5929 if (current_function().is_static()) { |
| 5932 ErrorMsg(ident_pos, "identifier '%s' is not declared in this scope", | 5930 ErrorMsg(ident_pos, "identifier '%s' is not declared in this scope", |
| 5933 ident.ToCString()); | 5931 ident.ToCString()); |
| 5934 } else { | 5932 } else { |
| 5935 // Treat as call to unresolved instance field. | 5933 // Treat as call to unresolved instance field. |
| 5936 var_or_field = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); | 5934 var_or_field = CallGetter(ident_pos, LoadReceiver(ident_pos), ident); |
| 5937 } | 5935 } |
| 5938 } else if (primary->primary().IsFunction()) { | 5936 } else if (primary->primary().IsFunction()) { |
| 5939 ErrorMsg(ident_pos, "illegal reference to method '%s'", | 5937 ErrorMsg(ident_pos, "illegal reference to method '%s'", |
| 5940 ident.ToCString()); | 5938 ident.ToCString()); |
| 5941 } else { | 5939 } else { |
| (...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6644 primary = ParseCompoundLiteral(); | 6642 primary = ParseCompoundLiteral(); |
| 6645 } else { | 6643 } else { |
| 6646 primary = ParseNewOperator(); | 6644 primary = ParseNewOperator(); |
| 6647 } | 6645 } |
| 6648 } else if (CurrentToken() == Token::kLT || | 6646 } else if (CurrentToken() == Token::kLT || |
| 6649 CurrentToken() == Token::kLBRACK || | 6647 CurrentToken() == Token::kLBRACK || |
| 6650 CurrentToken() == Token::kINDEX || | 6648 CurrentToken() == Token::kINDEX || |
| 6651 CurrentToken() == Token::kLBRACE) { | 6649 CurrentToken() == Token::kLBRACE) { |
| 6652 primary = ParseCompoundLiteral(); | 6650 primary = ParseCompoundLiteral(); |
| 6653 } else if (CurrentToken() == Token::kSUPER) { | 6651 } else if (CurrentToken() == Token::kSUPER) { |
| 6654 if (current_function().IsInStaticScope()) { | 6652 if (current_function().is_static()) { |
| 6655 ErrorMsg("cannot access superclass from static method"); | 6653 ErrorMsg("cannot access superclass from static method"); |
| 6656 } else if (current_function().IsLocalFunction()) { | 6654 } else if (current_function().IsLocalFunction()) { |
| 6657 ErrorMsg("cannot access superclass from local function"); | 6655 ErrorMsg("cannot access superclass from local function"); |
| 6658 } | 6656 } |
| 6659 ConsumeToken(); | 6657 ConsumeToken(); |
| 6660 if (CurrentToken() == Token::kPERIOD) { | 6658 if (CurrentToken() == Token::kPERIOD) { |
| 6661 ConsumeToken(); | 6659 ConsumeToken(); |
| 6662 const String& ident = *ExpectIdentifier("identifier expected"); | 6660 const String& ident = *ExpectIdentifier("identifier expected"); |
| 6663 if (CurrentToken() == Token::kLPAREN) { | 6661 if (CurrentToken() == Token::kLPAREN) { |
| 6664 primary = ParseSuperCall(ident); | 6662 primary = ParseSuperCall(ident); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6929 } | 6927 } |
| 6930 | 6928 |
| 6931 | 6929 |
| 6932 void Parser::SkipNestedExpr() { | 6930 void Parser::SkipNestedExpr() { |
| 6933 const bool saved_mode = SetAllowFunctionLiterals(true); | 6931 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 6934 SkipExpr(); | 6932 SkipExpr(); |
| 6935 SetAllowFunctionLiterals(saved_mode); | 6933 SetAllowFunctionLiterals(saved_mode); |
| 6936 } | 6934 } |
| 6937 | 6935 |
| 6938 } // namespace dart | 6936 } // namespace dart |
| OLD | NEW |