| 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 10 matching lines...) Expand all Loading... |
| 21 MapLiteral, | 21 MapLiteral, |
| 22 MethodInvocation, | 22 MethodInvocation, |
| 23 ProcedureKind, | 23 ProcedureKind, |
| 24 ReturnStatement, | 24 ReturnStatement, |
| 25 StaticGet, | 25 StaticGet, |
| 26 StringLiteral, | 26 StringLiteral, |
| 27 SuperInitializer, | 27 SuperInitializer, |
| 28 ThisExpression, | 28 ThisExpression, |
| 29 VariableGet; | 29 VariableGet; |
| 30 | 30 |
| 31 import '../fasta_codes.dart' show messageNoUnamedConstructorInObject; | 31 import '../fasta_codes.dart' |
| 32 show |
| 33 messageEnumDeclartionEmpty, |
| 34 messageNoUnamedConstructorInObject, |
| 35 templateDuplicatedName, |
| 36 templateEnumConstantSameNameAsEnclosing; |
| 32 | 37 |
| 33 import '../modifier.dart' show constMask, finalMask, staticMask; | 38 import '../modifier.dart' show constMask, finalMask, staticMask; |
| 34 | 39 |
| 35 import '../names.dart' show indexGetName; | 40 import '../names.dart' show indexGetName; |
| 36 | 41 |
| 37 import '../source/source_class_builder.dart' show SourceClassBuilder; | 42 import '../source/source_class_builder.dart' show SourceClassBuilder; |
| 38 | 43 |
| 39 import 'kernel_builder.dart' | 44 import 'kernel_builder.dart' |
| 40 show | 45 show |
| 41 Builder, | 46 Builder, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 parent, | 157 parent, |
| 153 charOffset, | 158 charOffset, |
| 154 charOffset, | 159 charOffset, |
| 155 charEndOffset); | 160 charEndOffset); |
| 156 members["toString"] = toStringBuilder; | 161 members["toString"] = toStringBuilder; |
| 157 String className = name; | 162 String className = name; |
| 158 for (int i = 0; i < constantNamesAndOffsets.length; i += 2) { | 163 for (int i = 0; i < constantNamesAndOffsets.length; i += 2) { |
| 159 String name = constantNamesAndOffsets[i]; | 164 String name = constantNamesAndOffsets[i]; |
| 160 int charOffset = constantNamesAndOffsets[i + 1]; | 165 int charOffset = constantNamesAndOffsets[i + 1]; |
| 161 if (members.containsKey(name)) { | 166 if (members.containsKey(name)) { |
| 162 parent.deprecated_addCompileTimeError( | 167 parent.addCompileTimeError(templateDuplicatedName.withArguments(name), |
| 163 charOffset, "Duplicated name: '$name'."); | 168 charOffset, parent.fileUri); |
| 164 constantNamesAndOffsets[i] = null; | 169 constantNamesAndOffsets[i] = null; |
| 165 continue; | 170 continue; |
| 166 } | 171 } |
| 167 if (name == className) { | 172 if (name == className) { |
| 168 parent.deprecated_addCompileTimeError( | 173 parent.addCompileTimeError( |
| 174 templateEnumConstantSameNameAsEnclosing.withArguments(name), |
| 169 charOffset, | 175 charOffset, |
| 170 "Name of enum constant '$name' can't be the same as the enum's " | 176 parent.fileUri); |
| 171 "own name."); | |
| 172 constantNamesAndOffsets[i] = null; | 177 constantNamesAndOffsets[i] = null; |
| 173 continue; | 178 continue; |
| 174 } | 179 } |
| 175 KernelFieldBuilder fieldBuilder = new KernelFieldBuilder(null, selfType, | 180 KernelFieldBuilder fieldBuilder = new KernelFieldBuilder(null, selfType, |
| 176 name, constMask | staticMask, parent, charOffset, null, true); | 181 name, constMask | staticMask, parent, charOffset, null, true); |
| 177 members[name] = fieldBuilder; | 182 members[name] = fieldBuilder; |
| 178 toStringEntries.add(new MapEntry( | 183 toStringEntries.add(new MapEntry( |
| 179 new IntLiteral(index), new StringLiteral("$className.$name"))); | 184 new IntLiteral(index), new StringLiteral("$className.$name"))); |
| 180 index++; | 185 index++; |
| 181 } | 186 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 209 KernelTypeBuilder get mixedInType => null; | 214 KernelTypeBuilder get mixedInType => null; |
| 210 | 215 |
| 211 InterfaceType buildType( | 216 InterfaceType buildType( |
| 212 LibraryBuilder library, List<KernelTypeBuilder> arguments) { | 217 LibraryBuilder library, List<KernelTypeBuilder> arguments) { |
| 213 return cls.rawType; | 218 return cls.rawType; |
| 214 } | 219 } |
| 215 | 220 |
| 216 @override | 221 @override |
| 217 Class build(KernelLibraryBuilder libraryBuilder, LibraryBuilder coreLibrary) { | 222 Class build(KernelLibraryBuilder libraryBuilder, LibraryBuilder coreLibrary) { |
| 218 if (constantNamesAndOffsets.isEmpty) { | 223 if (constantNamesAndOffsets.isEmpty) { |
| 219 libraryBuilder.deprecated_addCompileTimeError( | 224 libraryBuilder.addCompileTimeError( |
| 220 -1, "An enum declaration can't be empty."); | 225 messageEnumDeclartionEmpty, charOffset, fileUri); |
| 221 } | 226 } |
| 222 intType.resolveIn(coreLibrary.scope); | 227 intType.resolveIn(coreLibrary.scope); |
| 223 stringType.resolveIn(coreLibrary.scope); | 228 stringType.resolveIn(coreLibrary.scope); |
| 224 objectType.resolveIn(coreLibrary.scope); | 229 objectType.resolveIn(coreLibrary.scope); |
| 225 listType.resolveIn(coreLibrary.scope); | 230 listType.resolveIn(coreLibrary.scope); |
| 226 toStringMap.keyType = intType.build(libraryBuilder); | 231 toStringMap.keyType = intType.build(libraryBuilder); |
| 227 toStringMap.valueType = stringType.build(libraryBuilder); | 232 toStringMap.valueType = stringType.build(libraryBuilder); |
| 228 KernelFieldBuilder indexFieldBuilder = this["index"]; | 233 KernelFieldBuilder indexFieldBuilder = this["index"]; |
| 229 Field indexField = indexFieldBuilder.build(libraryBuilder); | 234 Field indexField = indexFieldBuilder.build(libraryBuilder); |
| 230 KernelProcedureBuilder toStringBuilder = this["toString"]; | 235 KernelProcedureBuilder toStringBuilder = this["toString"]; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 } | 286 } |
| 282 return super.build(libraryBuilder, coreLibrary); | 287 return super.build(libraryBuilder, coreLibrary); |
| 283 } | 288 } |
| 284 | 289 |
| 285 @override | 290 @override |
| 286 Builder findConstructorOrFactory( | 291 Builder findConstructorOrFactory( |
| 287 String name, int charOffset, Uri uri, LibraryBuilder library) { | 292 String name, int charOffset, Uri uri, LibraryBuilder library) { |
| 288 return null; | 293 return null; |
| 289 } | 294 } |
| 290 } | 295 } |
| OLD | NEW |