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

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

Issue 11299225: Revert "Canonicalize raw type" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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) 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 library elements; 5 library elements;
6 6
7 import 'dart:uri'; 7 import 'dart:uri';
8 8
9 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed. 9 // TODO(ahe): Rename prefix to 'api' when VM bug is fixed.
10 import '../../compiler.dart' as api_e; 10 import '../../compiler.dart' as api_e;
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 lookupLocalMember(SourceString memberName) => imported[memberName]; 831 lookupLocalMember(SourceString memberName) => imported[memberName];
832 832
833 DartType computeType(Compiler compiler) => compiler.types.dynamicType; 833 DartType computeType(Compiler compiler) => compiler.types.dynamicType;
834 834
835 Token position() => firstPosition; 835 Token position() => firstPosition;
836 } 836 }
837 837
838 class TypedefElement extends Element implements TypeDeclarationElement { 838 class TypedefElement extends Element implements TypeDeclarationElement {
839 Typedef cachedNode; 839 Typedef cachedNode;
840 TypedefType cachedType; 840 TypedefType cachedType;
841
842 /**
843 * Canonicalize raw version of [cachedType].
844 *
845 * See [ClassElement.rawType] for motivation.
846 *
847 * The [rawType] is computed together with [cachedType] in [computeType].
848 */
849 TypedefType rawType;
850
851 /**
852 * The type annotation which defines this typedef.
853 */
854 DartType alias; 841 DartType alias;
855 842
856 bool isResolved = false; 843 bool isResolved = false;
857 bool isBeingResolved = false; 844 bool isBeingResolved = false;
858 845
859 TypedefElement(SourceString name, Element enclosing) 846 TypedefElement(SourceString name, Element enclosing)
860 : super(name, ElementKind.TYPEDEF, enclosing); 847 : super(name, ElementKind.TYPEDEF, enclosing);
861 848
862 /** 849 /**
863 * Function signature for a typedef of a function type. The signature is 850 * Function signature for a typedef of a function type. The signature is
864 * kept to provide full information about parameter names through the mirror 851 * kept to provide full information about parameter names through the mirror
865 * system. 852 * system.
866 * 853 *
867 * The [functionSignature] is not available until the typedef element has been 854 * The [functionSignature] is not available until the typedef element has been
868 * resolved. 855 * resolved.
869 */ 856 */
870 FunctionSignature functionSignature; 857 FunctionSignature functionSignature;
871 858
872 TypedefType computeType(Compiler compiler) { 859 TypedefType computeType(Compiler compiler) {
873 if (cachedType != null) return cachedType; 860 if (cachedType != null) return cachedType;
874 Typedef node = parseNode(compiler); 861 Typedef node = parseNode(compiler);
875 Link<DartType> parameters = 862 Link<DartType> parameters =
876 TypeDeclarationElement.createTypeVariables(this, node.typeParameters); 863 TypeDeclarationElement.createTypeVariables(this, node.typeParameters);
877 cachedType = new TypedefType(this, parameters); 864 cachedType = new TypedefType(this, parameters);
878 if (parameters.isEmpty) {
879 rawType = cachedType;
880 } else {
881 var dynamicParameters = const Link<DartType>();
882 parameters.forEach((_) {
883 dynamicParameters =
884 dynamicParameters.prepend(compiler.types.dynamicType);
885 });
886 rawType = new TypedefType(this, dynamicParameters);
887 }
888 compiler.resolveTypedef(this); 865 compiler.resolveTypedef(this);
889 return cachedType; 866 return cachedType;
890 } 867 }
891 868
892 Link<DartType> get typeVariables => cachedType.typeArguments; 869 Link<DartType> get typeVariables => cachedType.typeArguments;
893 870
894 Scope buildScope() { 871 Scope buildScope() {
895 return new TypeDeclarationScope(enclosingElement.buildScope(), this); 872 return new TypeDeclarationScope(enclosingElement.buildScope(), this);
896 } 873 }
897 } 874 }
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 variableElement.type = variableType; 1376 variableElement.type = variableType;
1400 arguments.addLast(variableType); 1377 arguments.addLast(variableType);
1401 } 1378 }
1402 return arguments.toLink(); 1379 return arguments.toLink();
1403 } 1380 }
1404 } 1381 }
1405 1382
1406 abstract class ClassElement extends ScopeContainerElement 1383 abstract class ClassElement extends ScopeContainerElement
1407 implements TypeDeclarationElement { 1384 implements TypeDeclarationElement {
1408 final int id; 1385 final int id;
1409 /** 1386 InterfaceType type;
1410 * The type of [:this:] for this class declaration.
1411 *
1412 * The type of [:this:] is the interface type based on this element in which
1413 * the type arguments are the declared type variables. For instance,
1414 * [:List<E>:] for [:List:] and [:Map<K,V>:] for [:Map:].
1415 *
1416 * This type is computed in [computeType].
1417 */
1418 InterfaceType thisType;
1419
1420 /**
1421 * The raw type for this class declaration.
1422 *
1423 * The raw type is the interface type base on this element in which the type
1424 * arguments are all [dynamic]. For instance [:List<dynamic>:] for [:List:]
1425 * and [:Map<dynamic,dynamic>:] for [:Map:]. For non-generic classes [rawType]
1426 * is the same as [thisType].
1427 *
1428 * The [rawType] field is a canonicalization of the raw type and should be
1429 * used to distinguish explicit and implicit uses of the [dynamic]
1430 * type arguments. For instance should [:List:] be the [rawType] of the
1431 * [:List:] class element whereas [:List<dynamic>:] should be its own
1432 * instantiation of [InterfaceType] with [:dynamic:] as type argument. Using
1433 * this distinction, we can print the raw type with type arguments only when
1434 * the input source has used explicit type arguments.
1435 *
1436 * This type is computed together with [thisType] in [computeType].
1437 */
1438 InterfaceType rawType;
1439 DartType supertype; 1387 DartType supertype;
1440 DartType defaultClass; 1388 DartType defaultClass;
1441 Link<DartType> interfaces; 1389 Link<DartType> interfaces;
1442 SourceString nativeName; 1390 SourceString nativeName;
1443 int supertypeLoadState; 1391 int supertypeLoadState;
1444 int resolutionState; 1392 int resolutionState;
1445 1393
1446 // backendMembers are members that have been added by the backend to simplify 1394 // backendMembers are members that have been added by the backend to simplify
1447 // compilation. They don't have any user-side counter-part. 1395 // compilation. They don't have any user-side counter-part.
1448 Link<Element> backendMembers = const Link<Element>(); 1396 Link<Element> backendMembers = const Link<Element>();
1449 1397
1450 Link<DartType> allSupertypes; 1398 Link<DartType> allSupertypes;
1451 1399
1452 // Lazily applied patch of class members. 1400 // Lazily applied patch of class members.
1453 ClassElement patch = null; 1401 ClassElement patch = null;
1454 ClassElement origin = null; 1402 ClassElement origin = null;
1455 1403
1456 ClassElement(SourceString name, Element enclosing, this.id, int initialState) 1404 ClassElement(SourceString name, Element enclosing, this.id, int initialState)
1457 : supertypeLoadState = initialState, 1405 : supertypeLoadState = initialState,
1458 resolutionState = initialState, 1406 resolutionState = initialState,
1459 super(name, ElementKind.CLASS, enclosing); 1407 super(name, ElementKind.CLASS, enclosing);
1460 1408
1461 ClassNode parseNode(Compiler compiler); 1409 ClassNode parseNode(Compiler compiler);
1462 1410
1463 InterfaceType computeType(compiler) { 1411 InterfaceType computeType(compiler) {
1464 if (thisType == null) { 1412 if (type == null) {
1465 if (origin == null) { 1413 if (origin == null) {
1466 ClassNode node = parseNode(compiler); 1414 ClassNode node = parseNode(compiler);
1467 Link<DartType> parameters = 1415 Link<DartType> parameters =
1468 TypeDeclarationElement.createTypeVariables(this, 1416 TypeDeclarationElement.createTypeVariables(this,
1469 node.typeParameters); 1417 node.typeParameters);
1470 thisType = new InterfaceType(this, parameters); 1418 type = new InterfaceType(this, parameters);
1471 if (parameters.isEmpty) {
1472 rawType = thisType;
1473 } else {
1474 var dynamicParameters = const Link<DartType>();
1475 parameters.forEach((_) {
1476 dynamicParameters =
1477 dynamicParameters.prepend(compiler.types.dynamicType);
1478 });
1479 rawType = new InterfaceType(this, dynamicParameters);
1480 }
1481 } else { 1419 } else {
1482 thisType = origin.computeType(compiler); 1420 type = origin.computeType(compiler);
1483 rawType = origin.rawType;
1484 } 1421 }
1485 } 1422 }
1486 return thisType; 1423 return type;
1487 } 1424 }
1488 1425
1489 bool get isPatched => patch != null; 1426 bool get isPatched => patch != null;
1490 bool get isPatch => origin != null; 1427 bool get isPatch => origin != null;
1491 1428
1492 ClassElement get declaration => super.declaration; 1429 ClassElement get declaration => super.declaration;
1493 ClassElement get implementation => super.implementation; 1430 ClassElement get implementation => super.implementation;
1494 1431
1495 /** 1432 /**
1496 * Return [:true:] if this element is the [:Object:] class for the [compiler]. 1433 * Return [:true:] if this element is the [:Object:] class for the [compiler].
1497 */ 1434 */
1498 bool isObject(Compiler compiler) => 1435 bool isObject(Compiler compiler) =>
1499 identical(declaration, compiler.objectClass); 1436 identical(declaration, compiler.objectClass);
1500 1437
1501 Link<DartType> get typeVariables => thisType.typeArguments; 1438 Link<DartType> get typeVariables => type.typeArguments;
1502 1439
1503 ClassElement ensureResolved(Compiler compiler) { 1440 ClassElement ensureResolved(Compiler compiler) {
1504 if (resolutionState == STATE_NOT_STARTED) { 1441 if (resolutionState == STATE_NOT_STARTED) {
1505 compiler.resolver.resolveClass(this); 1442 compiler.resolver.resolveClass(this);
1506 } 1443 }
1507 return this; 1444 return this;
1508 } 1445 }
1509 1446
1510 /** 1447 /**
1511 * Lookup local members in the class. This will ignore constructors. 1448 * Lookup local members in the class. This will ignore constructors.
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 } 1722 }
1786 return false; 1723 return false;
1787 } 1724 }
1788 1725
1789 bool isInterface() => false; 1726 bool isInterface() => false;
1790 bool isNative() => nativeName != null; 1727 bool isNative() => nativeName != null;
1791 int get hashCode => id; 1728 int get hashCode => id;
1792 1729
1793 Scope buildScope() => new ClassScope(enclosingElement.buildScope(), this); 1730 Scope buildScope() => new ClassScope(enclosingElement.buildScope(), this);
1794 1731
1732 Link<DartType> get allSupertypesAndSelf {
1733 return allSupertypes.prepend(new InterfaceType(this));
1734 }
1735
1795 String toString() { 1736 String toString() {
1796 if (origin != null) { 1737 if (origin != null) {
1797 return 'patch ${super.toString()}'; 1738 return 'patch ${super.toString()}';
1798 } else if (patch != null) { 1739 } else if (patch != null) {
1799 return 'origin ${super.toString()}'; 1740 return 'origin ${super.toString()}';
1800 } else { 1741 } else {
1801 return super.toString(); 1742 return super.toString();
1802 } 1743 }
1803 } 1744 }
1804 } 1745 }
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
2134 2075
2135 MetadataAnnotation ensureResolved(Compiler compiler) { 2076 MetadataAnnotation ensureResolved(Compiler compiler) {
2136 if (resolutionState == STATE_NOT_STARTED) { 2077 if (resolutionState == STATE_NOT_STARTED) {
2137 compiler.resolver.resolveMetadataAnnotation(this); 2078 compiler.resolver.resolveMetadataAnnotation(this);
2138 } 2079 }
2139 return this; 2080 return this;
2140 } 2081 }
2141 2082
2142 String toString() => 'MetadataAnnotation($value, $resolutionState)'; 2083 String toString() => 'MetadataAnnotation($value, $resolutionState)';
2143 } 2084 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698