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

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

Issue 9264051: Fix for bug 1229: Unary operator plus is not allowed ... except for literals. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 8 years, 10 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
« no previous file with comments | « runtime/vm/bigint_operations.cc ('k') | runtime/vm/scanner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5316 matching lines...) Expand 10 before | Expand all | Expand 10 after
5327 return IsIdentifier() && CurrentLiteral()->Equals(characters, len); 5327 return IsIdentifier() && CurrentLiteral()->Equals(characters, len);
5328 } 5328 }
5329 5329
5330 5330
5331 bool Parser::IsIncrementOperator(Token::Kind token) { 5331 bool Parser::IsIncrementOperator(Token::Kind token) {
5332 return token == Token::kINCR || token == Token::kDECR; 5332 return token == Token::kINCR || token == Token::kDECR;
5333 } 5333 }
5334 5334
5335 5335
5336 bool Parser::IsPrefixOperator(Token::Kind token) { 5336 bool Parser::IsPrefixOperator(Token::Kind token) {
5337 return token == Token::kADD || token == Token::kSUB 5337 return (token == Token::kTIGHTADD) || // Valid for literals only!
5338 || token == Token::kNOT || token == Token::kBIT_NOT; 5338 (token == Token::kSUB) ||
5339 (token == Token::kNOT) ||
5340 (token == Token::kBIT_NOT);
5339 } 5341 }
5340 5342
5341 5343
5342 SequenceNode* Parser::NodeAsSequenceNode(intptr_t sequence_pos, 5344 SequenceNode* Parser::NodeAsSequenceNode(intptr_t sequence_pos,
5343 AstNode* node, 5345 AstNode* node,
5344 LocalScope* scope) { 5346 LocalScope* scope) {
5345 if ((node == NULL) || !node->IsSequenceNode()) { 5347 if ((node == NULL) || !node->IsSequenceNode()) {
5346 SequenceNode* sequence = new SequenceNode(sequence_pos, scope); 5348 SequenceNode* sequence = new SequenceNode(sequence_pos, scope);
5347 if (node != NULL) { 5349 if (node != NULL) {
5348 sequence->Add(node); 5350 sequence->Add(node);
5349 } 5351 }
5350 return sequence; 5352 return sequence;
5351 } 5353 }
5352 return node->AsSequenceNode(); 5354 return node->AsSequenceNode();
5353 } 5355 }
5354 5356
5355 5357
5356 AstNode* Parser::ParseBinaryExpr(int min_preced) { 5358 AstNode* Parser::ParseBinaryExpr(int min_preced) {
5357 TRACE_PARSER("ParseBinaryExpr"); 5359 TRACE_PARSER("ParseBinaryExpr");
5358 ASSERT(min_preced >= 4); 5360 ASSERT(min_preced >= 4);
5359 AstNode* left_operand = ParseUnaryExpr(); 5361 AstNode* left_operand = ParseUnaryExpr();
5360 int current_preced = Token::Precedence(CurrentToken()); 5362 int current_preced = Token::Precedence(CurrentToken());
5361 while (current_preced >= min_preced) { 5363 while (current_preced >= min_preced) {
5362 while (Token::Precedence(CurrentToken()) == current_preced) { 5364 while (Token::Precedence(CurrentToken()) == current_preced) {
5363 Token::Kind op_kind = CurrentToken(); 5365 Token::Kind op_kind = CurrentToken();
5366 if (op_kind == Token::kTIGHTADD) {
5367 op_kind = Token::kADD;
5368 }
5364 const intptr_t op_pos = token_index_; 5369 const intptr_t op_pos = token_index_;
5365 ConsumeToken(); 5370 ConsumeToken();
5366 AstNode* right_operand = NULL; 5371 AstNode* right_operand = NULL;
5367 if (op_kind != Token::kIS) { 5372 if (op_kind != Token::kIS) {
5368 right_operand = ParseBinaryExpr(current_preced + 1); 5373 right_operand = ParseBinaryExpr(current_preced + 1);
5369 } else { 5374 } else {
5370 // For 'is' we expect the right operand to be a type. 5375 // For 'is' we expect the right operand to be a type.
5371 if (CurrentToken() == Token::kNOT) { 5376 if (CurrentToken() == Token::kNOT) {
5372 ConsumeToken(); 5377 ConsumeToken();
5373 op_kind = Token::kISNOT; 5378 op_kind = Token::kISNOT;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
5653 5658
5654 5659
5655 AstNode* Parser::ParseUnaryExpr() { 5660 AstNode* Parser::ParseUnaryExpr() {
5656 TRACE_PARSER("ParseUnaryExpr"); 5661 TRACE_PARSER("ParseUnaryExpr");
5657 AstNode* expr = NULL; 5662 AstNode* expr = NULL;
5658 const intptr_t op_pos = token_index_; 5663 const intptr_t op_pos = token_index_;
5659 if (IsPrefixOperator(CurrentToken())) { 5664 if (IsPrefixOperator(CurrentToken())) {
5660 Token::Kind unary_op = CurrentToken(); 5665 Token::Kind unary_op = CurrentToken();
5661 ConsumeToken(); 5666 ConsumeToken();
5662 expr = ParseUnaryExpr(); 5667 expr = ParseUnaryExpr();
5663 expr = UnaryOpNode::UnaryOpOrLiteral(op_pos, unary_op, expr); 5668 if (unary_op == Token::kTIGHTADD) {
5669 // kTIGHADD is added only in front of a number literal.
5670 if (!expr->IsLiteralNode()) {
5671 ErrorMsg(op_pos, "unexpected operator '+'");
5672 }
5673 // Expression is the literal itself.
5674 } else {
5675 expr = UnaryOpNode::UnaryOpOrLiteral(op_pos, unary_op, expr);
5676 }
5664 } else if (IsIncrementOperator(CurrentToken())) { 5677 } else if (IsIncrementOperator(CurrentToken())) {
5665 Token::Kind incr_op = CurrentToken(); 5678 Token::Kind incr_op = CurrentToken();
5666 ConsumeToken(); 5679 ConsumeToken();
5667 expr = ParseUnaryExpr(); 5680 expr = ParseUnaryExpr();
5668 if (!IsAssignableExpr(expr)) { 5681 if (!IsAssignableExpr(expr)) {
5669 ErrorMsg("expression is not assignable"); 5682 ErrorMsg("expression is not assignable");
5670 } 5683 }
5671 // is_prefix. 5684 // is_prefix.
5672 AstNode* incr_op_node = expr->MakeIncrOpNode(op_pos, incr_op, true); 5685 AstNode* incr_op_node = expr->MakeIncrOpNode(op_pos, incr_op, true);
5673 if (incr_op_node == NULL) { 5686 if (incr_op_node == NULL) {
(...skipping 2043 matching lines...) Expand 10 before | Expand all | Expand 10 after
7717 void Parser::SkipQualIdent() { 7730 void Parser::SkipQualIdent() {
7718 ASSERT(IsIdentifier()); 7731 ASSERT(IsIdentifier());
7719 ConsumeToken(); 7732 ConsumeToken();
7720 if (CurrentToken() == Token::kPERIOD) { 7733 if (CurrentToken() == Token::kPERIOD) {
7721 ConsumeToken(); // Consume the kPERIOD token. 7734 ConsumeToken(); // Consume the kPERIOD token.
7722 ExpectIdentifier("identifier expected after '.'"); 7735 ExpectIdentifier("identifier expected after '.'");
7723 } 7736 }
7724 } 7737 }
7725 7738
7726 } // namespace dart 7739 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/bigint_operations.cc ('k') | runtime/vm/scanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698