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

Unified Diff: pkg/fasta/lib/src/modifier.dart

Issue 2629063005: Fasta builders. (Closed)
Patch Set: Address review comments. 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 | « pkg/fasta/lib/src/import.dart ('k') | pkg/fasta/lib/src/quote.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/fasta/lib/src/modifier.dart
diff --git a/pkg/fasta/lib/src/modifier.dart b/pkg/fasta/lib/src/modifier.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8bd8eaf3289d8a268217e7225cb19aeef594d6d1
--- /dev/null
+++ b/pkg/fasta/lib/src/modifier.dart
@@ -0,0 +1,76 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library fasta.modifier;
+
+import 'errors.dart' show
+ internalError;
+
+enum ModifierEnum {
+ Abstract,
+ Const,
+ External,
+ Final,
+ Static,
+
+ // Not a real modifier.
+ Var,
+}
+
+const int abstractMask = 1;
+
+const int constMask = abstractMask << 1;
+
+const int externalMask = constMask << 1;
+
+const int finalMask = externalMask << 1;
+
+const int staticMask = finalMask << 1;
+
+/// Not a real modifier, and by setting it to null, it is automatically
+/// ignored by [Modifier.validate] below.
+const int varMask = 0;
+
+const Modifier Abstract = const Modifier(ModifierEnum.Abstract, abstractMask);
+
+const Modifier Const = const Modifier(ModifierEnum.Const, constMask);
+
+const Modifier External = const Modifier(ModifierEnum.External, externalMask);
+
+const Modifier Final = const Modifier(ModifierEnum.Final, finalMask);
+
+const Modifier Static = const Modifier(ModifierEnum.Static, staticMask);
+
+/// Not a real modifier.
+const Modifier Var = const Modifier(ModifierEnum.Var, varMask);
+
+class Modifier {
+ final ModifierEnum kind;
+
+ final int mask;
+
+ const Modifier(this.kind, this.mask);
+
+ factory Modifier.fromString(String string) {
+ if (identical('abstract', string)) return Abstract;
+ if (identical('const', string)) return Const;
+ if (identical('external', string)) return External;
+ if (identical('final', string)) return Final;
+ if (identical('static', string)) return Static;
+ if (identical('var', string)) return Var;
+ return internalError("Unhandled modifier: $string");
+ }
+
+ toString() => "modifier(${'$kind'.substring('ModifierEnum.'.length)})";
+
+ static int validate(List<Modifier> modifiers, {bool isAbstract: false}) {
+ // TODO(ahe): Implement modifier validation: ordering and uniqueness.
+ int result = isAbstract ? abstractMask : 0;
+ if (modifiers == null) return result;
+ for (Modifier modifier in modifiers) {
+ result |= modifier.mask;
+ }
+ return result;
+ }
+}
« no previous file with comments | « pkg/fasta/lib/src/import.dart ('k') | pkg/fasta/lib/src/quote.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698