| 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 AsyncMarker, | 10 AsyncMarker, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 return cls.rawType; | 186 return cls.rawType; |
| 187 } | 187 } |
| 188 | 188 |
| 189 Class build(KernelLibraryBuilder libraryBuilder) { | 189 Class build(KernelLibraryBuilder libraryBuilder) { |
| 190 if (constantNamesAndOffsets.isEmpty) { | 190 if (constantNamesAndOffsets.isEmpty) { |
| 191 libraryBuilder.addCompileTimeError( | 191 libraryBuilder.addCompileTimeError( |
| 192 -1, "An enum declaration can't be empty."); | 192 -1, "An enum declaration can't be empty."); |
| 193 } | 193 } |
| 194 toStringMap.keyType = intType.build(libraryBuilder); | 194 toStringMap.keyType = intType.build(libraryBuilder); |
| 195 toStringMap.valueType = stringType.build(libraryBuilder); | 195 toStringMap.valueType = stringType.build(libraryBuilder); |
| 196 KernelFieldBuilder indexFieldBuilder = members["index"]; | 196 KernelFieldBuilder indexFieldBuilder = this["index"]; |
| 197 Field indexField = indexFieldBuilder.build(libraryBuilder); | 197 Field indexField = indexFieldBuilder.build(libraryBuilder); |
| 198 KernelProcedureBuilder toStringBuilder = members["toString"]; | 198 KernelProcedureBuilder toStringBuilder = this["toString"]; |
| 199 toStringBuilder.body = new ReturnStatement(new MethodInvocation( | 199 toStringBuilder.body = new ReturnStatement(new MethodInvocation( |
| 200 toStringMap, | 200 toStringMap, |
| 201 indexGetName, | 201 indexGetName, |
| 202 new Arguments(<Expression>[ | 202 new Arguments(<Expression>[ |
| 203 new DirectPropertyGet(new ThisExpression(), indexField) | 203 new DirectPropertyGet(new ThisExpression(), indexField) |
| 204 ]))); | 204 ]))); |
| 205 List<Expression> values = <Expression>[]; | 205 List<Expression> values = <Expression>[]; |
| 206 for (int i = 0; i < constantNamesAndOffsets.length; i += 2) { | 206 for (int i = 0; i < constantNamesAndOffsets.length; i += 2) { |
| 207 String name = constantNamesAndOffsets[i]; | 207 String name = constantNamesAndOffsets[i]; |
| 208 KernelFieldBuilder builder = members[name]; | 208 KernelFieldBuilder builder = this[name]; |
| 209 values.add(new StaticGet(builder.build(libraryBuilder))); | 209 values.add(new StaticGet(builder.build(libraryBuilder))); |
| 210 } | 210 } |
| 211 KernelFieldBuilder valuesBuilder = members["values"]; | 211 KernelFieldBuilder valuesBuilder = this["values"]; |
| 212 valuesBuilder.build(libraryBuilder); | 212 valuesBuilder.build(libraryBuilder); |
| 213 valuesBuilder.initializer = | 213 valuesBuilder.initializer = |
| 214 new ListLiteral(values, typeArgument: cls.rawType, isConst: true); | 214 new ListLiteral(values, typeArgument: cls.rawType, isConst: true); |
| 215 KernelConstructorBuilder constructorBuilder = members[""]; | 215 KernelConstructorBuilder constructorBuilder = this[""]; |
| 216 Constructor constructor = constructorBuilder.build(libraryBuilder); | 216 Constructor constructor = constructorBuilder.build(libraryBuilder); |
| 217 constructor.initializers.insert( | 217 constructor.initializers.insert( |
| 218 0, | 218 0, |
| 219 new FieldInitializer(indexField, | 219 new FieldInitializer(indexField, |
| 220 new VariableGet(constructor.function.positionalParameters.single)) | 220 new VariableGet(constructor.function.positionalParameters.single)) |
| 221 ..parent = constructor); | 221 ..parent = constructor); |
| 222 int index = 0; | 222 int index = 0; |
| 223 for (int i = 0; i < constantNamesAndOffsets.length; i += 2) { | 223 for (int i = 0; i < constantNamesAndOffsets.length; i += 2) { |
| 224 String constant = constantNamesAndOffsets[i]; | 224 String constant = constantNamesAndOffsets[i]; |
| 225 KernelFieldBuilder field = members[constant]; | 225 KernelFieldBuilder field = this[constant]; |
| 226 field.build(libraryBuilder); | 226 field.build(libraryBuilder); |
| 227 Arguments arguments = | 227 Arguments arguments = |
| 228 new Arguments(<Expression>[new IntLiteral(index++)]); | 228 new Arguments(<Expression>[new IntLiteral(index++)]); |
| 229 field.initializer = | 229 field.initializer = |
| 230 new ConstructorInvocation(constructor, arguments, isConst: true); | 230 new ConstructorInvocation(constructor, arguments, isConst: true); |
| 231 } | 231 } |
| 232 return super.build(libraryBuilder); | 232 return super.build(libraryBuilder); |
| 233 } | 233 } |
| 234 | 234 |
| 235 Builder findConstructorOrFactory(String name) => null; | 235 @override |
| 236 Builder findConstructorOrFactory(String name, int charOffset, Uri uri) { |
| 237 return null; |
| 238 } |
| 236 } | 239 } |
| OLD | NEW |