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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/elements/modelx.dart

Issue 19754002: Rewrite how we handle synthesized constructors in the compiler. This was motivated by issue https:/… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library elements.modelx; 5 library elements.modelx;
6 6
7 import 'dart:collection' show LinkedHashMap; 7 import 'dart:collection' show LinkedHashMap;
8 8
9 import 'elements.dart'; 9 import 'elements.dart';
10 import '../../compiler.dart' as api; 10 import '../../compiler.dart' as api;
(...skipping 1380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 } 1391 }
1392 1392
1393 /** 1393 /**
1394 * A constructor that is not defined in the source code but rather implied by 1394 * A constructor that is not defined in the source code but rather implied by
1395 * the language semantics. 1395 * the language semantics.
1396 * 1396 *
1397 * This class is used to represent default constructors and forwarding 1397 * This class is used to represent default constructors and forwarding
1398 * constructors for mixin applications. 1398 * constructors for mixin applications.
1399 */ 1399 */
1400 class SynthesizedConstructorElementX extends FunctionElementX { 1400 class SynthesizedConstructorElementX extends FunctionElementX {
1401 /// The target constructor if this synthetic constructor is a forwarding 1401 final FunctionElement superMember;
1402 /// constructor in a mixin application.
1403 final FunctionElement target;
1404 1402
1405 SynthesizedConstructorElementX(Element enclosing) 1403 SynthesizedConstructorElementX(SourceString name,
1406 : super(enclosing.name, ElementKind.GENERATIVE_CONSTRUCTOR, 1404 this.superMember,
1407 Modifiers.EMPTY, enclosing), 1405 Element enclosing)
1408 target = null; 1406 : super(name,
1407 ElementKind.GENERATIVE_CONSTRUCTOR,
1408 Modifiers.EMPTY,
1409 enclosing);
1409 1410
1410 SynthesizedConstructorElementX.forDefault(Element enclosing, 1411 SynthesizedConstructorElementX.forDefault(superMember, Element enclosing)
1411 Compiler compiler) 1412 : this(const SourceString(''), superMember, enclosing);
1412 : super(const SourceString(''), ElementKind.GENERATIVE_CONSTRUCTOR,
1413 Modifiers.EMPTY, enclosing),
1414 target = null {
1415 // TODO(karlklose): get rid of the fake AST.
1416 type = new FunctionType(this,
1417 compiler.types.voidType,
1418 const Link<DartType>(),
1419 const Link<DartType>(),
1420 const Link<SourceString>(),
1421 const Link<DartType>());
1422 cachedNode = new FunctionExpression(
1423 new Identifier(enclosing.position()),
1424 new NodeList.empty(),
1425 new Block(new NodeList.empty()),
1426 null, Modifiers.EMPTY, null, null);
1427 }
1428
1429 /**
1430 * Create synthetic constructor that directly forwards to a constructor in the
1431 * super class of a mixin application.
1432 *
1433 * In a mixin application `Base with M`, any constructor defined in `Base` is
1434 * available as if they were a constructor defined in the mixin application
1435 * with the same formal parameters that calls the constructor in the super
1436 * class via a `super` initializer (see Ch. 9.1 in the specification).
1437 */
1438 SynthesizedConstructorElementX.forwarding(SourceString name, this.target,
1439 Element enclosing)
1440 : super(name, ElementKind.GENERATIVE_CONSTRUCTOR, Modifiers.EMPTY,
1441 enclosing);
1442 1413
1443 Token position() => enclosingElement.position(); 1414 Token position() => enclosingElement.position();
1444 1415
1445 bool get isSynthesized => true; 1416 bool get isSynthesized => true;
1446 1417
1447 bool get isForwardingConstructor => target != null; 1418 FunctionElement get targetConstructor => superMember;
1448
1449 FunctionElement get targetConstructor => target;
1450 1419
1451 FunctionSignature computeSignature(compiler) { 1420 FunctionSignature computeSignature(compiler) {
1452 if (target != null) { 1421 if (superMember.isErroneous()) {
1453 return target.computeSignature(compiler); 1422 return compiler.objectClass.localLookup(
1454 } else { 1423 const SourceString('')).computeSignature(compiler);
1455 assert(cachedNode != null);
1456 return super.computeSignature(compiler);
1457 } 1424 }
1425 return superMember.computeSignature(compiler);
1458 } 1426 }
1459 1427
1460 get declaration => this; 1428 get declaration => this;
1461 get implementation => this; 1429 get implementation => this;
1462 get defaultImplementation => this; 1430 get defaultImplementation => this;
1463 } 1431 }
1464 1432
1465 class VoidElementX extends ElementX { 1433 class VoidElementX extends ElementX {
1466 VoidElementX(Element enclosing) 1434 VoidElementX(Element enclosing)
1467 : super(const SourceString('void'), ElementKind.VOID, enclosing); 1435 : super(const SourceString('void'), ElementKind.VOID, enclosing);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 1565
1598 Link<DartType> get typeVariables => thisType.typeArguments; 1566 Link<DartType> get typeVariables => thisType.typeArguments;
1599 1567
1600 ClassElement ensureResolved(Compiler compiler) { 1568 ClassElement ensureResolved(Compiler compiler) {
1601 if (resolutionState == STATE_NOT_STARTED) { 1569 if (resolutionState == STATE_NOT_STARTED) {
1602 compiler.resolver.resolveClass(this); 1570 compiler.resolver.resolveClass(this);
1603 } 1571 }
1604 return this; 1572 return this;
1605 } 1573 }
1606 1574
1607 void addDefaultConstructorIfNeeded(Compiler compiler) {
1608 if (hasConstructor) return;
1609 FunctionElement constructor =
1610 new SynthesizedConstructorElementX.forDefault(this, compiler);
1611 setDefaultConstructor(constructor, compiler);
1612 }
1613
1614 void setDefaultConstructor(FunctionElement constructor, Compiler compiler); 1575 void setDefaultConstructor(FunctionElement constructor, Compiler compiler);
1615 1576
1616 void addBackendMember(Element member) { 1577 void addBackendMember(Element member) {
1617 // TODO(ngeoffray): Deprecate this method. 1578 // TODO(ngeoffray): Deprecate this method.
1618 assert(member.isGenerativeConstructorBody()); 1579 assert(member.isGenerativeConstructorBody());
1619 backendMembers = backendMembers.prepend(member); 1580 backendMembers = backendMembers.prepend(member);
1620 } 1581 }
1621 1582
1622 void reverseBackendMembers() { 1583 void reverseBackendMembers() {
1623 backendMembers = backendMembers.reverse(); 1584 backendMembers = backendMembers.reverse();
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
2219 2180
2220 MetadataAnnotation ensureResolved(Compiler compiler) { 2181 MetadataAnnotation ensureResolved(Compiler compiler) {
2221 if (resolutionState == STATE_NOT_STARTED) { 2182 if (resolutionState == STATE_NOT_STARTED) {
2222 compiler.resolver.resolveMetadataAnnotation(this); 2183 compiler.resolver.resolveMetadataAnnotation(this);
2223 } 2184 }
2224 return this; 2185 return this;
2225 } 2186 }
2226 2187
2227 String toString() => 'MetadataAnnotation($value, $resolutionState)'; 2188 String toString() => 'MetadataAnnotation($value, $resolutionState)';
2228 } 2189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698