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

Unified Diff: pkg/compiler/lib/src/parser/parser.dart

Issue 2626843003: Implement 'covariant' modifier for dart2js. (Closed)
Patch Set: Update status file for dartk. Created 3 years, 11 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 | pkg/compiler/lib/src/tokens/keyword.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/parser/parser.dart
diff --git a/pkg/compiler/lib/src/parser/parser.dart b/pkg/compiler/lib/src/parser/parser.dart
index 988cbf32c63d165be72ac4250dba5fc1b794c509..40389c560798a4345ce916dfb256c462b6abce4e 100644
--- a/pkg/compiler/lib/src/parser/parser.dart
+++ b/pkg/compiler/lib/src/parser/parser.dart
@@ -426,6 +426,15 @@ class Parser {
Token parseFormalParameter(Token token, FormalParameterType type) {
token = parseMetadataStar(token, forParameter: true);
listener.beginFormalParameter(token);
+
+ // Skip over `covariant` token, if the next token is an identifier or
+ // modifier.
+ // This enables the case where `covariant` is the name of the parameter:
+ // void foo(covariant);
+ if (identical(token.stringValue, 'covariant') &&
+ token.next.isIdentifier() || isModifier(token.next)) {
+ token = token.next;
+ }
token = parseModifiers(token);
// TODO(ahe): Validate that there are formal parameters if void.
token = parseReturnTypeOpt(token);
@@ -988,9 +997,29 @@ class Parser {
return null;
}
+ /// Removes the optional `covariant` token from the modifiers, if there
+ /// is no `static` in the list, and `covariant` is the first modifier.
+ Link<Token> removeOptCovariantTokenIfNotStatic(Link<Token> modifiers) {
+ if (modifiers.isEmpty ||
+ !identical(modifiers.first.stringValue, 'covariant')) {
+ return modifiers;
+ }
+ for (Token modifier in modifiers.tail) {
+ if (identical(modifier.stringValue, 'static')) {
+ return modifiers;
+ }
+ }
+ return modifiers.tail;
+ }
+
Token parseFields(Token start, Link<Token> modifiers, Token type,
Token getOrSet, Token name, bool isTopLevel) {
bool hasType = type != null;
+
+ if (getOrSet == null && !isTopLevel) {
+ modifiers = removeOptCovariantTokenIfNotStatic(modifiers);
+ }
+
Token varFinalOrConst =
expectVarFinalOrConst(modifiers, hasType, !isTopLevel);
bool isVar = false;
« no previous file with comments | « no previous file | pkg/compiler/lib/src/tokens/keyword.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698