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

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

Issue 917083003: Revert "dart2js: Refactoring, documentation, and a few bugfixes in Namer class." (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 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 backend.constants.getStaticNonFinalFieldsForEmission(); 203 backend.constants.getStaticNonFinalFieldsForEmission();
204 return Elements.sortedByPosition(staticNonFinalFields) 204 return Elements.sortedByPosition(staticNonFinalFields)
205 .map(_buildStaticField) 205 .map(_buildStaticField)
206 .toList(growable: false); 206 .toList(growable: false);
207 } 207 }
208 208
209 StaticField _buildStaticField(Element element) { 209 StaticField _buildStaticField(Element element) {
210 JavaScriptConstantCompiler handler = backend.constants; 210 JavaScriptConstantCompiler handler = backend.constants;
211 ConstantValue initialValue = handler.getInitialValueFor(element).value; 211 ConstantValue initialValue = handler.getInitialValueFor(element).value;
212 js.Expression code = _task.emitter.constantReference(initialValue); 212 js.Expression code = _task.emitter.constantReference(initialValue);
213 String name = namer.globalPropertyName(element); 213 String name = namer.getNameOfGlobalField(element);
214 bool isFinal = false; 214 bool isFinal = false;
215 bool isLazy = false; 215 bool isLazy = false;
216 return new StaticField(element, 216 return new StaticField(element,
217 name, _registry.registerHolder(r'$'), code, 217 name, _registry.registerHolder(r'$'), code,
218 isFinal, isLazy); 218 isFinal, isLazy);
219 } 219 }
220 220
221 List<StaticField> _buildStaticLazilyInitializedFields( 221 List<StaticField> _buildStaticLazilyInitializedFields(
222 LibrariesMap librariesMap) { 222 LibrariesMap librariesMap) {
223 // TODO(floitsch): lazy fields should just be in their respective 223 // TODO(floitsch): lazy fields should just be in their respective
(...skipping 11 matching lines...) Expand all
235 .toList(growable: false); 235 .toList(growable: false);
236 } 236 }
237 237
238 StaticField _buildLazyField(Element element) { 238 StaticField _buildLazyField(Element element) {
239 js.Expression code = backend.generatedCode[element]; 239 js.Expression code = backend.generatedCode[element];
240 // The code is null if we ended up not needing the lazily 240 // The code is null if we ended up not needing the lazily
241 // initialized field after all because of constant folding 241 // initialized field after all because of constant folding
242 // before code generation. 242 // before code generation.
243 if (code == null) return null; 243 if (code == null) return null;
244 244
245 String name = namer.globalPropertyName(element); 245 String name = namer.getNameOfGlobalField(element);
246 bool isFinal = element.isFinal; 246 bool isFinal = element.isFinal;
247 bool isLazy = true; 247 bool isLazy = true;
248 return new StaticField(element, 248 return new StaticField(element,
249 name, _registry.registerHolder(r'$'), code, 249 name, _registry.registerHolder(r'$'), code,
250 isFinal, isLazy); 250 isFinal, isLazy);
251 } 251 }
252 252
253 List<Library> _buildLibraries(LibrariesMap librariesMap) { 253 List<Library> _buildLibraries(LibrariesMap librariesMap) {
254 List<Library> libraries = new List<Library>(librariesMap.length); 254 List<Library> libraries = new List<Library>(librariesMap.length);
255 int count = 0; 255 int count = 0;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 staticFieldsForReflection); 288 staticFieldsForReflection);
289 } 289 }
290 290
291 /// HACK for Incremental Compilation. 291 /// HACK for Incremental Compilation.
292 /// 292 ///
293 /// Returns a class that contains the fields of a class. 293 /// Returns a class that contains the fields of a class.
294 Class buildFieldsHackForIncrementalCompilation(ClassElement element) { 294 Class buildFieldsHackForIncrementalCompilation(ClassElement element) {
295 assert(_compiler.hasIncrementalSupport); 295 assert(_compiler.hasIncrementalSupport);
296 296
297 List<Field> instanceFields = _buildFields(element, false); 297 List<Field> instanceFields = _buildFields(element, false);
298 String name = namer.className(element); 298 String name = namer.getNameOfClass(element);
299 299
300 return new Class( 300 return new Class(
301 element, name, null, [], instanceFields, [], [], [], [], [], null, 301 element, name, null, [], instanceFields, [], [], [], [], [], null,
302 isDirectlyInstantiated: true, 302 isDirectlyInstantiated: true,
303 onlyForRti: false, 303 onlyForRti: false,
304 isNative: element.isNative); 304 isNative: element.isNative);
305 } 305 }
306 306
307 Class _buildClass(ClassElement element) { 307 Class _buildClass(ClassElement element) {
308 bool onlyForRti = _task.typeTestRegistry.rtiNeededClasses.contains(element); 308 bool onlyForRti = _task.typeTestRegistry.rtiNeededClasses.contains(element);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 TypeTestProperties typeTests = 369 TypeTestProperties typeTests =
370 runtimeTypeGenerator.generateIsTests( 370 runtimeTypeGenerator.generateIsTests(
371 element, 371 element,
372 storeFunctionTypeInMetadata: _storeFunctionTypesInMetadata); 372 storeFunctionTypeInMetadata: _storeFunctionTypesInMetadata);
373 373
374 List<StubMethod> isChecks = <StubMethod>[]; 374 List<StubMethod> isChecks = <StubMethod>[];
375 typeTests.properties.forEach((String name, js.Node code) { 375 typeTests.properties.forEach((String name, js.Node code) {
376 isChecks.add(_buildStubMethod(name, code)); 376 isChecks.add(_buildStubMethod(name, code));
377 }); 377 });
378 378
379 String name = namer.className(element); 379 String name = namer.getNameOfClass(element);
380 String holderName = namer.globalObjectFor(element); 380 String holderName = namer.globalObjectFor(element);
381 Holder holder = _registry.registerHolder(holderName); 381 Holder holder = _registry.registerHolder(holderName);
382 bool isInstantiated = 382 bool isInstantiated =
383 _compiler.codegenWorld.directlyInstantiatedClasses.contains(element); 383 _compiler.codegenWorld.directlyInstantiatedClasses.contains(element);
384 384
385 Class result; 385 Class result;
386 if (element.isMixinApplication && !onlyForRti) { 386 if (element.isMixinApplication && !onlyForRti) {
387 assert(!element.isNative); 387 assert(!element.isNative);
388 assert(methods.isEmpty); 388 assert(methods.isEmpty);
389 389
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 Method buildMethodHackForIncrementalCompilation(FunctionElement element) { 434 Method buildMethodHackForIncrementalCompilation(FunctionElement element) {
435 assert(_compiler.hasIncrementalSupport); 435 assert(_compiler.hasIncrementalSupport);
436 if (element.isInstanceMember) { 436 if (element.isInstanceMember) {
437 return _buildMethod(element); 437 return _buildMethod(element);
438 } else { 438 } else {
439 return _buildStaticMethod(element); 439 return _buildStaticMethod(element);
440 } 440 }
441 } 441 }
442 442
443 DartMethod _buildMethod(FunctionElement element) { 443 DartMethod _buildMethod(FunctionElement element) {
444 String name = namer.methodPropertyName(element); 444 String name = namer.getNameOfInstanceMember(element);
445 js.Expression code = backend.generatedCode[element]; 445 js.Expression code = backend.generatedCode[element];
446 446
447 // TODO(kasperl): Figure out under which conditions code is null. 447 // TODO(kasperl): Figure out under which conditions code is null.
448 if (code == null) return null; 448 if (code == null) return null;
449 449
450 bool canTearOff = false; 450 bool canTearOff = false;
451 String tearOffName; 451 String tearOffName;
452 bool isClosure = false; 452 bool isClosure = false;
453 bool isNotApplyTarget = !element.isFunction || element.isAccessor; 453 bool isNotApplyTarget = !element.isFunction || element.isAccessor;
454 454
455 bool canBeReflected = _methodCanBeReflected(element); 455 bool canBeReflected = _methodCanBeReflected(element);
456 bool needsStubs = _methodNeedsStubs(element); 456 bool needsStubs = _methodNeedsStubs(element);
457 bool canBeApplied = _methodCanBeApplied(element); 457 bool canBeApplied = _methodCanBeApplied(element);
458 458
459 String aliasName = backend.isAliasedSuperMember(element) 459 String aliasName = backend.isAliasedSuperMember(element)
460 ? namer.aliasedSuperMemberPropertyName(element) 460 ? namer.getNameOfAliasedSuperMember(element)
461 : null; 461 : null;
462 462
463 if (isNotApplyTarget) { 463 if (isNotApplyTarget) {
464 canTearOff = false; 464 canTearOff = false;
465 } else { 465 } else {
466 if (element.enclosingClass.isClosure) { 466 if (element.enclosingClass.isClosure) {
467 canTearOff = false; 467 canTearOff = false;
468 isClosure = true; 468 isClosure = true;
469 } else { 469 } else {
470 // Careful with operators. 470 // Careful with operators.
471 canTearOff = universe.hasInvokedGetter(element, _compiler.world) || 471 canTearOff = universe.hasInvokedGetter(element, _compiler.world) ||
472 (canBeReflected && !element.isOperator); 472 (canBeReflected && !element.isOperator);
473 assert(canTearOff || 473 assert(canTearOff ||
474 !universe.methodsNeedingSuperGetter.contains(element)); 474 !universe.methodsNeedingSuperGetter.contains(element));
475 tearOffName = namer.getterForElement(element); 475 tearOffName = namer.getterName(element);
476 } 476 }
477 } 477 }
478 478
479 if (canTearOff) { 479 if (canTearOff) {
480 assert(invariant(element, !element.isGenerativeConstructor)); 480 assert(invariant(element, !element.isGenerativeConstructor));
481 assert(invariant(element, !element.isGenerativeConstructorBody)); 481 assert(invariant(element, !element.isGenerativeConstructorBody));
482 assert(invariant(element, !element.isConstructor)); 482 assert(invariant(element, !element.isConstructor));
483 } 483 }
484 484
485 String callName = null; 485 String callName = null;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 Holder holder = _registry.registerHolder(holderName); 611 Holder holder = _registry.registerHolder(holderName);
612 612
613 List<String> names = backend.oneShotInterceptors.keys.toList()..sort(); 613 List<String> names = backend.oneShotInterceptors.keys.toList()..sort();
614 return names.map((String name) { 614 return names.map((String name) {
615 js.Expression code = stubGenerator.generateOneShotInterceptor(name); 615 js.Expression code = stubGenerator.generateOneShotInterceptor(name);
616 return new StaticStubMethod(name, holder, code); 616 return new StaticStubMethod(name, holder, code);
617 }); 617 });
618 } 618 }
619 619
620 StaticDartMethod _buildStaticMethod(FunctionElement element) { 620 StaticDartMethod _buildStaticMethod(FunctionElement element) {
621 String name = namer.methodPropertyName(element); 621 String name = namer.getNameOfMember(element);
622 String holder = namer.globalObjectFor(element); 622 String holder = namer.globalObjectFor(element);
623 js.Expression code = backend.generatedCode[element]; 623 js.Expression code = backend.generatedCode[element];
624 624
625 bool isApplyTarget = !element.isConstructor && !element.isAccessor; 625 bool isApplyTarget = !element.isConstructor && !element.isAccessor;
626 bool canBeApplied = _methodCanBeApplied(element); 626 bool canBeApplied = _methodCanBeApplied(element);
627 bool canBeReflected = _methodCanBeReflected(element); 627 bool canBeReflected = _methodCanBeReflected(element);
628 628
629 bool needsTearOff = isApplyTarget && 629 bool needsTearOff = isApplyTarget &&
630 (canBeReflected || 630 (canBeReflected ||
631 universe.staticFunctionsNeedingGetter.contains(element)); 631 universe.staticFunctionsNeedingGetter.contains(element));
632 632
633 String tearOffName = 633 String tearOffName =
634 needsTearOff ? namer.staticClosureName(element) : null; 634 needsTearOff ? namer.getStaticClosureName(element) : null;
635 635
636 String callName = null; 636 String callName = null;
637 if (needsTearOff) { 637 if (needsTearOff) {
638 Selector callSelector = 638 Selector callSelector =
639 new Selector.fromElement(element).toCallSelector(); 639 new Selector.fromElement(element).toCallSelector();
640 callName = namer.invocationName(callSelector); 640 callName = namer.invocationName(callSelector);
641 } 641 }
642 642
643 return new StaticDartMethod(element, 643 return new StaticDartMethod(element,
644 name, _registry.registerHolder(holder), code, 644 name, _registry.registerHolder(holder), code,
(...skipping 13 matching lines...) Expand all
658 _registry.registerConstant(outputUnit, constantValue); 658 _registry.registerConstant(outputUnit, constantValue);
659 assert(!_constants.containsKey(constantValue)); 659 assert(!_constants.containsKey(constantValue));
660 String name = namer.constantName(constantValue); 660 String name = namer.constantName(constantValue);
661 String constantObject = namer.globalObjectForConstant(constantValue); 661 String constantObject = namer.globalObjectForConstant(constantValue);
662 Holder holder = _registry.registerHolder(constantObject); 662 Holder holder = _registry.registerHolder(constantObject);
663 Constant constant = new Constant(name, holder, constantValue); 663 Constant constant = new Constant(name, holder, constantValue);
664 _constants[constantValue] = constant; 664 _constants[constantValue] = constant;
665 } 665 }
666 } 666 }
667 } 667 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698