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 "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
8 #include "vm/bigint_operations.h" | 8 #include "vm/bigint_operations.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
(...skipping 6788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6799 return IsIdentifier() && CurrentLiteral()->Equals(literal); | 6799 return IsIdentifier() && CurrentLiteral()->Equals(literal); |
6800 } | 6800 } |
6801 | 6801 |
6802 | 6802 |
6803 static bool IsIncrementOperator(Token::Kind token) { | 6803 static bool IsIncrementOperator(Token::Kind token) { |
6804 return token == Token::kINCR || token == Token::kDECR; | 6804 return token == Token::kINCR || token == Token::kDECR; |
6805 } | 6805 } |
6806 | 6806 |
6807 | 6807 |
6808 static bool IsPrefixOperator(Token::Kind token) { | 6808 static bool IsPrefixOperator(Token::Kind token) { |
6809 return (token == Token::kTIGHTADD) || // Valid for literals only! | 6809 return (token == Token::kSUB) || |
6810 (token == Token::kSUB) || | |
6811 (token == Token::kNOT) || | 6810 (token == Token::kNOT) || |
6812 (token == Token::kBIT_NOT); | 6811 (token == Token::kBIT_NOT); |
6813 } | 6812 } |
6814 | 6813 |
6815 | 6814 |
6816 SequenceNode* Parser::NodeAsSequenceNode(intptr_t sequence_pos, | 6815 SequenceNode* Parser::NodeAsSequenceNode(intptr_t sequence_pos, |
6817 AstNode* node, | 6816 AstNode* node, |
6818 LocalScope* scope) { | 6817 LocalScope* scope) { |
6819 if ((node == NULL) || !node->IsSequenceNode()) { | 6818 if ((node == NULL) || !node->IsSequenceNode()) { |
6820 SequenceNode* sequence = new SequenceNode(sequence_pos, scope); | 6819 SequenceNode* sequence = new SequenceNode(sequence_pos, scope); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6913 (left_operand->AsPrimaryNode()->IsSuper())) { | 6912 (left_operand->AsPrimaryNode()->IsSuper())) { |
6914 ErrorMsg(left_operand->token_pos(), "illegal use of 'super'"); | 6913 ErrorMsg(left_operand->token_pos(), "illegal use of 'super'"); |
6915 } | 6914 } |
6916 if (IsLiteral("as")) { // Not a reserved word. | 6915 if (IsLiteral("as")) { // Not a reserved word. |
6917 token_kind_ = Token::kAS; | 6916 token_kind_ = Token::kAS; |
6918 } | 6917 } |
6919 int current_preced = Token::Precedence(CurrentToken()); | 6918 int current_preced = Token::Precedence(CurrentToken()); |
6920 while (current_preced >= min_preced) { | 6919 while (current_preced >= min_preced) { |
6921 while (Token::Precedence(CurrentToken()) == current_preced) { | 6920 while (Token::Precedence(CurrentToken()) == current_preced) { |
6922 Token::Kind op_kind = CurrentToken(); | 6921 Token::Kind op_kind = CurrentToken(); |
6923 if (op_kind == Token::kTIGHTADD) { | |
6924 op_kind = Token::kADD; | |
6925 } | |
6926 const intptr_t op_pos = TokenPos(); | 6922 const intptr_t op_pos = TokenPos(); |
6927 ConsumeToken(); | 6923 ConsumeToken(); |
6928 AstNode* right_operand = NULL; | 6924 AstNode* right_operand = NULL; |
6929 if ((op_kind != Token::kIS) && (op_kind != Token::kAS)) { | 6925 if ((op_kind != Token::kIS) && (op_kind != Token::kAS)) { |
6930 right_operand = ParseBinaryExpr(current_preced + 1); | 6926 right_operand = ParseBinaryExpr(current_preced + 1); |
6931 } else { | 6927 } else { |
6932 // For 'is' and 'as' we expect the right operand to be a type. | 6928 // For 'is' and 'as' we expect the right operand to be a type. |
6933 if ((op_kind == Token::kIS) && (CurrentToken() == Token::kNOT)) { | 6929 if ((op_kind == Token::kIS) && (CurrentToken() == Token::kNOT)) { |
6934 ConsumeToken(); | 6930 ConsumeToken(); |
6935 op_kind = Token::kISNOT; | 6931 op_kind = Token::kISNOT; |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7324 TRACE_PARSER("ParseUnaryExpr"); | 7320 TRACE_PARSER("ParseUnaryExpr"); |
7325 AstNode* expr = NULL; | 7321 AstNode* expr = NULL; |
7326 const intptr_t op_pos = TokenPos(); | 7322 const intptr_t op_pos = TokenPos(); |
7327 if (IsPrefixOperator(CurrentToken())) { | 7323 if (IsPrefixOperator(CurrentToken())) { |
7328 Token::Kind unary_op = CurrentToken(); | 7324 Token::Kind unary_op = CurrentToken(); |
7329 if (unary_op == Token::kSUB) { | 7325 if (unary_op == Token::kSUB) { |
7330 unary_op = Token::kNEGATE; | 7326 unary_op = Token::kNEGATE; |
7331 } | 7327 } |
7332 ConsumeToken(); | 7328 ConsumeToken(); |
7333 expr = ParseUnaryExpr(); | 7329 expr = ParseUnaryExpr(); |
7334 if (unary_op == Token::kTIGHTADD) { | 7330 if (expr->IsPrimaryNode() && (expr->AsPrimaryNode()->IsSuper())) { |
7335 // kTIGHADD is added only in front of a number literal. | |
7336 if (!expr->IsLiteralNode()) { | |
7337 ErrorMsg(op_pos, "unexpected operator '+'"); | |
7338 } | |
7339 // Expression is the literal itself. | |
7340 } else if (expr->IsPrimaryNode() && (expr->AsPrimaryNode()->IsSuper())) { | |
7341 expr = BuildUnarySuperOperator(unary_op, expr->AsPrimaryNode()); | 7331 expr = BuildUnarySuperOperator(unary_op, expr->AsPrimaryNode()); |
7342 } else { | 7332 } else { |
7343 expr = UnaryOpNode::UnaryOpOrLiteral(op_pos, unary_op, expr); | 7333 expr = UnaryOpNode::UnaryOpOrLiteral(op_pos, unary_op, expr); |
7344 } | 7334 } |
7345 } else if (IsIncrementOperator(CurrentToken())) { | 7335 } else if (IsIncrementOperator(CurrentToken())) { |
7346 Token::Kind incr_op = CurrentToken(); | 7336 Token::Kind incr_op = CurrentToken(); |
7347 ConsumeToken(); | 7337 ConsumeToken(); |
7348 expr = ParseUnaryExpr(); | 7338 expr = ParseUnaryExpr(); |
7349 if (!IsAssignableExpr(expr)) { | 7339 if (!IsAssignableExpr(expr)) { |
7350 ErrorMsg("expression is not assignable"); | 7340 ErrorMsg("expression is not assignable"); |
(...skipping 2749 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10100 void Parser::SkipQualIdent() { | 10090 void Parser::SkipQualIdent() { |
10101 ASSERT(IsIdentifier()); | 10091 ASSERT(IsIdentifier()); |
10102 ConsumeToken(); | 10092 ConsumeToken(); |
10103 if (CurrentToken() == Token::kPERIOD) { | 10093 if (CurrentToken() == Token::kPERIOD) { |
10104 ConsumeToken(); // Consume the kPERIOD token. | 10094 ConsumeToken(); // Consume the kPERIOD token. |
10105 ExpectIdentifier("identifier expected after '.'"); | 10095 ExpectIdentifier("identifier expected after '.'"); |
10106 } | 10096 } |
10107 } | 10097 } |
10108 | 10098 |
10109 } // namespace dart | 10099 } // namespace dart |
OLD | NEW |