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

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

Issue 895813006: dart2js: store typeVariableReader stubs in the model. (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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_emitter/model.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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; 9 final Compiler compiler;
10 final JavaScriptBackend backend; 10 final JavaScriptBackend backend;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 179
180 jsAst.Expression function; 180 jsAst.Expression function;
181 if (backend.isInterceptedName(selector.name)) { 181 if (backend.isInterceptedName(selector.name)) {
182 function = js(r'function($receiver, #) { return # }', 182 function = js(r'function($receiver, #) { return # }',
183 [parameterNames, expression]); 183 [parameterNames, expression]);
184 } else { 184 } else {
185 function = js(r'function(#) { return # }', [parameterNames, expression]); 185 function = js(r'function(#) { return # }', [parameterNames, expression]);
186 } 186 }
187 return new StubMethod(name, function); 187 return new StubMethod(name, function);
188 } 188 }
189
190 List<StubMethod> generateTypeVariableReaderStubs(ClassElement classElement) {
floitsch 2015/02/10 13:19:36 An alternative location would be in the type_test_
zarah 2015/02/10 13:34:39 Done.
191 List<StubMethod> stubs = <StubMethod>[];
192 List typeVariables = [];
193 ClassElement superclass = classElement;
194 while (superclass != null) {
195 for (TypeVariableType parameter in superclass.typeVariables) {
196 if (backend.emitter.readTypeVariables.contains(parameter.element)) {
197 stubs.add(
zarah 2015/02/10 12:50:30 This method is copied from class_emitter. This lin
198 _generateTypeVariableReader(classElement, parameter.element));
199 }
200 }
201 superclass = superclass.superclass;
202 }
203
204 return stubs;
205 }
206
207 StubMethod _generateTypeVariableReader(ClassElement cls,
208 TypeVariableElement element) {
209 String name = namer.readTypeVariableName(element);
210 int index = RuntimeTypes.getTypeVariableIndex(element);
211 jsAst.Expression computeTypeVariable;
212
213 Substitution substitution =
214 backend.rti.computeSubstitution(
215 cls, element.typeDeclaration, alwaysGenerateFunction: true);
216 if (substitution != null) {
217 computeTypeVariable =
218 js(r'#.apply(null, this.$builtinTypeInfo)',
219 substitution.getCodeForVariable(index, backend.rti));
220 } else {
221 // TODO(ahe): These can be generated dynamically.
222 computeTypeVariable =
223 js(r'this.$builtinTypeInfo && this.$builtinTypeInfo[#]',
224 js.number(index));
225 }
226 jsAst.Expression convertRtiToRuntimeType = backend.emitter
227 .staticFunctionAccess(backend.findHelper('convertRtiToRuntimeType'));
228
229 return new StubMethod(name,
zarah 2015/02/10 12:50:30 This method is copied from class_emitter. It diffe
230 js('function () { return #(#) }',
231 [convertRtiToRuntimeType, computeTypeVariable]));
232 }
233
189 } 234 }
190 235
191 /// Creates two JavaScript functions: `tearOffGetter` and `tearOff`. 236 /// Creates two JavaScript functions: `tearOffGetter` and `tearOff`.
192 /// 237 ///
193 /// `tearOffGetter` is internal and only used by `tearOff`. 238 /// `tearOffGetter` is internal and only used by `tearOff`.
194 /// 239 ///
195 /// `tearOff` takes the following arguments: 240 /// `tearOff` takes the following arguments:
196 /// * `funcs`: a list of functions. These are the functions representing the 241 /// * `funcs`: a list of functions. These are the functions representing the
197 /// member that is torn off. There can be more than one, since a member 242 /// member that is torn off. There can be more than one, since a member
198 /// can have several stubs. 243 /// can have several stubs.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 ? function() { 323 ? function() {
279 if (cache === void 0) cache = #tearOff( 324 if (cache === void 0) cache = #tearOff(
280 this, funcs, reflectionInfo, true, [], name).prototype; 325 this, funcs, reflectionInfo, true, [], name).prototype;
281 return cache; 326 return cache;
282 } 327 }
283 : tearOffGetter(funcs, reflectionInfo, name, isIntercepted); 328 : tearOffGetter(funcs, reflectionInfo, name, isIntercepted);
284 }''', {'tearOff': tearOffAccessExpression}); 329 }''', {'tearOff': tearOffAccessExpression});
285 330
286 return <jsAst.Statement>[tearOffGetter, tearOff]; 331 return <jsAst.Statement>[tearOffGetter, tearOff];
287 } 332 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/js_emitter/model.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698