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

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

Issue 906273002: 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 backend.constants.getStaticNonFinalFieldsForEmission(); 195 backend.constants.getStaticNonFinalFieldsForEmission();
196 return Elements.sortedByPosition(staticNonFinalFields) 196 return Elements.sortedByPosition(staticNonFinalFields)
197 .map(_buildStaticField) 197 .map(_buildStaticField)
198 .toList(growable: false); 198 .toList(growable: false);
199 } 199 }
200 200
201 StaticField _buildStaticField(Element element) { 201 StaticField _buildStaticField(Element element) {
202 JavaScriptConstantCompiler handler = backend.constants; 202 JavaScriptConstantCompiler handler = backend.constants;
203 ConstantValue initialValue = handler.getInitialValueFor(element).value; 203 ConstantValue initialValue = handler.getInitialValueFor(element).value;
204 js.Expression code = _task.emitter.constantReference(initialValue); 204 js.Expression code = _task.emitter.constantReference(initialValue);
205 String name = namer.globalPropertyName(element); 205 String name = namer.getNameOfGlobalField(element);
206 bool isFinal = false; 206 bool isFinal = false;
207 bool isLazy = false; 207 bool isLazy = false;
208 return new StaticField(element, 208 return new StaticField(element,
209 name, _registry.registerHolder(r'$'), code, 209 name, _registry.registerHolder(r'$'), code,
210 isFinal, isLazy); 210 isFinal, isLazy);
211 } 211 }
212 212
213 List<StaticField> _buildStaticLazilyInitializedFields( 213 List<StaticField> _buildStaticLazilyInitializedFields(
214 LibrariesMap librariesMap) { 214 LibrariesMap librariesMap) {
215 // TODO(floitsch): lazy fields should just be in their respective 215 // TODO(floitsch): lazy fields should just be in their respective
(...skipping 11 matching lines...) Expand all
227 .toList(growable: false); 227 .toList(growable: false);
228 } 228 }
229 229
230 StaticField _buildLazyField(Element element) { 230 StaticField _buildLazyField(Element element) {
231 js.Expression code = backend.generatedCode[element]; 231 js.Expression code = backend.generatedCode[element];
232 // The code is null if we ended up not needing the lazily 232 // The code is null if we ended up not needing the lazily
233 // initialized field after all because of constant folding 233 // initialized field after all because of constant folding
234 // before code generation. 234 // before code generation.
235 if (code == null) return null; 235 if (code == null) return null;
236 236
237 String name = namer.globalPropertyName(element); 237 String name = namer.getNameOfGlobalField(element);
238 bool isFinal = element.isFinal; 238 bool isFinal = element.isFinal;
239 bool isLazy = true; 239 bool isLazy = true;
240 return new StaticField(element, 240 return new StaticField(element,
241 name, _registry.registerHolder(r'$'), code, 241 name, _registry.registerHolder(r'$'), code,
242 isFinal, isLazy); 242 isFinal, isLazy);
243 } 243 }
244 244
245 List<Library> _buildLibraries(LibrariesMap librariesMap) { 245 List<Library> _buildLibraries(LibrariesMap librariesMap) {
246 List<Library> libraries = new List<Library>(librariesMap.length); 246 List<Library> libraries = new List<Library>(librariesMap.length);
247 int count = 0; 247 int count = 0;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 staticFieldsForReflection); 280 staticFieldsForReflection);
281 } 281 }
282 282
283 /// HACK for Incremental Compilation. 283 /// HACK for Incremental Compilation.
284 /// 284 ///
285 /// Returns a class that contains the fields of a class. 285 /// Returns a class that contains the fields of a class.
286 Class buildFieldsHackForIncrementalCompilation(ClassElement element) { 286 Class buildFieldsHackForIncrementalCompilation(ClassElement element) {
287 assert(_compiler.hasIncrementalSupport); 287 assert(_compiler.hasIncrementalSupport);
288 288
289 List<Field> instanceFields = _buildFields(element, false); 289 List<Field> instanceFields = _buildFields(element, false);
290 String name = namer.className(element); 290 String name = namer.getNameOfClass(element);
291 291
292 return new Class( 292 return new Class(
293 element, name, null, [], instanceFields, [], [], [], [], null, 293 element, name, null, [], instanceFields, [], [], [], [], null,
294 isDirectlyInstantiated: true, 294 isDirectlyInstantiated: true,
295 onlyForRti: false, 295 onlyForRti: false,
296 isNative: element.isNative); 296 isNative: element.isNative);
297 } 297 }
298 298
299 Class _buildClass(ClassElement element) { 299 Class _buildClass(ClassElement element) {
300 bool onlyForRti = _task.typeTestRegistry.rtiNeededClasses.contains(element); 300 bool onlyForRti = _task.typeTestRegistry.rtiNeededClasses.contains(element);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 TypeTestProperties typeTests = 358 TypeTestProperties typeTests =
359 generator.generateIsTests( 359 generator.generateIsTests(
360 element, 360 element,
361 storeFunctionTypeInMetadata: _storeFunctionTypesInMetadata); 361 storeFunctionTypeInMetadata: _storeFunctionTypesInMetadata);
362 362
363 List<StubMethod> isChecks = <StubMethod>[]; 363 List<StubMethod> isChecks = <StubMethod>[];
364 typeTests.properties.forEach((String name, js.Node code) { 364 typeTests.properties.forEach((String name, js.Node code) {
365 isChecks.add(_buildStubMethod(name, code)); 365 isChecks.add(_buildStubMethod(name, code));
366 }); 366 });
367 367
368 String name = namer.className(element); 368 String name = namer.getNameOfClass(element);
369 String holderName = namer.globalObjectFor(element); 369 String holderName = namer.globalObjectFor(element);
370 Holder holder = _registry.registerHolder(holderName); 370 Holder holder = _registry.registerHolder(holderName);
371 bool isInstantiated = 371 bool isInstantiated =
372 _compiler.codegenWorld.directlyInstantiatedClasses.contains(element); 372 _compiler.codegenWorld.directlyInstantiatedClasses.contains(element);
373 373
374 Class result; 374 Class result;
375 if (element.isMixinApplication && !onlyForRti) { 375 if (element.isMixinApplication && !onlyForRti) {
376 assert(!element.isNative); 376 assert(!element.isNative);
377 assert(methods.isEmpty); 377 assert(methods.isEmpty);
378 378
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 Method buildMethodHackForIncrementalCompilation(FunctionElement element) { 421 Method buildMethodHackForIncrementalCompilation(FunctionElement element) {
422 assert(_compiler.hasIncrementalSupport); 422 assert(_compiler.hasIncrementalSupport);
423 if (element.isInstanceMember) { 423 if (element.isInstanceMember) {
424 return _buildMethod(element); 424 return _buildMethod(element);
425 } else { 425 } else {
426 return _buildStaticMethod(element); 426 return _buildStaticMethod(element);
427 } 427 }
428 } 428 }
429 429
430 DartMethod _buildMethod(FunctionElement element) { 430 DartMethod _buildMethod(FunctionElement element) {
431 String name = namer.methodPropertyName(element); 431 String name = namer.getNameOfInstanceMember(element);
432 js.Expression code = backend.generatedCode[element]; 432 js.Expression code = backend.generatedCode[element];
433 433
434 // TODO(kasperl): Figure out under which conditions code is null. 434 // TODO(kasperl): Figure out under which conditions code is null.
435 if (code == null) return null; 435 if (code == null) return null;
436 436
437 bool canTearOff = false; 437 bool canTearOff = false;
438 String tearOffName; 438 String tearOffName;
439 bool isClosure = false; 439 bool isClosure = false;
440 bool isNotApplyTarget = !element.isFunction || element.isAccessor; 440 bool isNotApplyTarget = !element.isFunction || element.isAccessor;
441 441
442 bool canBeReflected = _methodCanBeReflected(element); 442 bool canBeReflected = _methodCanBeReflected(element);
443 bool needsStubs = _methodNeedsStubs(element); 443 bool needsStubs = _methodNeedsStubs(element);
444 bool canBeApplied = _methodCanBeApplied(element); 444 bool canBeApplied = _methodCanBeApplied(element);
445 445
446 String aliasName = backend.isAliasedSuperMember(element) 446 String aliasName = backend.isAliasedSuperMember(element)
447 ? namer.aliasedSuperMemberPropertyName(element) 447 ? namer.getNameOfAliasedSuperMember(element)
448 : null; 448 : null;
449 449
450 if (isNotApplyTarget) { 450 if (isNotApplyTarget) {
451 canTearOff = false; 451 canTearOff = false;
452 } else { 452 } else {
453 if (element.enclosingClass.isClosure) { 453 if (element.enclosingClass.isClosure) {
454 canTearOff = false; 454 canTearOff = false;
455 isClosure = true; 455 isClosure = true;
456 } else { 456 } else {
457 // Careful with operators. 457 // Careful with operators.
458 canTearOff = universe.hasInvokedGetter(element, _compiler.world) || 458 canTearOff = universe.hasInvokedGetter(element, _compiler.world) ||
459 (canBeReflected && !element.isOperator); 459 (canBeReflected && !element.isOperator);
460 assert(canTearOff || 460 assert(canTearOff ||
461 !universe.methodsNeedingSuperGetter.contains(element)); 461 !universe.methodsNeedingSuperGetter.contains(element));
462 tearOffName = namer.getterForElement(element); 462 tearOffName = namer.getterName(element);
463 } 463 }
464 } 464 }
465 465
466 if (canTearOff) { 466 if (canTearOff) {
467 assert(invariant(element, !element.isGenerativeConstructor)); 467 assert(invariant(element, !element.isGenerativeConstructor));
468 assert(invariant(element, !element.isGenerativeConstructorBody)); 468 assert(invariant(element, !element.isGenerativeConstructorBody));
469 assert(invariant(element, !element.isConstructor)); 469 assert(invariant(element, !element.isConstructor));
470 } 470 }
471 471
472 String callName = null; 472 String callName = null;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 Holder holder = _registry.registerHolder(holderName); 598 Holder holder = _registry.registerHolder(holderName);
599 599
600 List<String> names = backend.oneShotInterceptors.keys.toList()..sort(); 600 List<String> names = backend.oneShotInterceptors.keys.toList()..sort();
601 return names.map((String name) { 601 return names.map((String name) {
602 js.Expression code = stubGenerator.generateOneShotInterceptor(name); 602 js.Expression code = stubGenerator.generateOneShotInterceptor(name);
603 return new StaticStubMethod(name, holder, code); 603 return new StaticStubMethod(name, holder, code);
604 }); 604 });
605 } 605 }
606 606
607 StaticDartMethod _buildStaticMethod(FunctionElement element) { 607 StaticDartMethod _buildStaticMethod(FunctionElement element) {
608 String name = namer.methodPropertyName(element); 608 String name = namer.getNameOfMember(element);
609 String holder = namer.globalObjectFor(element); 609 String holder = namer.globalObjectFor(element);
610 js.Expression code = backend.generatedCode[element]; 610 js.Expression code = backend.generatedCode[element];
611 611
612 bool isApplyTarget = !element.isConstructor && !element.isAccessor; 612 bool isApplyTarget = !element.isConstructor && !element.isAccessor;
613 bool canBeApplied = _methodCanBeApplied(element); 613 bool canBeApplied = _methodCanBeApplied(element);
614 bool canBeReflected = _methodCanBeReflected(element); 614 bool canBeReflected = _methodCanBeReflected(element);
615 615
616 bool needsTearOff = isApplyTarget && 616 bool needsTearOff = isApplyTarget &&
617 (canBeReflected || 617 (canBeReflected ||
618 universe.staticFunctionsNeedingGetter.contains(element)); 618 universe.staticFunctionsNeedingGetter.contains(element));
619 619
620 String tearOffName = 620 String tearOffName =
621 needsTearOff ? namer.staticClosureName(element) : null; 621 needsTearOff ? namer.getStaticClosureName(element) : null;
622 622
623 String callName = null; 623 String callName = null;
624 if (needsTearOff) { 624 if (needsTearOff) {
625 Selector callSelector = 625 Selector callSelector =
626 new Selector.fromElement(element).toCallSelector(); 626 new Selector.fromElement(element).toCallSelector();
627 callName = namer.invocationName(callSelector); 627 callName = namer.invocationName(callSelector);
628 } 628 }
629 629
630 return new StaticDartMethod(element, 630 return new StaticDartMethod(element,
631 name, _registry.registerHolder(holder), code, 631 name, _registry.registerHolder(holder), code,
(...skipping 13 matching lines...) Expand all
645 _registry.registerConstant(outputUnit, constantValue); 645 _registry.registerConstant(outputUnit, constantValue);
646 assert(!_constants.containsKey(constantValue)); 646 assert(!_constants.containsKey(constantValue));
647 String name = namer.constantName(constantValue); 647 String name = namer.constantName(constantValue);
648 String constantObject = namer.globalObjectForConstant(constantValue); 648 String constantObject = namer.globalObjectForConstant(constantValue);
649 Holder holder = _registry.registerHolder(constantObject); 649 Holder holder = _registry.registerHolder(constantObject);
650 Constant constant = new Constant(name, holder, constantValue); 650 Constant constant = new Constant(name, holder, constantValue);
651 _constants[constantValue] = constant; 651 _constants[constantValue] = constant;
652 } 652 }
653 } 653 }
654 } 654 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_emitter/parameter_stub_generator.dart ('k') | pkg/compiler/lib/src/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698