| 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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 2738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 4243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 1715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |