Chromium Code Reviews| OLD | NEW |
|---|---|
| 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, Emitter; | 7 import '../js_emitter.dart' show computeMixinClass, Emitter; |
| 8 import '../model.dart'; | 8 import '../model.dart'; |
| 9 | 9 |
| 10 import '../../common.dart'; | 10 import '../../common.dart'; |
| 11 import '../../closure.dart' show ClosureFieldElement; | |
| 11 import '../../js/js.dart' as js; | 12 import '../../js/js.dart' as js; |
| 12 | 13 |
| 13 import '../../js_backend/js_backend.dart' show | 14 import '../../js_backend/js_backend.dart' show |
| 14 Namer, | 15 Namer, |
| 15 JavaScriptBackend, | 16 JavaScriptBackend, |
| 16 JavaScriptConstantCompiler; | 17 JavaScriptConstantCompiler; |
| 17 | 18 |
| 18 import '../js_emitter.dart' show | 19 import '../js_emitter.dart' show |
| 19 ClassStubGenerator, | 20 ClassStubGenerator, |
| 20 CodeEmitterTask, | 21 CodeEmitterTask, |
| 21 InterceptorStubGenerator, | 22 InterceptorStubGenerator, |
| 22 MainCallStubGenerator, | 23 MainCallStubGenerator, |
| 23 ParameterStubGenerator, | 24 ParameterStubGenerator, |
| 24 RuntimeTypeGenerator, | 25 RuntimeTypeGenerator, |
| 25 TypeTestProperties; | 26 TypeTestProperties; |
| 26 | 27 |
| 27 import '../../elements/elements.dart' show ParameterElement, MethodElement; | 28 import '../../elements/elements.dart' show |
| 29 ClosureFieldElement, | |
|
herhut
2015/07/09 13:28:39
I don't think this exists in elements.dart?
floitsch
2015/07/09 13:50:24
Done.
| |
| 30 FieldElement, | |
| 31 ParameterElement, | |
| 32 MethodElement; | |
| 28 | 33 |
| 29 import '../../universe/universe.dart' show Universe, TypeMaskSet; | 34 import '../../universe/universe.dart' show Universe, TypeMaskSet; |
| 30 import '../../deferred_load.dart' show DeferredLoadTask, OutputUnit; | 35 import '../../deferred_load.dart' show DeferredLoadTask, OutputUnit; |
| 31 | 36 |
| 32 part 'collector.dart'; | 37 part 'collector.dart'; |
| 33 part 'registry.dart'; | 38 part 'registry.dart'; |
| 39 part 'field_visitor.dart'; | |
| 34 | 40 |
| 35 /// Builds a self-contained representation of the program that can then be | 41 /// Builds a self-contained representation of the program that can then be |
| 36 /// emitted more easily by the individual emitters. | 42 /// emitted more easily by the individual emitters. |
| 37 class ProgramBuilder { | 43 class ProgramBuilder { |
| 38 final Compiler _compiler; | 44 final Compiler _compiler; |
| 39 final Namer namer; | 45 final Namer namer; |
| 40 final CodeEmitterTask _task; | 46 final CodeEmitterTask _task; |
| 41 | 47 |
| 42 /// Contains the collected information the program builder used to build | 48 /// Contains the collected information the program builder used to build |
| 43 /// the model. | 49 /// the model. |
| 44 // The collector will be filled on the first call to `buildProgram`. | 50 // The collector will be filled on the first call to `buildProgram`. |
| 45 // It is stored and publicly exposed for backwards compatibility. | 51 // It is stored and publicly exposed for backwards compatibility. New code |
| 52 // (and in particular new emitters) should not use it. | |
| 46 final Collector collector; | 53 final Collector collector; |
| 47 | 54 |
| 48 final Registry _registry; | 55 final Registry _registry; |
| 49 | 56 |
| 50 /// True if the program should store function types in the metadata. | 57 /// True if the program should store function types in the metadata. |
| 51 bool _storeFunctionTypesInMetadata = false; | 58 bool _storeFunctionTypesInMetadata = false; |
| 52 | 59 |
| 53 ProgramBuilder(Compiler compiler, | 60 ProgramBuilder(Compiler compiler, |
| 54 Namer namer, | 61 Namer namer, |
| 55 this._task, | 62 this._task, |
| 56 Emitter emitter, | 63 Emitter emitter, |
| 57 Emitter oldEmitter, | |
| 58 Set<ClassElement> rtiNeededClasses) | 64 Set<ClassElement> rtiNeededClasses) |
| 59 : this._compiler = compiler, | 65 : this._compiler = compiler, |
| 60 this.namer = namer, | 66 this.namer = namer, |
| 61 this.collector = new Collector( | 67 this.collector = |
| 62 compiler, namer, rtiNeededClasses, emitter, oldEmitter), | 68 new Collector(compiler, namer, rtiNeededClasses, emitter), |
| 63 this._registry = new Registry(compiler); | 69 this._registry = new Registry(compiler); |
| 64 | 70 |
| 65 JavaScriptBackend get backend => _compiler.backend; | 71 JavaScriptBackend get backend => _compiler.backend; |
| 66 Universe get universe => _compiler.codegenWorld; | 72 Universe get universe => _compiler.codegenWorld; |
| 67 | 73 |
| 68 /// Mapping from [ClassElement] to constructed [Class]. We need this to | 74 /// Mapping from [ClassElement] to constructed [Class]. We need this to |
| 69 /// update the superclass in the [Class]. | 75 /// update the superclass in the [Class]. |
| 70 final Map<ClassElement, Class> _classes = <ClassElement, Class>{}; | 76 final Map<ClassElement, Class> _classes = <ClassElement, Class>{}; |
| 71 | 77 |
| 72 /// Mapping from [OutputUnit] to constructed [Fragment]. We need this to | 78 /// Mapping from [OutputUnit] to constructed [Fragment]. We need this to |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 List<js.Name> names = specializedGetInterceptors.keys.toList()..sort(); | 660 List<js.Name> names = specializedGetInterceptors.keys.toList()..sort(); |
| 655 return names.map((js.Name name) { | 661 return names.map((js.Name name) { |
| 656 Set<ClassElement> classes = specializedGetInterceptors[name]; | 662 Set<ClassElement> classes = specializedGetInterceptors[name]; |
| 657 js.Expression code = stubGenerator.generateGetInterceptorMethod(classes); | 663 js.Expression code = stubGenerator.generateGetInterceptorMethod(classes); |
| 658 return new StaticStubMethod(name, holder, code); | 664 return new StaticStubMethod(name, holder, code); |
| 659 }); | 665 }); |
| 660 } | 666 } |
| 661 | 667 |
| 662 List<Field> _buildFields(Element holder, bool visitStatics) { | 668 List<Field> _buildFields(Element holder, bool visitStatics) { |
| 663 List<Field> fields = <Field>[]; | 669 List<Field> fields = <Field>[]; |
| 664 _task.oldEmitter.classEmitter.visitFields( | 670 new FieldVisitor(_compiler, namer).visitFields( |
| 665 holder, visitStatics, (VariableElement field, | 671 holder, visitStatics, (VariableElement field, |
| 666 js.Name name, | 672 js.Name name, |
| 667 js.Name accessorName, | 673 js.Name accessorName, |
| 668 bool needsGetter, | 674 bool needsGetter, |
| 669 bool needsSetter, | 675 bool needsSetter, |
| 670 bool needsCheckedSetter) { | 676 bool needsCheckedSetter) { |
| 671 assert(invariant(field, field.isDeclaration)); | 677 assert(invariant(field, field.isDeclaration)); |
| 672 | 678 |
| 673 int getterFlags = 0; | 679 int getterFlags = 0; |
| 674 if (needsGetter) { | 680 if (needsGetter) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 785 _registry.registerConstant(outputUnit, constantValue); | 791 _registry.registerConstant(outputUnit, constantValue); |
| 786 assert(!_constants.containsKey(constantValue)); | 792 assert(!_constants.containsKey(constantValue)); |
| 787 js.Name name = namer.constantName(constantValue); | 793 js.Name name = namer.constantName(constantValue); |
| 788 String constantObject = namer.globalObjectForConstant(constantValue); | 794 String constantObject = namer.globalObjectForConstant(constantValue); |
| 789 Holder holder = _registry.registerHolder(constantObject); | 795 Holder holder = _registry.registerHolder(constantObject); |
| 790 Constant constant = new Constant(name, holder, constantValue); | 796 Constant constant = new Constant(name, holder, constantValue); |
| 791 _constants[constantValue] = constant; | 797 _constants[constantValue] = constant; |
| 792 } | 798 } |
| 793 } | 799 } |
| 794 } | 800 } |
| OLD | NEW |