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

Side by Side Diff: pkg/compiler/lib/src/js_backend/constant_emitter.dart

Issue 750323003: Remove js.ArrayElement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add parsing and testing of array holes, make lists non-growable Created 6 years 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 ConstantLiteralEmitter _literalEmitter; 9 ConstantLiteralEmitter _literalEmitter;
10 10
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 * The string is assumed quoted by double quote characters. 227 * The string is assumed quoted by double quote characters.
228 */ 228 */
229 jsAst.Expression visitString(StringConstantValue constant) { 229 jsAst.Expression visitString(StringConstantValue constant) {
230 StringBuffer sb = new StringBuffer(); 230 StringBuffer sb = new StringBuffer();
231 writeJsonEscapedCharsOn(constant.primitiveValue.slowToString(), sb); 231 writeJsonEscapedCharsOn(constant.primitiveValue.slowToString(), sb);
232 return new jsAst.LiteralString('"$sb"'); 232 return new jsAst.LiteralString('"$sb"');
233 } 233 }
234 234
235 jsAst.Expression visitList(ListConstantValue constant) { 235 jsAst.Expression visitList(ListConstantValue constant) {
236 List<jsAst.Expression> elements = _array(constant.entries); 236 List<jsAst.Expression> elements = _array(constant.entries);
237 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer.from(elements); 237 jsAst.ArrayInitializer array = new jsAst.ArrayInitializer(elements);
238 jsAst.Expression value = makeConstantListTemplate.instantiate([array]); 238 jsAst.Expression value = makeConstantListTemplate.instantiate([array]);
239 return maybeAddTypeArguments(constant.type, value); 239 return maybeAddTypeArguments(constant.type, value);
240 } 240 }
241 241
242 jsAst.Expression getJsConstructor(ClassElement element) { 242 jsAst.Expression getJsConstructor(ClassElement element) {
243 return namer.elementAccess(element); 243 return namer.elementAccess(element);
244 } 244 }
245 245
246 jsAst.Expression visitMap(JavaScriptMapConstant constant) { 246 jsAst.Expression visitMap(JavaScriptMapConstant constant) {
247 jsAst.Expression jsMap() { 247 jsAst.Expression jsMap() {
(...skipping 16 matching lines...) Expand all
264 jsAst.Expression jsGeneralMap() { 264 jsAst.Expression jsGeneralMap() {
265 List<jsAst.Expression> data = <jsAst.Expression>[]; 265 List<jsAst.Expression> data = <jsAst.Expression>[];
266 for (int i = 0; i < constant.keys.length; i++) { 266 for (int i = 0; i < constant.keys.length; i++) {
267 jsAst.Expression keyExpression = 267 jsAst.Expression keyExpression =
268 constantEmitter.reference(constant.keys[i]); 268 constantEmitter.reference(constant.keys[i]);
269 jsAst.Expression valueExpression = 269 jsAst.Expression valueExpression =
270 constantEmitter.reference(constant.values[i]); 270 constantEmitter.reference(constant.values[i]);
271 data.add(keyExpression); 271 data.add(keyExpression);
272 data.add(valueExpression); 272 data.add(valueExpression);
273 } 273 }
274 return new jsAst.ArrayInitializer.from(data); 274 return new jsAst.ArrayInitializer(data);
275 } 275 }
276 276
277 ClassElement classElement = constant.type.element; 277 ClassElement classElement = constant.type.element;
278 String className = classElement.name; 278 String className = classElement.name;
279 279
280 List<jsAst.Expression> arguments = <jsAst.Expression>[]; 280 List<jsAst.Expression> arguments = <jsAst.Expression>[];
281 281
282 // The arguments of the JavaScript constructor for any given Dart class 282 // The arguments of the JavaScript constructor for any given Dart class
283 // are in the same order as the members of the class element. 283 // are in the same order as the members of the class element.
284 int emittedArgumentCount = 0; 284 int emittedArgumentCount = 0;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 getJsConstructor(constant.type.element), 355 getJsConstructor(constant.type.element),
356 _array(constant.fields)); 356 _array(constant.fields));
357 return maybeAddTypeArguments(constant.type, instantiation); 357 return maybeAddTypeArguments(constant.type, instantiation);
358 } 358 }
359 359
360 String stripComments(String rawJavaScript) { 360 String stripComments(String rawJavaScript) {
361 return rawJavaScript.replaceAll(COMMENT_RE, ''); 361 return rawJavaScript.replaceAll(COMMENT_RE, '');
362 } 362 }
363 363
364 List<jsAst.Expression> _array(List<ConstantValue> values) { 364 List<jsAst.Expression> _array(List<ConstantValue> values) {
365 List<jsAst.Expression> valueList = <jsAst.Expression>[]; 365 return values.map(constantEmitter.reference).toList(growable: false);
366 for (int i = 0; i < values.length; i++) {
367 valueList.add(constantEmitter.reference(values[i]));
368 }
369 return valueList;
370 } 366 }
371 367
372 jsAst.Expression maybeAddTypeArguments(InterfaceType type, 368 jsAst.Expression maybeAddTypeArguments(InterfaceType type,
373 jsAst.Expression value) { 369 jsAst.Expression value) {
374 if (type is InterfaceType && 370 if (type is InterfaceType &&
375 !type.treatAsRaw && 371 !type.treatAsRaw &&
376 backend.classNeedsRti(type.element)) { 372 backend.classNeedsRti(type.element)) {
377 InterfaceType interface = type; 373 InterfaceType interface = type;
378 RuntimeTypes rti = backend.rti; 374 RuntimeTypes rti = backend.rti;
379 Iterable<String> arguments = interface.typeArguments 375 Iterable<String> arguments = interface.typeArguments
380 .map((DartType type) => 376 .map((DartType type) =>
381 rti.getTypeRepresentationWithHashes(type, (_){})); 377 rti.getTypeRepresentationWithHashes(type, (_){}));
382 jsAst.Expression argumentList = 378 jsAst.Expression argumentList =
383 new jsAst.LiteralString('[${arguments.join(', ')}]'); 379 new jsAst.LiteralString('[${arguments.join(', ')}]');
384 return new jsAst.Call(getHelperProperty(backend.getSetRuntimeTypeInfo()), 380 return new jsAst.Call(getHelperProperty(backend.getSetRuntimeTypeInfo()),
385 [value, argumentList]); 381 [value, argumentList]);
386 } 382 }
387 return value; 383 return value;
388 } 384 }
389 385
390 jsAst.Expression visitDeferred(DeferredConstantValue constant) { 386 jsAst.Expression visitDeferred(DeferredConstantValue constant) {
391 return constantEmitter.reference(constant.referenced); 387 return constantEmitter.reference(constant.referenced);
392 } 388 }
393 } 389 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698