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

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: 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
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 } 874 }
875 AstNode* expr = NULL; 875 AstNode* expr = NULL;
876 if ((LookaheadToken(1) == Token::kLPAREN) || 876 if ((LookaheadToken(1) == Token::kLPAREN) ||
877 ((LookaheadToken(1) == Token::kPERIOD) && 877 ((LookaheadToken(1) == Token::kPERIOD) &&
878 (LookaheadToken(3) == Token::kLPAREN)) || 878 (LookaheadToken(3) == Token::kLPAREN)) ||
879 ((LookaheadToken(1) == Token::kPERIOD) && 879 ((LookaheadToken(1) == Token::kPERIOD) &&
880 (LookaheadToken(3) == Token::kPERIOD) && 880 (LookaheadToken(3) == Token::kPERIOD) &&
881 (LookaheadToken(5) == Token::kLPAREN))) { 881 (LookaheadToken(5) == Token::kLPAREN))) {
882 expr = ParseNewOperator(Token::kCONST); 882 expr = ParseNewOperator(Token::kCONST);
883 } else { 883 } else {
884 expr = ParsePrimary(); 884 // Can be x, C.x, or L.C.x.
885 expr = ParsePrimary(); // Consumes x, C or L.C.
886 Class& cls = Class::Handle();
887 if (expr->IsPrimaryNode()) {
888 PrimaryNode* primary_node = expr->AsPrimaryNode();
889 if (primary_node->primary().IsClass()) {
890 // If the primary node referred to a class we are loading a
891 // qualified static field.
892 cls ^= primary_node->primary().raw();
893 } else {
894 ErrorMsg(expr_pos, "Metadata expressions must refer to a const field "
895 "or constructor");
896 }
897 }
898 if (CurrentToken() == Token::kPERIOD) {
899 // C.x or L.C.X.
900 if (cls.IsNull()) {
901 ErrorMsg(expr_pos, "Metadata expressions must refer to a const field "
902 "or constructor");
903 }
904 ConsumeToken();
905 const intptr_t ident_pos = TokenPos();
906 String* ident = ExpectIdentifier("identifier expected");
907 const Field& field = Field::Handle(cls.LookupStaticField(*ident));
908 if (field.IsNull()) {
909 ErrorMsg(ident_pos,
910 "Class '%s' has no field '%s'",
911 cls.ToCString(),
912 ident->ToCString());
913 }
914 if (!field.is_const()) {
915 ErrorMsg(ident_pos,
916 "Field '%s' of class '%s' is not const",
917 ident->ToCString(),
918 cls.ToCString());
919 }
920 expr = GenerateStaticFieldLookup(field, TokenPos());
921 }
885 } 922 }
886 if (expr->EvalConstExpr() == NULL) { 923 if (expr->EvalConstExpr() == NULL) {
887 ErrorMsg(expr_pos, "expression must be a compile-time constant"); 924 ErrorMsg(expr_pos, "expression must be a compile-time constant");
888 } 925 }
889 const Instance& val = EvaluateConstExpr(expr_pos, expr); 926 const Instance& val = EvaluateConstExpr(expr_pos, expr);
890 meta_values.Add(val); 927 meta_values.Add(val);
891 } 928 }
892 return Array::MakeArray(meta_values); 929 return Array::MakeArray(meta_values);
893 } 930 }
894 931
(...skipping 9736 matching lines...) Expand 10 before | Expand all | Expand 10 after
10631 void Parser::SkipQualIdent() { 10668 void Parser::SkipQualIdent() {
10632 ASSERT(IsIdentifier()); 10669 ASSERT(IsIdentifier());
10633 ConsumeToken(); 10670 ConsumeToken();
10634 if (CurrentToken() == Token::kPERIOD) { 10671 if (CurrentToken() == Token::kPERIOD) {
10635 ConsumeToken(); // Consume the kPERIOD token. 10672 ConsumeToken(); // Consume the kPERIOD token.
10636 ExpectIdentifier("identifier expected after '.'"); 10673 ExpectIdentifier("identifier expected after '.'");
10637 } 10674 }
10638 } 10675 }
10639 10676
10640 } // namespace dart 10677 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698