| 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 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 return clazz_.raw(); | 619 return clazz_.raw(); |
| 620 } | 620 } |
| 621 | 621 |
| 622 const String& class_name() const { | 622 const String& class_name() const { |
| 623 return class_name_; | 623 return class_name_; |
| 624 } | 624 } |
| 625 | 625 |
| 626 bool has_constructor() const { | 626 bool has_constructor() const { |
| 627 Function& func = Function::Handle(); | 627 Function& func = Function::Handle(); |
| 628 for (int i = 0; i < functions_.Length(); i++) { | 628 for (int i = 0; i < functions_.Length(); i++) { |
| 629 func ^= functions_.At(i); | 629 func |= functions_.At(i); |
| 630 if (func.kind() == RawFunction::kConstructor) { | 630 if (func.kind() == RawFunction::kConstructor) { |
| 631 return true; | 631 return true; |
| 632 } | 632 } |
| 633 } | 633 } |
| 634 return false; | 634 return false; |
| 635 } | 635 } |
| 636 | 636 |
| 637 intptr_t token_pos() const { | 637 intptr_t token_pos() const { |
| 638 return token_pos_; | 638 return token_pos_; |
| 639 } | 639 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 653 } | 653 } |
| 654 } | 654 } |
| 655 return NULL; | 655 return NULL; |
| 656 } | 656 } |
| 657 | 657 |
| 658 private: | 658 private: |
| 659 Field* LookupField(const String& name) const { | 659 Field* LookupField(const String& name) const { |
| 660 String& test_name = String::Handle(); | 660 String& test_name = String::Handle(); |
| 661 Field& field = Field::Handle(); | 661 Field& field = Field::Handle(); |
| 662 for (int i = 0; i < fields_.Length(); i++) { | 662 for (int i = 0; i < fields_.Length(); i++) { |
| 663 field ^= fields_.At(i); | 663 field |= fields_.At(i); |
| 664 test_name = field.name(); | 664 test_name = field.name(); |
| 665 if (name.Equals(test_name)) { | 665 if (name.Equals(test_name)) { |
| 666 return &field; | 666 return &field; |
| 667 } | 667 } |
| 668 } | 668 } |
| 669 return NULL; | 669 return NULL; |
| 670 } | 670 } |
| 671 | 671 |
| 672 bool FieldExists(const String& name) const { | 672 bool FieldExists(const String& name) const { |
| 673 return LookupField(name) != NULL; | 673 return LookupField(name) != NULL; |
| 674 } | 674 } |
| 675 | 675 |
| 676 Function* LookupFunction(const String& name) const { | 676 Function* LookupFunction(const String& name) const { |
| 677 String& test_name = String::Handle(); | 677 String& test_name = String::Handle(); |
| 678 Function& func = Function::Handle(); | 678 Function& func = Function::Handle(); |
| 679 for (int i = 0; i < functions_.Length(); i++) { | 679 for (int i = 0; i < functions_.Length(); i++) { |
| 680 func ^= functions_.At(i); | 680 func |= functions_.At(i); |
| 681 test_name = func.name(); | 681 test_name = func.name(); |
| 682 if (name.Equals(test_name)) { | 682 if (name.Equals(test_name)) { |
| 683 return &func; | 683 return &func; |
| 684 } | 684 } |
| 685 } | 685 } |
| 686 return NULL; | 686 return NULL; |
| 687 } | 687 } |
| 688 | 688 |
| 689 bool FunctionExists(const String& name) const { | 689 bool FunctionExists(const String& name) const { |
| 690 return LookupFunction(name) != NULL; | 690 return LookupFunction(name) != NULL; |
| (...skipping 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1725 AstNode* instance = new LoadLocalNode(field_pos, receiver); | 1725 AstNode* instance = new LoadLocalNode(field_pos, receiver); |
| 1726 return new StoreInstanceFieldNode(field_pos, instance, field, init_expr); | 1726 return new StoreInstanceFieldNode(field_pos, instance, field, init_expr); |
| 1727 } | 1727 } |
| 1728 | 1728 |
| 1729 | 1729 |
| 1730 void Parser::CheckConstFieldsInitialized(const Class& cls) { | 1730 void Parser::CheckConstFieldsInitialized(const Class& cls) { |
| 1731 const Array& fields = Array::Handle(cls.fields()); | 1731 const Array& fields = Array::Handle(cls.fields()); |
| 1732 Field& field = Field::Handle(); | 1732 Field& field = Field::Handle(); |
| 1733 SequenceNode* initializers = current_block_->statements; | 1733 SequenceNode* initializers = current_block_->statements; |
| 1734 for (int field_num = 0; field_num < fields.Length(); field_num++) { | 1734 for (int field_num = 0; field_num < fields.Length(); field_num++) { |
| 1735 field ^= fields.At(field_num); | 1735 field |= fields.At(field_num); |
| 1736 if (field.is_static() || !field.is_final()) { | 1736 if (field.is_static() || !field.is_final()) { |
| 1737 continue; | 1737 continue; |
| 1738 } | 1738 } |
| 1739 bool found = false; | 1739 bool found = false; |
| 1740 for (int i = 0; i < initializers->length(); i++) { | 1740 for (int i = 0; i < initializers->length(); i++) { |
| 1741 found = false; | 1741 found = false; |
| 1742 if (initializers->NodeAt(i)->IsStoreInstanceFieldNode()) { | 1742 if (initializers->NodeAt(i)->IsStoreInstanceFieldNode()) { |
| 1743 StoreInstanceFieldNode* initializer = | 1743 StoreInstanceFieldNode* initializer = |
| 1744 initializers->NodeAt(i)->AsStoreInstanceFieldNode(); | 1744 initializers->NodeAt(i)->AsStoreInstanceFieldNode(); |
| 1745 if (initializer->field().raw() == field.raw()) { | 1745 if (initializer->field().raw() == field.raw()) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1757 | 1757 |
| 1758 | 1758 |
| 1759 void Parser::ParseInitializedInstanceFields(const Class& cls, | 1759 void Parser::ParseInitializedInstanceFields(const Class& cls, |
| 1760 LocalVariable* receiver, | 1760 LocalVariable* receiver, |
| 1761 GrowableArray<Field*>* initialized_fields) { | 1761 GrowableArray<Field*>* initialized_fields) { |
| 1762 TRACE_PARSER("ParseInitializedInstanceFields"); | 1762 TRACE_PARSER("ParseInitializedInstanceFields"); |
| 1763 const Array& fields = Array::Handle(cls.fields()); | 1763 const Array& fields = Array::Handle(cls.fields()); |
| 1764 Field& f = Field::Handle(); | 1764 Field& f = Field::Handle(); |
| 1765 const intptr_t saved_pos = TokenPos(); | 1765 const intptr_t saved_pos = TokenPos(); |
| 1766 for (int i = 0; i < fields.Length(); i++) { | 1766 for (int i = 0; i < fields.Length(); i++) { |
| 1767 f ^= fields.At(i); | 1767 f |= fields.At(i); |
| 1768 if (!f.is_static() && f.has_initializer()) { | 1768 if (!f.is_static() && f.has_initializer()) { |
| 1769 Field& field = Field::ZoneHandle(); | 1769 Field& field = Field::ZoneHandle(); |
| 1770 field ^= fields.At(i); | 1770 field |= fields.At(i); |
| 1771 if (field.is_final()) { | 1771 if (field.is_final()) { |
| 1772 // Final fields with initializer expression may not be initialized | 1772 // Final fields with initializer expression may not be initialized |
| 1773 // again by constructors. Remember that this field is already | 1773 // again by constructors. Remember that this field is already |
| 1774 // initialized. | 1774 // initialized. |
| 1775 initialized_fields->Add(&field); | 1775 initialized_fields->Add(&field); |
| 1776 } | 1776 } |
| 1777 intptr_t field_pos = field.token_pos(); | 1777 intptr_t field_pos = field.token_pos(); |
| 1778 SetPosition(field_pos); | 1778 SetPosition(field_pos); |
| 1779 ASSERT(IsIdentifier()); | 1779 ASSERT(IsIdentifier()); |
| 1780 ConsumeToken(); | 1780 ConsumeToken(); |
| (...skipping 5291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7072 ASSERT((CurrentToken() == Token::kLPAREN) || | 7072 ASSERT((CurrentToken() == Token::kLPAREN) || |
| 7073 (CurrentToken() == Token::kCOMMA)); | 7073 (CurrentToken() == Token::kCOMMA)); |
| 7074 ConsumeToken(); | 7074 ConsumeToken(); |
| 7075 if (IsIdentifier() && (LookaheadToken(1) == Token::kCOLON)) { | 7075 if (IsIdentifier() && (LookaheadToken(1) == Token::kCOLON)) { |
| 7076 named_argument_seen = true; | 7076 named_argument_seen = true; |
| 7077 // The canonicalization of the arguments descriptor array built in | 7077 // The canonicalization of the arguments descriptor array built in |
| 7078 // the code generator requires that the names are symbols, i.e. | 7078 // the code generator requires that the names are symbols, i.e. |
| 7079 // canonicalized strings. | 7079 // canonicalized strings. |
| 7080 ASSERT(CurrentLiteral()->IsSymbol()); | 7080 ASSERT(CurrentLiteral()->IsSymbol()); |
| 7081 for (int i = 0; i < names.Length(); i++) { | 7081 for (int i = 0; i < names.Length(); i++) { |
| 7082 arg_name ^= names.At(i); | 7082 arg_name |= names.At(i); |
| 7083 if (CurrentLiteral()->Equals(arg_name)) { | 7083 if (CurrentLiteral()->Equals(arg_name)) { |
| 7084 ErrorMsg("duplicate named argument"); | 7084 ErrorMsg("duplicate named argument"); |
| 7085 } | 7085 } |
| 7086 } | 7086 } |
| 7087 names.Add(*CurrentLiteral()); | 7087 names.Add(*CurrentLiteral()); |
| 7088 ConsumeToken(); // ident. | 7088 ConsumeToken(); // ident. |
| 7089 ConsumeToken(); // colon. | 7089 ConsumeToken(); // colon. |
| 7090 } else if (named_argument_seen) { | 7090 } else if (named_argument_seen) { |
| 7091 ErrorMsg("named argument expected"); | 7091 ErrorMsg("named argument expected"); |
| 7092 } | 7092 } |
| (...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8094 TRACE_PARSER("ResolveNameInCurrentLibraryScope"); | 8094 TRACE_PARSER("ResolveNameInCurrentLibraryScope"); |
| 8095 Object& obj = Object::Handle(LookupNameInLibrary(library_, name)); | 8095 Object& obj = Object::Handle(LookupNameInLibrary(library_, name)); |
| 8096 if (obj.IsNull()) { | 8096 if (obj.IsNull()) { |
| 8097 // Name is not found in current library. Check scope of all | 8097 // Name is not found in current library. Check scope of all |
| 8098 // imported libraries. | 8098 // imported libraries. |
| 8099 String& first_lib_url = String::Handle(); | 8099 String& first_lib_url = String::Handle(); |
| 8100 Namespace& import = Namespace::Handle(); | 8100 Namespace& import = Namespace::Handle(); |
| 8101 intptr_t num_imports = library_.num_imports(); | 8101 intptr_t num_imports = library_.num_imports(); |
| 8102 Object& imported_obj = Object::Handle(); | 8102 Object& imported_obj = Object::Handle(); |
| 8103 for (int i = 0; i < num_imports; i++) { | 8103 for (int i = 0; i < num_imports; i++) { |
| 8104 import ^= library_.ImportAt(i); | 8104 import |= library_.ImportAt(i); |
| 8105 imported_obj = LookupNameInImport(import, name); | 8105 imported_obj = LookupNameInImport(import, name); |
| 8106 if (!imported_obj.IsNull()) { | 8106 if (!imported_obj.IsNull()) { |
| 8107 const Library& lib = Library::Handle(import.library()); | 8107 const Library& lib = Library::Handle(import.library()); |
| 8108 if (!first_lib_url.IsNull()) { | 8108 if (!first_lib_url.IsNull()) { |
| 8109 // Found duplicate definition. | 8109 // Found duplicate definition. |
| 8110 Error& ambiguous_ref_error = Error::Handle(); | 8110 Error& ambiguous_ref_error = Error::Handle(); |
| 8111 if (first_lib_url.raw() == lib.url()) { | 8111 if (first_lib_url.raw() == lib.url()) { |
| 8112 ambiguous_ref_error = FormatErrorMsg( | 8112 ambiguous_ref_error = FormatErrorMsg( |
| 8113 script_, ident_pos, "Error", | 8113 script_, ident_pos, "Error", |
| 8114 "ambiguous reference: " | 8114 "ambiguous reference: " |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8197 const LibraryPrefix& prefix, | 8197 const LibraryPrefix& prefix, |
| 8198 const String& name, | 8198 const String& name, |
| 8199 Error* error) { | 8199 Error* error) { |
| 8200 TRACE_PARSER("ResolveNameInPrefixScope"); | 8200 TRACE_PARSER("ResolveNameInPrefixScope"); |
| 8201 Namespace& import = Namespace::Handle(); | 8201 Namespace& import = Namespace::Handle(); |
| 8202 String& first_lib_url = String::Handle(); | 8202 String& first_lib_url = String::Handle(); |
| 8203 Object& obj = Object::Handle(); | 8203 Object& obj = Object::Handle(); |
| 8204 Object& resolved_obj = Object::Handle(); | 8204 Object& resolved_obj = Object::Handle(); |
| 8205 const Array& imports = Array::Handle(prefix.imports()); | 8205 const Array& imports = Array::Handle(prefix.imports()); |
| 8206 for (intptr_t i = 0; i < prefix.num_imports(); i++) { | 8206 for (intptr_t i = 0; i < prefix.num_imports(); i++) { |
| 8207 import ^= imports.At(i); | 8207 import |= imports.At(i); |
| 8208 resolved_obj = LookupNameInImport(import, name); | 8208 resolved_obj = LookupNameInImport(import, name); |
| 8209 if (!resolved_obj.IsNull()) { | 8209 if (!resolved_obj.IsNull()) { |
| 8210 obj = resolved_obj.raw(); | 8210 obj = resolved_obj.raw(); |
| 8211 const Library& lib = Library::Handle(import.library()); | 8211 const Library& lib = Library::Handle(import.library()); |
| 8212 if (first_lib_url.IsNull()) { | 8212 if (first_lib_url.IsNull()) { |
| 8213 first_lib_url = lib.url(); | 8213 first_lib_url = lib.url(); |
| 8214 } else { | 8214 } else { |
| 8215 // Found duplicate definition. | 8215 // Found duplicate definition. |
| 8216 Error& ambiguous_ref_error = Error::Handle(); | 8216 Error& ambiguous_ref_error = Error::Handle(); |
| 8217 if (first_lib_url.raw() == lib.url()) { | 8217 if (first_lib_url.raw() == lib.url()) { |
| (...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9675 void Parser::SkipQualIdent() { | 9675 void Parser::SkipQualIdent() { |
| 9676 ASSERT(IsIdentifier()); | 9676 ASSERT(IsIdentifier()); |
| 9677 ConsumeToken(); | 9677 ConsumeToken(); |
| 9678 if (CurrentToken() == Token::kPERIOD) { | 9678 if (CurrentToken() == Token::kPERIOD) { |
| 9679 ConsumeToken(); // Consume the kPERIOD token. | 9679 ConsumeToken(); // Consume the kPERIOD token. |
| 9680 ExpectIdentifier("identifier expected after '.'"); | 9680 ExpectIdentifier("identifier expected after '.'"); |
| 9681 } | 9681 } |
| 9682 } | 9682 } |
| 9683 | 9683 |
| 9684 } // namespace dart | 9684 } // namespace dart |
| OLD | NEW |