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

Unified 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, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc
index c5af00babb96719cf28fcdcf65305ea850a88370..da49e7ae893bd0722576b0524ea0ed49a36099d4 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -881,7 +881,44 @@ RawArray* Parser::EvaluateMetadata() {
(LookaheadToken(5) == Token::kLPAREN))) {
expr = ParseNewOperator(Token::kCONST);
} else {
- expr = ParsePrimary();
+ // Can be x, C.x, or L.C.x.
+ expr = ParsePrimary(); // Consumes x, C or L.C.
+ Class& cls = Class::Handle();
+ if (expr->IsPrimaryNode()) {
+ PrimaryNode* primary_node = expr->AsPrimaryNode();
+ if (primary_node->primary().IsClass()) {
+ // If the primary node referred to a class we are loading a
+ // qualified static field.
+ cls ^= primary_node->primary().raw();
+ } else {
+ ErrorMsg(expr_pos, "Metadata expressions must refer to a const field "
+ "or constructor");
+ }
+ }
+ if (CurrentToken() == Token::kPERIOD) {
+ // C.x or L.C.X.
+ if (cls.IsNull()) {
+ ErrorMsg(expr_pos, "Metadata expressions must refer to a const field "
+ "or constructor");
+ }
+ ConsumeToken();
+ const intptr_t ident_pos = TokenPos();
+ String* ident = ExpectIdentifier("identifier expected");
+ const Field& field = Field::Handle(cls.LookupStaticField(*ident));
+ if (field.IsNull()) {
+ ErrorMsg(ident_pos,
+ "Class '%s' has no field '%s'",
+ cls.ToCString(),
+ ident->ToCString());
+ }
+ if (!field.is_const()) {
+ ErrorMsg(ident_pos,
+ "Field '%s' of class '%s' is not const",
+ ident->ToCString(),
+ cls.ToCString());
+ }
+ expr = GenerateStaticFieldLookup(field, TokenPos());
+ }
}
if (expr->EvalConstExpr() == NULL) {
ErrorMsg(expr_pos, "expression must be a compile-time constant");
« 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