| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, Class cls, this.constants, this.toStringMap, |
| 69 this.constants, this.toStringMap, this.intType, this.stringType, | 69 this.intType, this.stringType, LibraryBuilder parent, int charOffset) |
| 70 LibraryBuilder parent, int charOffset) | 70 : super(metadata, 0, name, null, null, null, members, parent, null, |
| 71 : super(metadata, 0, name, null, null, null, members, types, parent, null, | |
| 72 charOffset, cls); | 71 charOffset, cls); |
| 73 | 72 |
| 74 factory KernelEnumBuilder(List<MetadataBuilder> metadata, String name, | 73 factory KernelEnumBuilder(List<MetadataBuilder> metadata, String name, |
| 75 List<String> constants, LibraryBuilder parent, int charOffset) { | 74 List<String> constants, KernelLibraryBuilder parent, int charOffset) { |
| 76 constants ??= const <String>[]; | 75 constants ??= const <String>[]; |
| 77 // TODO(ahe): These types shouldn't be looked up in scope, they come | 76 // TODO(ahe): These types shouldn't be looked up in scope, they come |
| 78 // directly from dart:core. | 77 // directly from dart:core. |
| 79 KernelTypeBuilder objectType = | 78 KernelTypeBuilder intType = parent.addType( |
| 80 new KernelNamedTypeBuilder("Object", null, charOffset, parent.fileUri); | 79 new KernelNamedTypeBuilder("int", null, charOffset, parent.fileUri)); |
| 81 KernelTypeBuilder intType = | 80 KernelTypeBuilder stringType = parent.addType( |
| 82 new KernelNamedTypeBuilder("int", null, charOffset, parent.fileUri); | 81 new KernelNamedTypeBuilder("String", null, charOffset, parent.fileUri)); |
| 83 KernelTypeBuilder stringType = | |
| 84 new KernelNamedTypeBuilder("String", null, charOffset, parent.fileUri); | |
| 85 List<KernelTypeBuilder> types = <KernelTypeBuilder>[ | |
| 86 objectType, | |
| 87 intType, | |
| 88 stringType]; | |
| 89 Class cls = new Class(name: name); | 82 Class cls = new Class(name: name); |
| 90 Map<String, Builder> members = <String, Builder>{}; | 83 Map<String, Builder> members = <String, Builder>{}; |
| 91 KernelNamedTypeBuilder selfType = new KernelNamedTypeBuilder( | 84 KernelNamedTypeBuilder selfType = new KernelNamedTypeBuilder( |
| 92 name, null, charOffset, parent.fileUri); | 85 name, null, charOffset, parent.fileUri); |
| 93 KernelTypeBuilder listType = | 86 KernelTypeBuilder listType = parent.addType( |
| 94 new KernelNamedTypeBuilder( | 87 new KernelNamedTypeBuilder( |
| 95 "List", <KernelTypeBuilder>[selfType], charOffset, parent.fileUri); | 88 "List", <KernelTypeBuilder>[selfType], charOffset, parent.fileUri)); |
| 96 types.add(listType); | |
| 97 | 89 |
| 98 /// From Dart Programming Language Specification 4th Edition/December 2015: | 90 /// From Dart Programming Language Specification 4th Edition/December 2015: |
| 99 /// metadata class E { | 91 /// metadata class E { |
| 100 /// final int index; | 92 /// final int index; |
| 101 /// const E(this.index); | 93 /// const E(this.index); |
| 102 /// static const E id0 = const E(0); | 94 /// static const E id0 = const E(0); |
| 103 /// ... | 95 /// ... |
| 104 /// static const E idn-1 = const E(n - 1); | 96 /// static const E idn-1 = const E(n - 1); |
| 105 /// static const List<E> values = const <E>[id0, ..., idn-1]; | 97 /// static const List<E> values = const <E>[id0, ..., idn-1]; |
| 106 /// String toString() => { 0: ‘E.id0’, . . ., n-1: ‘E.idn-1’}[index] | 98 /// String toString() => { 0: ‘E.id0’, . . ., n-1: ‘E.idn-1’}[index] |
| (...skipping 23 matching lines...) Expand all Loading... |
| 130 KernelFieldBuilder fieldBuilder = | 122 KernelFieldBuilder fieldBuilder = |
| 131 new KernelFieldBuilder(null, selfType, name, constMask | staticMask, | 123 new KernelFieldBuilder(null, selfType, name, constMask | staticMask, |
| 132 parent, charOffset); // TODO(ahe): Get charOffset from [name]. | 124 parent, charOffset); // TODO(ahe): Get charOffset from [name]. |
| 133 members[name] = fieldBuilder; | 125 members[name] = fieldBuilder; |
| 134 toStringEntries.add(new MapEntry( | 126 toStringEntries.add(new MapEntry( |
| 135 new IntLiteral(index), new StringLiteral("$className.$name"))); | 127 new IntLiteral(index), new StringLiteral("$className.$name"))); |
| 136 index++; | 128 index++; |
| 137 } | 129 } |
| 138 MapLiteral toStringMap = new MapLiteral(toStringEntries, isConst: true); | 130 MapLiteral toStringMap = new MapLiteral(toStringEntries, isConst: true); |
| 139 KernelEnumBuilder enumBuilder = new KernelEnumBuilder.internal(metadata, | 131 KernelEnumBuilder enumBuilder = new KernelEnumBuilder.internal(metadata, |
| 140 name, members, types, cls, constants, toStringMap, intType, stringType, | 132 name, members, cls, constants, toStringMap, intType, stringType, |
| 141 parent, charOffset); | 133 parent, charOffset); |
| 142 members.forEach((String name, MemberBuilder builder) { | 134 members.forEach((String name, MemberBuilder builder) { |
| 143 builder.parent = enumBuilder; | 135 builder.parent = enumBuilder; |
| 144 }); | 136 }); |
| 145 selfType.builder = enumBuilder; | 137 selfType.builder = enumBuilder; |
| 146 return enumBuilder; | 138 return enumBuilder; |
| 147 } | 139 } |
| 148 | 140 |
| 149 InterfaceType buildType(List<KernelTypeBuilder> arguments) { | 141 InterfaceType buildType(List<KernelTypeBuilder> arguments) { |
| 150 return cls.rawType; | 142 return cls.rawType; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 Arguments arguments = | 177 Arguments arguments = |
| 186 new Arguments(<Expression>[new IntLiteral(index++)]); | 178 new Arguments(<Expression>[new IntLiteral(index++)]); |
| 187 field.initializer = | 179 field.initializer = |
| 188 new ConstructorInvocation(constructor, arguments, isConst: true); | 180 new ConstructorInvocation(constructor, arguments, isConst: true); |
| 189 } | 181 } |
| 190 return super.build(libraryBuilder); | 182 return super.build(libraryBuilder); |
| 191 } | 183 } |
| 192 | 184 |
| 193 Builder findConstructorOrFactory(String name) => null; | 185 Builder findConstructorOrFactory(String name) => null; |
| 194 } | 186 } |
| OLD | NEW |