| 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 } | 258 } |
| 259 | 259 |
| 260 | 260 |
| 261 String* Parser::CurrentLiteral() const { | 261 String* Parser::CurrentLiteral() const { |
| 262 String& result = String::ZoneHandle(); | 262 String& result = String::ZoneHandle(); |
| 263 result ^= tokens_.LiteralAt(token_index_); | 263 result ^= tokens_.LiteralAt(token_index_); |
| 264 return &result; | 264 return &result; |
| 265 } | 265 } |
| 266 | 266 |
| 267 | 267 |
| 268 RawDouble* Parser::CurrentDoubleLiteral() const { |
| 269 LiteralToken& token = LiteralToken::Handle(); |
| 270 token ^= tokens_.TokenAt(token_index_); |
| 271 ASSERT(token.kind() == Token::kDOUBLE); |
| 272 return reinterpret_cast<RawDouble*>(token.value()); |
| 273 } |
| 274 |
| 275 |
| 276 RawInteger* Parser::CurrentIntegerLiteral() const { |
| 277 LiteralToken& token = LiteralToken::Handle(); |
| 278 token ^= tokens_.TokenAt(token_index_); |
| 279 ASSERT(token.kind() == Token::kINTEGER); |
| 280 return reinterpret_cast<RawInteger*>(token.value()); |
| 281 } |
| 282 |
| 283 |
| 268 // A QualIdent is an optionally qualified identifier. | 284 // A QualIdent is an optionally qualified identifier. |
| 269 struct QualIdent { | 285 struct QualIdent { |
| 270 QualIdent() { | 286 QualIdent() { |
| 271 Clear(); | 287 Clear(); |
| 272 } | 288 } |
| 273 void Clear() { | 289 void Clear() { |
| 274 lib_prefix = NULL; | 290 lib_prefix = NULL; |
| 275 ident_pos = 0; | 291 ident_pos = 0; |
| 276 ident = NULL; | 292 ident = NULL; |
| 277 } | 293 } |
| (...skipping 7265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7543 ASSERT(primary != NULL); | 7559 ASSERT(primary != NULL); |
| 7544 } else if (CurrentToken() == Token::kTHIS) { | 7560 } else if (CurrentToken() == Token::kTHIS) { |
| 7545 const String& this_name = String::Handle(String::NewSymbol(kThisName)); | 7561 const String& this_name = String::Handle(String::NewSymbol(kThisName)); |
| 7546 LocalVariable* local = LookupLocalScope(this_name); | 7562 LocalVariable* local = LookupLocalScope(this_name); |
| 7547 if (local == NULL) { | 7563 if (local == NULL) { |
| 7548 ErrorMsg("unexpected use of 'this' in primary expression"); | 7564 ErrorMsg("unexpected use of 'this' in primary expression"); |
| 7549 } | 7565 } |
| 7550 primary = new LoadLocalNode(token_index_, *local); | 7566 primary = new LoadLocalNode(token_index_, *local); |
| 7551 ConsumeToken(); | 7567 ConsumeToken(); |
| 7552 } else if (CurrentToken() == Token::kINTEGER) { | 7568 } else if (CurrentToken() == Token::kINTEGER) { |
| 7553 String* int_literal = CurrentLiteral(); | 7569 const Integer& literal = Integer::ZoneHandle(CurrentIntegerLiteral()); |
| 7554 ASSERT(int_literal != NULL); | |
| 7555 ASSERT(int_literal->Length() > 0); | |
| 7556 const Integer& literal = Integer::ZoneHandle(Integer::New(*int_literal)); | |
| 7557 primary = new LiteralNode(token_index_, literal); | 7570 primary = new LiteralNode(token_index_, literal); |
| 7558 ConsumeToken(); | 7571 ConsumeToken(); |
| 7559 } else if (CurrentToken() == Token::kTRUE) { | 7572 } else if (CurrentToken() == Token::kTRUE) { |
| 7560 primary = new LiteralNode(token_index_, Bool::ZoneHandle(Bool::True())); | 7573 primary = new LiteralNode(token_index_, Bool::ZoneHandle(Bool::True())); |
| 7561 ConsumeToken(); | 7574 ConsumeToken(); |
| 7562 } else if (CurrentToken() == Token::kFALSE) { | 7575 } else if (CurrentToken() == Token::kFALSE) { |
| 7563 primary = new LiteralNode(token_index_, Bool::ZoneHandle(Bool::False())); | 7576 primary = new LiteralNode(token_index_, Bool::ZoneHandle(Bool::False())); |
| 7564 ConsumeToken(); | 7577 ConsumeToken(); |
| 7565 } else if (CurrentToken() == Token::kNULL) { | 7578 } else if (CurrentToken() == Token::kNULL) { |
| 7566 primary = new LiteralNode(token_index_, Instance::ZoneHandle()); | 7579 primary = new LiteralNode(token_index_, Instance::ZoneHandle()); |
| 7567 ConsumeToken(); | 7580 ConsumeToken(); |
| 7568 } else if (CurrentToken() == Token::kLPAREN) { | 7581 } else if (CurrentToken() == Token::kLPAREN) { |
| 7569 ConsumeToken(); | 7582 ConsumeToken(); |
| 7570 const bool saved_mode = SetAllowFunctionLiterals(true); | 7583 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7571 primary = ParseExpr(kAllowConst); | 7584 primary = ParseExpr(kAllowConst); |
| 7572 SetAllowFunctionLiterals(saved_mode); | 7585 SetAllowFunctionLiterals(saved_mode); |
| 7573 ExpectToken(Token::kRPAREN); | 7586 ExpectToken(Token::kRPAREN); |
| 7574 } else if (CurrentToken() == Token::kDOUBLE) { | 7587 } else if (CurrentToken() == Token::kDOUBLE) { |
| 7575 String* double_literal = CurrentLiteral(); | 7588 Double& double_value = Double::ZoneHandle(CurrentDoubleLiteral()); |
| 7576 ASSERT(double_literal != NULL); | |
| 7577 ASSERT(double_literal->Length() > 0); | |
| 7578 Double& double_value = | |
| 7579 Double::ZoneHandle(Double::NewCanonical(*double_literal)); | |
| 7580 if (double_value.IsNull()) { | 7589 if (double_value.IsNull()) { |
| 7581 ErrorMsg("invalid double literal"); | 7590 ErrorMsg("invalid double literal"); |
| 7582 } | 7591 } |
| 7583 primary = new LiteralNode(token_index_, double_value); | 7592 primary = new LiteralNode(token_index_, double_value); |
| 7584 ConsumeToken(); | 7593 ConsumeToken(); |
| 7585 } else if (CurrentToken() == Token::kSTRING) { | 7594 } else if (CurrentToken() == Token::kSTRING) { |
| 7586 primary = ParseStringLiteral(); | 7595 primary = ParseStringLiteral(); |
| 7587 } else if (CurrentToken() == Token::kNEW) { | 7596 } else if (CurrentToken() == Token::kNEW) { |
| 7588 primary = ParseNewOperator(); | 7597 primary = ParseNewOperator(); |
| 7589 } else if (CurrentToken() == Token::kCONST) { | 7598 } else if (CurrentToken() == Token::kCONST) { |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7909 void Parser::SkipQualIdent() { | 7918 void Parser::SkipQualIdent() { |
| 7910 ASSERT(IsIdentifier()); | 7919 ASSERT(IsIdentifier()); |
| 7911 ConsumeToken(); | 7920 ConsumeToken(); |
| 7912 if (CurrentToken() == Token::kPERIOD) { | 7921 if (CurrentToken() == Token::kPERIOD) { |
| 7913 ConsumeToken(); // Consume the kPERIOD token. | 7922 ConsumeToken(); // Consume the kPERIOD token. |
| 7914 ExpectIdentifier("identifier expected after '.'"); | 7923 ExpectIdentifier("identifier expected after '.'"); |
| 7915 } | 7924 } |
| 7916 } | 7925 } |
| 7917 | 7926 |
| 7918 } // namespace dart | 7927 } // namespace dart |
| OLD | NEW |