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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart

Issue 750323003: Remove js.ArrayElement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address comments 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) 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 library dart2js.new_js_emitter.model_emitter; 5 library dart2js.new_js_emitter.model_emitter;
6 6
7 import '../../dart2jslib.dart' show Compiler; 7 import '../../dart2jslib.dart' show Compiler;
8 import '../../js/js.dart' as js; 8 import '../../js/js.dart' as js;
9 import '../../js_backend/js_backend.dart' show 9 import '../../js_backend/js_backend.dart' show
10 JavaScriptBackend, 10 JavaScriptBackend,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 var suffix = ''; 68 var suffix = '';
69 if (compiler.hasBuildId) suffix = ' version: ${compiler.buildId}'; 69 if (compiler.hasBuildId) suffix = ' version: ${compiler.buildId}';
70 return '// Generated by dart2js, the Dart to JavaScript compiler$suffix.\n'; 70 return '// Generated by dart2js, the Dart to JavaScript compiler$suffix.\n';
71 } 71 }
72 72
73 js.Statement emitMainUnit(Program program) { 73 js.Statement emitMainUnit(Program program) {
74 MainOutput unit = program.outputs.first; 74 MainOutput unit = program.outputs.first;
75 List<js.Expression> elements = unit.libraries.map(emitLibrary).toList(); 75 List<js.Expression> elements = unit.libraries.map(emitLibrary).toList();
76 elements.add( 76 elements.add(
77 emitLazilyInitializedStatics(unit.staticLazilyInitializedFields)); 77 emitLazilyInitializedStatics(unit.staticLazilyInitializedFields));
78 js.Expression code = new js.ArrayInitializer.from(elements); 78 js.Expression code = new js.ArrayInitializer(elements);
79 return js.js.statement( 79 return js.js.statement(
80 boilerplate, 80 boilerplate,
81 {'deferredInitializer': emitDeferredInitializerGlobal(program.loadMap), 81 {'deferredInitializer': emitDeferredInitializerGlobal(program.loadMap),
82 'holders': emitHolders(unit.holders), 82 'holders': emitHolders(unit.holders),
83 'cyclicThrow': namer.elementAccess(backend.getCyclicThrowHelper()), 83 'cyclicThrow': namer.elementAccess(backend.getCyclicThrowHelper()),
84 'outputContainsConstantList': program.outputContainsConstantList, 84 'outputContainsConstantList': program.outputContainsConstantList,
85 'embeddedGlobals': emitEmbeddedGlobals(program.loadMap), 85 'embeddedGlobals': emitEmbeddedGlobals(program.loadMap),
86 'constants': emitConstants(unit.constants), 86 'constants': emitConstants(unit.constants),
87 'staticNonFinals': emitStaticNonFinalFields(unit.staticNonFinalFields), 87 'staticNonFinals': emitStaticNonFinalFields(unit.staticNonFinalFields),
88 'eagerClasses': emitEagerClassInitializations(unit.libraries), 88 'eagerClasses': emitEagerClassInitializations(unit.libraries),
(...skipping 11 matching lines...) Expand all
100 // 100 //
101 // and it is inserted at the top of the top-level function expression 101 // and it is inserted at the top of the top-level function expression
102 // that covers the entire program. 102 // that covers the entire program.
103 103
104 List<js.Statement> statements = [ 104 List<js.Statement> statements = [
105 new js.ExpressionStatement( 105 new js.ExpressionStatement(
106 new js.VariableDeclarationList(holders.map((e) => 106 new js.VariableDeclarationList(holders.map((e) =>
107 new js.VariableInitialization( 107 new js.VariableInitialization(
108 new js.VariableDeclaration(e.name, allowRename: false), 108 new js.VariableDeclaration(e.name, allowRename: false),
109 new js.ObjectInitializer(const []))).toList())), 109 new js.ObjectInitializer(const []))).toList())),
110 js.js.statement('var holders = #', new js.ArrayInitializer.from( 110 js.js.statement('var holders = #', new js.ArrayInitializer(
111 holders.map((e) => new js.VariableUse(e.name)))) 111 holders.map((e) => new js.VariableUse(e.name))
112 .toList(growable: false)))
112 ]; 113 ];
113 return new js.Block(statements); 114 return new js.Block(statements);
114 } 115 }
115 116
116 static js.Template get makeConstantListTemplate { 117 static js.Template get makeConstantListTemplate {
117 // TODO(floitsch): remove hard-coded name. 118 // TODO(floitsch): remove hard-coded name.
118 // TODO(floitsch): there is no harm in caching the template. 119 // TODO(floitsch): there is no harm in caching the template.
119 return js.js.uncachedExpressionTemplate('makeConstList(#)'); 120 return js.js.uncachedExpressionTemplate('makeConstList(#)');
120 } 121 }
121 122
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 192 }
192 193
193 js.Expression emitDeferredUnit(DeferredOutput unit, List<Holder> holders) { 194 js.Expression emitDeferredUnit(DeferredOutput unit, List<Holder> holders) {
194 // TODO(floitsch): initialize eager classes. 195 // TODO(floitsch): initialize eager classes.
195 // TODO(floitsch): the hash must depend on the output. 196 // TODO(floitsch): the hash must depend on the output.
196 int hash = this.hashCode; 197 int hash = this.hashCode;
197 if (unit.constants.isNotEmpty) { 198 if (unit.constants.isNotEmpty) {
198 throw new UnimplementedError("constants in deferred units"); 199 throw new UnimplementedError("constants in deferred units");
199 } 200 }
200 js.ArrayInitializer content = 201 js.ArrayInitializer content =
201 new js.ArrayInitializer.from(unit.libraries.map(emitLibrary)); 202 new js.ArrayInitializer(unit.libraries.map(emitLibrary)
203 .toList(growable: false));
202 return js.js("$deferredInitializersGlobal[$hash] = #", content); 204 return js.js("$deferredInitializersGlobal[$hash] = #", content);
203 } 205 }
204 206
205 js.Block emitConstants(List<Constant> constants) { 207 js.Block emitConstants(List<Constant> constants) {
206 Iterable<js.Statement> statements = constants.map((Constant constant) { 208 Iterable<js.Statement> statements = constants.map((Constant constant) {
207 js.Expression code = 209 js.Expression code =
208 constantEmitter.initializationExpression(constant.value); 210 constantEmitter.initializationExpression(constant.value);
209 return js.js.statement("#.# = #;", 211 return js.js.statement("#.# = #;",
210 [constant.holder.name, constant.name, code]); 212 [constant.holder.name, constant.name, code]);
211 }); 213 });
212 return new js.Block(statements.toList()); 214 return new js.Block(statements.toList());
213 } 215 }
214 216
215 js.Block emitStaticNonFinalFields(List<StaticField> fields) { 217 js.Block emitStaticNonFinalFields(List<StaticField> fields) {
216 Iterable<js.Statement> statements = fields.map((StaticField field) { 218 Iterable<js.Statement> statements = fields.map((StaticField field) {
217 return js.js.statement("#.# = #;", 219 return js.js.statement("#.# = #;",
218 [field.holder.name, field.name, field.code]); 220 [field.holder.name, field.name, field.code]);
219 }); 221 });
220 return new js.Block(statements.toList()); 222 return new js.Block(statements.toList());
221 } 223 }
222 224
223 js.Expression emitLazilyInitializedStatics(List<StaticField> fields) { 225 js.Expression emitLazilyInitializedStatics(List<StaticField> fields) {
224 Iterable fieldDescriptors = fields.expand((field) => 226 Iterable fieldDescriptors = fields.expand((field) =>
225 [ js.string(field.name), 227 [ js.string(field.name),
226 js.string("${namer.getterPrefix}${field.name}"), 228 js.string("${namer.getterPrefix}${field.name}"),
227 js.number(field.holder.index), 229 js.number(field.holder.index),
228 emitLazyInitializer(field) ]); 230 emitLazyInitializer(field) ]);
229 return new js.ArrayInitializer.from(fieldDescriptors); 231 return new js.ArrayInitializer(fieldDescriptors.toList(growable: false));
230 } 232 }
231 233
232 js.Block emitEagerClassInitializations(List<Library> libraries) { 234 js.Block emitEagerClassInitializations(List<Library> libraries) {
233 js.Statement createInstantiation(Class cls) { 235 js.Statement createInstantiation(Class cls) {
234 return js.js.statement('new #.#()', [cls.holder.name, cls.name]); 236 return js.js.statement('new #.#()', [cls.holder.name, cls.name]);
235 } 237 }
236 238
237 List<js.Statement> instantiations = 239 List<js.Statement> instantiations =
238 libraries.expand((Library library) => library.classes) 240 libraries.expand((Library library) => library.classes)
239 .where((Class cls) => cls.isEager) 241 .where((Class cls) => cls.isEager)
240 .map(createInstantiation) 242 .map(createInstantiation)
241 .toList(growable: false); 243 .toList(growable: false);
242 return new js.Block(instantiations); 244 return new js.Block(instantiations);
243 } 245 }
244 246
245 js.Expression emitLibrary(Library library) { 247 js.Expression emitLibrary(Library library) {
246 Iterable staticDescriptors = library.statics.expand((e) => 248 Iterable staticDescriptors = library.statics.expand((e) =>
247 [ js.string(e.name), js.number(e.holder.index), emitStaticMethod(e) ]); 249 [ js.string(e.name), js.number(e.holder.index), emitStaticMethod(e) ]);
248 Iterable classDescriptors = library.classes.expand((e) => 250 Iterable classDescriptors = library.classes.expand((e) =>
249 [ js.string(e.name), js.number(e.holder.index), emitClass(e) ]); 251 [ js.string(e.name), js.number(e.holder.index), emitClass(e) ]);
250 252
251 js.Expression staticArray = new js.ArrayInitializer.from(staticDescriptors); 253 js.Expression staticArray =
252 js.Expression classArray = new js.ArrayInitializer.from(classDescriptors); 254 new js.ArrayInitializer(staticDescriptors.toList(growable: false));
255 js.Expression classArray =
256 new js.ArrayInitializer(classDescriptors.toList(growable: false));
253 257
254 return new js.ArrayInitializer.from([staticArray, classArray]); 258 return new js.ArrayInitializer([staticArray, classArray]);
255 } 259 }
256 260
257 js.Expression _generateConstructor(Class cls) { 261 js.Expression _generateConstructor(Class cls) {
258 List<String> allFieldNames = <String>[]; 262 List<String> allFieldNames = <String>[];
259 263
260 // If the class is not directly instantiated we only need it for inheritance 264 // If the class is not directly instantiated we only need it for inheritance
261 // or RTI. In either case we don't need its fields. 265 // or RTI. In either case we don't need its fields.
262 if (cls.isDirectlyInstantiated) { 266 if (cls.isDirectlyInstantiated) {
263 Class currentClass = cls; 267 Class currentClass = cls;
264 while (currentClass != null) { 268 while (currentClass != null) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 js.Expression emitClass(Class cls) { 331 js.Expression emitClass(Class cls) {
328 if (cls.isMixinApplication) return emitMixinApplication(cls); 332 if (cls.isMixinApplication) return emitMixinApplication(cls);
329 333
330 List elements = [js.string(cls.superclassName), 334 List elements = [js.string(cls.superclassName),
331 js.number(cls.superclassHolderIndex), 335 js.number(cls.superclassHolderIndex),
332 _generateConstructor(cls)]; 336 _generateConstructor(cls)];
333 Iterable<Method> methods = cls.methods; 337 Iterable<Method> methods = cls.methods;
334 Iterable<Method> gettersSetters = _generateGettersSetters(cls); 338 Iterable<Method> gettersSetters = _generateGettersSetters(cls);
335 Iterable<Method> allMethods = [methods, gettersSetters].expand((x) => x); 339 Iterable<Method> allMethods = [methods, gettersSetters].expand((x) => x);
336 elements.addAll(allMethods.expand((e) => [js.string(e.name), e.code])); 340 elements.addAll(allMethods.expand((e) => [js.string(e.name), e.code]));
337 return unparse(compiler, new js.ArrayInitializer.from(elements)); 341 return unparse(compiler, new js.ArrayInitializer(elements));
338 } 342 }
339 343
340 // This string should be referenced wherever JavaScript code makes assumptions 344 // This string should be referenced wherever JavaScript code makes assumptions
341 // on the mixin format. 345 // on the mixin format.
342 static final String mixinFormatDescription = 346 static final String mixinFormatDescription =
343 "Mixins have no constructor, but a reference to their mixin class."; 347 "Mixins have no constructor, but a reference to their mixin class.";
344 348
345 js.Expression emitMixinApplication(MixinApplication cls) { 349 js.Expression emitMixinApplication(MixinApplication cls) {
346 List elements = [js.string(cls.superclassName), 350 List elements = [js.string(cls.superclassName),
347 js.number(cls.superclassHolderIndex), 351 js.number(cls.superclassHolderIndex),
348 js.string(cls.mixinClass.name), 352 js.string(cls.mixinClass.name),
349 js.number(cls.mixinClass.holder.index)]; 353 js.number(cls.mixinClass.holder.index)];
350 return unparse(compiler, new js.ArrayInitializer.from(elements)); 354 return unparse(compiler, new js.ArrayInitializer(elements));
351 } 355 }
352 356
353 js.Expression emitLazyInitializer(StaticField field) { 357 js.Expression emitLazyInitializer(StaticField field) {
354 assert(field.isLazy); 358 assert(field.isLazy);
355 return unparse(compiler, field.code); 359 return unparse(compiler, field.code);
356 } 360 }
357 361
358 js.Expression emitStaticMethod(StaticMethod method) { 362 js.Expression emitStaticMethod(StaticMethod method) {
359 return unparse(compiler, method.code); 363 return unparse(compiler, method.code);
360 } 364 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 543
540 var end = Date.now(); 544 var end = Date.now();
541 print('Setup: ' + (end - start) + ' ms.'); 545 print('Setup: ' + (end - start) + ' ms.');
542 546
543 #main(); // Start main. 547 #main(); // Start main.
544 548
545 }(Date.now(), #code) 549 }(Date.now(), #code)
546 }"""; 550 }""";
547 551
548 } 552 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/runtime_types.dart ('k') | pkg/compiler/lib/src/js_emitter/old_emitter/class_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698