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

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: 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');
ngeoffray 2012/11/19 16:54:09 See my comment in compile_time_constant.dart. I'd
karlklose 2012/11/20 14:04:38 http://code.google.com/p/dart/issues/detail?id=682
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 =
213 compiler.codegenWorld.rti.generateRuntimeTypeString(element, 0);
214 } else {
215 assert(type.kind == TypeKind.TYPEDEF);
216 typeName = element.name.slowToString();
217 }
218 buffer.add("${namer.CURRENT_ISOLATE}.$helperName('$typeName')");
219 }
220 }
221
199 void visitConstructed(ConstructedConstant constant) { 222 void visitConstructed(ConstructedConstant constant) {
200 if (shouldEmitCanonicalVersion) { 223 if (shouldEmitCanonicalVersion) {
201 emitCanonicalVersion(constant); 224 emitCanonicalVersion(constant);
202 } else { 225 } else {
203 shouldEmitCanonicalVersion = true; 226 shouldEmitCanonicalVersion = true;
204 227
205 buffer.add("new "); 228 buffer.add("new ");
206 buffer.add(getJsConstructor(constant.type.element)); 229 buffer.add(getJsConstructor(constant.type.element));
207 buffer.add("("); 230 buffer.add("(");
208 for (int i = 0; i < constant.fields.length; i++) { 231 for (int i = 0; i < constant.fields.length; i++) {
209 if (i != 0) buffer.add(", "); 232 if (i != 0) buffer.add(", ");
210 _visit(constant.fields[i]); 233 _visit(constant.fields[i]);
211 } 234 }
212 buffer.add(")"); 235 buffer.add(")");
213 } 236 }
214 } 237 }
215 } 238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698