| 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 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 ClassElement ensureResolved(Compiler compiler) { | 923 ClassElement ensureResolved(Compiler compiler) { |
| 924 compiler.resolveClass(this); | 924 compiler.resolveClass(this); |
| 925 return this; | 925 return this; |
| 926 } | 926 } |
| 927 | 927 |
| 928 Element lookupLocalMember(SourceString memberName) { | 928 Element lookupLocalMember(SourceString memberName) { |
| 929 return localMembers[memberName]; | 929 return localMembers[memberName]; |
| 930 } | 930 } |
| 931 | 931 |
| 932 Element lookupSuperMember(SourceString memberName) { | 932 Element lookupSuperMember(SourceString memberName) { |
| 933 bool isPrivate = memberName.isPrivate(); |
| 933 for (ClassElement s = superclass; s != null; s = s.superclass) { | 934 for (ClassElement s = superclass; s != null; s = s.superclass) { |
| 935 // Private members from a different library are not visible. |
| 936 if (isPrivate && getLibrary() !== s.getLibrary()) continue; |
| 934 Element e = s.lookupLocalMember(memberName); | 937 Element e = s.lookupLocalMember(memberName); |
| 935 if (e === null) continue; | 938 if (e === null) continue; |
| 936 // Private members from a different library are not visible. | |
| 937 if (memberName.isPrivate() && getLibrary() !== e.getLibrary()) continue; | |
| 938 // Static members are not inherited. | 939 // Static members are not inherited. |
| 939 if (e.modifiers.isStatic()) continue; | 940 if (e.modifiers.isStatic()) continue; |
| 940 return e; | 941 return e; |
| 941 } | 942 } |
| 942 return null; | 943 return null; |
| 943 } | 944 } |
| 944 | 945 |
| 945 /** | 946 /** |
| 946 * Find the first member in the class chain with the given | 947 * Find the first member in the class chain with the given |
| 947 * [memberName]. This method is NOT to be used for resolving | 948 * [memberName]. This method is NOT to be used for resolving |
| 948 * unqualified sends because it does not implement the scoping | 949 * unqualified sends because it does not implement the scoping |
| 949 * rules, where library scope comes before superclass scope. | 950 * rules, where library scope comes before superclass scope. |
| 950 */ | 951 */ |
| 951 Element lookupMember(SourceString memberName) { | 952 Element lookupMember(SourceString memberName) { |
| 952 Element localMember = localMembers[memberName]; | 953 Element localMember = localMembers[memberName]; |
| 953 return localMember === null ? lookupSuperMember(memberName) : localMember; | 954 return localMember === null ? lookupSuperMember(memberName) : localMember; |
| 954 } | 955 } |
| 955 | 956 |
| 957 /** |
| 958 * Returns true if the [fieldMember] is shadowed by another field. The given |
| 959 * [fieldMember] must be a member of this class. |
| 960 * |
| 961 * This method also works if the [fieldMember] is private. |
| 962 */ |
| 963 bool isShadowedByField(Element fieldMember) { |
| 964 assert(fieldMember.isField()); |
| 965 // Note that we cannot use [lookupMember] or [lookupSuperMember] since it |
| 966 // will not do the right thing for private elements. |
| 967 ClassElement lookupClass = this; |
| 968 LibraryElement memberLibrary = fieldMember.getLibrary(); |
| 969 if (fieldMember.name.isPrivate()) { |
| 970 // We find a super class in the same library as the field. This way the |
| 971 // lookupMember will work. |
| 972 while (lookupClass.getLibrary() != memberLibrary) { |
| 973 lookupClass = lookupClass.superclass; |
| 974 } |
| 975 } |
| 976 SourceString fieldName = fieldMember.name; |
| 977 while (true) { |
| 978 Element foundMember = lookupClass.lookupMember(fieldName); |
| 979 if (foundMember == fieldMember) return false; |
| 980 if (foundMember.isField()) return true; |
| 981 lookupClass = (foundMember.enclosingElement as ClassElement).superclass; |
| 982 } |
| 983 } |
| 984 |
| 956 Element lookupConstructor(SourceString className, | 985 Element lookupConstructor(SourceString className, |
| 957 [SourceString constructorName = | 986 [SourceString constructorName = |
| 958 const SourceString(''), | 987 const SourceString(''), |
| 959 Element noMatch(Element)]) { | 988 Element noMatch(Element)]) { |
| 960 // TODO(karlklose): have a map from class names to a map of constructors | 989 // TODO(karlklose): have a map from class names to a map of constructors |
| 961 // instead of creating the name here? | 990 // instead of creating the name here? |
| 962 SourceString normalizedName; | 991 SourceString normalizedName; |
| 963 if (constructorName !== const SourceString('')) { | 992 if (constructorName !== const SourceString('')) { |
| 964 normalizedName = Elements.constructConstructorName(className, | 993 normalizedName = Elements.constructConstructorName(className, |
| 965 constructorName); | 994 constructorName); |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 TypeVariableElement(name, Element enclosing, this.cachedNode, | 1277 TypeVariableElement(name, Element enclosing, this.cachedNode, |
| 1249 [this.type, this.bound]) | 1278 [this.type, this.bound]) |
| 1250 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | 1279 : super(name, ElementKind.TYPE_VARIABLE, enclosing); |
| 1251 | 1280 |
| 1252 TypeVariableType computeType(compiler) => type; | 1281 TypeVariableType computeType(compiler) => type; |
| 1253 | 1282 |
| 1254 Node parseNode(compiler) => cachedNode; | 1283 Node parseNode(compiler) => cachedNode; |
| 1255 | 1284 |
| 1256 String toString() => "${enclosingElement.toString()}.${name.slowToString()}"; | 1285 String toString() => "${enclosingElement.toString()}.${name.slowToString()}"; |
| 1257 } | 1286 } |
| OLD | NEW |