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

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

Issue 10659005: Implement type cast in the VM. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 6 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
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 5914 matching lines...) Expand 10 before | Expand all | Expand 10 after
5925 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle( 5925 arguments->Add(new LiteralNode(type_pos, String::ZoneHandle(
5926 String::NewSymbol(error.ToErrorCString())))); 5926 String::NewSymbol(error.ToErrorCString()))));
5927 return MakeStaticCall(kTypeErrorName, kThrowNewName, arguments); 5927 return MakeStaticCall(kTypeErrorName, kThrowNewName, arguments);
5928 } 5928 }
5929 5929
5930 5930
5931 AstNode* Parser::ParseBinaryExpr(int min_preced) { 5931 AstNode* Parser::ParseBinaryExpr(int min_preced) {
5932 TRACE_PARSER("ParseBinaryExpr"); 5932 TRACE_PARSER("ParseBinaryExpr");
5933 ASSERT(min_preced >= 4); 5933 ASSERT(min_preced >= 4);
5934 AstNode* left_operand = ParseUnaryExpr(); 5934 AstNode* left_operand = ParseUnaryExpr();
5935 if (IsLiteral("as")) { // Not a reserved word.
5936 token_kind_ = Token::kAS;
5937 }
5935 int current_preced = Token::Precedence(CurrentToken()); 5938 int current_preced = Token::Precedence(CurrentToken());
5936 while (current_preced >= min_preced) { 5939 while (current_preced >= min_preced) {
5937 while (Token::Precedence(CurrentToken()) == current_preced) { 5940 while (Token::Precedence(CurrentToken()) == current_preced) {
5938 Token::Kind op_kind = CurrentToken(); 5941 Token::Kind op_kind = CurrentToken();
5939 if (op_kind == Token::kTIGHTADD) { 5942 if (op_kind == Token::kTIGHTADD) {
5940 op_kind = Token::kADD; 5943 op_kind = Token::kADD;
5941 } 5944 }
5942 const intptr_t op_pos = TokenPos(); 5945 const intptr_t op_pos = TokenPos();
5943 ConsumeToken(); 5946 ConsumeToken();
5944 AstNode* right_operand = NULL; 5947 AstNode* right_operand = NULL;
5945 if (op_kind != Token::kIS) { 5948 if ((op_kind != Token::kIS) && (op_kind != Token::kAS)) {
5946 right_operand = ParseBinaryExpr(current_preced + 1); 5949 right_operand = ParseBinaryExpr(current_preced + 1);
5947 } else { 5950 } else {
5948 // For 'is' we expect the right operand to be a type. 5951 // For 'is' and 'as' we expect the right operand to be a type.
5949 if (CurrentToken() == Token::kNOT) { 5952 if ((op_kind == Token::kIS) && (CurrentToken() == Token::kNOT)) {
5950 ConsumeToken(); 5953 ConsumeToken();
5951 op_kind = Token::kISNOT; 5954 op_kind = Token::kISNOT;
5952 } 5955 }
5953 const intptr_t type_pos = TokenPos(); 5956 const intptr_t type_pos = TokenPos();
5954 const AbstractType& type = 5957 const AbstractType& type =
5955 AbstractType::ZoneHandle(ParseType(ClassFinalizer::kFinalize)); 5958 AbstractType::ZoneHandle(ParseType(ClassFinalizer::kFinalize));
5956 if (!type.IsInstantiated() && 5959 if (!type.IsInstantiated() &&
5957 (current_block_->scope->function_level() > 0)) { 5960 (current_block_->scope->function_level() > 0)) {
5958 // Make sure that the instantiator is captured. 5961 // Make sure that the instantiator is captured.
5959 CaptureReceiver(); 5962 CaptureReceiver();
5960 } 5963 }
5961 right_operand = new TypeNode(type_pos, type); 5964 right_operand = new TypeNode(type_pos, type);
5962 if (type.IsMalformed()) { 5965 if ((op_kind == Token::kIS) && type.IsMalformed()) {
5963 // Note that a type error is thrown even if the tested value is null. 5966 // Note that a type error is thrown even if the tested value is null
5967 // in a type test. However, no cast exception is thrown if the value
5968 // is null in a type cast.
5964 return ThrowTypeError(type_pos, type); 5969 return ThrowTypeError(type_pos, type);
5965 } 5970 }
5966 } 5971 }
5967 if (Token::IsRelationalOperator(op_kind) 5972 if (Token::IsRelationalOperator(op_kind)
5968 || Token::IsInstanceofOperator(op_kind) 5973 || Token::IsTypeTestOperator(op_kind)
5974 || Token::IsTypeCastOperator(op_kind)
5969 || Token::IsEqualityOperator(op_kind)) { 5975 || Token::IsEqualityOperator(op_kind)) {
5970 if (Token::IsInstanceofOperator(op_kind)) { 5976 if (Token::IsTypeTestOperator(op_kind) ||
5977 Token::IsTypeCastOperator(op_kind)) {
5971 if (!right_operand->AsTypeNode()->type().IsInstantiated()) { 5978 if (!right_operand->AsTypeNode()->type().IsInstantiated()) {
5972 EnsureExpressionTemp(); 5979 EnsureExpressionTemp();
5973 } 5980 }
5974 } 5981 }
5975 left_operand = new ComparisonNode( 5982 left_operand = new ComparisonNode(
5976 op_pos, op_kind, left_operand, right_operand); 5983 op_pos, op_kind, left_operand, right_operand);
5977 break; // Equality and relational operators cannot be chained. 5984 break; // Equality and relational operators cannot be chained.
5978 } else { 5985 } else {
5979 left_operand = OptimizeBinaryOpNode( 5986 left_operand = OptimizeBinaryOpNode(
5980 op_pos, op_kind, left_operand, right_operand); 5987 op_pos, op_kind, left_operand, right_operand);
(...skipping 2629 matching lines...) Expand 10 before | Expand all | Expand 10 after
8610 void Parser::SkipQualIdent() { 8617 void Parser::SkipQualIdent() {
8611 ASSERT(IsIdentifier()); 8618 ASSERT(IsIdentifier());
8612 ConsumeToken(); 8619 ConsumeToken();
8613 if (CurrentToken() == Token::kPERIOD) { 8620 if (CurrentToken() == Token::kPERIOD) {
8614 ConsumeToken(); // Consume the kPERIOD token. 8621 ConsumeToken(); // Consume the kPERIOD token.
8615 ExpectIdentifier("identifier expected after '.'"); 8622 ExpectIdentifier("identifier expected after '.'");
8616 } 8623 }
8617 } 8624 }
8618 8625
8619 } // namespace dart 8626 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698