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

Side by Side Diff: pkg/front_end/lib/src/fasta/modifier.dart

Issue 2876813002: Implement generalized function types. (Closed)
Patch Set: Fixes for analyzer and dart2js. Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 library fasta.modifier; 5 library fasta.modifier;
6 6
7 import 'errors.dart' show internalError; 7 import 'errors.dart' show internalError;
8 8
9 enum ModifierEnum { 9 enum ModifierEnum {
10 Abstract, 10 Abstract,
11 Const, 11 Const,
12 Covariant,
12 External, 13 External,
13 Final, 14 Final,
14 Static, 15 Static,
15 16
16 // Not a real modifier. 17 // Not a real modifier.
17 Var, 18 Var,
18 } 19 }
19 20
20 const int abstractMask = 1; 21 const int abstractMask = 1;
21 22
22 const int constMask = abstractMask << 1; 23 const int constMask = abstractMask << 1;
23 24
24 const int externalMask = constMask << 1; 25 const int covariantMask = constMask << 1;
26
27 const int externalMask = covariantMask << 1;
25 28
26 const int finalMask = externalMask << 1; 29 const int finalMask = externalMask << 1;
27 30
28 const int staticMask = finalMask << 1; 31 const int staticMask = finalMask << 1;
29 32
30 const int namedMixinApplicationMask = staticMask << 1; 33 const int namedMixinApplicationMask = staticMask << 1;
31 34
32 /// Not a real modifier, and by setting it to zero, it is automatically ignored 35 /// Not a real modifier, and by setting it to zero, it is automatically ignored
33 /// by [Modifier.validate] below. 36 /// by [Modifier.validate] below.
34 const int varMask = 0; 37 const int varMask = 0;
35 38
36 const Modifier Abstract = const Modifier(ModifierEnum.Abstract, abstractMask); 39 const Modifier Abstract = const Modifier(ModifierEnum.Abstract, abstractMask);
37 40
38 const Modifier Const = const Modifier(ModifierEnum.Const, constMask); 41 const Modifier Const = const Modifier(ModifierEnum.Const, constMask);
39 42
43 const Modifier Covariant =
44 const Modifier(ModifierEnum.Covariant, covariantMask);
45
40 const Modifier External = const Modifier(ModifierEnum.External, externalMask); 46 const Modifier External = const Modifier(ModifierEnum.External, externalMask);
41 47
42 const Modifier Final = const Modifier(ModifierEnum.Final, finalMask); 48 const Modifier Final = const Modifier(ModifierEnum.Final, finalMask);
43 49
44 const Modifier Static = const Modifier(ModifierEnum.Static, staticMask); 50 const Modifier Static = const Modifier(ModifierEnum.Static, staticMask);
45 51
46 /// Not a real modifier. 52 /// Not a real modifier.
47 const Modifier Var = const Modifier(ModifierEnum.Var, varMask); 53 const Modifier Var = const Modifier(ModifierEnum.Var, varMask);
48 54
49 class Modifier { 55 class Modifier {
50 final ModifierEnum kind; 56 final ModifierEnum kind;
51 57
52 final int mask; 58 final int mask;
53 59
54 const Modifier(this.kind, this.mask); 60 const Modifier(this.kind, this.mask);
55 61
56 factory Modifier.fromString(String string) { 62 factory Modifier.fromString(String string) {
57 if (identical('abstract', string)) return Abstract; 63 if (identical('abstract', string)) return Abstract;
58 if (identical('const', string)) return Const; 64 if (identical('const', string)) return Const;
65 if (identical('covariant', string)) return Covariant;
59 if (identical('external', string)) return External; 66 if (identical('external', string)) return External;
60 if (identical('final', string)) return Final; 67 if (identical('final', string)) return Final;
61 if (identical('static', string)) return Static; 68 if (identical('static', string)) return Static;
62 if (identical('var', string)) return Var; 69 if (identical('var', string)) return Var;
63 return internalError("Unhandled modifier: $string"); 70 return internalError("Unhandled modifier: $string");
64 } 71 }
65 72
66 toString() => "modifier(${'$kind'.substring('ModifierEnum.'.length)})"; 73 toString() => "modifier(${'$kind'.substring('ModifierEnum.'.length)})";
67 74
68 static int validate(List<Modifier> modifiers, {bool isAbstract: false}) { 75 static int validate(List<Modifier> modifiers, {bool isAbstract: false}) {
69 // TODO(ahe): Implement modifier validation: ordering and uniqueness. 76 // TODO(ahe): Rename this method, validation is now taken care of by the
77 // parser.
70 int result = isAbstract ? abstractMask : 0; 78 int result = isAbstract ? abstractMask : 0;
71 if (modifiers == null) return result; 79 if (modifiers == null) return result;
72 for (Modifier modifier in modifiers) { 80 for (Modifier modifier in modifiers) {
73 result |= modifier.mask; 81 result |= modifier.mask;
74 } 82 }
75 return result; 83 return result;
76 } 84 }
77 } 85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698