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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/bigint_operations.cc ('k') | runtime/vm/scanner.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 3743)
+++ runtime/vm/parser.cc (working copy)
@@ -5334,8 +5334,10 @@
bool Parser::IsPrefixOperator(Token::Kind token) {
- return token == Token::kADD || token == Token::kSUB
- || token == Token::kNOT || token == Token::kBIT_NOT;
+ return (token == Token::kTIGHTADD) || // Valid for literals only!
+ (token == Token::kSUB) ||
+ (token == Token::kNOT) ||
+ (token == Token::kBIT_NOT);
}
@@ -5361,6 +5363,9 @@
while (current_preced >= min_preced) {
while (Token::Precedence(CurrentToken()) == current_preced) {
Token::Kind op_kind = CurrentToken();
+ if (op_kind == Token::kTIGHTADD) {
+ op_kind = Token::kADD;
+ }
const intptr_t op_pos = token_index_;
ConsumeToken();
AstNode* right_operand = NULL;
@@ -5660,7 +5665,15 @@
Token::Kind unary_op = CurrentToken();
ConsumeToken();
expr = ParseUnaryExpr();
- expr = UnaryOpNode::UnaryOpOrLiteral(op_pos, unary_op, expr);
+ if (unary_op == Token::kTIGHTADD) {
+ // kTIGHADD is added only in front of a number literal.
+ if (!expr->IsLiteralNode()) {
+ ErrorMsg(op_pos, "unexpected operator '+'");
+ }
+ // Expression is the literal itself.
+ } else {
+ expr = UnaryOpNode::UnaryOpOrLiteral(op_pos, unary_op, expr);
+ }
} else if (IsIncrementOperator(CurrentToken())) {
Token::Kind incr_op = CurrentToken();
ConsumeToken();
« 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