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

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

Issue 662663003: dart2js: Add interceptors to new emitter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | 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 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
11 import '../js_backend/js_backend.dart' show 11 import '../js_backend/js_backend.dart' show
12 Namer, 12 Namer,
13 JavaScriptBackend, 13 JavaScriptBackend,
14 JavaScriptConstantCompiler; 14 JavaScriptConstantCompiler;
15 15
16 import '../js_emitter/js_emitter.dart' as emitterTask show 16 import 'js_emitter.dart' as emitterTask show
17 CodeEmitterTask, 17 CodeEmitterTask,
18 Emitter; 18 Emitter,
19 InterceptorStubGenerator;
19 20
20 import '../universe/universe.dart' show Universe; 21 import '../universe/universe.dart' show Universe;
21 import '../deferred_load.dart' show DeferredLoadTask, OutputUnit; 22 import '../deferred_load.dart' show DeferredLoadTask, OutputUnit;
22 23
23 part 'registry.dart'; 24 part 'registry.dart';
24 25
25 class ProgramBuilder { 26 class ProgramBuilder {
26 final Compiler _compiler; 27 final Compiler _compiler;
27 final Namer namer; 28 final Namer namer;
28 final emitterTask.CodeEmitterTask _task; 29 final emitterTask.CodeEmitterTask _task;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 String uri = library.canonicalUri.toString(); 183 String uri = library.canonicalUri.toString();
183 184
184 List<StaticMethod> statics = elements 185 List<StaticMethod> statics = elements
185 .where((e) => e is FunctionElement).map(_buildStaticMethod).toList(); 186 .where((e) => e is FunctionElement).map(_buildStaticMethod).toList();
186 187
187 statics.addAll(elements 188 statics.addAll(elements
188 .where((e) => e is FunctionElement) 189 .where((e) => e is FunctionElement)
189 .where((e) => universe.staticFunctionsNeedingGetter.contains(e)) 190 .where((e) => universe.staticFunctionsNeedingGetter.contains(e))
190 .map(_buildStaticMethodTearOff)); 191 .map(_buildStaticMethodTearOff));
191 192
193 if (library == backend.interceptorsLibrary) {
194 statics.addAll(_generateGetInterceptorMethods());
195 statics.addAll(_generateOneShotInterceptors());
196 }
197
192 List<Class> classes = elements 198 List<Class> classes = elements
193 .where((e) => e is ClassElement) 199 .where((e) => e is ClassElement)
194 .map(_buildClass) 200 .map(_buildClass)
195 .toList(growable: false); 201 .toList(growable: false);
196 202
197 return new Library(uri, statics, classes); 203 return new Library(uri, statics, classes);
198 } 204 }
199 205
200 Class _buildClass(ClassElement element) { 206 Class _buildClass(ClassElement element) {
201 List<Method> methods = []; 207 List<Method> methods = [];
(...skipping 12 matching lines...) Expand all
214 Class result = new Class(name, _registry.registerHolder(holder), methods); 220 Class result = new Class(name, _registry.registerHolder(holder), methods);
215 _classes[element] = result; 221 _classes[element] = result;
216 return result; 222 return result;
217 } 223 }
218 224
219 Method _buildMethod(FunctionElement element, js.Expression code) { 225 Method _buildMethod(FunctionElement element, js.Expression code) {
220 String name = namer.getNameOfInstanceMember(element); 226 String name = namer.getNameOfInstanceMember(element);
221 return new Method(name, code); 227 return new Method(name, code);
222 } 228 }
223 229
230 Iterable<StaticMethod> _generateGetInterceptorMethods() {
231 emitterTask.InterceptorStubGenerator stubGenerator =
232 new emitterTask.InterceptorStubGenerator(_compiler, namer, backend);
233
234 String holderName = namer.globalObjectFor(backend.interceptorsLibrary);
235 Holder holder = _registry.registerHolder(holderName);
236
237 Map<String, Set<ClassElement>> specializedGetInterceptors =
238 backend.specializedGetInterceptors;
239 List<String> names = specializedGetInterceptors.keys.toList()..sort();
240 return names.map((String name) {
241 Set<ClassElement> classes = specializedGetInterceptors[name];
242 js.Expression code = stubGenerator.generateGetInterceptorMethod(classes);
243 return new StaticMethod(name, holder, code);
244 });
245 }
246
247 Iterable<StaticMethod> _generateOneShotInterceptors() {
248 emitterTask.InterceptorStubGenerator stubGenerator =
249 new emitterTask.InterceptorStubGenerator(_compiler, namer, backend);
250
251 String holderName = namer.globalObjectFor(backend.interceptorsLibrary);
252 Holder holder = _registry.registerHolder(holderName);
253
254 List<String> names = backend.oneShotInterceptors.keys.toList()..sort();
255 return names.map((String name) {
256 js.Expression code = stubGenerator.generateOneShotInterceptor(name);
257 return new StaticMethod(name, holder, code);
258 });
259 }
260
224 StaticMethod _buildStaticMethod(FunctionElement element) { 261 StaticMethod _buildStaticMethod(FunctionElement element) {
225 String name = namer.getNameOfMember(element); 262 String name = namer.getNameOfMember(element);
226 String holder = namer.globalObjectFor(element); 263 String holder = namer.globalObjectFor(element);
227 js.Expression code = backend.generatedCode[element]; 264 js.Expression code = backend.generatedCode[element];
228 return new StaticMethod(name, _registry.registerHolder(holder), code); 265 return new StaticMethod(name, _registry.registerHolder(holder), code);
229 } 266 }
230 267
231 StaticMethod _buildStaticMethodTearOff(FunctionElement element) { 268 StaticMethod _buildStaticMethodTearOff(FunctionElement element) {
232 String name = namer.getStaticClosureName(element); 269 String name = namer.getStaticClosureName(element);
233 String holder = namer.globalObjectFor(element); 270 String holder = namer.globalObjectFor(element);
234 // TODO(kasperl): This clearly doesn't work yet. 271 // TODO(kasperl): This clearly doesn't work yet.
235 js.Expression code = js.string("<<unimplemented>>"); 272 js.Expression code = js.string("<<unimplemented>>");
236 return new StaticMethod(name, _registry.registerHolder(holder), code); 273 return new StaticMethod(name, _registry.registerHolder(holder), code);
237 } 274 }
238 275
239 void _registerConstants(OutputUnit outputUnit, 276 void _registerConstants(OutputUnit outputUnit,
240 List<ConstantValue> constantValues) { 277 List<ConstantValue> constantValues) {
241 if (constantValues == null) return; 278 if (constantValues == null) return;
242 for (ConstantValue constantValue in constantValues) { 279 for (ConstantValue constantValue in constantValues) {
243 assert(!_constants.containsKey(constantValue)); 280 assert(!_constants.containsKey(constantValue));
244 String name = namer.constantName(constantValue); 281 String name = namer.constantName(constantValue);
245 String constantObject = namer.globalObjectForConstant(constantValue); 282 String constantObject = namer.globalObjectForConstant(constantValue);
246 Holder holder = _registry.registerHolder(constantObject); 283 Holder holder = _registry.registerHolder(constantObject);
247 Constant constant = new Constant(name, holder, constantValue); 284 Constant constant = new Constant(name, holder, constantValue);
248 _constants[constantValue] = constant; 285 _constants[constantValue] = constant;
249 }; 286 };
250 } 287 }
251 } 288 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698