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

Unified Diff: sdk/lib/_internal/compiler/implementation/resolution/members.dart

Issue 19754002: Rewrite how we handle synthesized constructors in the compiler. This was motivated by issue https:/… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/resolution/members.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/resolution/members.dart (revision 25147)
+++ sdk/lib/_internal/compiler/implementation/resolution/members.dart (working copy)
@@ -339,6 +339,14 @@
assert(isConstructor);
return elements;
}
+ if (element.isSynthesized) {
+ Element target = element.targetConstructor;
+ if (!target.isErroneous()) {
+ compiler.enqueuer.resolution.registerStaticUse(
+ element.targetConstructor);
+ }
+ return new TreeElementMapping(element);
+ }
if (element.isPatched) {
checkMatchingPatchSignatures(element, element.patch);
element = element.patch;
@@ -2536,7 +2544,9 @@
{ // This entire block is temporary code per the above TODO.
FunctionElement targetImplementation = redirectionTarget.implementation;
FunctionExpression function = targetImplementation.parseNode(compiler);
- if (function.body != null && function.body.asReturn() != null
+ if (function != null
+ && function.body != null
+ && function.body.asReturn() != null
&& function.body.asReturn().isRedirectingFactoryBody) {
unimplemented(node.expression, 'redirecting to redirecting factory');
}
@@ -3273,7 +3283,21 @@
element.interfaces = resolveInterfaces(node.interfaces, node.superclass);
calculateAllSupertypes(element);
- element.addDefaultConstructorIfNeeded(compiler);
+ if (!element.hasConstructor) {
+ Element superMember =
+ element.superclass.localLookup(const SourceString(''));
+ if (superMember == null || !superMember.isGenerativeConstructor()) {
+ MessageKind kind = MessageKind.CANNOT_FIND_CONSTRUCTOR;
+ Map arguments = {'constructorName': const SourceString('')};
+ compiler.reportErrorCode(node, kind, arguments);
+ superMember = new ErroneousElementX(
+ kind, arguments, const SourceString(''), element);
+ compiler.backend.registerThrowNoSuchMethod(mapping);
+ }
+ FunctionElement constructor =
+ new SynthesizedConstructorElementX.forDefault(superMember, element);
+ element.setDefaultConstructor(constructor, compiler);
+ }
return element.computeType(compiler);
}
@@ -3317,11 +3341,11 @@
constructor.computeSignature(compiler).parameterCount == 0;
}
- FunctionElement createForwardingConstructor(FunctionElement constructor,
- ClassElement target) {
- return new SynthesizedConstructorElementX.forwarding(constructor.name,
- constructor,
- target);
+ FunctionElement createForwardingConstructor(FunctionElement target,
+ ClassElement enclosing) {
+ return new SynthesizedConstructorElementX(target.name,
+ target,
+ enclosing);
}
void doApplyMixinTo(MixinApplicationElement mixinApplication,
@@ -3360,20 +3384,11 @@
// because they are now hidden by the mixin application.
ClassElement superclass = supertype.element;
superclass.forEachLocalMember((Element member) {
- if (!member.isConstructor()) return;
- if (member.isSynthesized && !member.isForwardingConstructor) return;
- if (isDefaultConstructor(member)) return;
- assert(invariant(node, !member.isFactoryConstructor(),
- message: 'mixins cannot have factory constructors'));
- // Skip forwarding constructors and use their target.
- FunctionElement constructor =
- member.isForwardingConstructor ? member.targetConstructor : member;
- assert(invariant(node, !constructor.isForwardingConstructor));
+ if (!member.isGenerativeConstructor()) return;
FunctionElement forwarder =
- createForwardingConstructor(constructor, mixinApplication);
+ createForwardingConstructor(member, mixinApplication);
mixinApplication.addConstructor(forwarder);
});
- mixinApplication.addDefaultConstructorIfNeeded(compiler);
calculateAllSupertypes(mixinApplication);
}

Powered by Google App Engine
This is Rietveld 408576698