| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 const ElementKind('typedef', ElementCategory.ALIAS); | 89 const ElementKind('typedef', ElementCategory.ALIAS); |
| 90 | 90 |
| 91 static final ElementKind STATEMENT = | 91 static final ElementKind STATEMENT = |
| 92 const ElementKind('statement', ElementCategory.NONE); | 92 const ElementKind('statement', ElementCategory.NONE); |
| 93 static final ElementKind LABEL = | 93 static final ElementKind LABEL = |
| 94 const ElementKind('label', ElementCategory.NONE); | 94 const ElementKind('label', ElementCategory.NONE); |
| 95 | 95 |
| 96 toString() => id; | 96 toString() => id; |
| 97 } | 97 } |
| 98 | 98 |
| 99 class Element implements Hashable { | 99 class Element implements Comparable, Hashable { |
| 100 final SourceString name; | 100 final SourceString name; |
| 101 final ElementKind kind; | 101 final ElementKind kind; |
| 102 final Element enclosingElement; | 102 final Element enclosingElement; |
| 103 Modifiers get modifiers() => null; | 103 Modifiers get modifiers() => null; |
| 104 | 104 |
| 105 Node parseNode(DiagnosticListener listener) { | 105 Node parseNode(DiagnosticListener listener) { |
| 106 listener.cancel("Internal Error: $this.parseNode", token: position()); | 106 listener.cancel("Internal Error: $this.parseNode", token: position()); |
| 107 } | 107 } |
| 108 | 108 |
| 109 Type computeType(Compiler compiler) { | 109 Type computeType(Compiler compiler) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 Element(this.name, this.kind, this.enclosingElement) { | 150 Element(this.name, this.kind, this.enclosingElement) { |
| 151 assert(getLibrary() !== null); | 151 assert(getLibrary() !== null); |
| 152 } | 152 } |
| 153 | 153 |
| 154 // TODO(kasperl): This is a very bad hash code for the element and | 154 // TODO(kasperl): This is a very bad hash code for the element and |
| 155 // there's no reason why two elements with the same name should have | 155 // there's no reason why two elements with the same name should have |
| 156 // the same hash code. Replace this with a simple id in the element? | 156 // the same hash code. Replace this with a simple id in the element? |
| 157 int hashCode() => name.hashCode(); | 157 int hashCode() => name.hashCode(); |
| 158 | 158 |
| 159 /** Two elements are compared first according to their library name, then |
| 160 * by their position in the source. */ |
| 161 int compareTo(Element other) { |
| 162 SourceString lib1Name = this.getLibrary().name; |
| 163 SourceString lib2Name = other.getLibrary().name; |
| 164 int libComparison = lib1Name.compareTo(lib2Name); |
| 165 if (libComparison != 0) return libComparison; |
| 166 SourceString compilationUnitName1 = this.getCompilationUnit().name; |
| 167 SourceString compilationUnitName2 = other.getCompilationUnit().name; |
| 168 int compilationUnitComparison = |
| 169 compilationUnitName1.compareTo(compilationUnitName2); |
| 170 if (compilationUnitComparison != 0) return compilationUnitComparison; |
| 171 int charOffset1 = this.position().charOffset; |
| 172 int charOffset2 = other.position().charOffset; |
| 173 return charOffset1.compareTo(charOffset2); |
| 174 } |
| 175 |
| 159 CompilationUnitElement getCompilationUnit() { | 176 CompilationUnitElement getCompilationUnit() { |
| 160 Element element = this; | 177 Element element = this; |
| 161 while (element !== null && !element.isCompilationUnit()) { | 178 while (element !== null && !element.isCompilationUnit()) { |
| 162 element = element.enclosingElement; | 179 element = element.enclosingElement; |
| 163 } | 180 } |
| 164 return element; | 181 return element; |
| 165 } | 182 } |
| 166 | 183 |
| 167 LibraryElement getLibrary() { | 184 LibraryElement getLibrary() { |
| 168 Element element = this; | 185 Element element = this; |
| (...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 final Node node; | 1047 final Node node; |
| 1031 Type bound; | 1048 Type bound; |
| 1032 Type type; | 1049 Type type; |
| 1033 TypeVariableElement(name, Element enclosing, this.node, this.type, | 1050 TypeVariableElement(name, Element enclosing, this.node, this.type, |
| 1034 [this.bound]) | 1051 [this.bound]) |
| 1035 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | 1052 : super(name, ElementKind.TYPE_VARIABLE, enclosing); |
| 1036 Type computeType(compiler) => type; | 1053 Type computeType(compiler) => type; |
| 1037 Node parseNode(compiler) => node; | 1054 Node parseNode(compiler) => node; |
| 1038 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; | 1055 toString() => "${enclosingElement.toString()}.${name.slowToString()}"; |
| 1039 } | 1056 } |
| OLD | NEW |