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

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

Issue 40863002: Handle metadata with type literals or qualified identifiers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: simplify Created 7 years, 1 month 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 "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/bootstrap.h" 9 #include "vm/bootstrap.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 AstNode* expr = NULL; 870 AstNode* expr = NULL;
871 if ((LookaheadToken(1) == Token::kLPAREN) || 871 if ((LookaheadToken(1) == Token::kLPAREN) ||
872 ((LookaheadToken(1) == Token::kPERIOD) && 872 ((LookaheadToken(1) == Token::kPERIOD) &&
873 (LookaheadToken(3) == Token::kLPAREN)) || 873 (LookaheadToken(3) == Token::kLPAREN)) ||
874 ((LookaheadToken(1) == Token::kPERIOD) && 874 ((LookaheadToken(1) == Token::kPERIOD) &&
875 (LookaheadToken(3) == Token::kPERIOD) && 875 (LookaheadToken(3) == Token::kPERIOD) &&
876 (LookaheadToken(5) == Token::kLPAREN))) { 876 (LookaheadToken(5) == Token::kLPAREN))) {
877 expr = ParseNewOperator(Token::kCONST); 877 expr = ParseNewOperator(Token::kCONST);
878 } else { 878 } else {
879 expr = ParsePrimary(); 879 expr = ParsePrimary();
880 expr = ParseMemberSelection(expr);
880 } 881 }
881 if (expr->EvalConstExpr() == NULL) { 882 if (expr->EvalConstExpr() == NULL) {
882 ErrorMsg(expr_pos, "expression must be a compile-time constant"); 883 ErrorMsg(expr_pos, "expression must be a compile-time constant");
883 } 884 }
884 const Instance& val = EvaluateConstExpr(expr_pos, expr); 885 const Instance& val = EvaluateConstExpr(expr_pos, expr);
885 meta_values.Add(val); 886 meta_values.Add(val);
886 } 887 }
887 return Array::MakeArray(meta_values); 888 return Array::MakeArray(meta_values);
888 } 889 }
889 890
(...skipping 7522 matching lines...) Expand 10 before | Expand all | Expand 10 after
8412 } 8413 }
8413 // Done parsing selectors. 8414 // Done parsing selectors.
8414 return left; 8415 return left;
8415 } 8416 }
8416 ASSERT(selector != NULL); 8417 ASSERT(selector != NULL);
8417 left = selector; 8418 left = selector;
8418 } 8419 }
8419 } 8420 }
8420 8421
8421 8422
8423 AstNode* Parser::ParseMemberSelection(AstNode* primary) {
8424 AstNode* left = primary;
8425
8426 if (CurrentToken() == Token::kPERIOD) {
8427 ConsumeToken();
8428 if (left->IsPrimaryNode()) {
8429 if (left->AsPrimaryNode()->primary().IsFunction()) {
hausner 2013/10/25 20:24:25 I still don't understand why you handle this case.
8430 left = LoadClosure(left->AsPrimaryNode());
8431 } else {
8432 // Super field access handled in ParseSuperFieldAccess(),
8433 // super calls handled in ParseSuperCall().
8434 ASSERT(!left->AsPrimaryNode()->IsSuper());
8435 left = LoadFieldIfUnresolved(left);
8436 }
8437 }
8438 const intptr_t ident_pos = TokenPos();
8439 String* ident = ExpectIdentifier("identifier expected");
8440
8441 Class& cls = Class::Handle();
8442 if (left->IsPrimaryNode()) {
8443 PrimaryNode* primary_node = left->AsPrimaryNode();
8444 if (primary_node->primary().IsClass()) {
8445 // If the primary node referred to a class we are loading a
8446 // qualified static field.
8447 cls ^= primary_node->primary().raw();
8448 }
8449 }
8450 if (cls.IsNull()) {
8451 // Instance field access.
8452 return CallGetter(ident_pos, left, *ident);
8453 } else {
8454 // Static field access.
8455 return ParseStaticFieldAccess(cls, *ident, ident_pos, true);
8456 }
8457 }
8458
8459 // No selector to parse.
8460 if (left->IsPrimaryNode()) {
8461 PrimaryNode* primary = left->AsPrimaryNode();
8462 if (primary->primary().IsFunction()) {
hausner 2013/10/25 20:24:25 ditto
8463 // Treat as implicit closure.
8464 left = LoadClosure(primary);
8465 } else if (primary->primary().IsClass()) {
8466 const Class& type_class = Class::Cast(primary->primary());
8467 AbstractType& type = Type::ZoneHandle(
8468 Type::New(type_class, TypeArguments::Handle(),
8469 primary->token_pos(), Heap::kOld));
8470 type = ClassFinalizer::FinalizeType(
8471 current_class(), type, ClassFinalizer::kCanonicalize);
8472 // Type may be malbounded, but not malformed.
8473 ASSERT(!type.IsMalformed());
8474 left = new TypeNode(primary->token_pos(), type);
8475 }
8476 }
8477 return left;
8478 }
8479
8480
8422 AstNode* Parser::ParsePostfixExpr() { 8481 AstNode* Parser::ParsePostfixExpr() {
8423 TRACE_PARSER("ParsePostfixExpr"); 8482 TRACE_PARSER("ParsePostfixExpr");
8424 String* expr_ident = 8483 String* expr_ident =
8425 Token::IsIdentifier(CurrentToken()) ? CurrentLiteral() : NULL; 8484 Token::IsIdentifier(CurrentToken()) ? CurrentLiteral() : NULL;
8426 const intptr_t expr_pos = TokenPos(); 8485 const intptr_t expr_pos = TokenPos();
8427 AstNode* expr = ParsePrimary(); 8486 AstNode* expr = ParsePrimary();
8428 expr = ParseSelectors(expr, false); 8487 expr = ParseSelectors(expr, false);
8429 if (IsIncrementOperator(CurrentToken())) { 8488 if (IsIncrementOperator(CurrentToken())) {
8430 TRACE_PARSER("IncrementOperator"); 8489 TRACE_PARSER("IncrementOperator");
8431 Token::Kind incr_op = CurrentToken(); 8490 Token::Kind incr_op = CurrentToken();
(...skipping 2179 matching lines...) Expand 10 before | Expand all | Expand 10 after
10611 void Parser::SkipQualIdent() { 10670 void Parser::SkipQualIdent() {
10612 ASSERT(IsIdentifier()); 10671 ASSERT(IsIdentifier());
10613 ConsumeToken(); 10672 ConsumeToken();
10614 if (CurrentToken() == Token::kPERIOD) { 10673 if (CurrentToken() == Token::kPERIOD) {
10615 ConsumeToken(); // Consume the kPERIOD token. 10674 ConsumeToken(); // Consume the kPERIOD token.
10616 ExpectIdentifier("identifier expected after '.'"); 10675 ExpectIdentifier("identifier expected after '.'");
10617 } 10676 }
10618 } 10677 }
10619 10678
10620 } // namespace dart 10679 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698