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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart

Issue 869513003: dart2js: Move metadata from old_emitter to shared directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 7
8 class OldEmitter implements Emitter { 8 class OldEmitter implements Emitter {
9 final Compiler compiler; 9 final Compiler compiler;
10 final CodeEmitterTask task; 10 final CodeEmitterTask task;
11 11
12 final ContainerBuilder containerBuilder = new ContainerBuilder(); 12 final ContainerBuilder containerBuilder = new ContainerBuilder();
13 final ClassEmitter classEmitter = new ClassEmitter(); 13 final ClassEmitter classEmitter = new ClassEmitter();
14 final NsmEmitter nsmEmitter = new NsmEmitter(); 14 final NsmEmitter nsmEmitter = new NsmEmitter();
15 final InterceptorEmitter interceptorEmitter = new InterceptorEmitter(); 15 final InterceptorEmitter interceptorEmitter = new InterceptorEmitter();
16 final MetadataEmitter metadataEmitter = new MetadataEmitter();
17 16
18 // TODO(johnniwinther): Wrap these fields in a caching strategy. 17 // TODO(johnniwinther): Wrap these fields in a caching strategy.
19 final Set<ConstantValue> cachedEmittedConstants; 18 final Set<ConstantValue> cachedEmittedConstants;
20 final CodeBuffer cachedEmittedConstantsBuffer = new CodeBuffer(); 19 final CodeBuffer cachedEmittedConstantsBuffer = new CodeBuffer();
21 final Map<Element, ClassBuilder> cachedClassBuilders; 20 final Map<Element, ClassBuilder> cachedClassBuilders;
22 final Set<Element> cachedElements; 21 final Set<Element> cachedElements;
23 22
24 bool needsClassSupport = false; 23 bool needsClassSupport = false;
25 bool needsMixinSupport = false; 24 bool needsMixinSupport = false;
26 bool needsLazyInitializer = false; 25 bool needsLazyInitializer = false;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 this.namer = namer, 94 this.namer = namer,
96 cachedEmittedConstants = compiler.cacheStrategy.newSet(), 95 cachedEmittedConstants = compiler.cacheStrategy.newSet(),
97 cachedClassBuilders = compiler.cacheStrategy.newMap(), 96 cachedClassBuilders = compiler.cacheStrategy.newMap(),
98 cachedElements = compiler.cacheStrategy.newSet() { 97 cachedElements = compiler.cacheStrategy.newSet() {
99 constantEmitter = 98 constantEmitter =
100 new ConstantEmitter(compiler, namer, makeConstantListTemplate); 99 new ConstantEmitter(compiler, namer, makeConstantListTemplate);
101 containerBuilder.emitter = this; 100 containerBuilder.emitter = this;
102 classEmitter.emitter = this; 101 classEmitter.emitter = this;
103 nsmEmitter.emitter = this; 102 nsmEmitter.emitter = this;
104 interceptorEmitter.emitter = this; 103 interceptorEmitter.emitter = this;
105 metadataEmitter.emitter = this;
106 } 104 }
107 105
108 List<jsAst.Node> cspPrecompiledFunctionFor(OutputUnit outputUnit) { 106 List<jsAst.Node> cspPrecompiledFunctionFor(OutputUnit outputUnit) {
109 return _cspPrecompiledFunctions.putIfAbsent( 107 return _cspPrecompiledFunctions.putIfAbsent(
110 outputUnit, 108 outputUnit,
111 () => new List<jsAst.Node>()); 109 () => new List<jsAst.Node>());
112 } 110 }
113 111
114 List<jsAst.Expression> cspPrecompiledConstructorNamesFor( 112 List<jsAst.Expression> cspPrecompiledConstructorNamesFor(
115 OutputUnit outputUnit) { 113 OutputUnit outputUnit) {
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 // closure that constructs the initial value. 787 // closure that constructs the initial value.
790 return js('#(#,#,#,#,#)', 788 return js('#(#,#,#,#,#)',
791 [js(lazyInitializerName), 789 [js(lazyInitializerName),
792 js(isolateProperties), 790 js(isolateProperties),
793 js.string(element.name), 791 js.string(element.name),
794 js.string(namer.getNameX(element)), 792 js.string(namer.getNameX(element)),
795 js.string(namer.getLazyInitializerName(element)), 793 js.string(namer.getLazyInitializerName(element)),
796 code]); 794 code]);
797 } 795 }
798 796
797 void emitMetadata(List<String> globalMetadata, CodeOutput output) {
798 String metadataAccess =
799 generateEmbeddedGlobalAccessString(embeddedNames.METADATA);
800 output.add('$metadataAccess$_=$_[');
801 for (String metadata in globalMetadata) {
802 if (metadata is String) {
803 if (metadata != 'null') {
804 output.add(metadata);
805 }
806 } else {
807 throw 'Unexpected value in metadata: ${Error.safeToString(metadata)}';
808 }
809 output.add(',$n');
810 }
811 output.add('];$n');
812 }
813
799 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant) { 814 bool isConstantInlinedOrAlreadyEmitted(ConstantValue constant) {
800 if (constant.isFunction) return true; // Already emitted. 815 if (constant.isFunction) return true; // Already emitted.
801 if (constant.isPrimitive) return true; // Inlined. 816 if (constant.isPrimitive) return true; // Inlined.
802 if (constant.isDummy) return true; // Inlined. 817 if (constant.isDummy) return true; // Inlined.
803 // The name is null when the constant is already a JS constant. 818 // The name is null when the constant is already a JS constant.
804 // TODO(floitsch): every constant should be registered, so that we can 819 // TODO(floitsch): every constant should be registered, so that we can
805 // share the ones that take up too much space (like some strings). 820 // share the ones that take up too much space (like some strings).
806 if (namer.constantName(constant) == null) return true; 821 if (namer.constantName(constant) == null) return true;
807 return false; 822 return false;
808 } 823 }
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 // with language/prefix6_negative_test.dart where we have an instance 1177 // with language/prefix6_negative_test.dart where we have an instance
1163 // method without its corresponding class. 1178 // method without its corresponding class.
1164 return; 1179 return;
1165 } 1180 }
1166 1181
1167 String libraryName = 1182 String libraryName =
1168 (!compiler.enableMinification || backend.mustRetainLibraryNames) ? 1183 (!compiler.enableMinification || backend.mustRetainLibraryNames) ?
1169 library.getLibraryName() : 1184 library.getLibraryName() :
1170 ""; 1185 "";
1171 1186
1172 jsAst.Fun metadata = metadataEmitter.buildMetadataFunction(library); 1187 jsAst.Fun metadata = task.metadataEmitter.buildMetadataFunction(library);
1173 1188
1174 jsAst.ObjectInitializer initializers = descriptor.toObjectInitializer(); 1189 jsAst.ObjectInitializer initializers = descriptor.toObjectInitializer();
1175 1190
1176 compiler.dumpInfoTask.registerElementAst(library, metadata); 1191 compiler.dumpInfoTask.registerElementAst(library, metadata);
1177 compiler.dumpInfoTask.registerElementAst(library, initializers); 1192 compiler.dumpInfoTask.registerElementAst(library, initializers);
1178 output 1193 output
1179 ..add('["$libraryName",$_') 1194 ..add('["$libraryName",$_')
1180 ..add('"${uri}",$_'); 1195 ..add('"${uri}",$_');
1181 if (metadata != null) { 1196 if (metadata != null) {
1182 output.addBuffer(jsAst.prettyPrint(metadata, 1197 output.addBuffer(jsAst.prettyPrint(metadata,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 void emitTypedefs() { 1246 void emitTypedefs() {
1232 OutputUnit mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; 1247 OutputUnit mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit;
1233 1248
1234 // Emit all required typedef declarations into the main output unit. 1249 // Emit all required typedef declarations into the main output unit.
1235 // TODO(karlklose): unify required classes and typedefs to declarations 1250 // TODO(karlklose): unify required classes and typedefs to declarations
1236 // and have builders for each kind. 1251 // and have builders for each kind.
1237 for (TypedefElement typedef in typedefsNeededForReflection) { 1252 for (TypedefElement typedef in typedefsNeededForReflection) {
1238 LibraryElement library = typedef.library; 1253 LibraryElement library = typedef.library;
1239 // TODO(karlklose): add a TypedefBuilder and move this code there. 1254 // TODO(karlklose): add a TypedefBuilder and move this code there.
1240 DartType type = typedef.alias; 1255 DartType type = typedef.alias;
1241 int typeIndex = metadataEmitter.reifyType(type); 1256 int typeIndex = task.metadataEmitter.reifyType(type);
1242 ClassBuilder builder = new ClassBuilder(typedef, namer); 1257 ClassBuilder builder = new ClassBuilder(typedef, namer);
1243 builder.addProperty(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, 1258 builder.addProperty(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME,
1244 js.number(typeIndex)); 1259 js.number(typeIndex));
1245 builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, 1260 builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME,
1246 js.boolean(true)); 1261 js.boolean(true));
1247 1262
1248 // We can be pretty sure that the objectClass is initialized, since 1263 // We can be pretty sure that the objectClass is initialized, since
1249 // typedefs are only emitted with reflection, which requires lots of 1264 // typedefs are only emitted with reflection, which requires lots of
1250 // classes. 1265 // classes.
1251 assert(compiler.objectClass != null); 1266 assert(compiler.objectClass != null);
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 } 1507 }
1493 1508
1494 // Static field initializations require the classes and compile-time 1509 // Static field initializations require the classes and compile-time
1495 // constants to be set up. 1510 // constants to be set up.
1496 emitStaticNonFinalFieldInitializations(mainOutput, mainOutputUnit); 1511 emitStaticNonFinalFieldInitializations(mainOutput, mainOutputUnit);
1497 interceptorEmitter.emitTypeToInterceptorMap(program, mainOutput); 1512 interceptorEmitter.emitTypeToInterceptorMap(program, mainOutput);
1498 emitLazilyInitializedStaticFields(mainOutput); 1513 emitLazilyInitializedStaticFields(mainOutput);
1499 1514
1500 mainOutput.add('\n'); 1515 mainOutput.add('\n');
1501 1516
1502 metadataEmitter.emitMetadata(mainOutput); 1517 emitMetadata(task.metadataEmitter.globalMetadata, mainOutput);
1503 1518
1504 isolateProperties = isolatePropertiesName; 1519 isolateProperties = isolatePropertiesName;
1505 // The following code should not use the short-hand for the 1520 // The following code should not use the short-hand for the
1506 // initialStatics. 1521 // initialStatics.
1507 mainOutput.add('${namer.currentIsolate}$_=${_}null$N'); 1522 mainOutput.add('${namer.currentIsolate}$_=${_}null$N');
1508 1523
1509 emitFinishIsolateConstructorInvocation(mainOutput); 1524 emitFinishIsolateConstructorInvocation(mainOutput);
1510 mainOutput.add( 1525 mainOutput.add(
1511 '${namer.currentIsolate}$_=${_}new ${namer.isolateName}()$N'); 1526 '${namer.currentIsolate}$_=${_}new ${namer.isolateName}()$N');
1512 1527
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
2038 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 2053 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
2039 if (element.isInstanceMember) { 2054 if (element.isInstanceMember) {
2040 cachedClassBuilders.remove(element.enclosingClass); 2055 cachedClassBuilders.remove(element.enclosingClass);
2041 2056
2042 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2057 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
2043 2058
2044 } 2059 }
2045 } 2060 }
2046 } 2061 }
2047 } 2062 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698