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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/dart_backend/backend.dart

Issue 526263002: Remove unneeded generation of default constructors from the dart backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added language test. Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/compiler/dart2js/backend_dart/dart_backend_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart_backend; 5 part of dart_backend;
6 6
7 // TODO(ahe): This class is simply wrong. This backend should use 7 // TODO(ahe): This class is simply wrong. This backend should use
8 // elements when it can, not AST nodes. Perhaps a [Map<Element, 8 // elements when it can, not AST nodes. Perhaps a [Map<Element,
9 // TreeElements>] is what is needed. 9 // TreeElements>] is what is needed.
10 class ElementAst { 10 class ElementAst {
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 usedTypeLiterals.forEach((ClassElement element) { 339 usedTypeLiterals.forEach((ClassElement element) {
340 if (shouldOutput(element)) { 340 if (shouldOutput(element)) {
341 if (!topLevelElements.contains(element)) { 341 if (!topLevelElements.contains(element)) {
342 // The class is only referenced by type literals. 342 // The class is only referenced by type literals.
343 emitNoMembersFor.add(element); 343 emitNoMembersFor.add(element);
344 } 344 }
345 addClass(element); 345 addClass(element);
346 } 346 }
347 }); 347 });
348 348
349 // Add synthesized constructors to classes with no resolved constructors,
350 // but which originally had any constructor. That should prevent
351 // those classes from being instantiable with default constructor.
352 Identifier synthesizedIdentifier = new Identifier(
353 new StringToken.fromString(IDENTIFIER_INFO, '', -1));
354
355 NextClassElement:
356 for (ClassElement classElement in classMembers.keys) {
357 if (emitNoMembersFor.contains(classElement)) continue;
358 for (Element member in classMembers[classElement]) {
359 if (member.isConstructor) continue NextClassElement;
360 }
361 if (classElement.constructors.isEmpty) continue NextClassElement;
362
363 // TODO(antonm): check with AAR team if there is better approach.
364 // As an idea: provide template as a Dart code---class C { C.name(); }---
365 // and then overwrite necessary parts.
366 var classNode = classElement.node;
367 SynthesizedConstructorElementX constructor =
368 new SynthesizedConstructorElementX(
369 classElement.name, null, classElement, false);
370 constructor.typeCache =
371 new FunctionType(constructor, const VoidType());
372 if (!constructor.isSynthesized) {
373 classMembers[classElement].add(constructor);
374 }
375 FunctionExpression node = new FunctionExpression(
376 new Send(classNode.name, synthesizedIdentifier),
377 new NodeList(new StringToken.fromString(OPEN_PAREN_INFO, '(', -1),
378 const Link<Node>(),
379 new StringToken.fromString(CLOSE_PAREN_INFO, ')', -1)),
380 new EmptyStatement(
381 new StringToken.fromString(SEMICOLON_INFO, ';', -1)),
382 null, Modifiers.EMPTY, null, null);
383
384 elementAsts[constructor] =
385 new ElementAst.internal(node, new TreeElementMapping(null));
386 }
387
388 // Create all necessary placeholders. 349 // Create all necessary placeholders.
389 PlaceholderCollector collector = 350 PlaceholderCollector collector =
390 new PlaceholderCollector(compiler, fixedMemberNames, elementAsts); 351 new PlaceholderCollector(compiler, fixedMemberNames, elementAsts);
391 // Add synthesizedIdentifier to set of unresolved names to rename it to
392 // some unused identifier.
393 collector.unresolvedNodes.add(synthesizedIdentifier);
394 makePlaceholders(element) { 352 makePlaceholders(element) {
395 bool oldUseHelper = useMirrorHelperLibrary; 353 bool oldUseHelper = useMirrorHelperLibrary;
396 useMirrorHelperLibrary = (useMirrorHelperLibrary 354 useMirrorHelperLibrary = (useMirrorHelperLibrary
397 && element.library != mirrorHelperLibrary); 355 && element.library != mirrorHelperLibrary);
398 collector.collect(element); 356 collector.collect(element);
399 useMirrorHelperLibrary = oldUseHelper; 357 useMirrorHelperLibrary = oldUseHelper;
400 358
401 if (element.isClass) { 359 if (element.isClass) {
402 classMembers[element].forEach(makePlaceholders); 360 classMembers[element].forEach(makePlaceholders);
403 } 361 }
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 } 739 }
782 740
783 Constant compileMetadata(MetadataAnnotation metadata, 741 Constant compileMetadata(MetadataAnnotation metadata,
784 Node node, 742 Node node,
785 TreeElements elements) { 743 TreeElements elements) {
786 return measure(() { 744 return measure(() {
787 return constantCompiler.compileMetadata(metadata, node, elements); 745 return constantCompiler.compileMetadata(metadata, node, elements);
788 }); 746 });
789 } 747 }
790 } 748 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/backend_dart/dart_backend_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698