| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 125 |
| 126 Token position() => null; | 126 Token position() => null; |
| 127 | 127 |
| 128 Token findMyName(Token token) { | 128 Token findMyName(Token token) { |
| 129 for (Token t = token; t !== EOF_TOKEN; t = t.next) { | 129 for (Token t = token; t !== EOF_TOKEN; t = t.next) { |
| 130 if (t.value == name) return t; | 130 if (t.value == name) return t; |
| 131 } | 131 } |
| 132 return token; | 132 return token; |
| 133 } | 133 } |
| 134 | 134 |
| 135 const Element(this.name, this.kind, this.enclosingElement); | 135 Element(this.name, this.kind, this.enclosingElement) { |
| 136 assert(getLibrary() !== null); |
| 137 } |
| 136 | 138 |
| 137 // TODO(kasperl): This is a very bad hash code for the element and | 139 // TODO(kasperl): This is a very bad hash code for the element and |
| 138 // there's no reason why two elements with the same name should have | 140 // there's no reason why two elements with the same name should have |
| 139 // the same hash code. Replace this with a simple id in the element? | 141 // the same hash code. Replace this with a simple id in the element? |
| 140 int hashCode() => name.hashCode(); | 142 int hashCode() => name.hashCode(); |
| 141 | 143 |
| 142 CompilationUnitElement getCompilationUnit() { | 144 CompilationUnitElement getCompilationUnit() { |
| 143 Element element = this; | 145 Element element = this; |
| 144 while (element !== null && !element.isCompilationUnit()) { | 146 while (element !== null && !element.isCompilationUnit()) { |
| 145 element = element.enclosingElement; | 147 element = element.enclosingElement; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 277 |
| 276 Element find(SourceString name) { | 278 Element find(SourceString name) { |
| 277 return elements[name]; | 279 return elements[name]; |
| 278 } | 280 } |
| 279 | 281 |
| 280 void forEachExport(f(Element element)) { | 282 void forEachExport(f(Element element)) { |
| 281 elements.forEach((SourceString _, Element e) { | 283 elements.forEach((SourceString _, Element e) { |
| 282 if (this === e.getLibrary() | 284 if (this === e.getLibrary() |
| 283 && e.kind !== ElementKind.PREFIX | 285 && e.kind !== ElementKind.PREFIX |
| 284 && e.kind !== ElementKind.FOREIGN) { | 286 && e.kind !== ElementKind.FOREIGN) { |
| 285 f(e); | 287 if (!e.name.isPrivate()) f(e); |
| 286 } | 288 } |
| 287 }); | 289 }); |
| 288 } | 290 } |
| 289 } | 291 } |
| 290 | 292 |
| 291 class PrefixElement extends Element { | 293 class PrefixElement extends Element { |
| 292 Map<SourceString, Element> imported; | 294 Map<SourceString, Element> imported; |
| 293 | 295 |
| 294 PrefixElement(SourceString prefix, Element enclosing) | 296 PrefixElement(SourceString prefix, Element enclosing) |
| 295 : imported = new Map<SourceString, Element>(), | 297 : imported = new Map<SourceString, Element>(), |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 return this; | 677 return this; |
| 676 } | 678 } |
| 677 | 679 |
| 678 Element lookupLocalMember(SourceString memberName) { | 680 Element lookupLocalMember(SourceString memberName) { |
| 679 return localMembers[memberName]; | 681 return localMembers[memberName]; |
| 680 } | 682 } |
| 681 | 683 |
| 682 Element lookupSuperMember(SourceString name) { | 684 Element lookupSuperMember(SourceString name) { |
| 683 for (ClassElement s = superclass; s != null; s = s.superclass) { | 685 for (ClassElement s = superclass; s != null; s = s.superclass) { |
| 684 Element e = s.lookupLocalMember(name); | 686 Element e = s.lookupLocalMember(name); |
| 685 if (e !== null) return e; | 687 if (e !== null) { |
| 688 if (!name.isPrivate() || getLibrary() === e.getLibrary()) { |
| 689 return e; |
| 690 } |
| 691 } |
| 686 } | 692 } |
| 687 return null; | 693 return null; |
| 688 } | 694 } |
| 689 | 695 |
| 690 Element lookupConstructor(SourceString className, | 696 Element lookupConstructor(SourceString className, |
| 691 [SourceString constructorName = | 697 [SourceString constructorName = |
| 692 const SourceString(''), | 698 const SourceString(''), |
| 693 Element noMatch(Element)]) { | 699 Element noMatch(Element)]) { |
| 694 // TODO(karlklose): have a map from class names to a map of constructors | 700 // TODO(karlklose): have a map from class names to a map of constructors |
| 695 // instead of creating the name here? | 701 // instead of creating the name here? |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 | 869 |
| 864 LabelElement addLabel(Identifier label, String labelName) { | 870 LabelElement addLabel(Identifier label, String labelName) { |
| 865 LabelElement result = new LabelElement(label, labelName, this, | 871 LabelElement result = new LabelElement(label, labelName, this, |
| 866 enclosingElement); | 872 enclosingElement); |
| 867 labels = labels.prepend(result); | 873 labels = labels.prepend(result); |
| 868 return result; | 874 return result; |
| 869 } | 875 } |
| 870 | 876 |
| 871 Node parseNode(DiagnosticListener l) => statement; | 877 Node parseNode(DiagnosticListener l) => statement; |
| 872 } | 878 } |
| OLD | NEW |