| 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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 | 526 |
| 527 class ClassDesc : public ValueObject { | 527 class ClassDesc : public ValueObject { |
| 528 public: | 528 public: |
| 529 ClassDesc(const Class& cls, | 529 ClassDesc(const Class& cls, |
| 530 const String& cls_name, | 530 const String& cls_name, |
| 531 bool is_interface, | 531 bool is_interface, |
| 532 intptr_t token_pos) | 532 intptr_t token_pos) |
| 533 : clazz_(cls), | 533 : clazz_(cls), |
| 534 class_name_(cls_name), | 534 class_name_(cls_name), |
| 535 is_interface_(is_interface), | 535 is_interface_(is_interface), |
| 536 is_abstract_(false), | |
| 537 token_pos_(token_pos), | 536 token_pos_(token_pos), |
| 538 functions_(GrowableObjectArray::Handle(GrowableObjectArray::New())), | 537 functions_(GrowableObjectArray::Handle(GrowableObjectArray::New())), |
| 539 fields_(GrowableObjectArray::Handle(GrowableObjectArray::New())) { | 538 fields_(GrowableObjectArray::Handle(GrowableObjectArray::New())) { |
| 540 } | 539 } |
| 541 | 540 |
| 542 bool FunctionNameExists(const String& name, RawFunction::Kind kind) const { | 541 bool FunctionNameExists(const String& name, RawFunction::Kind kind) const { |
| 543 // First check if a function or field of same name exists. | 542 // First check if a function or field of same name exists. |
| 544 if (NameExists<Function>(functions_, name) || | 543 if (NameExists<Function>(functions_, name) || |
| 545 NameExists<Field>(fields_, name)) { | 544 NameExists<Field>(fields_, name)) { |
| 546 return true; | 545 return true; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 } | 601 } |
| 603 | 602 |
| 604 const String& class_name() const { | 603 const String& class_name() const { |
| 605 return class_name_; | 604 return class_name_; |
| 606 } | 605 } |
| 607 | 606 |
| 608 bool is_interface() const { | 607 bool is_interface() const { |
| 609 return is_interface_; | 608 return is_interface_; |
| 610 } | 609 } |
| 611 | 610 |
| 612 void set_is_abstract() { | |
| 613 is_abstract_ = true; | |
| 614 } | |
| 615 | |
| 616 bool is_abstract() const { | |
| 617 return is_abstract_; | |
| 618 } | |
| 619 | |
| 620 bool has_constructor() const { | 611 bool has_constructor() const { |
| 621 Function& func = Function::Handle(); | 612 Function& func = Function::Handle(); |
| 622 for (int i = 0; i < functions_.Length(); i++) { | 613 for (int i = 0; i < functions_.Length(); i++) { |
| 623 func ^= functions_.At(i); | 614 func ^= functions_.At(i); |
| 624 if (func.kind() == RawFunction::kConstructor) { | 615 if (func.kind() == RawFunction::kConstructor) { |
| 625 return true; | 616 return true; |
| 626 } | 617 } |
| 627 } | 618 } |
| 628 return false; | 619 return false; |
| 629 } | 620 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 660 if (name.Equals(test_name)) { | 651 if (name.Equals(test_name)) { |
| 661 return true; | 652 return true; |
| 662 } | 653 } |
| 663 } | 654 } |
| 664 return false; | 655 return false; |
| 665 } | 656 } |
| 666 | 657 |
| 667 const Class& clazz_; | 658 const Class& clazz_; |
| 668 const String& class_name_; | 659 const String& class_name_; |
| 669 const bool is_interface_; | 660 const bool is_interface_; |
| 670 bool is_abstract_; | |
| 671 intptr_t token_pos_; // Token index of "class" keyword. | 661 intptr_t token_pos_; // Token index of "class" keyword. |
| 672 GrowableObjectArray& functions_; | 662 GrowableObjectArray& functions_; |
| 673 GrowableObjectArray& fields_; | 663 GrowableObjectArray& fields_; |
| 674 GrowableArray<MemberDesc> members_; | 664 GrowableArray<MemberDesc> members_; |
| 675 }; | 665 }; |
| 676 | 666 |
| 677 | 667 |
| 678 struct TopLevel { | 668 struct TopLevel { |
| 679 TopLevel() : | 669 TopLevel() : |
| 680 fields(GrowableObjectArray::Handle(GrowableObjectArray::New())), | 670 fields(GrowableObjectArray::Handle(GrowableObjectArray::New())), |
| (...skipping 1914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2595 method->has_external, | 2585 method->has_external, |
| 2596 current_class(), | 2586 current_class(), |
| 2597 method_pos)); | 2587 method_pos)); |
| 2598 func.set_result_type(*method->type); | 2588 func.set_result_type(*method->type); |
| 2599 func.set_end_token_pos(method_end_pos); | 2589 func.set_end_token_pos(method_end_pos); |
| 2600 | 2590 |
| 2601 // No need to resolve parameter types yet, or add parameters to local scope. | 2591 // No need to resolve parameter types yet, or add parameters to local scope. |
| 2602 ASSERT(is_top_level_); | 2592 ASSERT(is_top_level_); |
| 2603 AddFormalParamsToFunction(&method->params, func); | 2593 AddFormalParamsToFunction(&method->params, func); |
| 2604 members->AddFunction(func); | 2594 members->AddFunction(func); |
| 2605 if (method->has_abstract) { | |
| 2606 members->set_is_abstract(); | |
| 2607 } | |
| 2608 } | 2595 } |
| 2609 | 2596 |
| 2610 | 2597 |
| 2611 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) { | 2598 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) { |
| 2612 TRACE_PARSER("ParseFieldDefinition"); | 2599 TRACE_PARSER("ParseFieldDefinition"); |
| 2613 // The parser has read the first field name and is now at the token | 2600 // The parser has read the first field name and is now at the token |
| 2614 // after the field name. | 2601 // after the field name. |
| 2615 ASSERT(CurrentToken() == Token::kSEMICOLON || | 2602 ASSERT(CurrentToken() == Token::kSEMICOLON || |
| 2616 CurrentToken() == Token::kCOMMA || | 2603 CurrentToken() == Token::kCOMMA || |
| 2617 CurrentToken() == Token::kASSIGN); | 2604 CurrentToken() == Token::kASSIGN); |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3105 } | 3092 } |
| 3106 | 3093 |
| 3107 ExpectToken(Token::kLBRACE); | 3094 ExpectToken(Token::kLBRACE); |
| 3108 ClassDesc members(cls, class_name, false, class_pos); | 3095 ClassDesc members(cls, class_name, false, class_pos); |
| 3109 while (CurrentToken() != Token::kRBRACE) { | 3096 while (CurrentToken() != Token::kRBRACE) { |
| 3110 SkipMetadata(); | 3097 SkipMetadata(); |
| 3111 ParseClassMemberDefinition(&members); | 3098 ParseClassMemberDefinition(&members); |
| 3112 } | 3099 } |
| 3113 ExpectToken(Token::kRBRACE); | 3100 ExpectToken(Token::kRBRACE); |
| 3114 | 3101 |
| 3115 if (is_abstract || members.is_abstract()) { | 3102 if (is_abstract) { |
| 3116 cls.set_is_abstract(); | 3103 cls.set_is_abstract(); |
| 3117 } | 3104 } |
| 3118 | 3105 |
| 3119 // Add an implicit constructor if no explicit constructor is present. No | 3106 // Add an implicit constructor if no explicit constructor is present. No |
| 3120 // implicit constructors are needed for patch classes. | 3107 // implicit constructors are needed for patch classes. |
| 3121 if (!members.has_constructor() && !is_patch) { | 3108 if (!members.has_constructor() && !is_patch) { |
| 3122 AddImplicitConstructor(&members); | 3109 AddImplicitConstructor(&members); |
| 3123 } | 3110 } |
| 3124 CheckConstructors(&members); | 3111 CheckConstructors(&members); |
| 3125 | 3112 |
| (...skipping 6396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9522 void Parser::SkipQualIdent() { | 9509 void Parser::SkipQualIdent() { |
| 9523 ASSERT(IsIdentifier()); | 9510 ASSERT(IsIdentifier()); |
| 9524 ConsumeToken(); | 9511 ConsumeToken(); |
| 9525 if (CurrentToken() == Token::kPERIOD) { | 9512 if (CurrentToken() == Token::kPERIOD) { |
| 9526 ConsumeToken(); // Consume the kPERIOD token. | 9513 ConsumeToken(); // Consume the kPERIOD token. |
| 9527 ExpectIdentifier("identifier expected after '.'"); | 9514 ExpectIdentifier("identifier expected after '.'"); |
| 9528 } | 9515 } |
| 9529 } | 9516 } |
| 9530 | 9517 |
| 9531 } // namespace dart | 9518 } // namespace dart |
| OLD | NEW |