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

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

Issue 891673003: dart2js: Refactoring, documentation, and a few bugfixes in Namer class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Typo and TODO about clash in named parameters 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 library dart2js.js_emitter.program_builder; 5 library dart2js.js_emitter.program_builder;
6 6
7 import 'js_emitter.dart' show computeMixinClass; 7 import 'js_emitter.dart' show computeMixinClass;
8 import 'model.dart'; 8 import 'model.dart';
9 9
10 import '../common.dart'; 10 import '../common.dart';
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 backend.constants.getStaticNonFinalFieldsForEmission(); 193 backend.constants.getStaticNonFinalFieldsForEmission();
194 return Elements.sortedByPosition(staticNonFinalFields) 194 return Elements.sortedByPosition(staticNonFinalFields)
195 .map(_buildStaticField) 195 .map(_buildStaticField)
196 .toList(growable: false); 196 .toList(growable: false);
197 } 197 }
198 198
199 StaticField _buildStaticField(Element element) { 199 StaticField _buildStaticField(Element element) {
200 JavaScriptConstantCompiler handler = backend.constants; 200 JavaScriptConstantCompiler handler = backend.constants;
201 ConstantValue initialValue = handler.getInitialValueFor(element).value; 201 ConstantValue initialValue = handler.getInitialValueFor(element).value;
202 js.Expression code = _task.emitter.constantReference(initialValue); 202 js.Expression code = _task.emitter.constantReference(initialValue);
203 String name = namer.getNameOfGlobalField(element); 203 String name = namer.globalPropertyName(element);
204 bool isFinal = false; 204 bool isFinal = false;
205 bool isLazy = false; 205 bool isLazy = false;
206 return new StaticField(element, 206 return new StaticField(element,
207 name, _registry.registerHolder(r'$'), code, 207 name, _registry.registerHolder(r'$'), code,
208 isFinal, isLazy); 208 isFinal, isLazy);
209 } 209 }
210 210
211 List<StaticField> _buildStaticLazilyInitializedFields( 211 List<StaticField> _buildStaticLazilyInitializedFields(
212 LibrariesMap librariesMap) { 212 LibrariesMap librariesMap) {
213 // TODO(floitsch): lazy fields should just be in their respective 213 // TODO(floitsch): lazy fields should just be in their respective
(...skipping 11 matching lines...) Expand all
225 .toList(growable: false); 225 .toList(growable: false);
226 } 226 }
227 227
228 StaticField _buildLazyField(Element element) { 228 StaticField _buildLazyField(Element element) {
229 js.Expression code = backend.generatedCode[element]; 229 js.Expression code = backend.generatedCode[element];
230 // The code is null if we ended up not needing the lazily 230 // The code is null if we ended up not needing the lazily
231 // initialized field after all because of constant folding 231 // initialized field after all because of constant folding
232 // before code generation. 232 // before code generation.
233 if (code == null) return null; 233 if (code == null) return null;
234 234
235 String name = namer.getNameOfGlobalField(element); 235 String name = namer.globalPropertyName(element);
236 bool isFinal = element.isFinal; 236 bool isFinal = element.isFinal;
237 bool isLazy = true; 237 bool isLazy = true;
238 return new StaticField(element, 238 return new StaticField(element,
239 name, _registry.registerHolder(r'$'), code, 239 name, _registry.registerHolder(r'$'), code,
240 isFinal, isLazy); 240 isFinal, isLazy);
241 } 241 }
242 242
243 List<Library> _buildLibraries(LibrariesMap librariesMap) { 243 List<Library> _buildLibraries(LibrariesMap librariesMap) {
244 List<Library> libraries = new List<Library>(librariesMap.length); 244 List<Library> libraries = new List<Library>(librariesMap.length);
245 int count = 0; 245 int count = 0;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 typeTests.functionTypeIndex, 379 typeTests.functionTypeIndex,
380 isDirectlyInstantiated: isInstantiated, 380 isDirectlyInstantiated: isInstantiated,
381 onlyForRti: onlyForRti, 381 onlyForRti: onlyForRti,
382 isNative: element.isNative); 382 isNative: element.isNative);
383 } 383 }
384 _classes[element] = result; 384 _classes[element] = result;
385 return result; 385 return result;
386 } 386 }
387 387
388 Method _buildMethod(FunctionElement element, js.Expression code) { 388 Method _buildMethod(FunctionElement element, js.Expression code) {
389 String name = namer.getNameOfInstanceMember(element); 389 String name = namer.instanceMethodName(element);
390 // TODO(floitsch): compute `needsTearOff`. 390 // TODO(floitsch): compute `needsTearOff`.
391 return new Method(element, name, code, needsTearOff: false); 391 return new Method(element, name, code, needsTearOff: false);
392 } 392 }
393 393
394 /// Builds a stub method. 394 /// Builds a stub method.
395 /// 395 ///
396 /// Stub methods may have an element that can be used for code-size 396 /// Stub methods may have an element that can be used for code-size
397 /// attribution. 397 /// attribution.
398 Method _buildStubMethod(String name, js.Expression code, 398 Method _buildStubMethod(String name, js.Expression code,
399 {Element element}) { 399 {Element element}) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 Holder holder = _registry.registerHolder(holderName); 487 Holder holder = _registry.registerHolder(holderName);
488 488
489 List<String> names = backend.oneShotInterceptors.keys.toList()..sort(); 489 List<String> names = backend.oneShotInterceptors.keys.toList()..sort();
490 return names.map((String name) { 490 return names.map((String name) {
491 js.Expression code = stubGenerator.generateOneShotInterceptor(name); 491 js.Expression code = stubGenerator.generateOneShotInterceptor(name);
492 return new StaticStubMethod(name, holder, code, needsTearOff: false); 492 return new StaticStubMethod(name, holder, code, needsTearOff: false);
493 }); 493 });
494 } 494 }
495 495
496 StaticMethod _buildStaticMethod(FunctionElement element) { 496 StaticMethod _buildStaticMethod(FunctionElement element) {
497 String name = namer.getNameOfMember(element); 497 String name = namer.getNameOfMethod(element);
498 String holder = namer.globalObjectFor(element); 498 String holder = namer.globalObjectFor(element);
499 js.Expression code = backend.generatedCode[element]; 499 js.Expression code = backend.generatedCode[element];
500 bool needsTearOff = 500 bool needsTearOff =
501 universe.staticFunctionsNeedingGetter.contains(element); 501 universe.staticFunctionsNeedingGetter.contains(element);
502 // TODO(floitsch): add tear-off name: namer.getStaticClosureName(element). 502 // TODO(floitsch): add tear-off name: namer.getStaticClosureName(element).
503 return new StaticMethod(element, 503 return new StaticMethod(element,
504 name, _registry.registerHolder(holder), code, 504 name, _registry.registerHolder(holder), code,
505 needsTearOff: needsTearOff); 505 needsTearOff: needsTearOff);
506 } 506 }
507 507
508 void _registerConstants(OutputUnit outputUnit, 508 void _registerConstants(OutputUnit outputUnit,
509 Iterable<ConstantValue> constantValues) { 509 Iterable<ConstantValue> constantValues) {
510 // `constantValues` is null if an outputUnit doesn't contain any constants. 510 // `constantValues` is null if an outputUnit doesn't contain any constants.
511 if (constantValues == null) return; 511 if (constantValues == null) return;
512 for (ConstantValue constantValue in constantValues) { 512 for (ConstantValue constantValue in constantValues) {
513 _registry.registerConstant(outputUnit, constantValue); 513 _registry.registerConstant(outputUnit, constantValue);
514 assert(!_constants.containsKey(constantValue)); 514 assert(!_constants.containsKey(constantValue));
515 String name = namer.constantName(constantValue); 515 String name = namer.constantName(constantValue);
516 String constantObject = namer.globalObjectForConstant(constantValue); 516 String constantObject = namer.globalObjectForConstant(constantValue);
517 Holder holder = _registry.registerHolder(constantObject); 517 Holder holder = _registry.registerHolder(constantObject);
518 Constant constant = new Constant(name, holder, constantValue); 518 Constant constant = new Constant(name, holder, constantValue);
519 _constants[constantValue] = constant; 519 _constants[constantValue] = constant;
520 } 520 }
521 } 521 }
522 } 522 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698