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

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

Issue 16549004: Add type arguments to constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Adjust test status. Created 7 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 | 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 jsAst.Expression visitFalse(FalseConstant constant) { 202 jsAst.Expression visitFalse(FalseConstant constant) {
203 return _reference(constant); 203 return _reference(constant);
204 } 204 }
205 205
206 jsAst.Expression visitString(StringConstant constant) { 206 jsAst.Expression visitString(StringConstant constant) {
207 // TODO(sra): Some larger strings are worth sharing. 207 // TODO(sra): Some larger strings are worth sharing.
208 return _reference(constant); 208 return _reference(constant);
209 } 209 }
210 210
211 jsAst.Expression visitList(ListConstant constant) { 211 jsAst.Expression visitList(ListConstant constant) {
212 return new jsAst.Call( 212 jsAst.Expression value = new jsAst.Call(
213 new jsAst.PropertyAccess.field( 213 new jsAst.PropertyAccess.field(
214 new jsAst.VariableUse(namer.isolateName), 214 new jsAst.VariableUse(namer.isolateName),
215 'makeConstantList'), 215 'makeConstantList'),
216 [new jsAst.ArrayInitializer.from(_array(constant.entries))]); 216 [new jsAst.ArrayInitializer.from(_array(constant.entries))]);
217 return maybeAddTypeArguments(constant.type, value);
217 } 218 }
218 219
219 String getJsConstructor(ClassElement element) { 220 String getJsConstructor(ClassElement element) {
220 return namer.isolateAccess(element); 221 return namer.isolateAccess(element);
221 } 222 }
222 223
223 jsAst.Expression visitMap(MapConstant constant) { 224 jsAst.Expression visitMap(MapConstant constant) {
224 jsAst.Expression jsMap() { 225 jsAst.Expression jsMap() {
225 List<jsAst.Property> properties = <jsAst.Property>[]; 226 List<jsAst.Property> properties = <jsAst.Property>[];
226 int valueIndex = 0; 227 int valueIndex = 0;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 270 }
270 emittedArgumentCount++; 271 emittedArgumentCount++;
271 }, 272 },
272 includeSuperAndInjectedMembers: true); 273 includeSuperAndInjectedMembers: true);
273 274
274 if ((constant.protoValue == null && emittedArgumentCount != 3) || 275 if ((constant.protoValue == null && emittedArgumentCount != 3) ||
275 (constant.protoValue != null && emittedArgumentCount != 4)) { 276 (constant.protoValue != null && emittedArgumentCount != 4)) {
276 badFieldCountError(); 277 badFieldCountError();
277 } 278 }
278 279
279 return new jsAst.New( 280 jsAst.Expression value = new jsAst.New(
280 new jsAst.VariableUse(getJsConstructor(classElement)), 281 new jsAst.VariableUse(getJsConstructor(classElement)),
281 arguments); 282 arguments);
283 return maybeAddTypeArguments(constant.type, value);
284 }
285
286 JavaScriptBackend get backend => compiler.backend;
287
288 jsAst.PropertyAccess getHelperProperty(Element helper) {
289 String helperName = backend.namer.getName(helper);
290 return new jsAst.PropertyAccess.field(
291 new jsAst.VariableUse(namer.CURRENT_ISOLATE),
292 helperName);
282 } 293 }
283 294
284 jsAst.Expression visitType(TypeConstant constant) { 295 jsAst.Expression visitType(TypeConstant constant) {
285 JavaScriptBackend backend = compiler.backend;
286 Element helper = backend.getCreateRuntimeType();
287 String helperName = backend.namer.getName(helper);
288 DartType type = constant.representedType; 296 DartType type = constant.representedType;
289 String name = namer.getRuntimeTypeName(type.element); 297 String name = namer.getRuntimeTypeName(type.element);
290 jsAst.Expression typeName = new jsAst.LiteralString("'$name'"); 298 jsAst.Expression typeName = new jsAst.LiteralString("'$name'");
291 return new jsAst.Call( 299 return new jsAst.Call(getHelperProperty(backend.getCreateRuntimeType()),
292 new jsAst.PropertyAccess.field( 300 [typeName]);
293 new jsAst.VariableUse(namer.CURRENT_ISOLATE),
294 helperName),
295 [typeName]);
296 } 301 }
297 302
298 jsAst.Expression visitInterceptor(InterceptorConstant constant) { 303 jsAst.Expression visitInterceptor(InterceptorConstant constant) {
299 return new jsAst.PropertyAccess.field( 304 return new jsAst.PropertyAccess.field(
300 new jsAst.VariableUse( 305 new jsAst.VariableUse(
301 getJsConstructor(constant.dispatchedType.element)), 306 getJsConstructor(constant.dispatchedType.element)),
302 'prototype'); 307 'prototype');
303 } 308 }
304 309
305 jsAst.Expression visitConstructed(ConstructedConstant constant) { 310 jsAst.Expression visitConstructed(ConstructedConstant constant) {
306 return new jsAst.New( 311 jsAst.New instantiation = new jsAst.New(
307 new jsAst.VariableUse(getJsConstructor(constant.type.element)), 312 new jsAst.VariableUse(getJsConstructor(constant.type.element)),
308 _array(constant.fields)); 313 _array(constant.fields));
314 return maybeAddTypeArguments(constant.type, instantiation);
309 } 315 }
310 316
311 List<jsAst.Expression> _array(List<Constant> values) { 317 List<jsAst.Expression> _array(List<Constant> values) {
312 List<jsAst.Expression> valueList = <jsAst.Expression>[]; 318 List<jsAst.Expression> valueList = <jsAst.Expression>[];
313 for (int i = 0; i < values.length; i++) { 319 for (int i = 0; i < values.length; i++) {
314 valueList.add(_reference(values[i])); 320 valueList.add(_reference(values[i]));
315 } 321 }
316 return valueList; 322 return valueList;
317 } 323 }
324
325 jsAst.Expression maybeAddTypeArguments(InterfaceType type,
326 jsAst.Expression value) {
327 if (type is! InterfaceType || type.isRaw) {
328 return value;
329 } else {
ngeoffray 2013/06/17 09:15:03 Same comment as in compile_time_constants: you don
karlklose 2013/06/19 15:29:05 Done.
330 InterfaceType interface = type;
331 RuntimeTypes rti = backend.rti;
332 Iterable<String> arguments = interface.typeArguments
333 .toList(growable: false)
334 .map((DartType type) => rti.getTypeRepresentation(type, (_){}));
335 jsAst.Expression argumentList =
336 new jsAst.LiteralString('[${arguments.join(', ')}]');
337 return new jsAst.Call(getHelperProperty(backend.getSetRuntimeTypeInfo()),
338 [value, argumentList]);
339 }
340 }
318 } 341 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698