Chromium Code Reviews| 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) { |