| 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 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 Element lookupTypeParameter(SourceString parameterName) { | 865 Element lookupTypeParameter(SourceString parameterName) { |
| 866 Element result = typeParameters[parameterName]; | 866 Element result = typeParameters[parameterName]; |
| 867 return result; | 867 return result; |
| 868 } | 868 } |
| 869 | 869 |
| 870 Element lookupLocalMember(SourceString memberName) { | 870 Element lookupLocalMember(SourceString memberName) { |
| 871 return localMembers[memberName]; | 871 return localMembers[memberName]; |
| 872 } | 872 } |
| 873 | 873 |
| 874 Element lookupSuperMember(SourceString memberName) { | 874 Element lookupSuperMember(SourceString memberName) { |
| 875 bool isPrivate = memberName.isPrivate(); |
| 875 for (ClassElement s = superclass; s != null; s = s.superclass) { | 876 for (ClassElement s = superclass; s != null; s = s.superclass) { |
| 877 // Private members from a different library are not visible. |
| 878 if (isPrivate && getLibrary() !== s.getLibrary()) continue; |
| 876 Element e = s.lookupLocalMember(memberName); | 879 Element e = s.lookupLocalMember(memberName); |
| 877 if (e === null) continue; | 880 if (e === null) continue; |
| 878 // Private members from a different library are not visible. | |
| 879 if (memberName.isPrivate() && getLibrary() !== e.getLibrary()) continue; | |
| 880 // Static members are not inherited. | 881 // Static members are not inherited. |
| 881 if (e.modifiers.isStatic()) continue; | 882 if (e.modifiers.isStatic()) continue; |
| 882 return e; | 883 return e; |
| 883 } | 884 } |
| 884 return null; | 885 return null; |
| 885 } | 886 } |
| 886 | 887 |
| 887 /** | 888 /** |
| 888 * Find the first member in the class chain with the given | 889 * Find the first member in the class chain with the given |
| 889 * [memberName]. This method is NOT to be used for resolving | 890 * [memberName]. This method is NOT to be used for resolving |
| 890 * unqualified sends because it does not implement the scoping | 891 * unqualified sends because it does not implement the scoping |
| 891 * rules, where library scope comes before superclass scope. | 892 * rules, where library scope comes before superclass scope. |
| 892 */ | 893 */ |
| 893 Element lookupMember(SourceString memberName) { | 894 Element lookupMember(SourceString memberName) { |
| 894 Element localMember = localMembers[memberName]; | 895 Element localMember = localMembers[memberName]; |
| 895 return localMember === null ? lookupSuperMember(memberName) : localMember; | 896 return localMember === null ? lookupSuperMember(memberName) : localMember; |
| 896 } | 897 } |
| 897 | 898 |
| 899 /** |
| 900 * Returns true if the [fieldMember] is shadowed by another field. The given |
| 901 * [fieldMember] must be a member of this class. |
| 902 * |
| 903 * This method also works if the [fieldMember] is private. |
| 904 */ |
| 905 bool isShadowedByField(Element fieldMember) { |
| 906 assert(fieldMember.isField()); |
| 907 // Note that we cannot use [lookupMember] or [lookupSuperMember] since it |
| 908 // will not do the right thing for private elements. |
| 909 ClassElement lookupClass = this; |
| 910 LibraryElement memberLibrary = fieldMember.getLibrary(); |
| 911 if (fieldMember.name.isPrivate()) { |
| 912 // We find a super class in the same library as the field. This way the |
| 913 // lookupMember will work. |
| 914 while (lookupClass.getLibrary() != memberLibrary) { |
| 915 lookupClass = lookupClass.superclass; |
| 916 } |
| 917 } |
| 918 SourceString fieldName = fieldMember.name; |
| 919 while (true) { |
| 920 Element foundMember = lookupClass.lookupMember(fieldName); |
| 921 if (foundMember == fieldMember) return false; |
| 922 if (foundMember.isField()) return true; |
| 923 lookupClass = (foundMember.enclosingElement as ClassElement).superclass; |
| 924 } |
| 925 } |
| 926 |
| 898 Element lookupConstructor(SourceString className, | 927 Element lookupConstructor(SourceString className, |
| 899 [SourceString constructorName = | 928 [SourceString constructorName = |
| 900 const SourceString(''), | 929 const SourceString(''), |
| 901 Element noMatch(Element)]) { | 930 Element noMatch(Element)]) { |
| 902 // TODO(karlklose): have a map from class names to a map of constructors | 931 // TODO(karlklose): have a map from class names to a map of constructors |
| 903 // instead of creating the name here? | 932 // instead of creating the name here? |
| 904 SourceString normalizedName; | 933 SourceString normalizedName; |
| 905 if (constructorName !== const SourceString('')) { | 934 if (constructorName !== const SourceString('')) { |
| 906 normalizedName = Elements.constructConstructorName(className, | 935 normalizedName = Elements.constructConstructorName(className, |
| 907 constructorName); | 936 constructorName); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 final Node node; | 1212 final Node node; |
| 1184 Type bound; | 1213 Type bound; |
| 1185 Type type; | 1214 Type type; |
| 1186 TypeVariableElement(name, Element enclosing, this.node, this.type, | 1215 TypeVariableElement(name, Element enclosing, this.node, this.type, |
| 1187 [this.bound]) | 1216 [this.bound]) |
| 1188 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | 1217 : super(name, ElementKind.TYPE_VARIABLE, enclosing); |
| 1189 Type computeType(compiler) => type; | 1218 Type computeType(compiler) => type; |
| 1190 Node parseNode(compiler) => node; | 1219 Node parseNode(compiler) => node; |
| 1191 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; | 1220 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; |
| 1192 } | 1221 } |
| OLD | NEW |