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

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

Issue 1062913003: Extract CallStructure from Selector. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 'js_emitter.dart' show computeMixinClass; 7 import 'js_emitter.dart' show computeMixinClass;
8 import 'model.dart'; 8 import 'model.dart';
9 9
10 import '../common.dart'; 10 import '../common.dart';
11 import '../js/js.dart' as js; 11 import '../js/js.dart' as js;
12 12
13 import '../js_backend/js_backend.dart' show 13 import '../js_backend/js_backend.dart' show
14 Namer, 14 Namer,
15 JavaScriptBackend, 15 JavaScriptBackend,
16 JavaScriptConstantCompiler; 16 JavaScriptConstantCompiler;
17 17
18 import 'js_emitter.dart' show 18 import 'js_emitter.dart' show
19 ClassStubGenerator, 19 ClassStubGenerator,
20 CodeEmitterTask, 20 CodeEmitterTask,
21 InterceptorStubGenerator, 21 InterceptorStubGenerator,
22 MainCallStubGenerator, 22 MainCallStubGenerator,
23 ParameterStubGenerator, 23 ParameterStubGenerator,
24 RuntimeTypeGenerator, 24 RuntimeTypeGenerator,
25 TypeTestProperties; 25 TypeTestProperties;
26 26
27 import '../elements/elements.dart' show ParameterElement; 27 import '../elements/elements.dart' show ParameterElement, MethodElement;
28 28
29 import '../universe/universe.dart' show Universe; 29 import '../universe/universe.dart' show Universe;
30 import '../deferred_load.dart' show DeferredLoadTask, OutputUnit; 30 import '../deferred_load.dart' show DeferredLoadTask, OutputUnit;
31 import '../constants/expressions.dart' show ConstantExpression, ConstantValue; 31 import '../constants/expressions.dart' show ConstantExpression, ConstantValue;
32 32
33 part 'registry.dart'; 33 part 'registry.dart';
34 34
35 class ProgramBuilder { 35 class ProgramBuilder {
36 final Compiler _compiler; 36 final Compiler _compiler;
37 final Namer namer; 37 final Namer namer;
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 selectors.forEach((String name, Selector selector) { 364 selectors.forEach((String name, Selector selector) {
365 noSuchMethodStubs 365 noSuchMethodStubs
366 .add(classStubGenerator.generateStubForNoSuchMethod(name, 366 .add(classStubGenerator.generateStubForNoSuchMethod(name,
367 selector)); 367 selector));
368 }); 368 });
369 } 369 }
370 370
371 if (element == backend.closureClass) { 371 if (element == backend.closureClass) {
372 // We add a special getter here to allow for tearing off a closure from 372 // We add a special getter here to allow for tearing off a closure from
373 // itself. 373 // itself.
374 String name = namer.getterForPublicMember(Compiler.CALL_OPERATOR_NAME); 374 String name = namer.getterForMember(Selector.CALL_NAME);
375 js.Fun function = js.js('function() { return this; }'); 375 js.Fun function = js.js('function() { return this; }');
376 callStubs.add(_buildStubMethod(name, function)); 376 callStubs.add(_buildStubMethod(name, function));
377 } 377 }
378 378
379 ClassElement implementation = element.implementation; 379 ClassElement implementation = element.implementation;
380 380
381 // MixinApplications run through the members of their mixin. Here, we are 381 // MixinApplications run through the members of their mixin. Here, we are
382 // only interested in direct members. 382 // only interested in direct members.
383 if (!onlyForRti && !element.isMixinApplication) { 383 if (!onlyForRti && !element.isMixinApplication) {
384 implementation.forEachMember(visitMember, includeBackendMembers: true); 384 implementation.forEachMember(visitMember, includeBackendMembers: true);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 optionalParameterDefaultValues = <ConstantValue>[]; 478 optionalParameterDefaultValues = <ConstantValue>[];
479 signature.forEachOptionalParameter((ParameterElement parameter) { 479 signature.forEachOptionalParameter((ParameterElement parameter) {
480 ConstantExpression def = 480 ConstantExpression def =
481 backend.constants.getConstantForVariable(parameter); 481 backend.constants.getConstantForVariable(parameter);
482 optionalParameterDefaultValues.add(def.value); 482 optionalParameterDefaultValues.add(def.value);
483 }); 483 });
484 } 484 }
485 return optionalParameterDefaultValues; 485 return optionalParameterDefaultValues;
486 } 486 }
487 487
488 DartMethod _buildMethod(FunctionElement element) { 488 DartMethod _buildMethod(MethodElement element) {
489 String name = namer.methodPropertyName(element); 489 String name = namer.methodPropertyName(element);
490 js.Expression code = backend.generatedCode[element]; 490 js.Expression code = backend.generatedCode[element];
491 491
492 // TODO(kasperl): Figure out under which conditions code is null. 492 // TODO(kasperl): Figure out under which conditions code is null.
493 if (code == null) return null; 493 if (code == null) return null;
494 494
495 bool canTearOff = false; 495 bool canTearOff = false;
496 String tearOffName; 496 String tearOffName;
497 bool isClosure = false; 497 bool isClosure = false;
498 bool isNotApplyTarget = !element.isFunction || element.isAccessor; 498 bool isNotApplyTarget = !element.isFunction || element.isAccessor;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 571
572 js.Expression _generateFunctionType(DartType type) { 572 js.Expression _generateFunctionType(DartType type) {
573 if (type.containsTypeVariables) { 573 if (type.containsTypeVariables) {
574 js.Expression thisAccess = js.js(r'this.$receiver'); 574 js.Expression thisAccess = js.js(r'this.$receiver');
575 return backend.rti.getSignatureEncoding(type, thisAccess); 575 return backend.rti.getSignatureEncoding(type, thisAccess);
576 } else { 576 } else {
577 return js.number(backend.emitter.metadataCollector.reifyType(type)); 577 return js.number(backend.emitter.metadataCollector.reifyType(type));
578 } 578 }
579 } 579 }
580 580
581 List<ParameterStubMethod> _generateParameterStubs(FunctionElement element, 581 List<ParameterStubMethod> _generateParameterStubs(MethodElement element,
582 bool canTearOff) { 582 bool canTearOff) {
583 583
584 if (!_methodNeedsStubs(element)) return const <ParameterStubMethod>[]; 584 if (!_methodNeedsStubs(element)) return const <ParameterStubMethod>[];
585 585
586 ParameterStubGenerator generator = 586 ParameterStubGenerator generator =
587 new ParameterStubGenerator(_compiler, namer, backend); 587 new ParameterStubGenerator(_compiler, namer, backend);
588 return generator.generateParameterStubs(element, canTearOff: canTearOff); 588 return generator.generateParameterStubs(element, canTearOff: canTearOff);
589 } 589 }
590 590
591 /// Builds a stub method. 591 /// Builds a stub method.
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 _registry.registerConstant(outputUnit, constantValue); 754 _registry.registerConstant(outputUnit, constantValue);
755 assert(!_constants.containsKey(constantValue)); 755 assert(!_constants.containsKey(constantValue));
756 String name = namer.constantName(constantValue); 756 String name = namer.constantName(constantValue);
757 String constantObject = namer.globalObjectForConstant(constantValue); 757 String constantObject = namer.globalObjectForConstant(constantValue);
758 Holder holder = _registry.registerHolder(constantObject); 758 Holder holder = _registry.registerHolder(constantObject);
759 Constant constant = new Constant(name, holder, constantValue); 759 Constant constant = new Constant(name, holder, constantValue);
760 _constants[constantValue] = constant; 760 _constants[constantValue] = constant;
761 } 761 }
762 } 762 }
763 } 763 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698