Chromium Code Reviews| 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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 | 433 |
| 434 class TypedefElement extends Element implements TypeDeclarationElement { | 434 class TypedefElement extends Element implements TypeDeclarationElement { |
| 435 Type cachedType; | 435 Type cachedType; |
| 436 Typedef cachedNode; | 436 Typedef cachedNode; |
| 437 | 437 |
| 438 TypedefElement(SourceString name, Element enclosing) | 438 TypedefElement(SourceString name, Element enclosing) |
| 439 : super(name, ElementKind.TYPEDEF, enclosing); | 439 : super(name, ElementKind.TYPEDEF, enclosing); |
| 440 | 440 |
| 441 Type computeType(Compiler compiler) { | 441 Type computeType(Compiler compiler) { |
| 442 if (cachedType !== null) return cachedType; | 442 if (cachedType !== null) return cachedType; |
| 443 cachedType = compiler.computeFunctionType( | 443 cachedType = new FunctionType(null, null, this); |
| 444 this, compiler.resolveTypedef(this)); | 444 cachedType.initializeFrom( |
| 445 compiler.computeFunctionType(this, compiler.resolveTypedef(this))); | |
| 445 return cachedType; | 446 return cachedType; |
| 446 } | 447 } |
| 447 | 448 |
| 448 Link<Type> get typeVariables() => const EmptyLink<Type>(); | 449 Link<Type> get typeVariables() => const EmptyLink<Type>(); |
| 449 | 450 |
| 450 Scope buildScope() => | 451 Scope buildScope() => |
| 451 new TypeDeclarationScope(enclosingElement.buildScope(), this); | 452 new TypeDeclarationScope(enclosingElement.buildScope(), this); |
| 452 } | 453 } |
| 453 | 454 |
| 454 class VariableElement extends Element { | 455 class VariableElement extends Element { |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 876 final int id; | 877 final int id; |
| 877 InterfaceType type; | 878 InterfaceType type; |
| 878 Type supertype; | 879 Type supertype; |
| 879 Type defaultClass; | 880 Type defaultClass; |
| 880 Link<Element> members = const EmptyLink<Element>(); | 881 Link<Element> members = const EmptyLink<Element>(); |
| 881 Map<SourceString, Element> localMembers; | 882 Map<SourceString, Element> localMembers; |
| 882 Map<SourceString, Element> constructors; | 883 Map<SourceString, Element> constructors; |
| 883 Link<Type> interfaces = const EmptyLink<Type>(); | 884 Link<Type> interfaces = const EmptyLink<Type>(); |
| 884 bool isResolved = false; | 885 bool isResolved = false; |
| 885 bool isBeingResolved = false; | 886 bool isBeingResolved = false; |
| 887 bool isLoadingSupertypes = false; | |
| 888 bool supertypesAreLoaded = false; | |
|
Lasse Reichstein Nielsen
2012/08/07 09:02:17
Should we consider some kind of "state" type with
| |
| 889 | |
| 886 // backendMembers are members that have been added by the backend to simplify | 890 // backendMembers are members that have been added by the backend to simplify |
| 887 // compilation. They don't have any user-side counter-part. | 891 // compilation. They don't have any user-side counter-part. |
| 888 Link<Element> backendMembers = const EmptyLink<Element>(); | 892 Link<Element> backendMembers = const EmptyLink<Element>(); |
| 889 | 893 |
| 890 Link<Type> allSupertypes; | 894 Link<Type> allSupertypes; |
| 891 ClassElement patch = null; | 895 ClassElement patch = null; |
| 892 | 896 |
| 893 ClassElement(SourceString name, CompilationUnitElement enclosing, this.id) | 897 ClassElement(SourceString name, CompilationUnitElement enclosing, this.id) |
| 894 : localMembers = new Map<SourceString, Element>(), | 898 : localMembers = new Map<SourceString, Element>(), |
| 895 constructors = new Map<SourceString, Element>(), | 899 constructors = new Map<SourceString, Element>(), |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 914 Link<Type> parameters = | 918 Link<Type> parameters = |
| 915 TypeDeclarationElement.createTypeVariables(this, node.typeParameters); | 919 TypeDeclarationElement.createTypeVariables(this, node.typeParameters); |
| 916 type = new InterfaceType(this, parameters); | 920 type = new InterfaceType(this, parameters); |
| 917 } | 921 } |
| 918 return type; | 922 return type; |
| 919 } | 923 } |
| 920 | 924 |
| 921 Link<Type> get typeVariables() => type.arguments; | 925 Link<Type> get typeVariables() => type.arguments; |
| 922 | 926 |
| 923 ClassElement ensureResolved(Compiler compiler) { | 927 ClassElement ensureResolved(Compiler compiler) { |
| 924 compiler.resolveClass(this); | 928 if (!isResolved && !isBeingResolved) { |
| 929 isBeingResolved = true; | |
| 930 compiler.resolver.resolveClass(this); | |
|
Lasse Reichstein Nielsen
2012/08/07 09:02:17
This looks like the job for a work queue.
Can't w
| |
| 931 isBeingResolved = false; | |
| 932 isResolved = true; | |
| 933 } | |
| 925 return this; | 934 return this; |
| 926 } | 935 } |
| 927 | 936 |
| 928 Element lookupLocalMember(SourceString memberName) { | 937 Element lookupLocalMember(SourceString memberName) { |
| 929 return localMembers[memberName]; | 938 return localMembers[memberName]; |
| 930 } | 939 } |
| 931 | 940 |
| 932 Element lookupSuperMember(SourceString memberName) { | 941 Element lookupSuperMember(SourceString memberName) { |
| 933 for (ClassElement s = superclass; s != null; s = s.superclass) { | 942 for (ClassElement s = superclass; s != null; s = s.superclass) { |
| 934 Element e = s.lookupLocalMember(memberName); | 943 Element e = s.lookupLocalMember(memberName); |
| 935 if (e === null) continue; | 944 if (e === null) continue; |
| 936 // Private members from a different library are not visible. | 945 // Private members from a different library are not visible. |
| 937 if (memberName.isPrivate() && getLibrary() !== e.getLibrary()) continue; | 946 if (memberName.isPrivate() && getLibrary() !== e.getLibrary()) continue; |
| 938 // Static members are not inherited. | 947 // Static members are not inherited. |
| 939 if (e.modifiers.isStatic()) continue; | 948 if (e.modifiers.isStatic()) continue; |
| 940 return e; | 949 return e; |
| 941 } | 950 } |
| 951 if (isInterface()) { | |
| 952 return lookupSuperInterfaceMember(memberName, getLibrary()); | |
| 953 } | |
| 942 return null; | 954 return null; |
| 943 } | 955 } |
| 944 | 956 |
| 957 Element lookupSuperInterfaceMember(SourceString memberName, | |
| 958 LibraryElement fromLibrary) { | |
| 959 for (Type t in interfaces) { | |
| 960 Element e = t.element.lookupLocalMember(memberName); | |
| 961 if (e === null) continue; | |
| 962 // Private members from a different library are not visible. | |
| 963 if (memberName.isPrivate() && fromLibrary !== e.getLibrary()) continue; | |
| 964 // Static members are not inherited. | |
| 965 if (e.modifiers.isStatic()) continue; | |
| 966 return e; | |
| 967 } | |
| 968 } | |
| 969 | |
| 945 /** | 970 /** |
| 946 * Find the first member in the class chain with the given | 971 * Find the first member in the class chain with the given |
| 947 * [memberName]. This method is NOT to be used for resolving | 972 * [memberName]. This method is NOT to be used for resolving |
| 948 * unqualified sends because it does not implement the scoping | 973 * unqualified sends because it does not implement the scoping |
| 949 * rules, where library scope comes before superclass scope. | 974 * rules, where library scope comes before superclass scope. |
| 950 */ | 975 */ |
| 951 Element lookupMember(SourceString memberName) { | 976 Element lookupMember(SourceString memberName) { |
| 952 Element localMember = localMembers[memberName]; | 977 Element localMember = localMembers[memberName]; |
| 953 return localMember === null ? lookupSuperMember(memberName) : localMember; | 978 return localMember === null ? lookupSuperMember(memberName) : localMember; |
| 954 } | 979 } |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1248 TypeVariableElement(name, Element enclosing, this.cachedNode, | 1273 TypeVariableElement(name, Element enclosing, this.cachedNode, |
| 1249 [this.type, this.bound]) | 1274 [this.type, this.bound]) |
| 1250 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | 1275 : super(name, ElementKind.TYPE_VARIABLE, enclosing); |
| 1251 | 1276 |
| 1252 TypeVariableType computeType(compiler) => type; | 1277 TypeVariableType computeType(compiler) => type; |
| 1253 | 1278 |
| 1254 Node parseNode(compiler) => cachedNode; | 1279 Node parseNode(compiler) => cachedNode; |
| 1255 | 1280 |
| 1256 String toString() => "${enclosingElement.toString()}.${name.slowToString()}"; | 1281 String toString() => "${enclosingElement.toString()}.${name.slowToString()}"; |
| 1257 } | 1282 } |
| OLD | NEW |