OLD | NEW |
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.kernel_enum_builder; | 5 library fasta.kernel_enum_builder; |
6 | 6 |
7 import 'package:kernel/ast.dart' show | 7 import 'package:kernel/ast.dart' show |
8 Arguments, | 8 Arguments, |
9 AsyncMarker, | 9 AsyncMarker, |
10 Class, | 10 Class, |
(...skipping 28 matching lines...) Expand all Loading... |
39 import "../source/source_class_builder.dart" show | 39 import "../source/source_class_builder.dart" show |
40 SourceClassBuilder; | 40 SourceClassBuilder; |
41 | 41 |
42 import 'kernel_builder.dart' show | 42 import 'kernel_builder.dart' show |
43 Builder, | 43 Builder, |
44 EnumBuilder, | 44 EnumBuilder, |
45 FormalParameterBuilder, | 45 FormalParameterBuilder, |
46 KernelConstructorBuilder, | 46 KernelConstructorBuilder, |
47 KernelFieldBuilder, | 47 KernelFieldBuilder, |
48 KernelFormalParameterBuilder, | 48 KernelFormalParameterBuilder, |
49 KernelInterfaceTypeBuilder, | |
50 KernelLibraryBuilder, | 49 KernelLibraryBuilder, |
| 50 KernelNamedTypeBuilder, |
51 KernelProcedureBuilder, | 51 KernelProcedureBuilder, |
52 KernelTypeBuilder, | 52 KernelTypeBuilder, |
53 LibraryBuilder, | 53 LibraryBuilder, |
54 MemberBuilder, | 54 MemberBuilder, |
55 MetadataBuilder; | 55 MetadataBuilder; |
56 | 56 |
57 class KernelEnumBuilder extends SourceClassBuilder | 57 class KernelEnumBuilder extends SourceClassBuilder |
58 implements EnumBuilder<KernelTypeBuilder, InterfaceType> { | 58 implements EnumBuilder<KernelTypeBuilder, InterfaceType> { |
59 final List<String> constants; | 59 final List<String> constants; |
60 | 60 |
61 final MapLiteral toStringMap; | 61 final MapLiteral toStringMap; |
62 | 62 |
63 final KernelTypeBuilder intType; | 63 final KernelTypeBuilder intType; |
64 | 64 |
65 final KernelTypeBuilder stringType; | 65 final KernelTypeBuilder stringType; |
66 | 66 |
67 KernelEnumBuilder.internal(List<MetadataBuilder> metadata, String name, | 67 KernelEnumBuilder.internal(List<MetadataBuilder> metadata, String name, |
68 Map<String, Builder> members, List<KernelTypeBuilder> types, Class cls, | 68 Map<String, Builder> members, List<KernelTypeBuilder> types, Class cls, |
69 this.constants, this.toStringMap, this.intType, this.stringType, | 69 this.constants, this.toStringMap, this.intType, this.stringType, |
70 LibraryBuilder parent) | 70 LibraryBuilder parent) |
71 : super(metadata, 0, name, null, null, null, members, types, parent, null, | 71 : super(metadata, 0, name, null, null, null, members, types, parent, null, |
72 cls); | 72 cls); |
73 | 73 |
74 factory KernelEnumBuilder(List<MetadataBuilder> metadata, String name, | 74 factory KernelEnumBuilder(List<MetadataBuilder> metadata, String name, |
75 List<String> constants, LibraryBuilder parent) { | 75 List<String> constants, LibraryBuilder parent) { |
76 constants ??= const <String>[]; | 76 constants ??= const <String>[]; |
77 // TODO(ahe): These types shouldn't be looked up in scope, they come | 77 // TODO(ahe): These types shouldn't be looked up in scope, they come |
78 // directly from dart:core. | 78 // directly from dart:core. |
79 KernelTypeBuilder objectType = | 79 KernelTypeBuilder objectType = |
80 new KernelInterfaceTypeBuilder("Object", null); | 80 new KernelNamedTypeBuilder("Object", null); |
81 KernelTypeBuilder intType = | 81 KernelTypeBuilder intType = |
82 new KernelInterfaceTypeBuilder("int", null); | 82 new KernelNamedTypeBuilder("int", null); |
83 KernelTypeBuilder stringType = | 83 KernelTypeBuilder stringType = |
84 new KernelInterfaceTypeBuilder("String", null); | 84 new KernelNamedTypeBuilder("String", null); |
85 List<KernelTypeBuilder> types = <KernelTypeBuilder>[ | 85 List<KernelTypeBuilder> types = <KernelTypeBuilder>[ |
86 objectType, | 86 objectType, |
87 intType, | 87 intType, |
88 stringType]; | 88 stringType]; |
89 Class cls = new Class(name: name); | 89 Class cls = new Class(name: name); |
90 Map<String, Builder> members = <String, Builder>{}; | 90 Map<String, Builder> members = <String, Builder>{}; |
91 KernelInterfaceTypeBuilder selfType = new KernelInterfaceTypeBuilder( | 91 KernelNamedTypeBuilder selfType = new KernelNamedTypeBuilder( |
92 name, null); | 92 name, null); |
93 KernelTypeBuilder listType = | 93 KernelTypeBuilder listType = |
94 new KernelInterfaceTypeBuilder("List", <KernelTypeBuilder>[selfType]); | 94 new KernelNamedTypeBuilder("List", <KernelTypeBuilder>[selfType]); |
95 types.add(listType); | 95 types.add(listType); |
96 | 96 |
97 /// From Dart Programming Language Specification 4th Edition/December 2015: | 97 /// From Dart Programming Language Specification 4th Edition/December 2015: |
98 /// metadata class E { | 98 /// metadata class E { |
99 /// final int index; | 99 /// final int index; |
100 /// const E(this.index); | 100 /// const E(this.index); |
101 /// static const E id0 = const E(0); | 101 /// static const E id0 = const E(0); |
102 /// ... | 102 /// ... |
103 /// static const E idn-1 = const E(n - 1); | 103 /// static const E idn-1 = const E(n - 1); |
104 /// static const List<E> values = const <E>[id0, ..., idn-1]; | 104 /// static const List<E> values = const <E>[id0, ..., idn-1]; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 Arguments arguments = | 182 Arguments arguments = |
183 new Arguments(<Expression>[new IntLiteral(index++)]); | 183 new Arguments(<Expression>[new IntLiteral(index++)]); |
184 field.initializer = | 184 field.initializer = |
185 new ConstructorInvocation(constructor, arguments, isConst: true); | 185 new ConstructorInvocation(constructor, arguments, isConst: true); |
186 } | 186 } |
187 return super.build(libraryBuilder); | 187 return super.build(libraryBuilder); |
188 } | 188 } |
189 | 189 |
190 Builder findConstructorOrFactory(String name) => null; | 190 Builder findConstructorOrFactory(String name) => null; |
191 } | 191 } |
OLD | NEW |