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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_emitter/program_builder.dart

Issue 642813005: dart2js: Emit constants in new emitter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove code that isn't yet used. Created 6 years, 2 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 'model.dart'; 7 import 'model.dart';
8 import '../common.dart'; 8 import '../common.dart';
9 import '../js/js.dart' as js; 9 import '../js/js.dart' as js;
10 10
(...skipping 24 matching lines...) Expand all
35 Universe get universe => _compiler.codegenWorld; 35 Universe get universe => _compiler.codegenWorld;
36 36
37 /// Mapping from [ClassElement] to constructed [Class]. We need this to 37 /// Mapping from [ClassElement] to constructed [Class]. We need this to
38 /// update the superclass in the [Class]. 38 /// update the superclass in the [Class].
39 final Map<ClassElement, Class> _classes = <ClassElement, Class>{}; 39 final Map<ClassElement, Class> _classes = <ClassElement, Class>{};
40 40
41 /// Mapping from [OutputUnit] to constructed [Output]. We need this to 41 /// Mapping from [OutputUnit] to constructed [Output]. We need this to
42 /// generate the deferredLoadingMap (to know which hunks to load). 42 /// generate the deferredLoadingMap (to know which hunks to load).
43 final Map<OutputUnit, Output> _outputs = <OutputUnit, Output>{}; 43 final Map<OutputUnit, Output> _outputs = <OutputUnit, Output>{};
44 44
45 /// Mapping from [ConstantValue] to constructed [Constant]. We need this to
46 /// update field-initializers to point to the ConstantModel.
47 final Map<ConstantValue, Constant> _constants = <ConstantValue, Constant>{};
48
45 Program buildProgram() { 49 Program buildProgram() {
46 Set<ClassElement> neededClasses = _task.neededClasses;
47 Iterable<Element> neededStatics = backend.generatedCode.keys
48 .where((Element e) => !e.isInstanceMember && !e.isField);
49
50 _task.outputClassLists.forEach(_registry.registerElements); 50 _task.outputClassLists.forEach(_registry.registerElements);
51 _task.outputStaticLists.forEach(_registry.registerElements); 51 _task.outputStaticLists.forEach(_registry.registerElements);
52 52
53 // TODO(kasperl): There's code that implicitly needs access to the special 53 // TODO(kasperl): There's code that implicitly needs access to the special
54 // $ holder so we have to register that. Can we track if we have to? 54 // $ holder so we have to register that. Can we track if we have to?
55 _registry.registerHolder(r'$'); 55 _registry.registerHolder(r'$');
56 56
57 MainOutput mainOutput = _buildMainOutput(_registry.mainFragment); 57 MainOutput mainOutput = _buildMainOutput(_registry.mainFragment);
58 Iterable<Output> deferredOutputs = _registry.deferredFragments 58 Iterable<Output> deferredOutputs = _registry.deferredFragments
59 .map((fragment) => _buildDeferredOutput(mainOutput, fragment)); 59 .map((fragment) => _buildDeferredOutput(mainOutput, fragment));
(...skipping 29 matching lines...) Expand all
89 }); 89 });
90 return loadMap; 90 return loadMap;
91 } 91 }
92 92
93 MainOutput _buildMainOutput(Fragment fragment) { 93 MainOutput _buildMainOutput(Fragment fragment) {
94 // Construct the main output from the libraries and the registered holders. 94 // Construct the main output from the libraries and the registered holders.
95 MainOutput result = new MainOutput( 95 MainOutput result = new MainOutput(
96 "", // The empty string is the name for the main output file. 96 "", // The empty string is the name for the main output file.
97 namer.elementAccess(_compiler.mainFunction), 97 namer.elementAccess(_compiler.mainFunction),
98 _buildLibraries(fragment), 98 _buildLibraries(fragment),
99 _buildConstants(_task.outputConstantLists[fragment.outputUnit]),
99 _registry.holders.toList(growable: false)); 100 _registry.holders.toList(growable: false));
100 _outputs[fragment.outputUnit] = result; 101 _outputs[fragment.outputUnit] = result;
101 return result; 102 return result;
102 } 103 }
103 104
104 /// Returns a name composed of the main output file name and [name]. 105 /// Returns a name composed of the main output file name and [name].
105 String _outputFileName(String name) { 106 String _outputFileName(String name) {
106 assert(name != ""); 107 assert(name != "");
107 String outPath = _compiler.outputUri != null 108 String outPath = _compiler.outputUri != null
108 ? _compiler.outputUri.path 109 ? _compiler.outputUri.path
109 : "out"; 110 : "out";
110 String outName = outPath.substring(outPath.lastIndexOf('/') + 1); 111 String outName = outPath.substring(outPath.lastIndexOf('/') + 1);
111 return "${outName}_$name"; 112 return "${outName}_$name";
112 } 113 }
113 114
114 DeferredOutput _buildDeferredOutput(MainOutput mainOutput, 115 DeferredOutput _buildDeferredOutput(MainOutput mainOutput,
115 Fragment fragment) { 116 Fragment fragment) {
116 DeferredOutput result = new DeferredOutput( 117 DeferredOutput result = new DeferredOutput(
117 _outputFileName(fragment.name), fragment.name, 118 _outputFileName(fragment.name), fragment.name,
118 mainOutput, _buildLibraries(fragment)); 119 mainOutput, _buildLibraries(fragment),
120 _buildConstants(_task.outputConstantLists[fragment.outputUnit]));
119 _outputs[fragment.outputUnit] = result; 121 _outputs[fragment.outputUnit] = result;
120 return result; 122 return result;
121 } 123 }
122 124
125 List<Constant> _buildConstants(List<ConstantValue> constantValues) {
kasperl 2014/10/16 07:01:57 Should this be _buildConstantsForFragment to avoid
floitsch 2014/10/16 12:59:54 Done.
126 if (constantValues == null) return const <Constant>[];
127 return constantValues.map((ConstantValue constantValue) {
128 assert(!_constants.containsKey(constantValue));
129 String name = namer.constantName(constantValue);
130 String constantObject = namer.globalObjectForConstant(constantValue);
131 Holder holder = _registry.registerHolder(constantObject);
132 Constant constant = new Constant(name, holder, constantValue);
133 _constants[constantValue] = constant;
134 return constant;
135 }).toList();
136 }
137
123 List<Library> _buildLibraries(Fragment fragment) { 138 List<Library> _buildLibraries(Fragment fragment) {
124 List<Library> libraries = new List<Library>(fragment.length); 139 List<Library> libraries = new List<Library>(fragment.length);
125 int count = 0; 140 int count = 0;
126 fragment.forEach((LibraryElement library, List<Element> elements) { 141 fragment.forEach((LibraryElement library, List<Element> elements) {
127 libraries[count++] = _buildLibrary(library, elements); 142 libraries[count++] = _buildLibrary(library, elements);
128 }); 143 });
129 return libraries; 144 return libraries;
130 } 145 }
131 146
132 // Note that a library-element may have multiple [Library]s, if it is split 147 // Note that a library-element may have multiple [Library]s, if it is split
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 197 }
183 198
184 StaticMethod _buildStaticMethodTearOff(FunctionElement element) { 199 StaticMethod _buildStaticMethodTearOff(FunctionElement element) {
185 String name = namer.getStaticClosureName(element); 200 String name = namer.getStaticClosureName(element);
186 String holder = namer.globalObjectFor(element); 201 String holder = namer.globalObjectFor(element);
187 // TODO(kasperl): This clearly doesn't work yet. 202 // TODO(kasperl): This clearly doesn't work yet.
188 js.Expression code = js.string("<<unimplemented>>"); 203 js.Expression code = js.string("<<unimplemented>>");
189 return new StaticMethod(name, _registry.registerHolder(holder), code); 204 return new StaticMethod(name, _registry.registerHolder(holder), code);
190 } 205 }
191 } 206 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698