| 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('dart:uri'); | 7 #import('dart:uri'); |
| 8 | 8 |
| 9 #import('../tree/tree.dart'); | 9 #import('../tree/tree.dart'); |
| 10 #import('../scanner/scannerlib.dart'); | 10 #import('../scanner/scannerlib.dart'); |
| (...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 /** | 1052 /** |
| 1053 * Lookup local members in the class. This will ignore constructors. | 1053 * Lookup local members in the class. This will ignore constructors. |
| 1054 */ | 1054 */ |
| 1055 Element lookupLocalMember(SourceString memberName) { | 1055 Element lookupLocalMember(SourceString memberName) { |
| 1056 var result = localLookup(memberName); | 1056 var result = localLookup(memberName); |
| 1057 if (result !== null && result.isConstructor()) return null; | 1057 if (result !== null && result.isConstructor()) return null; |
| 1058 return result; | 1058 return result; |
| 1059 } | 1059 } |
| 1060 | 1060 |
| 1061 /** | 1061 /** |
| 1062 * Lookup super members for the class. This will ignore constructors. | 1062 * Lookup super members for the class. This will ignore constructors. |
| 1063 */ | 1063 */ |
| 1064 Element lookupSuperMember(SourceString memberName) { | 1064 Element lookupSuperMember(SourceString memberName) { |
| 1065 return lookupSuperMemberInLibrary(memberName, getLibrary()); |
| 1066 } |
| 1067 |
| 1068 /** |
| 1069 * Lookup super members for the class that is accessible in [library]. |
| 1070 * This will ignore constructors. |
| 1071 */ |
| 1072 Element lookupSuperMemberInLibrary(SourceString memberName, |
| 1073 LibraryElement library) { |
| 1065 bool isPrivate = memberName.isPrivate(); | 1074 bool isPrivate = memberName.isPrivate(); |
| 1066 for (ClassElement s = superclass; s != null; s = s.superclass) { | 1075 for (ClassElement s = superclass; s != null; s = s.superclass) { |
| 1067 // Private members from a different library are not visible. | 1076 // Private members from a different library are not visible. |
| 1068 if (isPrivate && getLibrary() !== s.getLibrary()) continue; | 1077 if (isPrivate && library !== s.getLibrary()) continue; |
| 1069 Element e = s.lookupLocalMember(memberName); | 1078 Element e = s.lookupLocalMember(memberName); |
| 1070 if (e === null) continue; | 1079 if (e === null) continue; |
| 1071 // Static members are not inherited. | 1080 // Static members are not inherited. |
| 1072 if (e.modifiers.isStatic()) continue; | 1081 if (e.modifiers.isStatic()) continue; |
| 1073 return e; | 1082 return e; |
| 1074 } | 1083 } |
| 1075 if (isInterface()) { | 1084 if (isInterface()) { |
| 1076 return lookupSuperInterfaceMember(memberName, getLibrary()); | 1085 return lookupSuperInterfaceMember(memberName, getLibrary()); |
| 1077 } | 1086 } |
| 1078 return null; | 1087 return null; |
| 1079 } | 1088 } |
| 1080 | 1089 |
| 1081 Element lookupSuperInterfaceMember(SourceString memberName, | 1090 Element lookupSuperInterfaceMember(SourceString memberName, |
| 1082 LibraryElement fromLibrary) { | 1091 LibraryElement fromLibrary) { |
| 1083 bool isPrivate = memberName.isPrivate(); | 1092 bool isPrivate = memberName.isPrivate(); |
| 1084 for (Type t in interfaces) { | 1093 for (Type t in interfaces) { |
| 1085 Element e = t.element.lookupLocalMember(memberName); | 1094 Element e = t.element.lookupLocalMember(memberName); |
| 1086 if (e === null) continue; | 1095 if (e === null) continue; |
| 1087 // Private members from a different library are not visible. | 1096 // Private members from a different library are not visible. |
| 1088 if (isPrivate && fromLibrary !== e.getLibrary()) continue; | 1097 if (isPrivate && fromLibrary !== e.getLibrary()) continue; |
| 1089 // Static members are not inherited. | 1098 // Static members are not inherited. |
| 1090 if (e.modifiers.isStatic()) continue; | 1099 if (e.modifiers.isStatic()) continue; |
| 1091 return e; | 1100 return e; |
| 1092 } | 1101 } |
| 1093 return null; | 1102 return null; |
| 1094 } | 1103 } |
| 1095 | 1104 |
| 1096 /** | 1105 /** |
| 1106 * Find the first member in the class chain with the given [selector]. |
| 1107 * |
| 1108 * This method is NOT to be used for resolving |
| 1109 * unqualified sends because it does not implement the scoping |
| 1110 * rules, where library scope comes before superclass scope. |
| 1111 */ |
| 1112 Element lookupSelector(Selector selector) { |
| 1113 SourceString memberName = selector.name; |
| 1114 LibraryElement library = selector.library; |
| 1115 Element localMember = lookupLocalMember(memberName); |
| 1116 if (localMember != null && |
| 1117 (!memberName.isPrivate() || getLibrary() == library)) { |
| 1118 return localMember; |
| 1119 } |
| 1120 return lookupSuperMemberInLibrary(memberName, library); |
| 1121 } |
| 1122 |
| 1123 /** |
| 1097 * Find the first member in the class chain with the given | 1124 * Find the first member in the class chain with the given |
| 1098 * [memberName]. This method is NOT to be used for resolving | 1125 * [memberName]. This method is NOT to be used for resolving |
| 1099 * unqualified sends because it does not implement the scoping | 1126 * unqualified sends because it does not implement the scoping |
| 1100 * rules, where library scope comes before superclass scope. | 1127 * rules, where library scope comes before superclass scope. |
| 1101 */ | 1128 */ |
| 1102 Element lookupMember(SourceString memberName) { | 1129 Element lookupMember(SourceString memberName) { |
| 1103 Element localMember = lookupLocalMember(memberName); | 1130 Element localMember = lookupLocalMember(memberName); |
| 1104 return localMember === null ? lookupSuperMember(memberName) : localMember; | 1131 return localMember === null ? lookupSuperMember(memberName) : localMember; |
| 1105 } | 1132 } |
| 1106 | 1133 |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1452 Node parseNode(compiler) => cachedNode; | 1479 Node parseNode(compiler) => cachedNode; |
| 1453 | 1480 |
| 1454 String toString() => "${enclosingElement.toString()}.${name.slowToString()}"; | 1481 String toString() => "${enclosingElement.toString()}.${name.slowToString()}"; |
| 1455 | 1482 |
| 1456 TypeVariableElement cloneTo(Element enclosing, DiagnosticListener listener) { | 1483 TypeVariableElement cloneTo(Element enclosing, DiagnosticListener listener) { |
| 1457 TypeVariableElement result = | 1484 TypeVariableElement result = |
| 1458 new TypeVariableElement(name, enclosing, node, type, bound); | 1485 new TypeVariableElement(name, enclosing, node, type, bound); |
| 1459 return result; | 1486 return result; |
| 1460 } | 1487 } |
| 1461 } | 1488 } |
| OLD | NEW |