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

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

Issue 1192103002: Support serialization of the compiler backbone. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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 '../dart_types.dart'; 7 import '../dart_types.dart';
8 import '../dart2jslib.dart'; 8 import '../dart2jslib.dart';
9 import '../elements/elements.dart'; 9 import '../elements/elements.dart';
10 import '../elements/modelx.dart'; 10 import '../elements/modelx.dart';
11 import '../scanner/scannerlib.dart'; 11 import '../scanner/scannerlib.dart';
12 import '../tree/tree.dart'; 12 import '../tree/tree.dart';
13 import '../util/util.dart'; 13 import '../util/util.dart';
14 14
15 // TODO(johnniwinther): Merge functionality with the `TreePrinter`. 15 // TODO(johnniwinther): Merge functionality with the `TreePrinter`.
16 class AstBuilder { 16 class AstBuilder {
17 final Token position; 17 final int charOffset;
18 18
19 AstBuilder(this.position); 19 AstBuilder(this.charOffset);
20
21 int get charOffset => position.charOffset;
22 20
23 Modifiers modifiers({bool isConst: false, 21 Modifiers modifiers({bool isConst: false,
24 bool isFinal: false, 22 bool isFinal: false,
25 bool isStatic: false}) { 23 bool isStatic: false}) {
26 List identifiers = []; 24 List identifiers = [];
27 int flags = 0; 25 int flags = 0;
28 if (isConst) { 26 if (isConst) {
29 identifiers.add(identifier('const')); 27 identifiers.add(identifier('const'));
30 flags |= Modifiers.FLAG_CONST; 28 flags |= Modifiers.FLAG_CONST;
31 } 29 }
32 if (isFinal) { 30 if (isFinal) {
33 identifiers.add(identifier('final')); 31 identifiers.add(identifier('final'));
34 flags |= Modifiers.FLAG_FINAL; 32 flags |= Modifiers.FLAG_FINAL;
35 } 33 }
36 if (isStatic) { 34 if (isStatic) {
37 identifiers.add(identifier('static')); 35 identifiers.add(identifier('static'));
38 flags |= Modifiers.FLAG_STATIC; 36 flags |= Modifiers.FLAG_STATIC;
39 } 37 }
40 return new Modifiers.withFlags( 38 return new Modifiers.withFlags(
41 new NodeList(null, linkedList(identifiers), null, ''), 39 new NodeList(null, linkedList(identifiers), null, ''),
42 flags); 40 flags);
43 } 41 }
44 42
45 Token keywordToken(String text) { 43 Token keywordToken(String text) {
46 return new KeywordToken(Keyword.keywords[text], position.charOffset); 44 return new KeywordToken(Keyword.keywords[text], charOffset);
47 } 45 }
48 46
49 Token stringToken(String text) { 47 Token stringToken(String text) {
50 return new StringToken.fromString(IDENTIFIER_INFO, text, charOffset); 48 return new StringToken.fromString(IDENTIFIER_INFO, text, charOffset);
51 } 49 }
52 50
53 Token symbolToken(PrecedenceInfo info) { 51 Token symbolToken(PrecedenceInfo info) {
54 return new SymbolToken(info, charOffset); 52 return new SymbolToken(info, charOffset);
55 } 53 }
56 54
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 174
177 class EnumCreator { 175 class EnumCreator {
178 final Compiler compiler; 176 final Compiler compiler;
179 final EnumClassElementX enumClass; 177 final EnumClassElementX enumClass;
180 178
181 EnumCreator(this.compiler, this.enumClass); 179 EnumCreator(this.compiler, this.enumClass);
182 180
183 void createMembers() { 181 void createMembers() {
184 Enum node = enumClass.node; 182 Enum node = enumClass.node;
185 InterfaceType enumType = enumClass.thisType; 183 InterfaceType enumType = enumClass.thisType;
186 AstBuilder builder = new AstBuilder(enumClass.position); 184 AstBuilder builder = new AstBuilder(enumClass.position.charOffset);
187 185
188 InterfaceType intType = compiler.intClass.computeType(compiler); 186 InterfaceType intType = compiler.intClass.computeType(compiler);
189 InterfaceType stringType = compiler.stringClass.computeType(compiler); 187 InterfaceType stringType = compiler.stringClass.computeType(compiler);
190 188
191 EnumFieldElementX addInstanceMember(String name, InterfaceType type) { 189 EnumFieldElementX addInstanceMember(String name, InterfaceType type) {
192 Identifier identifier = builder.identifier(name); 190 Identifier identifier = builder.identifier(name);
193 VariableList variableList = 191 VariableList variableList =
194 new VariableList(builder.modifiers(isFinal: true)); 192 new VariableList(builder.modifiers(isFinal: true));
195 variableList.type = type; 193 variableList.type = type;
196 EnumFieldElementX variable = new EnumFieldElementX( 194 EnumFieldElementX variable = new EnumFieldElementX(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 VariableList variableList = 230 VariableList variableList =
233 new VariableList(builder.modifiers(isStatic: true, isConst: true)); 231 new VariableList(builder.modifiers(isStatic: true, isConst: true));
234 variableList.type = enumType; 232 variableList.type = enumType;
235 int index = 0; 233 int index = 0;
236 List<Node> valueReferences = <Node>[]; 234 List<Node> valueReferences = <Node>[];
237 List<LiteralMapEntry> mapEntries = <LiteralMapEntry>[]; 235 List<LiteralMapEntry> mapEntries = <LiteralMapEntry>[];
238 for (Link<Node> link = node.names.nodes; 236 for (Link<Node> link = node.names.nodes;
239 !link.isEmpty; 237 !link.isEmpty;
240 link = link.tail) { 238 link = link.tail) {
241 Identifier name = link.head; 239 Identifier name = link.head;
242 AstBuilder valueBuilder = new AstBuilder(name.token); 240 AstBuilder valueBuilder = new AstBuilder(name.token.charOffset);
243 241
244 // Add reference for the `values` field. 242 // Add reference for the `values` field.
245 valueReferences.add(valueBuilder.reference(name)); 243 valueReferences.add(valueBuilder.reference(name));
246 244
247 // Add map entry for `toString` implementation. 245 // Add map entry for `toString` implementation.
248 mapEntries.add(valueBuilder.mapLiteralEntry( 246 mapEntries.add(valueBuilder.mapLiteralEntry(
249 valueBuilder.literalInt(index), 247 valueBuilder.literalInt(index),
250 valueBuilder.literalString('${enumClass.name}.${name.source}'))); 248 valueBuilder.literalString('${enumClass.name}.${name.source}')));
251 249
252 Expression initializer = valueBuilder.newExpression( 250 Expression initializer = valueBuilder.newExpression(
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 EnumMethodElementX toString = new EnumMethodElementX('toString', 294 EnumMethodElementX toString = new EnumMethodElementX('toString',
297 enumClass, Modifiers.EMPTY, toStringNode); 295 enumClass, Modifiers.EMPTY, toStringNode);
298 FunctionSignatureX toStringSignature = new FunctionSignatureX( 296 FunctionSignatureX toStringSignature = new FunctionSignatureX(
299 type: new FunctionType(toString, stringType)); 297 type: new FunctionType(toString, stringType));
300 toString.functionSignatureCache = toStringSignature; 298 toString.functionSignatureCache = toStringSignature;
301 enumClass.addMember(toString, compiler); 299 enumClass.addMember(toString, compiler);
302 300
303 enumClass.enumValues = enumValues; 301 enumClass.enumValues = enumValues;
304 } 302 }
305 } 303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698