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

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

Issue 1180903002: null-aware operators in the VM (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add test for opt compiler Created 5 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
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 "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/ast_transformer.h" 9 #include "vm/ast_transformer.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 2961 matching lines...) Expand 10 before | Expand all | Expand 10 after
2972 // is the "super call" and is implicitly at the end of the 2972 // is the "super call" and is implicitly at the end of the
2973 // initializer list. 2973 // initializer list.
2974 ASSERT(!is_redirecting_constructor); 2974 ASSERT(!is_redirecting_constructor);
2975 ArgumentListNode* ctor_args = super_call->arguments(); 2975 ArgumentListNode* ctor_args = super_call->arguments();
2976 // The super initializer call has at least 2 arguments: the 2976 // The super initializer call has at least 2 arguments: the
2977 // implicit receiver, and the hidden construction phase. 2977 // implicit receiver, and the hidden construction phase.
2978 ASSERT(ctor_args->length() >= 2); 2978 ASSERT(ctor_args->length() >= 2);
2979 for (int i = 2; i < ctor_args->length(); i++) { 2979 for (int i = 2; i < ctor_args->length(); i++) {
2980 AstNode* arg = ctor_args->NodeAt(i); 2980 AstNode* arg = ctor_args->NodeAt(i);
2981 if (!IsSimpleLocalOrLiteralNode(arg)) { 2981 if (!IsSimpleLocalOrLiteralNode(arg)) {
2982 LocalVariable* temp = 2982 LocalVariable* temp = CreateTempConstVariable(arg->token_pos(), "sca");
2983 CreateTempConstVariable(arg->token_pos(), "sca");
2984 AstNode* save_temp = new StoreLocalNode(arg->token_pos(), temp, arg); 2983 AstNode* save_temp = new StoreLocalNode(arg->token_pos(), temp, arg);
2985 ctor_args->SetNodeAt(i, save_temp); 2984 ctor_args->SetNodeAt(i, save_temp);
2986 } 2985 }
2987 } 2986 }
2988 } 2987 }
2989 OpenBlock(); // Block to collect constructor body nodes. 2988 OpenBlock(); // Block to collect constructor body nodes.
2990 intptr_t body_pos = TokenPos(); 2989 intptr_t body_pos = TokenPos();
2991 2990
2992 // Insert the implicit super call to the super constructor body. 2991 // Insert the implicit super call to the super constructor body.
2993 if (super_call != NULL) { 2992 if (super_call != NULL) {
(...skipping 4135 matching lines...) Expand 10 before | Expand all | Expand 10 after
7129 // outermost enclosing function. 7128 // outermost enclosing function.
7130 const bool kTestOnly = false; 7129 const bool kTestOnly = false;
7131 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly); 7130 LocalVariable* receiver = LookupReceiver(current_block_->scope, kTestOnly);
7132 if (receiver == NULL) { 7131 if (receiver == NULL) {
7133 ReportError(token_pos, "illegal implicit access to receiver 'this'"); 7132 ReportError(token_pos, "illegal implicit access to receiver 'this'");
7134 } 7133 }
7135 return new(Z) LoadLocalNode(TokenPos(), receiver); 7134 return new(Z) LoadLocalNode(TokenPos(), receiver);
7136 } 7135 }
7137 7136
7138 7137
7139 AstNode* Parser::CallGetter(intptr_t token_pos, 7138 InstanceGetterNode* Parser::CallGetter(intptr_t token_pos,
7140 AstNode* object, 7139 AstNode* object,
7141 const String& name) { 7140 const String& name) {
7142 return new(Z) InstanceGetterNode(token_pos, object, name); 7141 return new(Z) InstanceGetterNode(token_pos, object, name);
7143 } 7142 }
7144 7143
7145 7144
7146 // Returns ast nodes of the variable initialization. 7145 // Returns ast nodes of the variable initialization.
7147 AstNode* Parser::ParseVariableDeclaration(const AbstractType& type, 7146 AstNode* Parser::ParseVariableDeclaration(const AbstractType& type,
7148 bool is_final, 7147 bool is_final,
7149 bool is_const, 7148 bool is_const,
7150 SequenceNode** await_preamble) { 7149 SequenceNode** await_preamble) {
7151 TRACE_PARSER("ParseVariableDeclaration"); 7150 TRACE_PARSER("ParseVariableDeclaration");
(...skipping 2982 matching lines...) Expand 10 before | Expand all | Expand 10 after
10134 arguments->Add(new(Z) LiteralNode(call_pos, array)); 10133 arguments->Add(new(Z) LiteralNode(call_pos, array));
10135 10134
10136 return MakeStaticCall(Symbols::NoSuchMethodError(), 10135 return MakeStaticCall(Symbols::NoSuchMethodError(),
10137 Library::PrivateCoreLibName(Symbols::ThrowNew()), 10136 Library::PrivateCoreLibName(Symbols::ThrowNew()),
10138 arguments); 10137 arguments);
10139 } 10138 }
10140 10139
10141 10140
10142 AstNode* Parser::ParseBinaryExpr(int min_preced) { 10141 AstNode* Parser::ParseBinaryExpr(int min_preced) {
10143 TRACE_PARSER("ParseBinaryExpr"); 10142 TRACE_PARSER("ParseBinaryExpr");
10144 ASSERT(min_preced >= Token::Precedence(Token::kOR)); 10143 ASSERT(min_preced >= Token::Precedence(Token::kIFNULL));
10145 AstNode* left_operand = ParseUnaryExpr(); 10144 AstNode* left_operand = ParseUnaryExpr();
10146 if (left_operand->IsPrimaryNode() && 10145 if (left_operand->IsPrimaryNode() &&
10147 (left_operand->AsPrimaryNode()->IsSuper())) { 10146 (left_operand->AsPrimaryNode()->IsSuper())) {
10148 ReportError(left_operand->token_pos(), "illegal use of 'super'"); 10147 ReportError(left_operand->token_pos(), "illegal use of 'super'");
10149 } 10148 }
10150 int current_preced = Token::Precedence(CurrentToken()); 10149 int current_preced = Token::Precedence(CurrentToken());
10151 while (current_preced >= min_preced) { 10150 while (current_preced >= min_preced) {
10152 while (Token::Precedence(CurrentToken()) == current_preced) { 10151 while (Token::Precedence(CurrentToken()) == current_preced) {
10153 Token::Kind op_kind = CurrentToken(); 10152 Token::Kind op_kind = CurrentToken();
10154 const intptr_t op_pos = TokenPos(); 10153 const intptr_t op_pos = TokenPos();
(...skipping 29 matching lines...) Expand all
10184 let->AddNode(left_operand); 10183 let->AddNode(left_operand);
10185 let->AddNode(ThrowTypeError(type_pos, type)); 10184 let->AddNode(ThrowTypeError(type_pos, type));
10186 left_operand = let; 10185 left_operand = let;
10187 break; // Type checks and casts can't be chained. 10186 break; // Type checks and casts can't be chained.
10188 } 10187 }
10189 } 10188 }
10190 if (Token::IsRelationalOperator(op_kind) 10189 if (Token::IsRelationalOperator(op_kind)
10191 || Token::IsTypeTestOperator(op_kind) 10190 || Token::IsTypeTestOperator(op_kind)
10192 || Token::IsTypeCastOperator(op_kind) 10191 || Token::IsTypeCastOperator(op_kind)
10193 || Token::IsEqualityOperator(op_kind)) { 10192 || Token::IsEqualityOperator(op_kind)) {
10194 if (Token::IsTypeTestOperator(op_kind) ||
10195 Token::IsTypeCastOperator(op_kind)) {
10196 if (!right_operand->AsTypeNode()->type().IsInstantiated()) {
10197 EnsureExpressionTemp();
10198 }
10199 }
10200 left_operand = new(Z) ComparisonNode( 10193 left_operand = new(Z) ComparisonNode(
10201 op_pos, op_kind, left_operand, right_operand); 10194 op_pos, op_kind, left_operand, right_operand);
10202 break; // Equality and relational operators cannot be chained. 10195 break; // Equality and relational operators cannot be chained.
10203 } else { 10196 } else {
10204 left_operand = OptimizeBinaryOpNode( 10197 left_operand = OptimizeBinaryOpNode(
10205 op_pos, op_kind, left_operand, right_operand); 10198 op_pos, op_kind, left_operand, right_operand);
10206 } 10199 }
10207 } 10200 }
10208 current_preced--; 10201 current_preced--;
10209 } 10202 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
10272 rhs_literal->literal().IsDouble()) { 10265 rhs_literal->literal().IsDouble()) {
10273 double left_double = Double::Cast(lhs_literal->literal()).value(); 10266 double left_double = Double::Cast(lhs_literal->literal()).value();
10274 double right_double = Double::Cast(rhs_literal->literal()).value(); 10267 double right_double = Double::Cast(rhs_literal->literal()).value();
10275 if (binary_op == Token::kDIV) { 10268 if (binary_op == Token::kDIV) {
10276 const Double& dbl_obj = Double::ZoneHandle(Z, 10269 const Double& dbl_obj = Double::ZoneHandle(Z,
10277 Double::NewCanonical((left_double / right_double))); 10270 Double::NewCanonical((left_double / right_double)));
10278 return new(Z) LiteralNode(op_pos, dbl_obj); 10271 return new(Z) LiteralNode(op_pos, dbl_obj);
10279 } 10272 }
10280 } 10273 }
10281 } 10274 }
10282 if ((binary_op == Token::kAND) || (binary_op == Token::kOR)) {
10283 EnsureExpressionTemp();
10284 }
10285 if (binary_op == Token::kBIT_AND) { 10275 if (binary_op == Token::kBIT_AND) {
10286 // Normalize so that rhs is a literal if any is. 10276 // Normalize so that rhs is a literal if any is.
10287 if ((rhs_literal == NULL) && (lhs_literal != NULL)) { 10277 if ((rhs_literal == NULL) && (lhs_literal != NULL)) {
10288 // Swap. 10278 // Swap.
10289 LiteralNode* temp = rhs_literal; 10279 LiteralNode* temp = rhs_literal;
10290 rhs_literal = lhs_literal; 10280 rhs_literal = lhs_literal;
10291 lhs_literal = temp; 10281 lhs_literal = temp;
10292 } 10282 }
10293 if ((rhs_literal != NULL) && 10283 if ((rhs_literal != NULL) &&
10294 (rhs_literal->literal().IsSmi() || rhs_literal->literal().IsMint())) { 10284 (rhs_literal->literal().IsSmi() || rhs_literal->literal().IsMint())) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
10332 case Token::kASSIGN_SHR: 10322 case Token::kASSIGN_SHR:
10333 return new(Z) BinaryOpNode(op_pos, Token::kSHR, lhs, rhs); 10323 return new(Z) BinaryOpNode(op_pos, Token::kSHR, lhs, rhs);
10334 case Token::kASSIGN_SHL: 10324 case Token::kASSIGN_SHL:
10335 return new(Z) BinaryOpNode(op_pos, Token::kSHL, lhs, rhs); 10325 return new(Z) BinaryOpNode(op_pos, Token::kSHL, lhs, rhs);
10336 case Token::kASSIGN_OR: 10326 case Token::kASSIGN_OR:
10337 return new(Z) BinaryOpNode(op_pos, Token::kBIT_OR, lhs, rhs); 10327 return new(Z) BinaryOpNode(op_pos, Token::kBIT_OR, lhs, rhs);
10338 case Token::kASSIGN_AND: 10328 case Token::kASSIGN_AND:
10339 return new(Z) BinaryOpNode(op_pos, Token::kBIT_AND, lhs, rhs); 10329 return new(Z) BinaryOpNode(op_pos, Token::kBIT_AND, lhs, rhs);
10340 case Token::kASSIGN_XOR: 10330 case Token::kASSIGN_XOR:
10341 return new(Z) BinaryOpNode(op_pos, Token::kBIT_XOR, lhs, rhs); 10331 return new(Z) BinaryOpNode(op_pos, Token::kBIT_XOR, lhs, rhs);
10332 case Token::kASSIGN_COND:
10333 return new(Z) BinaryOpNode(op_pos, Token::kIFNULL, lhs, rhs);
10342 default: 10334 default:
10343 ReportError(op_pos, 10335 ReportError(op_pos,
10344 "internal error: ExpandAssignableOp '%s' unimplemented", 10336 "internal error: ExpandAssignableOp '%s' unimplemented",
10345 Token::Name(assignment_op)); 10337 Token::Name(assignment_op));
10346 UNIMPLEMENTED(); 10338 UNIMPLEMENTED();
10347 return NULL; 10339 return NULL;
10348 } 10340 }
10349 } 10341 }
10350 10342
10351 10343
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
10387 return result; 10379 return result;
10388 } 10380 }
10389 if (node->IsInstanceGetterNode()) { 10381 if (node->IsInstanceGetterNode()) {
10390 InstanceGetterNode* getter = node->AsInstanceGetterNode(); 10382 InstanceGetterNode* getter = node->AsInstanceGetterNode();
10391 AstNode* receiver = getter->receiver(); 10383 AstNode* receiver = getter->receiver();
10392 if (!IsSimpleLocalOrLiteralNode(getter->receiver())) { 10384 if (!IsSimpleLocalOrLiteralNode(getter->receiver())) {
10393 LocalVariable* t0 = result->AddInitializer(getter->receiver()); 10385 LocalVariable* t0 = result->AddInitializer(getter->receiver());
10394 receiver = new(Z) LoadLocalNode(token_pos, t0); 10386 receiver = new(Z) LoadLocalNode(token_pos, t0);
10395 } 10387 }
10396 *expr = new(Z) InstanceGetterNode( 10388 *expr = new(Z) InstanceGetterNode(
10397 token_pos, receiver, getter->field_name()); 10389 token_pos, receiver, getter->field_name(), getter->is_conditional());
10398 return result; 10390 return result;
10399 } 10391 }
10400 return result; 10392 return result;
10401 } 10393 }
10402 10394
10403 10395
10404 // Check whether the syntax of expression expr is a grammatically legal 10396 // Check whether the syntax of expression expr is a grammatically legal
10405 // assignable expression. This check is used to detect situations where 10397 // assignable expression. This check is used to detect situations where
10406 // the expression itself is assignable, but the source is grammatically 10398 // the expression itself is assignable, but the source is grammatically
10407 // wrong. The AST representation of an expression cannot distinguish 10399 // wrong. The AST representation of an expression cannot distinguish
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
10450 let_node->AddNode(ThrowNoSuchMethodError( 10442 let_node->AddNode(ThrowNoSuchMethodError(
10451 original->token_pos(), 10443 original->token_pos(),
10452 *target_cls, 10444 *target_cls,
10453 String::Handle(Z, Field::SetterName(name)), 10445 String::Handle(Z, Field::SetterName(name)),
10454 NULL, // No arguments. 10446 NULL, // No arguments.
10455 InvocationMirror::kStatic, 10447 InvocationMirror::kStatic,
10456 original->IsLoadLocalNode() ? 10448 original->IsLoadLocalNode() ?
10457 InvocationMirror::kLocalVar : InvocationMirror::kSetter, 10449 InvocationMirror::kLocalVar : InvocationMirror::kSetter,
10458 NULL)); // No existing function. 10450 NULL)); // No existing function.
10459 result = let_node; 10451 result = let_node;
10460 } else if (result->IsStoreIndexedNode() || 10452 }
10461 result->IsInstanceSetterNode() || 10453 // The compound assignment operator a ??= b is different from other
10462 result->IsStaticSetterNode() || 10454 // a op= b assignments. If a is non-null, the assignment to a must be
10463 result->IsStoreStaticFieldNode() || 10455 // dropped:
10464 result->IsStoreLocalNode()) { 10456 // normally: a op= b ==> a = a op b
10465 // Ensure that the expression temp is allocated for nodes that may need it. 10457 // however: a ??= b ==> a ?? (a = b)
10466 EnsureExpressionTemp(); 10458 // Therefore, we need to transform a = (a ?? b) into a ?? (a = b)
10459 if (rhs->IsBinaryOpNode() &&
10460 (rhs->AsBinaryOpNode()->kind() == Token::kIFNULL)) {
10461 BinaryOpNode* ifnull = rhs->AsBinaryOpNode();
10462 AstNode* modified_assign =
10463 CreateAssignmentNode(ifnull->left(),
10464 ifnull->right(),
10465 left_ident,
10466 left_pos);
10467 result = new(Z) BinaryOpNode(rhs->token_pos(),
10468 Token::kIFNULL,
10469 original,
10470 modified_assign);
10467 } 10471 }
10468 return result; 10472 return result;
10469 } 10473 }
10470 10474
10471 10475
10472 AstNode* Parser::ParseCascades(AstNode* expr) { 10476 AstNode* Parser::ParseCascades(AstNode* expr) {
10473 intptr_t cascade_pos = TokenPos(); 10477 intptr_t cascade_pos = TokenPos();
10474 LetNode* cascade = new(Z) LetNode(cascade_pos); 10478 LetNode* cascade = new(Z) LetNode(cascade_pos);
10475 LocalVariable* cascade_receiver_var = cascade->AddInitializer(expr); 10479 LocalVariable* cascade_receiver_var = cascade->AddInitializer(expr);
10476 while (CurrentToken() == Token::kCASCADE) { 10480 while (CurrentToken() == Token::kCASCADE) {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
10638 if (!expr->IsLiteralNode()) { 10642 if (!expr->IsLiteralNode()) {
10639 ReportError(expr_pos, "expression must be a compile-time constant"); 10643 ReportError(expr_pos, "expression must be a compile-time constant");
10640 } 10644 }
10641 return expr->AsLiteralNode(); 10645 return expr->AsLiteralNode();
10642 } 10646 }
10643 10647
10644 10648
10645 AstNode* Parser::ParseConditionalExpr() { 10649 AstNode* Parser::ParseConditionalExpr() {
10646 TRACE_PARSER("ParseConditionalExpr"); 10650 TRACE_PARSER("ParseConditionalExpr");
10647 const intptr_t expr_pos = TokenPos(); 10651 const intptr_t expr_pos = TokenPos();
10648 AstNode* expr = ParseBinaryExpr(Token::Precedence(Token::kOR)); 10652 AstNode* expr = ParseBinaryExpr(Token::Precedence(Token::kIFNULL));
10649 if (CurrentToken() == Token::kCONDITIONAL) { 10653 if (CurrentToken() == Token::kCONDITIONAL) {
10650 EnsureExpressionTemp(); 10654 EnsureExpressionTemp();
10651 ConsumeToken(); 10655 ConsumeToken();
10652 AstNode* expr1 = ParseExpr(kAllowConst, kNoCascades); 10656 AstNode* expr1 = ParseExpr(kAllowConst, kNoCascades);
10653 ExpectToken(Token::kCOLON); 10657 ExpectToken(Token::kCOLON);
10654 AstNode* expr2 = ParseExpr(kAllowConst, kNoCascades); 10658 AstNode* expr2 = ParseExpr(kAllowConst, kNoCascades);
10655 expr = new(Z) ConditionalExprNode(expr_pos, expr, expr1, expr2); 10659 expr = new(Z) ConditionalExprNode(expr_pos, expr, expr1, expr2);
10656 } 10660 }
10657 return expr; 10661 return expr;
10658 } 10662 }
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
10845 arguments->NodeAt(0), 10849 arguments->NodeAt(0),
10846 arguments->NodeAt(1)); 10850 arguments->NodeAt(1));
10847 } 10851 }
10848 } 10852 }
10849 return new(Z) StaticCallNode(ident_pos, func, arguments); 10853 return new(Z) StaticCallNode(ident_pos, func, arguments);
10850 } 10854 }
10851 10855
10852 10856
10853 AstNode* Parser::ParseInstanceCall(AstNode* receiver, 10857 AstNode* Parser::ParseInstanceCall(AstNode* receiver,
10854 const String& func_name, 10858 const String& func_name,
10855 intptr_t ident_pos) { 10859 intptr_t ident_pos,
10860 bool is_conditional) {
10856 TRACE_PARSER("ParseInstanceCall"); 10861 TRACE_PARSER("ParseInstanceCall");
10857 CheckToken(Token::kLPAREN); 10862 CheckToken(Token::kLPAREN);
10858 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); 10863 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst);
10859 return new(Z) InstanceCallNode(ident_pos, receiver, func_name, arguments); 10864 return new(Z) InstanceCallNode(ident_pos,
10865 receiver,
10866 func_name,
10867 arguments,
10868 is_conditional);
10860 } 10869 }
10861 10870
10862 10871
10863 AstNode* Parser::ParseClosureCall(AstNode* closure) { 10872 AstNode* Parser::ParseClosureCall(AstNode* closure) {
10864 TRACE_PARSER("ParseClosureCall"); 10873 TRACE_PARSER("ParseClosureCall");
10865 const intptr_t call_pos = TokenPos(); 10874 const intptr_t call_pos = TokenPos();
10866 ASSERT(CurrentToken() == Token::kLPAREN); 10875 ASSERT(CurrentToken() == Token::kLPAREN);
10867 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst); 10876 ArgumentListNode* arguments = ParseActualParameters(NULL, kAllowConst);
10868 return BuildClosureCall(call_pos, closure, arguments); 10877 return BuildClosureCall(call_pos, closure, arguments);
10869 } 10878 }
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
10995 } 11004 }
10996 UNREACHABLE(); 11005 UNREACHABLE();
10997 return NULL; 11006 return NULL;
10998 } 11007 }
10999 11008
11000 11009
11001 AstNode* Parser::ParseSelectors(AstNode* primary, bool is_cascade) { 11010 AstNode* Parser::ParseSelectors(AstNode* primary, bool is_cascade) {
11002 AstNode* left = primary; 11011 AstNode* left = primary;
11003 while (true) { 11012 while (true) {
11004 AstNode* selector = NULL; 11013 AstNode* selector = NULL;
11005 if (CurrentToken() == Token::kPERIOD) { 11014 if ((CurrentToken() == Token::kPERIOD) ||
11015 (CurrentToken() == Token::kQM_PERIOD)) {
11016 // Unconditional or conditional property extraction or method call.
11017 bool is_conditional = CurrentToken() == Token::kQM_PERIOD;
11006 ConsumeToken(); 11018 ConsumeToken();
11007 if (left->IsPrimaryNode()) { 11019 if (left->IsPrimaryNode()) {
11008 PrimaryNode* primary_node = left->AsPrimaryNode(); 11020 PrimaryNode* primary_node = left->AsPrimaryNode();
11009 const intptr_t primary_pos = primary_node->token_pos(); 11021 const intptr_t primary_pos = primary_node->token_pos();
11010 if (primary_node->primary().IsFunction()) { 11022 if (primary_node->primary().IsFunction()) {
11011 left = LoadClosure(primary_node); 11023 left = LoadClosure(primary_node);
11012 } else if (primary_node->primary().IsTypeParameter()) { 11024 } else if (primary_node->primary().IsTypeParameter()) {
11013 if (ParsingStaticMember()) { 11025 if (ParsingStaticMember()) {
11014 const String& name = String::ZoneHandle(Z, 11026 const String& name = String::Handle(Z,
11015 TypeParameter::Cast(primary_node->primary()).name()); 11027 TypeParameter::Cast(primary_node->primary()).name());
11016 ReportError(primary_pos, 11028 ReportError(primary_pos,
11017 "cannot access type parameter '%s' " 11029 "cannot access type parameter '%s' "
11018 "from static function", 11030 "from static function",
11019 name.ToCString()); 11031 name.ToCString());
11020 } 11032 }
11021 if (current_block_->scope->function_level() > 0) { 11033 if (current_block_->scope->function_level() > 0) {
11022 // Make sure that the instantiator is captured. 11034 // Make sure that the instantiator is captured.
11023 CaptureInstantiator(); 11035 CaptureInstantiator();
11024 } 11036 }
11025 TypeParameter& type_parameter = TypeParameter::ZoneHandle(Z); 11037 TypeParameter& type_parameter = TypeParameter::ZoneHandle(Z);
11026 type_parameter ^= ClassFinalizer::FinalizeType( 11038 type_parameter ^= ClassFinalizer::FinalizeType(
11027 current_class(), 11039 current_class(),
11028 TypeParameter::Cast(primary_node->primary()), 11040 TypeParameter::Cast(primary_node->primary()),
11029 ClassFinalizer::kCanonicalize); 11041 ClassFinalizer::kCanonicalize);
11030 ASSERT(!type_parameter.IsMalformed()); 11042 ASSERT(!type_parameter.IsMalformed());
11031 left = new(Z) TypeNode(primary->token_pos(), type_parameter); 11043 left = new(Z) TypeNode(primary->token_pos(), type_parameter);
11044 } else if (is_conditional && primary_node->primary().IsClass()) {
11045 // The left-hand side of ?. is interpreted as an expression
11046 // of type Type, not as a class literal.
11047 const Class& type_class = Class::Cast(primary_node->primary());
11048 AbstractType& type = Type::ZoneHandle(Z,
11049 Type::New(type_class, TypeArguments::Handle(Z),
11050 primary_pos, Heap::kOld));
11051 type ^= ClassFinalizer::FinalizeType(
11052 current_class(), type, ClassFinalizer::kCanonicalize);
11053 // Type may be malbounded, but not malformed.
11054 ASSERT(!type.IsMalformed());
11055 left = new(Z) TypeNode(primary_pos, type);
11032 } else { 11056 } else {
11033 // Super field access handled in ParseSuperFieldAccess(), 11057 // Super field access handled in ParseSuperFieldAccess(),
11034 // super calls handled in ParseSuperCall(). 11058 // super calls handled in ParseSuperCall().
11035 ASSERT(!primary_node->IsSuper()); 11059 ASSERT(!primary_node->IsSuper());
11036 left = LoadFieldIfUnresolved(left); 11060 left = LoadFieldIfUnresolved(left);
11037 } 11061 }
11038 } 11062 }
11039 const intptr_t ident_pos = TokenPos(); 11063 const intptr_t ident_pos = TokenPos();
11040 String* ident = ExpectIdentifier("identifier expected"); 11064 String* ident = ExpectIdentifier("identifier expected");
11041 if (CurrentToken() == Token::kLPAREN) { 11065 if (CurrentToken() == Token::kLPAREN) {
11042 // Identifier followed by a opening paren: method call. 11066 // Identifier followed by a opening paren: method call.
11043 if (left->IsPrimaryNode() && 11067 if (left->IsPrimaryNode() &&
11044 left->AsPrimaryNode()->primary().IsClass()) { 11068 left->AsPrimaryNode()->primary().IsClass()) {
11045 // Static method call prefixed with class name. 11069 // Static method call prefixed with class name.
11070 ASSERT(!is_conditional);
11046 const Class& cls = Class::Cast(left->AsPrimaryNode()->primary()); 11071 const Class& cls = Class::Cast(left->AsPrimaryNode()->primary());
11047 selector = ParseStaticCall(cls, *ident, ident_pos); 11072 selector = ParseStaticCall(cls, *ident, ident_pos);
11048 } else { 11073 } else {
11049 selector = ParseInstanceCall(left, *ident, ident_pos); 11074 selector = ParseInstanceCall(left, *ident, ident_pos, is_conditional);
11050 } 11075 }
11051 } else { 11076 } else {
11052 // Field access. 11077 // Field access.
11053 Class& cls = Class::Handle(Z); 11078 Class& cls = Class::Handle(Z);
11054 bool is_deferred = false; 11079 bool is_deferred = false;
11055 if (left->IsPrimaryNode()) { 11080 if (left->IsPrimaryNode()) {
11056 PrimaryNode* primary_node = left->AsPrimaryNode(); 11081 PrimaryNode* primary_node = left->AsPrimaryNode();
11057 if (primary_node->primary().IsClass()) { 11082 if (primary_node->primary().IsClass()) {
11058 // If the primary node referred to a class we are loading a 11083 // If the primary node referred to a class we are loading a
11059 // qualified static field. 11084 // qualified static field.
11060 cls ^= primary_node->primary().raw(); 11085 cls ^= primary_node->primary().raw();
11061 is_deferred = primary_node->is_deferred_reference(); 11086 is_deferred = primary_node->is_deferred_reference();
11062 } 11087 }
11063 } 11088 }
11064 if (cls.IsNull()) { 11089 if (cls.IsNull()) {
11065 // Instance field access. 11090 // Instance field access.
11066 selector = CallGetter(ident_pos, left, *ident); 11091 selector = new(Z) InstanceGetterNode(ident_pos,
11092 left,
11093 *ident,
11094 is_conditional);
11067 } else { 11095 } else {
11068 // Static field access. 11096 // Static field access.
11097 ASSERT(!is_conditional);
11069 selector = GenerateStaticFieldAccess(cls, *ident, ident_pos); 11098 selector = GenerateStaticFieldAccess(cls, *ident, ident_pos);
11070 ASSERT(selector != NULL); 11099 ASSERT(selector != NULL);
11071 if (selector->IsLoadStaticFieldNode()) { 11100 if (selector->IsLoadStaticFieldNode()) {
11072 selector->AsLoadStaticFieldNode()->set_is_deferred(is_deferred); 11101 selector->AsLoadStaticFieldNode()->set_is_deferred(is_deferred);
11073 } else if (selector->IsStaticGetterNode()) { 11102 } else if (selector->IsStaticGetterNode()) {
11074 selector->AsStaticGetterNode()->set_is_deferred(is_deferred); 11103 selector->AsStaticGetterNode()->set_is_deferred(is_deferred);
11075 } 11104 }
11076 } 11105 }
11077 } 11106 }
11078 } else if (CurrentToken() == Token::kLBRACK) { 11107 } else if (CurrentToken() == Token::kLBRACK) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
11142 } else { 11171 } else {
11143 // Dynamic function call on implicit "this" parameter. 11172 // Dynamic function call on implicit "this" parameter.
11144 if (current_function().is_static()) { 11173 if (current_function().is_static()) {
11145 ReportError(primary_pos, 11174 ReportError(primary_pos,
11146 "cannot access instance method '%s' " 11175 "cannot access instance method '%s' "
11147 "from static function", 11176 "from static function",
11148 func_name.ToCString()); 11177 func_name.ToCString());
11149 } 11178 }
11150 selector = ParseInstanceCall(LoadReceiver(primary_pos), 11179 selector = ParseInstanceCall(LoadReceiver(primary_pos),
11151 func_name, 11180 func_name,
11152 primary_pos); 11181 primary_pos,
11182 false /* is_conditional */);
11153 } 11183 }
11154 } else if (primary_node->primary().IsString()) { 11184 } else if (primary_node->primary().IsString()) {
11155 // Primary is an unresolved name. 11185 // Primary is an unresolved name.
11156 if (primary_node->IsSuper()) { 11186 if (primary_node->IsSuper()) {
11157 ReportError(primary_pos, "illegal use of super"); 11187 ReportError(primary_pos, "illegal use of super");
11158 } 11188 }
11159 String& name = 11189 String& name =
11160 String::CheckedZoneHandle(primary_node->primary().raw()); 11190 String::CheckedZoneHandle(primary_node->primary().raw());
11161 if (current_function().is_static()) { 11191 if (current_function().is_static()) {
11162 // The static call will be converted to throwing a NSM error. 11192 // The static call will be converted to throwing a NSM error.
11163 selector = ParseStaticCall(current_class(), name, primary_pos); 11193 selector = ParseStaticCall(current_class(), name, primary_pos);
11164 } else { 11194 } else {
11165 // Treat as call to unresolved (instance) method. 11195 // Treat as call to unresolved (instance) method.
11166 selector = ParseInstanceCall(LoadReceiver(primary_pos), 11196 selector = ParseInstanceCall(LoadReceiver(primary_pos),
11167 name, 11197 name,
11168 primary_pos); 11198 primary_pos,
11199 false /* is_conditional */);
11169 } 11200 }
11170 } else if (primary_node->primary().IsTypeParameter()) { 11201 } else if (primary_node->primary().IsTypeParameter()) {
11171 const String& name = String::ZoneHandle(Z, 11202 const String& name = String::ZoneHandle(Z,
11172 TypeParameter::Cast(primary_node->primary()).name()); 11203 TypeParameter::Cast(primary_node->primary()).name());
11173 if (ParsingStaticMember()) { 11204 if (ParsingStaticMember()) {
11174 // Treat as this.T(), because T is in scope. 11205 // Treat as this.T(), because T is in scope.
11175 ReportError(primary_pos, 11206 ReportError(primary_pos,
11176 "cannot access type parameter '%s' " 11207 "cannot access type parameter '%s' "
11177 "from static function", 11208 "from static function",
11178 name.ToCString()); 11209 name.ToCString());
11179 } else { 11210 } else {
11180 // Treat as call to unresolved (instance) method. 11211 // Treat as call to unresolved (instance) method.
11181 selector = ParseInstanceCall(LoadReceiver(primary_pos), 11212 selector = ParseInstanceCall(LoadReceiver(primary_pos),
11182 name, 11213 name,
11183 primary_pos); 11214 primary_pos,
11215 false /* is_conditional */);
11184 } 11216 }
11185 } else if (primary_node->primary().IsClass()) { 11217 } else if (primary_node->primary().IsClass()) {
11186 const Class& type_class = Class::Cast(primary_node->primary()); 11218 const Class& type_class = Class::Cast(primary_node->primary());
11187 AbstractType& type = Type::ZoneHandle(Z, Type::New( 11219 AbstractType& type = Type::ZoneHandle(Z, Type::New(
11188 type_class, TypeArguments::Handle(Z), primary_pos)); 11220 type_class, TypeArguments::Handle(Z), primary_pos));
11189 type ^= ClassFinalizer::FinalizeType( 11221 type ^= ClassFinalizer::FinalizeType(
11190 current_class(), type, ClassFinalizer::kCanonicalize); 11222 current_class(), type, ClassFinalizer::kCanonicalize);
11191 // Type may be malbounded, but not malformed. 11223 // Type may be malbounded, but not malformed.
11192 ASSERT(!type.IsMalformed()); 11224 ASSERT(!type.IsMalformed());
11193 selector = new(Z) TypeNode(primary_pos, type); 11225 selector = new(Z) TypeNode(primary_pos, type);
(...skipping 1901 matching lines...) Expand 10 before | Expand all | Expand 10 after
13095 const String& ident = *ExpectIdentifier("identifier expected"); 13127 const String& ident = *ExpectIdentifier("identifier expected");
13096 if (CurrentToken() == Token::kLPAREN) { 13128 if (CurrentToken() == Token::kLPAREN) {
13097 primary = ParseSuperCall(ident); 13129 primary = ParseSuperCall(ident);
13098 } else { 13130 } else {
13099 primary = ParseSuperFieldAccess(ident, ident_pos); 13131 primary = ParseSuperFieldAccess(ident, ident_pos);
13100 } 13132 }
13101 } else if ((CurrentToken() == Token::kLBRACK) || 13133 } else if ((CurrentToken() == Token::kLBRACK) ||
13102 Token::CanBeOverloaded(CurrentToken()) || 13134 Token::CanBeOverloaded(CurrentToken()) ||
13103 (CurrentToken() == Token::kNE)) { 13135 (CurrentToken() == Token::kNE)) {
13104 primary = ParseSuperOperator(); 13136 primary = ParseSuperOperator();
13137 } else if (CurrentToken() == Token::kQM_PERIOD) {
13138 ReportError("super call or super getter may not use ?.");
13105 } else { 13139 } else {
13106 primary = new(Z) PrimaryNode(super_pos, Symbols::Super()); 13140 primary = new(Z) PrimaryNode(super_pos, Symbols::Super());
13107 } 13141 }
13108 } else { 13142 } else {
13109 UnexpectedToken(); 13143 UnexpectedToken();
13110 } 13144 }
13111 return primary; 13145 return primary;
13112 } 13146 }
13113 13147
13114 13148
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
13381 void Parser::SkipSelectors() { 13415 void Parser::SkipSelectors() {
13382 while (true) { 13416 while (true) {
13383 const Token::Kind current_token = CurrentToken(); 13417 const Token::Kind current_token = CurrentToken();
13384 if (current_token == Token::kCASCADE) { 13418 if (current_token == Token::kCASCADE) {
13385 ConsumeToken(); 13419 ConsumeToken();
13386 if (CurrentToken() == Token::kLBRACK) { 13420 if (CurrentToken() == Token::kLBRACK) {
13387 continue; // Consume [ in next loop iteration. 13421 continue; // Consume [ in next loop iteration.
13388 } else { 13422 } else {
13389 ExpectIdentifier("identifier or [ expected after .."); 13423 ExpectIdentifier("identifier or [ expected after ..");
13390 } 13424 }
13391 } else if (current_token == Token::kPERIOD) { 13425 } else if ((current_token == Token::kPERIOD) ||
13426 (current_token == Token::kQM_PERIOD)) {
13392 ConsumeToken(); 13427 ConsumeToken();
13393 ExpectIdentifier("identifier expected"); 13428 ExpectIdentifier("identifier expected");
13394 } else if (current_token == Token::kLBRACK) { 13429 } else if (current_token == Token::kLBRACK) {
13395 ConsumeToken(); 13430 ConsumeToken();
13396 SkipNestedExpr(); 13431 SkipNestedExpr();
13397 ExpectToken(Token::kRBRACK); 13432 ExpectToken(Token::kRBRACK);
13398 } else if (current_token == Token::kLPAREN) { 13433 } else if (current_token == Token::kLPAREN) {
13399 SkipActualParameters(); 13434 SkipActualParameters();
13400 } else { 13435 } else {
13401 break; 13436 break;
(...skipping 17 matching lines...) Expand all
13419 ConsumeToken(); 13454 ConsumeToken();
13420 SkipUnaryExpr(); 13455 SkipUnaryExpr();
13421 } else { 13456 } else {
13422 SkipPostfixExpr(); 13457 SkipPostfixExpr();
13423 } 13458 }
13424 } 13459 }
13425 13460
13426 13461
13427 void Parser::SkipBinaryExpr() { 13462 void Parser::SkipBinaryExpr() {
13428 SkipUnaryExpr(); 13463 SkipUnaryExpr();
13429 const int min_prec = Token::Precedence(Token::kOR); 13464 const int min_prec = Token::Precedence(Token::kIFNULL);
13430 const int max_prec = Token::Precedence(Token::kMUL); 13465 const int max_prec = Token::Precedence(Token::kMUL);
13431 while (((min_prec <= Token::Precedence(CurrentToken())) && 13466 while (((min_prec <= Token::Precedence(CurrentToken())) &&
13432 (Token::Precedence(CurrentToken()) <= max_prec))) { 13467 (Token::Precedence(CurrentToken()) <= max_prec))) {
13433 if (CurrentToken() == Token::kIS) { 13468 if (CurrentToken() == Token::kIS) {
13434 ConsumeToken(); 13469 ConsumeToken();
13435 if (CurrentToken() == Token::kNOT) { 13470 if (CurrentToken() == Token::kNOT) {
13436 ConsumeToken(); 13471 ConsumeToken();
13437 } 13472 }
13438 SkipType(false); 13473 SkipType(false);
13439 } else if (CurrentToken() == Token::kAS) { 13474 } else if (CurrentToken() == Token::kAS) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
13483 void Parser::SkipQualIdent() { 13518 void Parser::SkipQualIdent() {
13484 ASSERT(IsIdentifier()); 13519 ASSERT(IsIdentifier());
13485 ConsumeToken(); 13520 ConsumeToken();
13486 if (CurrentToken() == Token::kPERIOD) { 13521 if (CurrentToken() == Token::kPERIOD) {
13487 ConsumeToken(); // Consume the kPERIOD token. 13522 ConsumeToken(); // Consume the kPERIOD token.
13488 ExpectIdentifier("identifier expected after '.'"); 13523 ExpectIdentifier("identifier expected after '.'");
13489 } 13524 }
13490 } 13525 }
13491 13526
13492 } // namespace dart 13527 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698