| 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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 num_fixed_parameters = 0; | 428 num_fixed_parameters = 0; |
| 429 num_optional_parameters = 0; | 429 num_optional_parameters = 0; |
| 430 has_optional_positional_parameters = false; | 430 has_optional_positional_parameters = false; |
| 431 has_optional_named_parameters = false; | 431 has_optional_named_parameters = false; |
| 432 has_field_initializer = false; | 432 has_field_initializer = false; |
| 433 implicitly_final = false; | 433 implicitly_final = false; |
| 434 this->parameters = new ZoneGrowableArray<ParamDesc>(); | 434 this->parameters = new ZoneGrowableArray<ParamDesc>(); |
| 435 } | 435 } |
| 436 | 436 |
| 437 void AddFinalParameter(intptr_t name_pos, | 437 void AddFinalParameter(intptr_t name_pos, |
| 438 String* name, | 438 const String* name, |
| 439 const AbstractType* type) { | 439 const AbstractType* type) { |
| 440 this->num_fixed_parameters++; | 440 this->num_fixed_parameters++; |
| 441 ParamDesc param; | 441 ParamDesc param; |
| 442 param.name_pos = name_pos; | 442 param.name_pos = name_pos; |
| 443 param.name = name; | 443 param.name = name; |
| 444 param.is_final = true; | 444 param.is_final = true; |
| 445 param.type = type; | 445 param.type = type; |
| 446 this->parameters->Add(param); | 446 this->parameters->Add(param); |
| 447 } | 447 } |
| 448 | 448 |
| 449 void AddReceiver(const Type* receiver_type) { | 449 void AddReceiver(const Type* receiver_type) { |
| 450 ASSERT(this->parameters->is_empty()); | 450 ASSERT(this->parameters->is_empty()); |
| 451 AddFinalParameter(receiver_type->token_pos(), | 451 AddFinalParameter(receiver_type->token_pos(), |
| 452 &String::ZoneHandle(Symbols::This()), | 452 &Symbols::ThisHandle(), |
| 453 receiver_type); | 453 receiver_type); |
| 454 } | 454 } |
| 455 | 455 |
| 456 void SetImplicitlyFinal() { | 456 void SetImplicitlyFinal() { |
| 457 implicitly_final = true; | 457 implicitly_final = true; |
| 458 } | 458 } |
| 459 | 459 |
| 460 int num_fixed_parameters; | 460 int num_fixed_parameters; |
| 461 int num_optional_parameters; | 461 int num_optional_parameters; |
| 462 bool has_optional_positional_parameters; | 462 bool has_optional_positional_parameters; |
| (...skipping 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1890 } | 1890 } |
| 1891 | 1891 |
| 1892 | 1892 |
| 1893 SequenceNode* Parser::MakeImplicitConstructor(const Function& func) { | 1893 SequenceNode* Parser::MakeImplicitConstructor(const Function& func) { |
| 1894 ASSERT(func.IsConstructor()); | 1894 ASSERT(func.IsConstructor()); |
| 1895 const intptr_t ctor_pos = TokenPos(); | 1895 const intptr_t ctor_pos = TokenPos(); |
| 1896 OpenFunctionBlock(func); | 1896 OpenFunctionBlock(func); |
| 1897 const Class& cls = Class::Handle(func.Owner()); | 1897 const Class& cls = Class::Handle(func.Owner()); |
| 1898 LocalVariable* receiver = new LocalVariable( | 1898 LocalVariable* receiver = new LocalVariable( |
| 1899 ctor_pos, | 1899 ctor_pos, |
| 1900 String::ZoneHandle(Symbols::This()), | 1900 Symbols::ThisHandle(), |
| 1901 Type::ZoneHandle(Type::DynamicType())); | 1901 Type::ZoneHandle(Type::DynamicType())); |
| 1902 current_block_->scope->AddVariable(receiver); | 1902 current_block_->scope->AddVariable(receiver); |
| 1903 | 1903 |
| 1904 LocalVariable* phase_parameter = new LocalVariable( | 1904 LocalVariable* phase_parameter = new LocalVariable( |
| 1905 ctor_pos, | 1905 ctor_pos, |
| 1906 String::ZoneHandle(Symbols::PhaseParameter()), | 1906 String::ZoneHandle(Symbols::PhaseParameter()), |
| 1907 Type::ZoneHandle(Type::SmiType())); | 1907 Type::ZoneHandle(Type::SmiType())); |
| 1908 current_block_->scope->AddVariable(phase_parameter); | 1908 current_block_->scope->AddVariable(phase_parameter); |
| 1909 | 1909 |
| 1910 // Parse expressions of instance fields that have an explicit | 1910 // Parse expressions of instance fields that have an explicit |
| (...skipping 2614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4525 new ReturnNode(TokenPos(), | 4525 new ReturnNode(TokenPos(), |
| 4526 new NativeBodyNode(TokenPos(), | 4526 new NativeBodyNode(TokenPos(), |
| 4527 Function::ZoneHandle(func.raw()), | 4527 Function::ZoneHandle(func.raw()), |
| 4528 native_name, | 4528 native_name, |
| 4529 native_function))); | 4529 native_function))); |
| 4530 } | 4530 } |
| 4531 | 4531 |
| 4532 | 4532 |
| 4533 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) { | 4533 LocalVariable* Parser::LookupReceiver(LocalScope* from_scope, bool test_only) { |
| 4534 ASSERT(!current_function().is_static()); | 4534 ASSERT(!current_function().is_static()); |
| 4535 const String& this_name = String::Handle(Symbols::This()); | 4535 return from_scope->LookupVariable(Symbols::ThisHandle(), test_only); |
| 4536 return from_scope->LookupVariable(this_name, test_only); | |
| 4537 } | 4536 } |
| 4538 | 4537 |
| 4539 | 4538 |
| 4540 LocalVariable* Parser::LookupTypeArgumentsParameter(LocalScope* from_scope, | 4539 LocalVariable* Parser::LookupTypeArgumentsParameter(LocalScope* from_scope, |
| 4541 bool test_only) { | 4540 bool test_only) { |
| 4542 ASSERT(current_function().IsInFactoryScope()); | 4541 ASSERT(current_function().IsInFactoryScope()); |
| 4543 const String& param_name = String::Handle(Symbols::TypeArgumentsParameter()); | 4542 const String& param_name = String::Handle(Symbols::TypeArgumentsParameter()); |
| 4544 return from_scope->LookupVariable(param_name, test_only); | 4543 return from_scope->LookupVariable(param_name, test_only); |
| 4545 } | 4544 } |
| 4546 LocalVariable* Parser::LookupPhaseParameter() { | 4545 LocalVariable* Parser::LookupPhaseParameter() { |
| (...skipping 3137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7684 // Returns true if ident resolves to a formal parameter of the current function | 7683 // Returns true if ident resolves to a formal parameter of the current function |
| 7685 // or of one of its enclosing functions. | 7684 // or of one of its enclosing functions. |
| 7686 // Make sure not to capture the formal parameter, since it is not accessed. | 7685 // Make sure not to capture the formal parameter, since it is not accessed. |
| 7687 bool Parser::IsFormalParameter(const String& ident, | 7686 bool Parser::IsFormalParameter(const String& ident, |
| 7688 Function* owner_function, | 7687 Function* owner_function, |
| 7689 LocalScope** owner_scope, | 7688 LocalScope** owner_scope, |
| 7690 intptr_t* local_index) { | 7689 intptr_t* local_index) { |
| 7691 if (current_block_ == NULL) { | 7690 if (current_block_ == NULL) { |
| 7692 return false; | 7691 return false; |
| 7693 } | 7692 } |
| 7694 if (ident.Equals(String::Handle(Symbols::This()))) { | 7693 if (ident.Equals(Symbols::ThisHandle())) { |
| 7695 // 'this' is not a formal parameter. | 7694 // 'this' is not a formal parameter. |
| 7696 return false; | 7695 return false; |
| 7697 } | 7696 } |
| 7698 // Since an argument definition test does not use the value of the formal | 7697 // Since an argument definition test does not use the value of the formal |
| 7699 // parameter, there is no reason to capture it. | 7698 // parameter, there is no reason to capture it. |
| 7700 const bool kTestOnly = true; // No capturing. | 7699 const bool kTestOnly = true; // No capturing. |
| 7701 LocalVariable* local = | 7700 LocalVariable* local = |
| 7702 current_block_->scope->LookupVariable(ident, kTestOnly); | 7701 current_block_->scope->LookupVariable(ident, kTestOnly); |
| 7703 if (local == NULL) { | 7702 if (local == NULL) { |
| 7704 if (!current_function().IsLocalFunction()) { | 7703 if (!current_function().IsLocalFunction()) { |
| (...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9299 } else { | 9298 } else { |
| 9300 // This is a qualified identifier with a library prefix so resolve | 9299 // This is a qualified identifier with a library prefix so resolve |
| 9301 // the identifier locally in that library (we do not include the | 9300 // the identifier locally in that library (we do not include the |
| 9302 // libraries imported by that library). | 9301 // libraries imported by that library). |
| 9303 primary = ResolveIdentInPrefixScope(qual_ident.ident_pos, | 9302 primary = ResolveIdentInPrefixScope(qual_ident.ident_pos, |
| 9304 *qual_ident.lib_prefix, | 9303 *qual_ident.lib_prefix, |
| 9305 *qual_ident.ident); | 9304 *qual_ident.ident); |
| 9306 } | 9305 } |
| 9307 ASSERT(primary != NULL); | 9306 ASSERT(primary != NULL); |
| 9308 } else if (CurrentToken() == Token::kTHIS) { | 9307 } else if (CurrentToken() == Token::kTHIS) { |
| 9309 const String& this_name = String::Handle(Symbols::This()); | 9308 LocalVariable* local = LookupLocalScope(Symbols::ThisHandle()); |
| 9310 LocalVariable* local = LookupLocalScope(this_name); | |
| 9311 if (local == NULL) { | 9309 if (local == NULL) { |
| 9312 ErrorMsg("receiver 'this' is not in scope"); | 9310 ErrorMsg("receiver 'this' is not in scope"); |
| 9313 } | 9311 } |
| 9314 primary = new LoadLocalNode(TokenPos(), local); | 9312 primary = new LoadLocalNode(TokenPos(), local); |
| 9315 ConsumeToken(); | 9313 ConsumeToken(); |
| 9316 } else if (CurrentToken() == Token::kINTEGER) { | 9314 } else if (CurrentToken() == Token::kINTEGER) { |
| 9317 const Integer& literal = Integer::ZoneHandle(CurrentIntegerLiteral()); | 9315 const Integer& literal = Integer::ZoneHandle(CurrentIntegerLiteral()); |
| 9318 primary = new LiteralNode(TokenPos(), literal); | 9316 primary = new LiteralNode(TokenPos(), literal); |
| 9319 ConsumeToken(); | 9317 ConsumeToken(); |
| 9320 } else if (CurrentToken() == Token::kTRUE) { | 9318 } else if (CurrentToken() == Token::kTRUE) { |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9699 void Parser::SkipQualIdent() { | 9697 void Parser::SkipQualIdent() { |
| 9700 ASSERT(IsIdentifier()); | 9698 ASSERT(IsIdentifier()); |
| 9701 ConsumeToken(); | 9699 ConsumeToken(); |
| 9702 if (CurrentToken() == Token::kPERIOD) { | 9700 if (CurrentToken() == Token::kPERIOD) { |
| 9703 ConsumeToken(); // Consume the kPERIOD token. | 9701 ConsumeToken(); // Consume the kPERIOD token. |
| 9704 ExpectIdentifier("identifier expected after '.'"); | 9702 ExpectIdentifier("identifier expected after '.'"); |
| 9705 } | 9703 } |
| 9706 } | 9704 } |
| 9707 | 9705 |
| 9708 } // namespace dart | 9706 } // namespace dart |
| OLD | NEW |