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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/constant_emitter.dart

Issue 255843005: Avoid generating VariableUse nodes with non-identifier names (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of js_backend; 5 part of js_backend;
6 6
7 class ConstantEmitter { 7 class ConstantEmitter {
8 ConstantReferenceEmitter _referenceEmitter; 8 ConstantReferenceEmitter _referenceEmitter;
9 ConstantInitializerEmitter _initializerEmitter; 9 ConstantInitializerEmitter _initializerEmitter;
10 10
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 jsAst.Expression generateInInitializationContext(Constant constant) { 56 jsAst.Expression generateInInitializationContext(Constant constant) {
57 return _visit(constant); 57 return _visit(constant);
58 } 58 }
59 59
60 jsAst.Expression _visit(Constant constant) { 60 jsAst.Expression _visit(Constant constant) {
61 return constant.accept(this); 61 return constant.accept(this);
62 } 62 }
63 63
64 jsAst.Expression visitFunction(FunctionConstant constant) { 64 jsAst.Expression visitFunction(FunctionConstant constant) {
65 return new jsAst.VariableUse( 65 return namer.isolateStaticClosureAccess(constant.element);
66 namer.isolateStaticClosureAccess(constant.element));
67 } 66 }
68 67
69 jsAst.Expression visitNull(NullConstant constant) { 68 jsAst.Expression visitNull(NullConstant constant) {
70 return new jsAst.LiteralNull(); 69 return new jsAst.LiteralNull();
71 } 70 }
72 71
73 jsAst.Expression visitInt(IntConstant constant) { 72 jsAst.Expression visitInt(IntConstant constant) {
74 return new jsAst.LiteralNumber('${constant.value}'); 73 return new jsAst.LiteralNumber('${constant.value}');
75 } 74 }
76 75
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 210
212 jsAst.Expression visitList(ListConstant constant) { 211 jsAst.Expression visitList(ListConstant constant) {
213 jsAst.Expression value = new jsAst.Call( 212 jsAst.Expression value = new jsAst.Call(
214 new jsAst.PropertyAccess.field( 213 new jsAst.PropertyAccess.field(
215 new jsAst.VariableUse(namer.isolateName), 214 new jsAst.VariableUse(namer.isolateName),
216 'makeConstantList'), 215 'makeConstantList'),
217 [new jsAst.ArrayInitializer.from(_array(constant.entries))]); 216 [new jsAst.ArrayInitializer.from(_array(constant.entries))]);
218 return maybeAddTypeArguments(constant.type, value); 217 return maybeAddTypeArguments(constant.type, value);
219 } 218 }
220 219
221 String getJsConstructor(ClassElement element) { 220 jsAst.Expression getJsConstructor(ClassElement element) {
222 return namer.isolateAccess(element); 221 return namer.elementAccess(element);
223 } 222 }
224 223
225 jsAst.Expression visitMap(MapConstant constant) { 224 jsAst.Expression visitMap(MapConstant constant) {
226 jsAst.Expression jsMap() { 225 jsAst.Expression jsMap() {
227 List<jsAst.Property> properties = <jsAst.Property>[]; 226 List<jsAst.Property> properties = <jsAst.Property>[];
228 for (int i = 0; i < constant.keys.entries.length; i++) { 227 for (int i = 0; i < constant.keys.entries.length; i++) {
229 StringConstant key = constant.keys.entries[i]; 228 StringConstant key = constant.keys.entries[i];
230 if (key.value == MapConstant.PROTO_PROPERTY) continue; 229 if (key.value == MapConstant.PROTO_PROPERTY) continue;
231 230
232 // Keys in literal maps must be emitted in place. 231 // Keys in literal maps must be emitted in place.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 if ((className == MapConstant.DART_STRING_CLASS && 283 if ((className == MapConstant.DART_STRING_CLASS &&
285 emittedArgumentCount != 3) || 284 emittedArgumentCount != 3) ||
286 (className == MapConstant.DART_PROTO_CLASS && 285 (className == MapConstant.DART_PROTO_CLASS &&
287 emittedArgumentCount != 4) || 286 emittedArgumentCount != 4) ||
288 (className == MapConstant.DART_GENERAL_CLASS && 287 (className == MapConstant.DART_GENERAL_CLASS &&
289 emittedArgumentCount != 1)) { 288 emittedArgumentCount != 1)) {
290 compiler.internalError(classElement, 289 compiler.internalError(classElement,
291 "Compiler and ${className} disagree on number of fields."); 290 "Compiler and ${className} disagree on number of fields.");
292 } 291 }
293 292
294 jsAst.Expression value = new jsAst.New( 293 jsAst.Expression value =
295 new jsAst.VariableUse(getJsConstructor(classElement)), 294 new jsAst.New(getJsConstructor(classElement), arguments);
296 arguments);
297 return maybeAddTypeArguments(constant.type, value); 295 return maybeAddTypeArguments(constant.type, value);
298 } 296 }
299 297
300 JavaScriptBackend get backend => compiler.backend; 298 JavaScriptBackend get backend => compiler.backend;
301 299
302 jsAst.PropertyAccess getHelperProperty(Element helper) { 300 jsAst.PropertyAccess getHelperProperty(Element helper) {
303 return backend.namer.elementAccess(helper); 301 return backend.namer.elementAccess(helper);
304 } 302 }
305 303
306 jsAst.Expression visitType(TypeConstant constant) { 304 jsAst.Expression visitType(TypeConstant constant) {
307 DartType type = constant.representedType; 305 DartType type = constant.representedType;
308 String name = namer.getRuntimeTypeName(type.element); 306 String name = namer.getRuntimeTypeName(type.element);
309 jsAst.Expression typeName = new jsAst.LiteralString("'$name'"); 307 jsAst.Expression typeName = new jsAst.LiteralString("'$name'");
310 return new jsAst.Call(getHelperProperty(backend.getCreateRuntimeType()), 308 return new jsAst.Call(getHelperProperty(backend.getCreateRuntimeType()),
311 [typeName]); 309 [typeName]);
312 } 310 }
313 311
314 jsAst.Expression visitInterceptor(InterceptorConstant constant) { 312 jsAst.Expression visitInterceptor(InterceptorConstant constant) {
315 return new jsAst.PropertyAccess.field( 313 return new jsAst.PropertyAccess.field(
316 new jsAst.VariableUse( 314 getJsConstructor(constant.dispatchedType.element),
317 getJsConstructor(constant.dispatchedType.element)),
318 'prototype'); 315 'prototype');
319 } 316 }
320 317
321 jsAst.Expression visitDummy(DummyConstant constant) { 318 jsAst.Expression visitDummy(DummyConstant constant) {
322 return _reference(constant); 319 return _reference(constant);
323 } 320 }
324 321
325 jsAst.Expression visitConstructed(ConstructedConstant constant) { 322 jsAst.Expression visitConstructed(ConstructedConstant constant) {
326 Element element = constant.type.element; 323 Element element = constant.type.element;
327 if (element.isForeign(compiler) 324 if (element.isForeign(compiler)
328 && element.name == 'JS_CONST') { 325 && element.name == 'JS_CONST') {
329 StringConstant str = constant.fields[0]; 326 StringConstant str = constant.fields[0];
330 String value = str.value.slowToString(); 327 String value = str.value.slowToString();
331 return new jsAst.LiteralExpression(stripComments(value)); 328 return new jsAst.LiteralExpression(stripComments(value));
332 } 329 }
333 jsAst.New instantiation = new jsAst.New( 330 jsAst.New instantiation = new jsAst.New(
334 new jsAst.VariableUse(getJsConstructor(constant.type.element)), 331 getJsConstructor(constant.type.element),
335 _array(constant.fields)); 332 _array(constant.fields));
336 return maybeAddTypeArguments(constant.type, instantiation); 333 return maybeAddTypeArguments(constant.type, instantiation);
337 } 334 }
338 335
339 String stripComments(String rawJavaScript) { 336 String stripComments(String rawJavaScript) {
340 return rawJavaScript.replaceAll(COMMENT_RE, ''); 337 return rawJavaScript.replaceAll(COMMENT_RE, '');
341 } 338 }
342 339
343 List<jsAst.Expression> _array(List<Constant> values) { 340 List<jsAst.Expression> _array(List<Constant> values) {
344 List<jsAst.Expression> valueList = <jsAst.Expression>[]; 341 List<jsAst.Expression> valueList = <jsAst.Expression>[];
(...skipping 15 matching lines...) Expand all
360 .map((DartType type) => 357 .map((DartType type) =>
361 rti.getTypeRepresentationWithHashes(type, (_){})); 358 rti.getTypeRepresentationWithHashes(type, (_){}));
362 jsAst.Expression argumentList = 359 jsAst.Expression argumentList =
363 new jsAst.LiteralString('[${arguments.join(', ')}]'); 360 new jsAst.LiteralString('[${arguments.join(', ')}]');
364 return new jsAst.Call(getHelperProperty(backend.getSetRuntimeTypeInfo()), 361 return new jsAst.Call(getHelperProperty(backend.getSetRuntimeTypeInfo()),
365 [value, argumentList]); 362 [value, argumentList]);
366 } 363 }
367 return value; 364 return value;
368 } 365 }
369 } 366 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698