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

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 41bf6e975620d1f44f96f004318533d54e04575a..82e8fad2f6c208b1d55c5b862a7bb06b24a3819e 100644
--- a/lib/compiler/implementation/dart_backend/backend.dart
+++ b/lib/compiler/implementation/dart_backend/backend.dart
@@ -325,9 +325,44 @@ 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 =
Anton Muhin 2012/09/27 06:14:28 SCE assumes it's a default ctor at least as the el
+ 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());
Roman 2012/09/27 12:40:50 80 chars
Anton Muhin 2012/09/28 12:21:27 Done.
+ }
+
// Create all necessary placeholders.
PlaceholderCollector collector =
new PlaceholderCollector(compiler, fixedMemberNames, elementAsts);
+ collector.unresolvedNodes.add(synthesizedIdentifier);
Roman 2012/09/27 12:40:50 Please add a comment that this is for renamer cons
Anton Muhin 2012/09/28 12:21:27 Done.
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