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

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

Issue 11299009: Support type literals as compile-time constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 1 month 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 implements ConstantVisitor { 7 class ConstantEmitter implements ConstantVisitor {
8 final Compiler compiler; 8 final Compiler compiler;
9 final Namer namer; 9 final Namer namer;
10 10
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 includeBackendMembers: true, 189 includeBackendMembers: true,
190 includeSuperMembers: true); 190 includeSuperMembers: true);
191 if ((constant.protoValue == null && emittedArgumentCount != 3) || 191 if ((constant.protoValue == null && emittedArgumentCount != 3) ||
192 (constant.protoValue != null && emittedArgumentCount != 4)) { 192 (constant.protoValue != null && emittedArgumentCount != 4)) {
193 badFieldCountError(); 193 badFieldCountError();
194 } 194 }
195 buffer.add(")"); 195 buffer.add(")");
196 } 196 }
197 } 197 }
198 198
199 void visitType(TypeConstant constant) {
200 if (shouldEmitCanonicalVersion) {
201 emitCanonicalVersion(constant);
202 } else {
203 SourceString helperSourceName =
204 const SourceString('createRuntimeType');
205 Element helper = compiler.findHelper(helperSourceName);
206 JavaScriptBackend backend = compiler.backend;
207 String helperName = backend.namer.getName(helper);
208 DartType type = constant.representedType;
209 Element element = type.element;
210 String typeName;
211 if (type.kind == TypeKind.INTERFACE) {
212 typeName = backend.rti.generateRuntimeTypeString(element, 0);
213 } else {
214 assert(type.kind == TypeKind.TYPEDEF);
215 typeName = element.name.slowToString();
floitsch 2012/11/20 16:25:43 Discuss with Erik if (and potentially how) this sh
216 }
217 buffer.add("${namer.CURRENT_ISOLATE}.$helperName('$typeName')");
218 }
219 }
220
199 void visitConstructed(ConstructedConstant constant) { 221 void visitConstructed(ConstructedConstant constant) {
200 if (shouldEmitCanonicalVersion) { 222 if (shouldEmitCanonicalVersion) {
201 emitCanonicalVersion(constant); 223 emitCanonicalVersion(constant);
202 } else { 224 } else {
203 shouldEmitCanonicalVersion = true; 225 shouldEmitCanonicalVersion = true;
204 226
205 buffer.add("new "); 227 buffer.add("new ");
206 buffer.add(getJsConstructor(constant.type.element)); 228 buffer.add(getJsConstructor(constant.type.element));
207 buffer.add("("); 229 buffer.add("(");
208 for (int i = 0; i < constant.fields.length; i++) { 230 for (int i = 0; i < constant.fields.length; i++) {
209 if (i != 0) buffer.add(", "); 231 if (i != 0) buffer.add(", ");
210 _visit(constant.fields[i]); 232 _visit(constant.fields[i]);
211 } 233 }
212 buffer.add(")"); 234 buffer.add(")");
213 } 235 }
214 } 236 }
215 } 237 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698