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' | 7 import 'package:kernel/ast.dart' |
8 show | 8 show |
9 Arguments, | 9 Arguments, |
10 Class, | 10 Class, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 parent, | 150 parent, |
151 charOffset, | 151 charOffset, |
152 charOffset, | 152 charOffset, |
153 charEndOffset); | 153 charEndOffset); |
154 members["toString"] = toStringBuilder; | 154 members["toString"] = toStringBuilder; |
155 String className = name; | 155 String className = name; |
156 for (int i = 0; i < constantNamesAndOffsets.length; i += 2) { | 156 for (int i = 0; i < constantNamesAndOffsets.length; i += 2) { |
157 String name = constantNamesAndOffsets[i]; | 157 String name = constantNamesAndOffsets[i]; |
158 int charOffset = constantNamesAndOffsets[i + 1]; | 158 int charOffset = constantNamesAndOffsets[i + 1]; |
159 if (members.containsKey(name)) { | 159 if (members.containsKey(name)) { |
160 parent.addCompileTimeError(charOffset, "Duplicated name: '$name'."); | 160 parent.deprecated_addCompileTimeError( |
| 161 charOffset, "Duplicated name: '$name'."); |
161 constantNamesAndOffsets[i] = null; | 162 constantNamesAndOffsets[i] = null; |
162 continue; | 163 continue; |
163 } | 164 } |
164 if (name == className) { | 165 if (name == className) { |
165 parent.addCompileTimeError( | 166 parent.deprecated_addCompileTimeError( |
166 charOffset, | 167 charOffset, |
167 "Name of enum constant '$name' can't be the same as the enum's " | 168 "Name of enum constant '$name' can't be the same as the enum's " |
168 "own name."); | 169 "own name."); |
169 constantNamesAndOffsets[i] = null; | 170 constantNamesAndOffsets[i] = null; |
170 continue; | 171 continue; |
171 } | 172 } |
172 KernelFieldBuilder fieldBuilder = new KernelFieldBuilder(null, selfType, | 173 KernelFieldBuilder fieldBuilder = new KernelFieldBuilder(null, selfType, |
173 name, constMask | staticMask, parent, charOffset, null, true); | 174 name, constMask | staticMask, parent, charOffset, null, true); |
174 members[name] = fieldBuilder; | 175 members[name] = fieldBuilder; |
175 toStringEntries.add(new MapEntry( | 176 toStringEntries.add(new MapEntry( |
(...skipping 30 matching lines...) Expand all Loading... |
206 KernelTypeBuilder get mixedInType => null; | 207 KernelTypeBuilder get mixedInType => null; |
207 | 208 |
208 InterfaceType buildType( | 209 InterfaceType buildType( |
209 LibraryBuilder library, List<KernelTypeBuilder> arguments) { | 210 LibraryBuilder library, List<KernelTypeBuilder> arguments) { |
210 return cls.rawType; | 211 return cls.rawType; |
211 } | 212 } |
212 | 213 |
213 @override | 214 @override |
214 Class build(KernelLibraryBuilder libraryBuilder, LibraryBuilder coreLibrary) { | 215 Class build(KernelLibraryBuilder libraryBuilder, LibraryBuilder coreLibrary) { |
215 if (constantNamesAndOffsets.isEmpty) { | 216 if (constantNamesAndOffsets.isEmpty) { |
216 libraryBuilder.addCompileTimeError( | 217 libraryBuilder.deprecated_addCompileTimeError( |
217 -1, "An enum declaration can't be empty."); | 218 -1, "An enum declaration can't be empty."); |
218 } | 219 } |
219 intType.resolveIn(coreLibrary.scope); | 220 intType.resolveIn(coreLibrary.scope); |
220 stringType.resolveIn(coreLibrary.scope); | 221 stringType.resolveIn(coreLibrary.scope); |
221 objectType.resolveIn(coreLibrary.scope); | 222 objectType.resolveIn(coreLibrary.scope); |
222 listType.resolveIn(coreLibrary.scope); | 223 listType.resolveIn(coreLibrary.scope); |
223 toStringMap.keyType = intType.build(libraryBuilder); | 224 toStringMap.keyType = intType.build(libraryBuilder); |
224 toStringMap.valueType = stringType.build(libraryBuilder); | 225 toStringMap.valueType = stringType.build(libraryBuilder); |
225 KernelFieldBuilder indexFieldBuilder = this["index"]; | 226 KernelFieldBuilder indexFieldBuilder = this["index"]; |
226 Field indexField = indexFieldBuilder.build(libraryBuilder); | 227 Field indexField = indexFieldBuilder.build(libraryBuilder); |
(...skipping 24 matching lines...) Expand all Loading... |
251 new VariableGet(constructor.function.positionalParameters.single)) | 252 new VariableGet(constructor.function.positionalParameters.single)) |
252 ..parent = constructor); | 253 ..parent = constructor); |
253 KernelClassBuilder objectClass = objectType.builder; | 254 KernelClassBuilder objectClass = objectType.builder; |
254 MemberBuilder superConstructor = objectClass.findConstructorOrFactory( | 255 MemberBuilder superConstructor = objectClass.findConstructorOrFactory( |
255 "", charOffset, fileUri, libraryBuilder); | 256 "", charOffset, fileUri, libraryBuilder); |
256 if (superConstructor == null || !superConstructor.isConstructor) { | 257 if (superConstructor == null || !superConstructor.isConstructor) { |
257 // TODO(ahe): Ideally, we would also want to check that [Object]'s | 258 // TODO(ahe): Ideally, we would also want to check that [Object]'s |
258 // unnamed constructor requires no arguments. But that information isn't | 259 // unnamed constructor requires no arguments. But that information isn't |
259 // always available at this point, and it's not really a situation that | 260 // always available at this point, and it's not really a situation that |
260 // can happen unless you start modifying the SDK sources. | 261 // can happen unless you start modifying the SDK sources. |
261 addCompileTimeError(-1, "'Object' has no unnamed constructor."); | 262 deprecated_addCompileTimeError( |
| 263 -1, "'Object' has no unnamed constructor."); |
262 } else { | 264 } else { |
263 constructor.initializers.add( | 265 constructor.initializers.add( |
264 new SuperInitializer(superConstructor.target, new Arguments.empty()) | 266 new SuperInitializer(superConstructor.target, new Arguments.empty()) |
265 ..parent = constructor); | 267 ..parent = constructor); |
266 } | 268 } |
267 int index = 0; | 269 int index = 0; |
268 for (int i = 0; i < constantNamesAndOffsets.length; i += 2) { | 270 for (int i = 0; i < constantNamesAndOffsets.length; i += 2) { |
269 String constant = constantNamesAndOffsets[i]; | 271 String constant = constantNamesAndOffsets[i]; |
270 if (constant != null) { | 272 if (constant != null) { |
271 KernelFieldBuilder field = this[constant]; | 273 KernelFieldBuilder field = this[constant]; |
272 field.build(libraryBuilder); | 274 field.build(libraryBuilder); |
273 Arguments arguments = | 275 Arguments arguments = |
274 new Arguments(<Expression>[new IntLiteral(index++)]); | 276 new Arguments(<Expression>[new IntLiteral(index++)]); |
275 field.initializer = | 277 field.initializer = |
276 new ConstructorInvocation(constructor, arguments, isConst: true); | 278 new ConstructorInvocation(constructor, arguments, isConst: true); |
277 } | 279 } |
278 } | 280 } |
279 return super.build(libraryBuilder, coreLibrary); | 281 return super.build(libraryBuilder, coreLibrary); |
280 } | 282 } |
281 | 283 |
282 @override | 284 @override |
283 Builder findConstructorOrFactory( | 285 Builder findConstructorOrFactory( |
284 String name, int charOffset, Uri uri, LibraryBuilder library) { | 286 String name, int charOffset, Uri uri, LibraryBuilder library) { |
285 return null; | 287 return null; |
286 } | 288 } |
287 } | 289 } |
OLD | NEW |