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

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
Index: runtime/vm/parser.cc
===================================================================
--- runtime/vm/parser.cc (revision 3699)
+++ runtime/vm/parser.cc (working copy)
@@ -5357,8 +5357,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);
}
@@ -5384,6 +5386,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;
@@ -5683,7 +5688,14 @@
Token::Kind unary_op = CurrentToken();
ConsumeToken();
expr = ParseUnaryExpr();
- expr = UnaryOpNode::UnaryOpOrLiteral(op_pos, unary_op, expr);
+ if (unary_op == Token::kTIGHTADD) {
+ if (!expr->IsLiteralNode()) {
hausner 2012/01/31 18:09:46 This test is not strict enough. This also allows +
srdjan 2012/01/31 19:26:37 Changed scanner to produce TIGHTADD only if the +
+ ErrorMsg("'+' is not a valid prefix");
hausner 2012/01/31 18:09:46 I wouldn't call + a prefix. How about "unexpected
srdjan 2012/01/31 19:26:37 Using "unexpected". The other option would have be
+ }
+ // 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.cc » ('j') | runtime/vm/scanner.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698