From bb07322aa5dfb0ced819b41dc33c1a4fd180c19e Mon Sep 17 00:00:00 2001 From: "herhut@google.com" Date: Tue, 3 Feb 2015 10:30:55 +0000 Subject: [PATCH] Store the aliasName of a method in the model. BUG= R=floitsch@google.com, zarah@google.com Review URL: https://codereview.chromium.org//881363006 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43387 260f80e4-7a28-3924-810f-c04153c831b5 --- pkg/compiler/lib/src/js_emitter/model.dart | 12 ++++---- .../old_emitter/container_builder.dart | 28 +++++++++---------- .../lib/src/js_emitter/program_builder.dart | 22 +++++++++------ 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/pkg/compiler/lib/src/js_emitter/model.dart b/pkg/compiler/lib/src/js_emitter/model.dart index b7c348b9fcf..6b3ea300512 100644 --- a/pkg/compiler/lib/src/js_emitter/model.dart +++ b/pkg/compiler/lib/src/js_emitter/model.dart @@ -335,7 +335,6 @@ class DartMethod extends Method { final bool needsTearOff; final String tearOffName; final List parameterStubs; - // TODO(herhut): Directly store aliases instead. final bool canBeApplied; final bool canBeReflected; @@ -357,16 +356,20 @@ class DartMethod extends Method { } class InstanceMethod extends DartMethod { - // TODO(herhut): Directly store aliases instead. - final bool hasSuperAlias; + /// An alternative name for this method. This is used to model calls to + /// a method via `super`. If [aliasName] is non-null, the emitter has to + /// ensure that this method is registered on the prototype under both [name] + /// and [aliasName]. + final String aliasName; final bool isClosure; + InstanceMethod(Element element, String name, js.Expression code, List parameterStubs, String callName, {bool needsTearOff, String tearOffName, - this.hasSuperAlias, + this.aliasName, bool canBeApplied, bool canBeReflected, this.isClosure}) @@ -375,7 +378,6 @@ class InstanceMethod extends DartMethod { tearOffName: tearOffName, canBeApplied: canBeApplied, canBeReflected: canBeReflected) { - assert(hasSuperAlias != null); assert(isClosure != null); } } diff --git a/pkg/compiler/lib/src/js_emitter/old_emitter/container_builder.dart b/pkg/compiler/lib/src/js_emitter/old_emitter/container_builder.dart index f7a586a237b..b225fb92114 100644 --- a/pkg/compiler/lib/src/js_emitter/old_emitter/container_builder.dart +++ b/pkg/compiler/lib/src/js_emitter/old_emitter/container_builder.dart @@ -11,19 +11,20 @@ part of dart2js.js_emitter; class ContainerBuilder extends CodeEmitterHelper { void addMemberMethod(DartMethod method, ClassBuilder builder) { - final FunctionElement member = method.element; + FunctionElement member = method.element; String name = method.name; - final FunctionSignature parameters = member.functionSignature; + FunctionSignature parameters = member.functionSignature; jsAst.Expression code = method.code; - final bool needsStubs = method.parameterStubs.isNotEmpty; - final bool canTearOff = method.needsTearOff; - final String tearOffName = method.tearOffName; - final bool canBeReflected = method.canBeReflected; - final bool canBeApplied = method.canBeApplied; - final bool isClosure = method is InstanceMethod && method.isClosure; - final bool hasSuperAlias = method is InstanceMethod && method.hasSuperAlias; + bool needsStubs = method.parameterStubs.isNotEmpty; + bool canBeApplied = method.canBeApplied; + bool canBeReflected = method.canBeReflected; + bool canTearOff = method.needsTearOff; + String tearOffName = method.tearOffName; + bool isClosure = method is InstanceMethod && method.isClosure; + String superAlias = method is InstanceMethod ? method.aliasName : null; + bool hasSuperAlias = superAlias != null; - final bool needStructuredInfo = + bool needStructuredInfo = canTearOff || canBeReflected || canBeApplied || hasSuperAlias; emitter.interceptorEmitter.recordMangledNameOfMemberMethod(member, name); @@ -74,14 +75,13 @@ class ContainerBuilder extends CodeEmitterHelper { List expressions = []; // Create the optional aliasing entry if this method is called via super. - if (backend.isAliasedSuperMember(member)) { - expressions.add(new jsAst.LiteralString( - '"${namer.getNameOfAliasedSuperMember(member)}"')); + if (hasSuperAlias) { + expressions.add(new jsAst.LiteralString('"${superAlias}"')); } expressions.add(code); - final bool onlyNeedsSuperAlias = + bool onlyNeedsSuperAlias = !(canTearOff || canBeReflected || canBeApplied || needsStubs); if (onlyNeedsSuperAlias) { diff --git a/pkg/compiler/lib/src/js_emitter/program_builder.dart b/pkg/compiler/lib/src/js_emitter/program_builder.dart index ca7a25b8bf9..912ab3754d8 100644 --- a/pkg/compiler/lib/src/js_emitter/program_builder.dart +++ b/pkg/compiler/lib/src/js_emitter/program_builder.dart @@ -425,9 +425,13 @@ class ProgramBuilder { bool isClosure = false; bool isNotApplyTarget = !element.isFunction || element.isAccessor; - final bool canBeReflected = _methodCanBeReflected(element); - final bool canBeApplied = _methodCanBeApplied(element); - final bool hasSuperAlias = backend.isAliasedSuperMember(element); + bool canBeReflected = _methodCanBeReflected(element); + bool needsStubs = _methodNeedsStubs(element); + bool canBeApplied = _methodCanBeApplied(element); + + String aliasName = backend.isAliasedSuperMember(element) + ? namer.getNameOfAliasedSuperMember(element) + : null; if (isNotApplyTarget) { canTearOff = false; @@ -461,7 +465,7 @@ class ProgramBuilder { return new InstanceMethod(element, name, code, _generateParameterStubs(element, canTearOff), callName, needsTearOff: canTearOff, tearOffName: tearOffName, - isClosure: isClosure, hasSuperAlias: hasSuperAlias, + isClosure: isClosure, aliasName: aliasName, canBeApplied: canBeApplied, canBeReflected: canBeReflected); } @@ -580,15 +584,15 @@ class ProgramBuilder { String holder = namer.globalObjectFor(element); js.Expression code = backend.generatedCode[element]; - final bool isApplyTarget = !element.isConstructor && !element.isAccessor; - final bool canBeApplied = _methodCanBeApplied(element); - final bool canBeReflected = _methodCanBeReflected(element); + bool isApplyTarget = !element.isConstructor && !element.isAccessor; + bool canBeApplied = _methodCanBeApplied(element); + bool canBeReflected = _methodCanBeReflected(element); - final bool needsTearOff = isApplyTarget && + bool needsTearOff = isApplyTarget && (canBeReflected || universe.staticFunctionsNeedingGetter.contains(element)); - final String tearOffName = + String tearOffName = needsTearOff ? namer.getStaticClosureName(element) : null; String callName = null;