OLD | NEW |
---|---|
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('../tree/tree.dart'); | 7 #import('../tree/tree.dart'); |
8 #import('../scanner/scannerlib.dart'); | 8 #import('../scanner/scannerlib.dart'); |
9 #import('../leg.dart'); // TODO(karlklose): we only need type. | 9 #import('../leg.dart'); // TODO(karlklose): we only need type. |
10 #import('../util/util.dart'); | 10 #import('../util/util.dart'); |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 | 441 |
442 class TypedefElement extends Element implements TypeDeclarationElement { | 442 class TypedefElement extends Element implements TypeDeclarationElement { |
443 Type cachedType; | 443 Type cachedType; |
444 Typedef cachedNode; | 444 Typedef cachedNode; |
445 | 445 |
446 TypedefElement(SourceString name, Element enclosing) | 446 TypedefElement(SourceString name, Element enclosing) |
447 : super(name, ElementKind.TYPEDEF, enclosing); | 447 : super(name, ElementKind.TYPEDEF, enclosing); |
448 | 448 |
449 Type computeType(Compiler compiler) { | 449 Type computeType(Compiler compiler) { |
450 if (cachedType !== null) return cachedType; | 450 if (cachedType !== null) return cachedType; |
451 cachedType = compiler.computeFunctionType( | 451 cachedType = new FunctionType(null, null, this); |
452 this, compiler.resolveTypedef(this)); | 452 cachedType.initializeFrom( |
Lasse Reichstein Nielsen
2012/08/13 13:34:48
Make initialize a copy constructor instead.
ahe
2012/08/13 15:14:01
I don't think I can do that. I got to keep the sam
| |
453 compiler.computeFunctionType(this, compiler.resolveTypedef(this))); | |
453 return cachedType; | 454 return cachedType; |
454 } | 455 } |
455 | 456 |
456 Link<Type> get typeVariables() => const EmptyLink<Type>(); | 457 Link<Type> get typeVariables() => const EmptyLink<Type>(); |
457 | 458 |
458 Scope buildScope() => | 459 Scope buildScope() => |
459 new TypeDeclarationScope(enclosingElement.buildScope(), this); | 460 new TypeDeclarationScope(enclosingElement.buildScope(), this); |
460 } | 461 } |
461 | 462 |
462 class VariableElement extends Element { | 463 class VariableElement extends Element { |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
874 TypeVariableType variableType = new TypeVariableType(variableElement); | 875 TypeVariableType variableType = new TypeVariableType(variableElement); |
875 variableElement.type = variableType; | 876 variableElement.type = variableType; |
876 arguments.addLast(variableType); | 877 arguments.addLast(variableType); |
877 } | 878 } |
878 return arguments.toLink(); | 879 return arguments.toLink(); |
879 } | 880 } |
880 } | 881 } |
881 | 882 |
882 class ClassElement extends ContainerElement | 883 class ClassElement extends ContainerElement |
883 implements TypeDeclarationElement { | 884 implements TypeDeclarationElement { |
885 static final int STATE_NOT_STARTED = 0; | |
886 static final int STATE_STARTED = 1; | |
887 static final int STATE_DONE = 2; | |
888 | |
884 final int id; | 889 final int id; |
885 InterfaceType type; | 890 InterfaceType type; |
886 Type supertype; | 891 Type supertype; |
887 Type defaultClass; | 892 Type defaultClass; |
888 Link<Element> members = const EmptyLink<Element>(); | 893 Link<Element> members = const EmptyLink<Element>(); |
889 Map<SourceString, Element> localMembers; | 894 Map<SourceString, Element> localMembers; |
890 Map<SourceString, Element> constructors; | 895 Map<SourceString, Element> constructors; |
891 Link<Type> interfaces = const EmptyLink<Type>(); | 896 Link<Type> interfaces; |
892 bool isResolved = false; | 897 |
893 bool isBeingResolved = false; | 898 int _supertypeLoadState = STATE_NOT_STARTED; |
899 int get supertypeLoadState() => _supertypeLoadState; | |
900 void set supertypeLoadState(int state) { | |
901 assert(state == _supertypeLoadState + 1); | |
Lasse Reichstein Nielsen
2012/08/13 13:34:48
Also assert that it's not larger than STATE_DONE.
ahe
2012/08/13 15:14:01
Done.
| |
902 _supertypeLoadState = state; | |
903 } | |
904 | |
905 int _resolutionState = STATE_NOT_STARTED; | |
906 int get resolutionState() => _resolutionState; | |
907 void set resolutionState(int state) { | |
908 assert(state == _resolutionState + 1); | |
909 _resolutionState = state; | |
910 } | |
911 | |
894 // backendMembers are members that have been added by the backend to simplify | 912 // backendMembers are members that have been added by the backend to simplify |
895 // compilation. They don't have any user-side counter-part. | 913 // compilation. They don't have any user-side counter-part. |
896 Link<Element> backendMembers = const EmptyLink<Element>(); | 914 Link<Element> backendMembers = const EmptyLink<Element>(); |
897 | 915 |
898 Link<Type> allSupertypes; | 916 Link<Type> allSupertypes; |
899 ClassElement patch = null; | 917 ClassElement patch = null; |
900 | 918 |
901 ClassElement(SourceString name, CompilationUnitElement enclosing, this.id) | 919 ClassElement(SourceString name, CompilationUnitElement enclosing, this.id) |
902 : localMembers = new Map<SourceString, Element>(), | 920 : localMembers = new Map<SourceString, Element>(), |
903 constructors = new Map<SourceString, Element>(), | 921 constructors = new Map<SourceString, Element>(), |
(...skipping 18 matching lines...) Expand all Loading... | |
922 Link<Type> parameters = | 940 Link<Type> parameters = |
923 TypeDeclarationElement.createTypeVariables(this, node.typeParameters); | 941 TypeDeclarationElement.createTypeVariables(this, node.typeParameters); |
924 type = new InterfaceType(this, parameters); | 942 type = new InterfaceType(this, parameters); |
925 } | 943 } |
926 return type; | 944 return type; |
927 } | 945 } |
928 | 946 |
929 Link<Type> get typeVariables() => type.arguments; | 947 Link<Type> get typeVariables() => type.arguments; |
930 | 948 |
931 ClassElement ensureResolved(Compiler compiler) { | 949 ClassElement ensureResolved(Compiler compiler) { |
932 compiler.resolveClass(this); | 950 if (resolutionState == STATE_NOT_STARTED) { |
951 compiler.resolver.resolveClass(this); | |
952 } | |
933 return this; | 953 return this; |
934 } | 954 } |
935 | 955 |
936 Element lookupLocalMember(SourceString memberName) { | 956 Element lookupLocalMember(SourceString memberName) { |
937 return localMembers[memberName]; | 957 return localMembers[memberName]; |
938 } | 958 } |
939 | 959 |
940 Element lookupSuperMember(SourceString memberName) { | 960 Element lookupSuperMember(SourceString memberName) { |
941 bool isPrivate = memberName.isPrivate(); | 961 bool isPrivate = memberName.isPrivate(); |
942 for (ClassElement s = superclass; s != null; s = s.superclass) { | 962 for (ClassElement s = superclass; s != null; s = s.superclass) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1009 } | 1029 } |
1010 return result; | 1030 return result; |
1011 } | 1031 } |
1012 | 1032 |
1013 /** | 1033 /** |
1014 * Returns the super class, if any. | 1034 * Returns the super class, if any. |
1015 * | 1035 * |
1016 * The returned element may not be resolved yet. | 1036 * The returned element may not be resolved yet. |
1017 */ | 1037 */ |
1018 ClassElement get superclass() { | 1038 ClassElement get superclass() { |
1019 assert(isResolved); | 1039 assert(supertypeLoadState == STATE_DONE); |
1020 return supertype === null ? null : supertype.element; | 1040 return supertype === null ? null : supertype.element; |
1021 } | 1041 } |
1022 | 1042 |
1023 /** | 1043 /** |
1024 * Runs through all members of this class. | 1044 * Runs through all members of this class. |
1025 * | 1045 * |
1026 * The enclosing class is passed to the callback. This is useful when | 1046 * The enclosing class is passed to the callback. This is useful when |
1027 * [includeSuperMembers] is [:true:]. | 1047 * [includeSuperMembers] is [:true:]. |
1028 */ | 1048 */ |
1029 void forEachMember([void f(ClassElement enclosingClass, Element member), | 1049 void forEachMember([void f(ClassElement enclosingClass, Element member), |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1284 TypeVariableElement(name, Element enclosing, this.cachedNode, | 1304 TypeVariableElement(name, Element enclosing, this.cachedNode, |
1285 [this.type, this.bound]) | 1305 [this.type, this.bound]) |
1286 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | 1306 : super(name, ElementKind.TYPE_VARIABLE, enclosing); |
1287 | 1307 |
1288 TypeVariableType computeType(compiler) => type; | 1308 TypeVariableType computeType(compiler) => type; |
1289 | 1309 |
1290 Node parseNode(compiler) => cachedNode; | 1310 Node parseNode(compiler) => cachedNode; |
1291 | 1311 |
1292 String toString() => "${enclosingElement.toString()}.${name.slowToString()}"; | 1312 String toString() => "${enclosingElement.toString()}.${name.slowToString()}"; |
1293 } | 1313 } |
OLD | NEW |