Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Side by Side Diff: pkg/compiler/lib/src/resolution/enum_creator.dart

Issue 1873823002: Update elements, nodes and visitors for serialization. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix LocalVariableElementZ.constant Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 dart2js.resolution.enum_creator; 5 library dart2js.resolution.enum_creator;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../core_types.dart' show 8 import '../core_types.dart' show
9 CoreTypes; 9 CoreTypes;
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 indexVariable); 230 indexVariable);
231 231
232 FunctionSignatureX constructorSignature = new FunctionSignatureX( 232 FunctionSignatureX constructorSignature = new FunctionSignatureX(
233 requiredParameters: [indexFormal], 233 requiredParameters: [indexFormal],
234 requiredParameterCount: 1, 234 requiredParameterCount: 1,
235 type: new FunctionType(constructor, const VoidType(), 235 type: new FunctionType(constructor, const VoidType(),
236 <DartType>[intType])); 236 <DartType>[intType]));
237 constructor.functionSignature = constructorSignature; 237 constructor.functionSignature = constructorSignature;
238 enumClass.addMember(constructor, reporter); 238 enumClass.addMember(constructor, reporter);
239 239
240 List<FieldElement> enumValues = <FieldElement>[]; 240 List<EnumConstantElement> enumValues = <EnumConstantElement>[];
241 VariableList variableList = 241 VariableList variableList =
242 new VariableList(builder.modifiers(isStatic: true, isConst: true)); 242 new VariableList(builder.modifiers(isStatic: true, isConst: true));
243 variableList.type = enumType; 243 variableList.type = enumType;
244 int index = 0; 244 int index = 0;
245 List<Node> valueReferences = <Node>[]; 245 List<Node> valueReferences = <Node>[];
246 List<LiteralMapEntry> mapEntries = <LiteralMapEntry>[]; 246 List<LiteralMapEntry> mapEntries = <LiteralMapEntry>[];
247 for (Link<Node> link = node.names.nodes; 247 for (Link<Node> link = node.names.nodes;
248 !link.isEmpty; 248 !link.isEmpty;
249 link = link.tail) { 249 link = link.tail) {
250 Identifier name = link.head; 250 Identifier name = link.head;
251 AstBuilder valueBuilder = new AstBuilder(name.token.charOffset); 251 AstBuilder valueBuilder = new AstBuilder(name.token.charOffset);
252 252
253 // Add reference for the `values` field. 253 // Add reference for the `values` field.
254 valueReferences.add(valueBuilder.reference(name)); 254 valueReferences.add(valueBuilder.reference(name));
255 255
256 // Add map entry for `toString` implementation. 256 // Add map entry for `toString` implementation.
257 mapEntries.add(valueBuilder.mapLiteralEntry( 257 mapEntries.add(valueBuilder.mapLiteralEntry(
258 valueBuilder.literalInt(index), 258 valueBuilder.literalInt(index),
259 valueBuilder.literalString('${enumClass.name}.${name.source}'))); 259 valueBuilder.literalString('${enumClass.name}.${name.source}')));
260 260
261 Expression initializer = valueBuilder.newExpression( 261 Expression initializer = valueBuilder.newExpression(
262 enumClass.name, 262 enumClass.name,
263 valueBuilder.argumentList([valueBuilder.literalInt(index)]), 263 valueBuilder.argumentList([valueBuilder.literalInt(index)]),
264 isConst: true); 264 isConst: true);
265 SendSet definition = valueBuilder.createDefinition(name, initializer); 265 SendSet definition = valueBuilder.createDefinition(name, initializer);
266 266
267 EnumFieldElementX field = new EnumFieldElementX( 267 EnumConstantElementX field = new EnumConstantElementX(
268 name, enumClass, variableList, definition, initializer); 268 name, enumClass, variableList, definition, initializer, index);
269 enumValues.add(field); 269 enumValues.add(field);
270 enumClass.addMember(field, reporter); 270 enumClass.addMember(field, reporter);
271 index++; 271 index++;
272 } 272 }
273 273
274 VariableList valuesVariableList = 274 VariableList valuesVariableList =
275 new VariableList(builder.modifiers(isStatic: true, isConst: true)); 275 new VariableList(builder.modifiers(isStatic: true, isConst: true));
276 valuesVariableList.type = coreTypes.listType(enumType); 276 valuesVariableList.type = coreTypes.listType(enumType);
277 277
278 Identifier valuesIdentifier = builder.identifier('values'); 278 Identifier valuesIdentifier = builder.identifier('values');
(...skipping 25 matching lines...) Expand all
304 EnumMethodElementX toString = new EnumMethodElementX('toString', 304 EnumMethodElementX toString = new EnumMethodElementX('toString',
305 enumClass, Modifiers.EMPTY, toStringNode); 305 enumClass, Modifiers.EMPTY, toStringNode);
306 FunctionSignatureX toStringSignature = new FunctionSignatureX( 306 FunctionSignatureX toStringSignature = new FunctionSignatureX(
307 type: new FunctionType(toString, stringType)); 307 type: new FunctionType(toString, stringType));
308 toString.functionSignature = toStringSignature; 308 toString.functionSignature = toStringSignature;
309 enumClass.addMember(toString, reporter); 309 enumClass.addMember(toString, reporter);
310 310
311 enumClass.enumValues = enumValues; 311 enumClass.enumValues = enumValues;
312 } 312 }
313 } 313 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698