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

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

Issue 2568723007: Create Namer and Emitter on codegen start. (Closed)
Patch Set: Small fix. Created 4 years 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
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 part of dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 class ClassStubGenerator { 7 class ClassStubGenerator {
8 final Namer namer; 8 final Namer namer;
9 final Compiler compiler;
10 final JavaScriptBackend backend; 9 final JavaScriptBackend backend;
10 final CodegenWorldBuilder codegenWorld;
11 final ClosedWorld closedWorld;
12 final bool enableMinification;
11 13
12 ClassStubGenerator(this.compiler, this.namer, this.backend); 14 ClassStubGenerator(
15 this.namer, this.backend, this.codegenWorld, this.closedWorld,
16 {this.enableMinification});
13 17
14 jsAst.Expression generateClassConstructor(ClassElement classElement, 18 jsAst.Expression generateClassConstructor(ClassElement classElement,
15 Iterable<jsAst.Name> fields, bool hasRtiField) { 19 Iterable<jsAst.Name> fields, bool hasRtiField) {
16 // TODO(sra): Implement placeholders in VariableDeclaration position: 20 // TODO(sra): Implement placeholders in VariableDeclaration position:
17 // 21 //
18 // String constructorName = namer.getNameOfClass(classElement); 22 // String constructorName = namer.getNameOfClass(classElement);
19 // return js.statement('function #(#) { #; }', 23 // return js.statement('function #(#) { #; }',
20 // [ constructorName, fields, 24 // [ constructorName, fields,
21 // fields.map( 25 // fields.map(
22 // (name) => js('this.# = #', [name, name]))])); 26 // (name) => js('this.# = #', [name, name]))]));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 Map<jsAst.Name, jsAst.Expression> generatedStubs = 90 Map<jsAst.Name, jsAst.Expression> generatedStubs =
87 <jsAst.Name, jsAst.Expression>{}; 91 <jsAst.Name, jsAst.Expression>{};
88 92
89 // Two selectors may match but differ only in type. To avoid generating 93 // Two selectors may match but differ only in type. To avoid generating
90 // identical stubs for each we track untyped selectors which already have 94 // identical stubs for each we track untyped selectors which already have
91 // stubs. 95 // stubs.
92 Set<Selector> generatedSelectors = new Set<Selector>(); 96 Set<Selector> generatedSelectors = new Set<Selector>();
93 for (Selector selector in selectors.keys) { 97 for (Selector selector in selectors.keys) {
94 if (generatedSelectors.contains(selector)) continue; 98 if (generatedSelectors.contains(selector)) continue;
95 if (!selector.appliesUnnamed(member)) continue; 99 if (!selector.appliesUnnamed(member)) continue;
96 if (selectors[selector].applies(member, selector, compiler.closedWorld)) { 100 if (selectors[selector].applies(member, selector, closedWorld)) {
97 generatedSelectors.add(selector); 101 generatedSelectors.add(selector);
98 102
99 jsAst.Name invocationName = namer.invocationName(selector); 103 jsAst.Name invocationName = namer.invocationName(selector);
100 Selector callSelector = new Selector.callClosureFrom(selector); 104 Selector callSelector = new Selector.callClosureFrom(selector);
101 jsAst.Name closureCallName = namer.invocationName(callSelector); 105 jsAst.Name closureCallName = namer.invocationName(callSelector);
102 106
103 List<jsAst.Parameter> parameters = <jsAst.Parameter>[]; 107 List<jsAst.Parameter> parameters = <jsAst.Parameter>[];
104 List<jsAst.Expression> arguments = <jsAst.Expression>[]; 108 List<jsAst.Expression> arguments = <jsAst.Expression>[];
105 if (isInterceptedMethod) { 109 if (isInterceptedMethod) {
106 parameters.add(new jsAst.Parameter(receiverArgumentName)); 110 parameters.add(new jsAst.Parameter(receiverArgumentName));
(...skipping 12 matching lines...) Expand all
119 } 123 }
120 } 124 }
121 125
122 return generatedStubs; 126 return generatedStubs;
123 } 127 }
124 128
125 Map<jsAst.Name, Selector> computeSelectorsForNsmHandlers() { 129 Map<jsAst.Name, Selector> computeSelectorsForNsmHandlers() {
126 Map<jsAst.Name, Selector> jsNames = <jsAst.Name, Selector>{}; 130 Map<jsAst.Name, Selector> jsNames = <jsAst.Name, Selector>{};
127 131
128 // Do not generate no such method handlers if there is no class. 132 // Do not generate no such method handlers if there is no class.
129 if (compiler.codegenWorld.directlyInstantiatedClasses.isEmpty) { 133 if (codegenWorld.directlyInstantiatedClasses.isEmpty) {
130 return jsNames; 134 return jsNames;
131 } 135 }
132 136
133 void addNoSuchMethodHandlers( 137 void addNoSuchMethodHandlers(
134 String ignore, Map<Selector, SelectorConstraints> selectors) { 138 String ignore, Map<Selector, SelectorConstraints> selectors) {
135 for (Selector selector in selectors.keys) { 139 for (Selector selector in selectors.keys) {
136 SelectorConstraints maskSet = selectors[selector]; 140 SelectorConstraints maskSet = selectors[selector];
137 if (maskSet.needsNoSuchMethodHandling(selector, compiler.closedWorld)) { 141 if (maskSet.needsNoSuchMethodHandling(selector, closedWorld)) {
138 jsAst.Name jsName = namer.invocationMirrorInternalName(selector); 142 jsAst.Name jsName = namer.invocationMirrorInternalName(selector);
139 jsNames[jsName] = selector; 143 jsNames[jsName] = selector;
140 } 144 }
141 } 145 }
142 } 146 }
143 147
144 compiler.codegenWorld.forEachInvokedName(addNoSuchMethodHandlers); 148 codegenWorld.forEachInvokedName(addNoSuchMethodHandlers);
145 compiler.codegenWorld.forEachInvokedGetter(addNoSuchMethodHandlers); 149 codegenWorld.forEachInvokedGetter(addNoSuchMethodHandlers);
146 compiler.codegenWorld.forEachInvokedSetter(addNoSuchMethodHandlers); 150 codegenWorld.forEachInvokedSetter(addNoSuchMethodHandlers);
147 return jsNames; 151 return jsNames;
148 } 152 }
149 153
150 StubMethod generateStubForNoSuchMethod(jsAst.Name name, Selector selector) { 154 StubMethod generateStubForNoSuchMethod(jsAst.Name name, Selector selector) {
151 // Values match JSInvocationMirror in js-helper library. 155 // Values match JSInvocationMirror in js-helper library.
152 int type = selector.invocationMirrorKind; 156 int type = selector.invocationMirrorKind;
153 List<String> parameterNames = 157 List<String> parameterNames =
154 new List.generate(selector.argumentCount, (i) => '\$$i'); 158 new List.generate(selector.argumentCount, (i) => '\$$i');
155 159
156 List<jsAst.Expression> argNames = selector.callStructure 160 List<jsAst.Expression> argNames = selector.callStructure
(...skipping 11 matching lines...) Expand all
168 #createInvocationMirror(#methodName, 172 #createInvocationMirror(#methodName,
169 #internalName, 173 #internalName,
170 #type, 174 #type,
171 #arguments, 175 #arguments,
172 #namedArguments))''', 176 #namedArguments))''',
173 { 177 {
174 'receiver': isIntercepted ? r'$receiver' : 'this', 178 'receiver': isIntercepted ? r'$receiver' : 'this',
175 'noSuchMethodName': namer.noSuchMethodName, 179 'noSuchMethodName': namer.noSuchMethodName,
176 'createInvocationMirror': backend.emitter 180 'createInvocationMirror': backend.emitter
177 .staticFunctionAccess(backend.helpers.createInvocationMirror), 181 .staticFunctionAccess(backend.helpers.createInvocationMirror),
178 'methodName': js.quoteName( 182 'methodName':
179 compiler.options.enableMinification ? internalName : methodName), 183 js.quoteName(enableMinification ? internalName : methodName),
180 'internalName': js.quoteName(internalName), 184 'internalName': js.quoteName(internalName),
181 'type': js.number(type), 185 'type': js.number(type),
182 'arguments': 186 'arguments':
183 new jsAst.ArrayInitializer(parameterNames.map(js).toList()), 187 new jsAst.ArrayInitializer(parameterNames.map(js).toList()),
184 'namedArguments': new jsAst.ArrayInitializer(argNames) 188 'namedArguments': new jsAst.ArrayInitializer(argNames)
185 }); 189 });
186 190
187 jsAst.Expression function; 191 jsAst.Expression function;
188 if (isIntercepted) { 192 if (isIntercepted) {
189 function = js( 193 function = js(
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 if (cache === void 0) cache = #tearOff( 294 if (cache === void 0) cache = #tearOff(
291 this, funcs, reflectionInfo, true, [], name).prototype; 295 this, funcs, reflectionInfo, true, [], name).prototype;
292 return cache; 296 return cache;
293 } 297 }
294 : tearOffGetter(funcs, reflectionInfo, name, isIntercepted); 298 : tearOffGetter(funcs, reflectionInfo, name, isIntercepted);
295 }''', 299 }''',
296 {'tearOff': tearOffAccessExpression}); 300 {'tearOff': tearOffAccessExpression});
297 301
298 return <jsAst.Statement>[tearOffGetter, tearOff]; 302 return <jsAst.Statement>[tearOffGetter, tearOff];
299 } 303 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/namer.dart ('k') | pkg/compiler/lib/src/js_emitter/code_emitter_task.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698