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

Unified Diff: pkg/compiler/lib/src/elements/modelx.dart

Issue 2637533003: dart2js-kernel: Call generative constructor body functions (Closed)
Patch Set: fix analyzer warning Created 3 years, 11 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/ssa/builder.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/elements/modelx.dart
diff --git a/pkg/compiler/lib/src/elements/modelx.dart b/pkg/compiler/lib/src/elements/modelx.dart
index 6ff57cc0812853b7b839771819081f406764dea4..7f887ac200094c022a0349398c0e66926423be03 100644
--- a/pkg/compiler/lib/src/elements/modelx.dart
+++ b/pkg/compiler/lib/src/elements/modelx.dart
@@ -2414,6 +2414,51 @@ class ConstructorBodyElementX extends BaseFunctionElementX
functionSignature = constructor.functionSignature;
}
+ /// Returns the constructor body associated with the given constructor or
+ /// creates a new constructor body, if none can be found.
+ ///
+ /// Returns `null` if the constructor does not have a body.
+ static ConstructorBodyElementX createFromResolvedAst(
+ ResolvedAst constructorResolvedAst) {
+ ConstructorElement constructor =
+ constructorResolvedAst.element.implementation;
+ assert(constructor.isGenerativeConstructor);
+ if (constructorResolvedAst.kind != ResolvedAstKind.PARSED) return null;
+
+ FunctionExpression node = constructorResolvedAst.node;
+ // If we know the body doesn't have any code, we don't generate it.
+ if (!node.hasBody) return null;
+ if (node.hasEmptyBody) return null;
+ ClassElement classElement = constructor.enclosingClass;
+ ConstructorBodyElement bodyElement;
+ classElement.forEachBackendMember((Element backendMember) {
+ if (backendMember.isGenerativeConstructorBody) {
+ ConstructorBodyElement body = backendMember;
+ if (body.constructor == constructor) {
+ // TODO(kasperl): Find a way of stopping the iteration
+ // through the backend members.
+ bodyElement = backendMember;
+ }
+ }
+ });
+ if (bodyElement == null) {
+ bodyElement =
+ new ConstructorBodyElementX(constructorResolvedAst, constructor);
+ classElement.addBackendMember(bodyElement);
+
+ if (constructor.isPatch) {
+ // Create origin body element for patched constructors.
+ ConstructorBodyElementX patch = bodyElement;
+ ConstructorBodyElementX origin = new ConstructorBodyElementX(
+ constructorResolvedAst, constructor.origin);
+ origin.applyPatch(patch);
+ classElement.origin.addBackendMember(bodyElement.origin);
+ }
+ }
+ assert(bodyElement.isGenerativeConstructorBody);
+ return bodyElement;
+ }
+
bool get hasNode => _resolvedAst.kind == ResolvedAstKind.PARSED;
FunctionExpression get node => _resolvedAst.node;
« no previous file with comments | « no previous file | pkg/compiler/lib/src/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698