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

Unified Diff: lib/compiler/implementation/dart_backend/backend.dart

Issue 10990065: Synthesized a constructor if there is no resolved constructors in the class. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 | tests/co19/co19-dart2dart.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/dart_backend/backend.dart
diff --git a/lib/compiler/implementation/dart_backend/backend.dart b/lib/compiler/implementation/dart_backend/backend.dart
index 3f8ed70ce27dabf7ef29a76c360af150f6d3c7b6..1aa55792f582d029dfd4dd99313790a67a91b4fe 100644
--- a/lib/compiler/implementation/dart_backend/backend.dart
+++ b/lib/compiler/implementation/dart_backend/backend.dart
@@ -329,9 +329,47 @@ class DartBackend extends Backend {
}
});
+ // Add synthesized constructors to classes with no resolved constructors,
+ // but which originally had any constructor. That should prevent
+ // those classes from being instantiable with default constructor.
+ Identifier synthesizedIdentifier =
+ new Identifier(new StringToken(IDENTIFIER_INFO, '', -1));
+
+ NextClassElement:
+ for (ClassElement classElement in classMembers.getKeys()) {
+ for (Element member in classMembers[classElement]) {
+ if (member.isConstructor()) continue NextClassElement;
+ }
+ if (classElement.constructors.isEmpty()) continue NextClassElement;
+
+ // TODO(antonm): check with AAR team if there is better approach.
+ // As an idea: provide template as a Dart code---class C { C.name(); }---
+ // and then overwrite necessary parts.
+ SynthesizedConstructorElement constructor =
+ new SynthesizedConstructorElement(classElement);
+ constructor.type = new FunctionType(
+ compiler.types.voidType, const EmptyLink<DartType>(),
+ constructor);
+ constructor.cachedNode = new FunctionExpression(
+ new Send(receiver: classElement.parseNode(compiler).name,
+ selector: synthesizedIdentifier),
+ new NodeList(beginToken: new StringToken(OPEN_PAREN_INFO, '(', -1),
+ endToken: new StringToken(CLOSE_PAREN_INFO, ')', -1),
+ nodes: const EmptyLink<Node>()),
+ new EmptyStatement(new StringToken(SEMICOLON_INFO, ';', -1)),
+ null, null, null, null);
+
+ classMembers[classElement].add(constructor);
+ elementAsts[constructor] =
+ new ElementAst(constructor.cachedNode, new TreeElementMapping());
+ }
+
// Create all necessary placeholders.
PlaceholderCollector collector =
new PlaceholderCollector(compiler, fixedMemberNames, elementAsts);
+ // Add synthesizedIdentifier to set of unresolved names to rename it to
+ // some unused identifier.
+ collector.unresolvedNodes.add(synthesizedIdentifier);
makePlaceholders(element) {
collector.collect(element);
if (element is ClassElement) {
« no previous file with comments | « no previous file | tests/co19/co19-dart2dart.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698