| 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 7269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7547 ASSERT(primary != NULL); | 7563 ASSERT(primary != NULL); |
| 7548 } else if (CurrentToken() == Token::kTHIS) { | 7564 } else if (CurrentToken() == Token::kTHIS) { |
| 7549 const String& this_name = String::Handle(String::NewSymbol(kThisName)); | 7565 const String& this_name = String::Handle(String::NewSymbol(kThisName)); |
| 7550 LocalVariable* local = LookupLocalScope(this_name); | 7566 LocalVariable* local = LookupLocalScope(this_name); |
| 7551 if (local == NULL) { | 7567 if (local == NULL) { |
| 7552 ErrorMsg("unexpected use of 'this' in primary expression"); | 7568 ErrorMsg("unexpected use of 'this' in primary expression"); |
| 7553 } | 7569 } |
| 7554 primary = new LoadLocalNode(token_index_, *local); | 7570 primary = new LoadLocalNode(token_index_, *local); |
| 7555 ConsumeToken(); | 7571 ConsumeToken(); |
| 7556 } else if (CurrentToken() == Token::kINTEGER) { | 7572 } else if (CurrentToken() == Token::kINTEGER) { |
| 7557 String* int_literal = CurrentLiteral(); | 7573 const Integer& literal = Integer::ZoneHandle(CurrentIntegerLiteral()); |
| 7558 ASSERT(int_literal != NULL); | |
| 7559 ASSERT(int_literal->Length() > 0); | |
| 7560 const Integer& literal = Integer::ZoneHandle(Integer::New(*int_literal)); | |
| 7561 primary = new LiteralNode(token_index_, literal); | 7574 primary = new LiteralNode(token_index_, literal); |
| 7562 ConsumeToken(); | 7575 ConsumeToken(); |
| 7563 } else if (CurrentToken() == Token::kTRUE) { | 7576 } else if (CurrentToken() == Token::kTRUE) { |
| 7564 primary = new LiteralNode(token_index_, Bool::ZoneHandle(Bool::True())); | 7577 primary = new LiteralNode(token_index_, Bool::ZoneHandle(Bool::True())); |
| 7565 ConsumeToken(); | 7578 ConsumeToken(); |
| 7566 } else if (CurrentToken() == Token::kFALSE) { | 7579 } else if (CurrentToken() == Token::kFALSE) { |
| 7567 primary = new LiteralNode(token_index_, Bool::ZoneHandle(Bool::False())); | 7580 primary = new LiteralNode(token_index_, Bool::ZoneHandle(Bool::False())); |
| 7568 ConsumeToken(); | 7581 ConsumeToken(); |
| 7569 } else if (CurrentToken() == Token::kNULL) { | 7582 } else if (CurrentToken() == Token::kNULL) { |
| 7570 primary = new LiteralNode(token_index_, Instance::ZoneHandle()); | 7583 primary = new LiteralNode(token_index_, Instance::ZoneHandle()); |
| 7571 ConsumeToken(); | 7584 ConsumeToken(); |
| 7572 } else if (CurrentToken() == Token::kLPAREN) { | 7585 } else if (CurrentToken() == Token::kLPAREN) { |
| 7573 ConsumeToken(); | 7586 ConsumeToken(); |
| 7574 const bool saved_mode = SetAllowFunctionLiterals(true); | 7587 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 7575 primary = ParseExpr(kAllowConst); | 7588 primary = ParseExpr(kAllowConst); |
| 7576 SetAllowFunctionLiterals(saved_mode); | 7589 SetAllowFunctionLiterals(saved_mode); |
| 7577 ExpectToken(Token::kRPAREN); | 7590 ExpectToken(Token::kRPAREN); |
| 7578 } else if (CurrentToken() == Token::kDOUBLE) { | 7591 } else if (CurrentToken() == Token::kDOUBLE) { |
| 7579 String* double_literal = CurrentLiteral(); | 7592 Double& double_value = Double::ZoneHandle(CurrentDoubleLiteral()); |
| 7580 ASSERT(double_literal != NULL); | |
| 7581 ASSERT(double_literal->Length() > 0); | |
| 7582 Double& double_value = | |
| 7583 Double::ZoneHandle(Double::NewCanonical(*double_literal)); | |
| 7584 if (double_value.IsNull()) { | 7593 if (double_value.IsNull()) { |
| 7585 ErrorMsg("invalid double literal"); | 7594 ErrorMsg("invalid double literal"); |
| 7586 } | 7595 } |
| 7587 primary = new LiteralNode(token_index_, double_value); | 7596 primary = new LiteralNode(token_index_, double_value); |
| 7588 ConsumeToken(); | 7597 ConsumeToken(); |
| 7589 } else if (CurrentToken() == Token::kSTRING) { | 7598 } else if (CurrentToken() == Token::kSTRING) { |
| 7590 primary = ParseStringLiteral(); | 7599 primary = ParseStringLiteral(); |
| 7591 } else if (CurrentToken() == Token::kNEW) { | 7600 } else if (CurrentToken() == Token::kNEW) { |
| 7592 primary = ParseNewOperator(); | 7601 primary = ParseNewOperator(); |
| 7593 } else if (CurrentToken() == Token::kCONST) { | 7602 } else if (CurrentToken() == Token::kCONST) { |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7913 void Parser::SkipQualIdent() { | 7922 void Parser::SkipQualIdent() { |
| 7914 ASSERT(IsIdentifier()); | 7923 ASSERT(IsIdentifier()); |
| 7915 ConsumeToken(); | 7924 ConsumeToken(); |
| 7916 if (CurrentToken() == Token::kPERIOD) { | 7925 if (CurrentToken() == Token::kPERIOD) { |
| 7917 ConsumeToken(); // Consume the kPERIOD token. | 7926 ConsumeToken(); // Consume the kPERIOD token. |
| 7918 ExpectIdentifier("identifier expected after '.'"); | 7927 ExpectIdentifier("identifier expected after '.'"); |
| 7919 } | 7928 } |
| 7920 } | 7929 } |
| 7921 | 7930 |
| 7922 } // namespace dart | 7931 } // namespace dart |
| OLD | NEW |