Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: runtime/vm/parser.cc

Issue 12017020: Some more ^= to |= (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 357
358 Token::Kind Parser::LookaheadToken(int num_tokens) { 358 Token::Kind Parser::LookaheadToken(int num_tokens) {
359 CompilerStats::num_tokens_lookahead++; 359 CompilerStats::num_tokens_lookahead++;
360 CompilerStats::num_token_checks++; 360 CompilerStats::num_token_checks++;
361 return tokens_iterator_.LookaheadTokenKind(num_tokens); 361 return tokens_iterator_.LookaheadTokenKind(num_tokens);
362 } 362 }
363 363
364 364
365 String* Parser::CurrentLiteral() const { 365 String* Parser::CurrentLiteral() const {
366 String& result = String::ZoneHandle(); 366 String& result = String::ZoneHandle();
367 result ^= tokens_iterator_.CurrentLiteral(); 367 result |= tokens_iterator_.CurrentLiteral();
368 return &result; 368 return &result;
369 } 369 }
370 370
371 371
372 RawDouble* Parser::CurrentDoubleLiteral() const { 372 RawDouble* Parser::CurrentDoubleLiteral() const {
373 LiteralToken& token = LiteralToken::Handle(); 373 LiteralToken& token = LiteralToken::Handle();
374 token ^= tokens_iterator_.CurrentToken(); 374 token |= tokens_iterator_.CurrentToken();
375 ASSERT(token.kind() == Token::kDOUBLE); 375 ASSERT(token.kind() == Token::kDOUBLE);
376 return reinterpret_cast<RawDouble*>(token.value()); 376 return reinterpret_cast<RawDouble*>(token.value());
377 } 377 }
378 378
379 379
380 RawInteger* Parser::CurrentIntegerLiteral() const { 380 RawInteger* Parser::CurrentIntegerLiteral() const {
381 LiteralToken& token = LiteralToken::Handle(); 381 LiteralToken& token = LiteralToken::Handle();
382 token ^= tokens_iterator_.CurrentToken(); 382 token |= tokens_iterator_.CurrentToken();
383 ASSERT(token.kind() == Token::kINTEGER); 383 ASSERT(token.kind() == Token::kINTEGER);
384 return reinterpret_cast<RawInteger*>(token.value()); 384 return reinterpret_cast<RawInteger*>(token.value());
385 } 385 }
386 386
387 387
388 // A QualIdent is an optionally qualified identifier. 388 // A QualIdent is an optionally qualified identifier.
389 struct QualIdent { 389 struct QualIdent {
390 QualIdent() { 390 QualIdent() {
391 Clear(); 391 Clear();
392 } 392 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 AstNode* instance = new LoadLocalNode(field_pos, receiver); 1759 AstNode* instance = new LoadLocalNode(field_pos, receiver);
1760 return new StoreInstanceFieldNode(field_pos, instance, field, init_expr); 1760 return new StoreInstanceFieldNode(field_pos, instance, field, init_expr);
1761 } 1761 }
1762 1762
1763 1763
1764 void Parser::CheckConstFieldsInitialized(const Class& cls) { 1764 void Parser::CheckConstFieldsInitialized(const Class& cls) {
1765 const Array& fields = Array::Handle(cls.fields()); 1765 const Array& fields = Array::Handle(cls.fields());
1766 Field& field = Field::Handle(); 1766 Field& field = Field::Handle();
1767 SequenceNode* initializers = current_block_->statements; 1767 SequenceNode* initializers = current_block_->statements;
1768 for (int field_num = 0; field_num < fields.Length(); field_num++) { 1768 for (int field_num = 0; field_num < fields.Length(); field_num++) {
1769 field ^= fields.At(field_num); 1769 field |= fields.At(field_num);
1770 if (field.is_static() || !field.is_final()) { 1770 if (field.is_static() || !field.is_final()) {
1771 continue; 1771 continue;
1772 } 1772 }
1773 bool found = false; 1773 bool found = false;
1774 for (int i = 0; i < initializers->length(); i++) { 1774 for (int i = 0; i < initializers->length(); i++) {
1775 found = false; 1775 found = false;
1776 if (initializers->NodeAt(i)->IsStoreInstanceFieldNode()) { 1776 if (initializers->NodeAt(i)->IsStoreInstanceFieldNode()) {
1777 StoreInstanceFieldNode* initializer = 1777 StoreInstanceFieldNode* initializer =
1778 initializers->NodeAt(i)->AsStoreInstanceFieldNode(); 1778 initializers->NodeAt(i)->AsStoreInstanceFieldNode();
1779 if (initializer->field().raw() == field.raw()) { 1779 if (initializer->field().raw() == field.raw()) {
(...skipping 11 matching lines...) Expand all
1791 1791
1792 1792
1793 void Parser::ParseInitializedInstanceFields(const Class& cls, 1793 void Parser::ParseInitializedInstanceFields(const Class& cls,
1794 LocalVariable* receiver, 1794 LocalVariable* receiver,
1795 GrowableArray<Field*>* initialized_fields) { 1795 GrowableArray<Field*>* initialized_fields) {
1796 TRACE_PARSER("ParseInitializedInstanceFields"); 1796 TRACE_PARSER("ParseInitializedInstanceFields");
1797 const Array& fields = Array::Handle(cls.fields()); 1797 const Array& fields = Array::Handle(cls.fields());
1798 Field& f = Field::Handle(); 1798 Field& f = Field::Handle();
1799 const intptr_t saved_pos = TokenPos(); 1799 const intptr_t saved_pos = TokenPos();
1800 for (int i = 0; i < fields.Length(); i++) { 1800 for (int i = 0; i < fields.Length(); i++) {
1801 f ^= fields.At(i); 1801 f |= fields.At(i);
1802 if (!f.is_static() && f.has_initializer()) { 1802 if (!f.is_static() && f.has_initializer()) {
1803 Field& field = Field::ZoneHandle(); 1803 Field& field = Field::ZoneHandle();
1804 field ^= fields.At(i); 1804 field |= fields.At(i);
1805 if (field.is_final()) { 1805 if (field.is_final()) {
1806 // Final fields with initializer expression may not be initialized 1806 // Final fields with initializer expression may not be initialized
1807 // again by constructors. Remember that this field is already 1807 // again by constructors. Remember that this field is already
1808 // initialized. 1808 // initialized.
1809 initialized_fields->Add(&field); 1809 initialized_fields->Add(&field);
1810 } 1810 }
1811 intptr_t field_pos = field.token_pos(); 1811 intptr_t field_pos = field.token_pos();
1812 SetPosition(field_pos); 1812 SetPosition(field_pos);
1813 ASSERT(IsIdentifier()); 1813 ASSERT(IsIdentifier());
1814 ConsumeToken(); 1814 ConsumeToken();
(...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after
3131 ErrorMsg(classname_pos, "missing class '%s' cannot be patched", 3131 ErrorMsg(classname_pos, "missing class '%s' cannot be patched",
3132 class_name.ToCString()); 3132 class_name.ToCString());
3133 } 3133 }
3134 cls = Class::New(class_name, script_, classname_pos); 3134 cls = Class::New(class_name, script_, classname_pos);
3135 library_.AddClass(cls); 3135 library_.AddClass(cls);
3136 } else { 3136 } else {
3137 if (!obj.IsClass()) { 3137 if (!obj.IsClass()) {
3138 ErrorMsg(classname_pos, "'%s' is already defined", 3138 ErrorMsg(classname_pos, "'%s' is already defined",
3139 class_name.ToCString()); 3139 class_name.ToCString());
3140 } 3140 }
3141 cls ^= obj.raw(); 3141 cls |= obj.raw();
3142 if (is_patch) { 3142 if (is_patch) {
3143 String& patch = String::Handle( 3143 String& patch = String::Handle(
3144 String::Concat(Symbols::PatchSpace(), class_name)); 3144 String::Concat(Symbols::PatchSpace(), class_name));
3145 patch = Symbols::New(patch); 3145 patch = Symbols::New(patch);
3146 cls = Class::New(patch, script_, classname_pos); 3146 cls = Class::New(patch, script_, classname_pos);
3147 cls.set_library(library_); 3147 cls.set_library(library_);
3148 } else { 3148 } else {
3149 // Not patching a class, but it has been found. This must be one of the 3149 // Not patching a class, but it has been found. This must be one of the
3150 // pre-registered classes from object.cc or a duplicate definition. 3150 // pre-registered classes from object.cc or a duplicate definition.
3151 if (cls.functions() != Object::empty_array().raw()) { 3151 if (cls.functions() != Object::empty_array().raw()) {
(...skipping 3954 matching lines...) Expand 10 before | Expand all | Expand 10 after
7106 ASSERT((CurrentToken() == Token::kLPAREN) || 7106 ASSERT((CurrentToken() == Token::kLPAREN) ||
7107 (CurrentToken() == Token::kCOMMA)); 7107 (CurrentToken() == Token::kCOMMA));
7108 ConsumeToken(); 7108 ConsumeToken();
7109 if (IsIdentifier() && (LookaheadToken(1) == Token::kCOLON)) { 7109 if (IsIdentifier() && (LookaheadToken(1) == Token::kCOLON)) {
7110 named_argument_seen = true; 7110 named_argument_seen = true;
7111 // The canonicalization of the arguments descriptor array built in 7111 // The canonicalization of the arguments descriptor array built in
7112 // the code generator requires that the names are symbols, i.e. 7112 // the code generator requires that the names are symbols, i.e.
7113 // canonicalized strings. 7113 // canonicalized strings.
7114 ASSERT(CurrentLiteral()->IsSymbol()); 7114 ASSERT(CurrentLiteral()->IsSymbol());
7115 for (int i = 0; i < names.Length(); i++) { 7115 for (int i = 0; i < names.Length(); i++) {
7116 arg_name ^= names.At(i); 7116 arg_name |= names.At(i);
7117 if (CurrentLiteral()->Equals(arg_name)) { 7117 if (CurrentLiteral()->Equals(arg_name)) {
7118 ErrorMsg("duplicate named argument"); 7118 ErrorMsg("duplicate named argument");
7119 } 7119 }
7120 } 7120 }
7121 names.Add(*CurrentLiteral()); 7121 names.Add(*CurrentLiteral());
7122 ConsumeToken(); // ident. 7122 ConsumeToken(); // ident.
7123 ConsumeToken(); // colon. 7123 ConsumeToken(); // colon.
7124 } else if (named_argument_seen) { 7124 } else if (named_argument_seen) {
7125 ErrorMsg("named argument expected"); 7125 ErrorMsg("named argument expected");
7126 } 7126 }
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
7395 selector = ParseInstanceCall(left, *ident); 7395 selector = ParseInstanceCall(left, *ident);
7396 } 7396 }
7397 } else { 7397 } else {
7398 // Field access. 7398 // Field access.
7399 Class& cls = Class::Handle(); 7399 Class& cls = Class::Handle();
7400 if (left->IsPrimaryNode()) { 7400 if (left->IsPrimaryNode()) {
7401 PrimaryNode* primary_node = left->AsPrimaryNode(); 7401 PrimaryNode* primary_node = left->AsPrimaryNode();
7402 if (primary_node->primary().IsClass()) { 7402 if (primary_node->primary().IsClass()) {
7403 // If the primary node referred to a class we are loading a 7403 // If the primary node referred to a class we are loading a
7404 // qualified static field. 7404 // qualified static field.
7405 cls ^= primary_node->primary().raw(); 7405 cls |= primary_node->primary().raw();
7406 } 7406 }
7407 } 7407 }
7408 if (cls.IsNull()) { 7408 if (cls.IsNull()) {
7409 // Instance field access. 7409 // Instance field access.
7410 selector = CallGetter(ident_pos, left, *ident); 7410 selector = CallGetter(ident_pos, left, *ident);
7411 } else { 7411 } else {
7412 // Static field access. 7412 // Static field access.
7413 selector = 7413 selector =
7414 ParseStaticFieldAccess(cls, *ident, ident_pos, !is_cascade); 7414 ParseStaticFieldAccess(cls, *ident, ident_pos, !is_cascade);
7415 } 7415 }
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
8128 TRACE_PARSER("ResolveNameInCurrentLibraryScope"); 8128 TRACE_PARSER("ResolveNameInCurrentLibraryScope");
8129 Object& obj = Object::Handle(LookupNameInLibrary(library_, name)); 8129 Object& obj = Object::Handle(LookupNameInLibrary(library_, name));
8130 if (obj.IsNull()) { 8130 if (obj.IsNull()) {
8131 // Name is not found in current library. Check scope of all 8131 // Name is not found in current library. Check scope of all
8132 // imported libraries. 8132 // imported libraries.
8133 String& first_lib_url = String::Handle(); 8133 String& first_lib_url = String::Handle();
8134 Namespace& import = Namespace::Handle(); 8134 Namespace& import = Namespace::Handle();
8135 intptr_t num_imports = library_.num_imports(); 8135 intptr_t num_imports = library_.num_imports();
8136 Object& imported_obj = Object::Handle(); 8136 Object& imported_obj = Object::Handle();
8137 for (int i = 0; i < num_imports; i++) { 8137 for (int i = 0; i < num_imports; i++) {
8138 import ^= library_.ImportAt(i); 8138 import |= library_.ImportAt(i);
8139 imported_obj = LookupNameInImport(import, name); 8139 imported_obj = LookupNameInImport(import, name);
8140 if (!imported_obj.IsNull()) { 8140 if (!imported_obj.IsNull()) {
8141 const Library& lib = Library::Handle(import.library()); 8141 const Library& lib = Library::Handle(import.library());
8142 if (!first_lib_url.IsNull()) { 8142 if (!first_lib_url.IsNull()) {
8143 // Found duplicate definition. 8143 // Found duplicate definition.
8144 Error& ambiguous_ref_error = Error::Handle(); 8144 Error& ambiguous_ref_error = Error::Handle();
8145 if (first_lib_url.raw() == lib.url()) { 8145 if (first_lib_url.raw() == lib.url()) {
8146 ambiguous_ref_error = FormatErrorMsg( 8146 ambiguous_ref_error = FormatErrorMsg(
8147 script_, ident_pos, "Error", 8147 script_, ident_pos, "Error",
8148 "ambiguous reference: " 8148 "ambiguous reference: "
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
8231 const LibraryPrefix& prefix, 8231 const LibraryPrefix& prefix,
8232 const String& name, 8232 const String& name,
8233 Error* error) { 8233 Error* error) {
8234 TRACE_PARSER("ResolveNameInPrefixScope"); 8234 TRACE_PARSER("ResolveNameInPrefixScope");
8235 Namespace& import = Namespace::Handle(); 8235 Namespace& import = Namespace::Handle();
8236 String& first_lib_url = String::Handle(); 8236 String& first_lib_url = String::Handle();
8237 Object& obj = Object::Handle(); 8237 Object& obj = Object::Handle();
8238 Object& resolved_obj = Object::Handle(); 8238 Object& resolved_obj = Object::Handle();
8239 const Array& imports = Array::Handle(prefix.imports()); 8239 const Array& imports = Array::Handle(prefix.imports());
8240 for (intptr_t i = 0; i < prefix.num_imports(); i++) { 8240 for (intptr_t i = 0; i < prefix.num_imports(); i++) {
8241 import ^= imports.At(i); 8241 import |= imports.At(i);
8242 resolved_obj = LookupNameInImport(import, name); 8242 resolved_obj = LookupNameInImport(import, name);
8243 if (!resolved_obj.IsNull()) { 8243 if (!resolved_obj.IsNull()) {
8244 obj = resolved_obj.raw(); 8244 obj = resolved_obj.raw();
8245 const Library& lib = Library::Handle(import.library()); 8245 const Library& lib = Library::Handle(import.library());
8246 if (first_lib_url.IsNull()) { 8246 if (first_lib_url.IsNull()) {
8247 first_lib_url = lib.url(); 8247 first_lib_url = lib.url();
8248 } else { 8248 } else {
8249 // Found duplicate definition. 8249 // Found duplicate definition.
8250 Error& ambiguous_ref_error = Error::Handle(); 8250 Error& ambiguous_ref_error = Error::Handle();
8251 if (first_lib_url.raw() == lib.url()) { 8251 if (first_lib_url.raw() == lib.url()) {
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
9131 ASSERT(values->ElementAt(i)->IsLiteralNode()); 9131 ASSERT(values->ElementAt(i)->IsLiteralNode());
9132 value_arr.SetAt(i, values->ElementAt(i)->AsLiteralNode()->literal()); 9132 value_arr.SetAt(i, values->ElementAt(i)->AsLiteralNode()->literal());
9133 } 9133 }
9134 9134
9135 // Build argument array to pass to the interpolation function. 9135 // Build argument array to pass to the interpolation function.
9136 const Array& interpolate_arg = Array::Handle(Array::New(1)); 9136 const Array& interpolate_arg = Array::Handle(Array::New(1));
9137 interpolate_arg.SetAt(0, value_arr); 9137 interpolate_arg.SetAt(0, value_arr);
9138 9138
9139 // Call interpolation function. 9139 // Call interpolation function.
9140 String& concatenated = String::ZoneHandle(); 9140 String& concatenated = String::ZoneHandle();
9141 concatenated ^= DartEntry::InvokeStatic(func, interpolate_arg); 9141 concatenated |= DartEntry::InvokeStatic(func, interpolate_arg);
9142 if (concatenated.IsUnhandledException()) { 9142 if (concatenated.IsUnhandledException()) {
9143 ErrorMsg("Exception thrown in Parser::Interpolate"); 9143 ErrorMsg("Exception thrown in Parser::Interpolate");
9144 } 9144 }
9145 concatenated = Symbols::New(concatenated); 9145 concatenated = Symbols::New(concatenated);
9146 return concatenated; 9146 return concatenated;
9147 } 9147 }
9148 9148
9149 9149
9150 // A string literal consists of the concatenation of the next n tokens 9150 // A string literal consists of the concatenation of the next n tokens
9151 // that satisfy the EBNF grammar: 9151 // that satisfy the EBNF grammar:
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
9709 void Parser::SkipQualIdent() { 9709 void Parser::SkipQualIdent() {
9710 ASSERT(IsIdentifier()); 9710 ASSERT(IsIdentifier());
9711 ConsumeToken(); 9711 ConsumeToken();
9712 if (CurrentToken() == Token::kPERIOD) { 9712 if (CurrentToken() == Token::kPERIOD) {
9713 ConsumeToken(); // Consume the kPERIOD token. 9713 ConsumeToken(); // Consume the kPERIOD token.
9714 ExpectIdentifier("identifier expected after '.'"); 9714 ExpectIdentifier("identifier expected after '.'");
9715 } 9715 }
9716 } 9716 }
9717 9717
9718 } // namespace dart 9718 } // namespace dart
OLDNEW
« runtime/lib/isolate.cc ('K') | « runtime/lib/string.cc ('k') | runtime/vm/scanner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698