| 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 5928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5939 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( | 5939 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( |
| 5940 String::NewSymbol(error.ToErrorCString())))); | 5940 String::NewSymbol(error.ToErrorCString())))); |
| 5941 return MakeStaticCall(kTypeErrorName, kThrowNewName, arguments); | 5941 return MakeStaticCall(kTypeErrorName, kThrowNewName, arguments); |
| 5942 } | 5942 } |
| 5943 | 5943 |
| 5944 | 5944 |
| 5945 AstNode* Parser::ParseBinaryExpr(int min_preced) { | 5945 AstNode* Parser::ParseBinaryExpr(int min_preced) { |
| 5946 TRACE_PARSER("ParseBinaryExpr"); | 5946 TRACE_PARSER("ParseBinaryExpr"); |
| 5947 ASSERT(min_preced >= 4); | 5947 ASSERT(min_preced >= 4); |
| 5948 AstNode* left_operand = ParseUnaryExpr(); | 5948 AstNode* left_operand = ParseUnaryExpr(); |
| 5949 if (IsLiteral("as")) { // Not a reserved word. |
| 5950 token_kind_ = Token::kAS; |
| 5951 } |
| 5949 int current_preced = Token::Precedence(CurrentToken()); | 5952 int current_preced = Token::Precedence(CurrentToken()); |
| 5950 while (current_preced >= min_preced) { | 5953 while (current_preced >= min_preced) { |
| 5951 while (Token::Precedence(CurrentToken()) == current_preced) { | 5954 while (Token::Precedence(CurrentToken()) == current_preced) { |
| 5952 Token::Kind op_kind = CurrentToken(); | 5955 Token::Kind op_kind = CurrentToken(); |
| 5953 if (op_kind == Token::kTIGHTADD) { | 5956 if (op_kind == Token::kTIGHTADD) { |
| 5954 op_kind = Token::kADD; | 5957 op_kind = Token::kADD; |
| 5955 } | 5958 } |
| 5956 const intptr_t op_pos = TokenPos(); | 5959 const intptr_t op_pos = TokenPos(); |
| 5957 ConsumeToken(); | 5960 ConsumeToken(); |
| 5958 AstNode* right_operand = NULL; | 5961 AstNode* right_operand = NULL; |
| 5959 if (op_kind != Token::kIS) { | 5962 if ((op_kind != Token::kIS) && (op_kind != Token::kAS)) { |
| 5960 right_operand = ParseBinaryExpr(current_preced + 1); | 5963 right_operand = ParseBinaryExpr(current_preced + 1); |
| 5961 } else { | 5964 } else { |
| 5962 // For 'is' we expect the right operand to be a type. | 5965 // For 'is' and 'as' we expect the right operand to be a type. |
| 5963 if (CurrentToken() == Token::kNOT) { | 5966 if ((op_kind == Token::kIS) && (CurrentToken() == Token::kNOT)) { |
| 5964 ConsumeToken(); | 5967 ConsumeToken(); |
| 5965 op_kind = Token::kISNOT; | 5968 op_kind = Token::kISNOT; |
| 5966 } | 5969 } |
| 5967 const intptr_t type_pos = TokenPos(); | 5970 const intptr_t type_pos = TokenPos(); |
| 5968 const AbstractType& type = | 5971 const AbstractType& type = |
| 5969 AbstractType::ZoneHandle(ParseType(ClassFinalizer::kFinalize)); | 5972 AbstractType::ZoneHandle(ParseType(ClassFinalizer::kFinalize)); |
| 5970 if (!type.IsInstantiated() && | 5973 if (!type.IsInstantiated() && |
| 5971 (current_block_->scope->function_level() > 0)) { | 5974 (current_block_->scope->function_level() > 0)) { |
| 5972 // Make sure that the instantiator is captured. | 5975 // Make sure that the instantiator is captured. |
| 5973 CaptureReceiver(); | 5976 CaptureReceiver(); |
| 5974 } | 5977 } |
| 5975 right_operand = new TypeNode(type_pos, type); | 5978 right_operand = new TypeNode(type_pos, type); |
| 5976 if (type.IsMalformed()) { | 5979 if ((op_kind == Token::kIS) && type.IsMalformed()) { |
| 5977 // Note that a type error is thrown even if the tested value is null. | 5980 // Note that a type error is thrown even if the tested value is null |
| 5981 // in a type test. However, no cast exception is thrown if the value |
| 5982 // is null in a type cast. |
| 5978 return ThrowTypeError(type_pos, type); | 5983 return ThrowTypeError(type_pos, type); |
| 5979 } | 5984 } |
| 5980 } | 5985 } |
| 5981 if (Token::IsRelationalOperator(op_kind) | 5986 if (Token::IsRelationalOperator(op_kind) |
| 5982 || Token::IsInstanceofOperator(op_kind) | 5987 || Token::IsTypeTestOperator(op_kind) |
| 5988 || Token::IsTypeCastOperator(op_kind) |
| 5983 || Token::IsEqualityOperator(op_kind)) { | 5989 || Token::IsEqualityOperator(op_kind)) { |
| 5984 if (Token::IsInstanceofOperator(op_kind)) { | 5990 if (Token::IsTypeTestOperator(op_kind) || |
| 5991 Token::IsTypeCastOperator(op_kind)) { |
| 5985 if (!right_operand->AsTypeNode()->type().IsInstantiated()) { | 5992 if (!right_operand->AsTypeNode()->type().IsInstantiated()) { |
| 5986 EnsureExpressionTemp(); | 5993 EnsureExpressionTemp(); |
| 5987 } | 5994 } |
| 5988 } | 5995 } |
| 5989 left_operand = new ComparisonNode( | 5996 left_operand = new ComparisonNode( |
| 5990 op_pos, op_kind, left_operand, right_operand); | 5997 op_pos, op_kind, left_operand, right_operand); |
| 5991 break; // Equality and relational operators cannot be chained. | 5998 break; // Equality and relational operators cannot be chained. |
| 5992 } else { | 5999 } else { |
| 5993 left_operand = OptimizeBinaryOpNode( | 6000 left_operand = OptimizeBinaryOpNode( |
| 5994 op_pos, op_kind, left_operand, right_operand); | 6001 op_pos, op_kind, left_operand, right_operand); |
| (...skipping 2629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8624 void Parser::SkipQualIdent() { | 8631 void Parser::SkipQualIdent() { |
| 8625 ASSERT(IsIdentifier()); | 8632 ASSERT(IsIdentifier()); |
| 8626 ConsumeToken(); | 8633 ConsumeToken(); |
| 8627 if (CurrentToken() == Token::kPERIOD) { | 8634 if (CurrentToken() == Token::kPERIOD) { |
| 8628 ConsumeToken(); // Consume the kPERIOD token. | 8635 ConsumeToken(); // Consume the kPERIOD token. |
| 8629 ExpectIdentifier("identifier expected after '.'"); | 8636 ExpectIdentifier("identifier expected after '.'"); |
| 8630 } | 8637 } |
| 8631 } | 8638 } |
| 8632 | 8639 |
| 8633 } // namespace dart | 8640 } // namespace dart |
| OLD | NEW |