| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.modelx; | 5 library elements.modelx; |
| 6 | 6 |
| 7 import 'common.dart'; | 7 import 'common.dart'; |
| 8 import 'elements.dart'; | 8 import 'elements.dart'; |
| 9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
| 10 import '../constants/constructors.dart'; | 10 import '../constants/constructors.dart'; |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 field.getter = accessor; | 645 field.getter = accessor; |
| 646 } else { | 646 } else { |
| 647 field.setter = accessor; | 647 field.setter = accessor; |
| 648 } | 648 } |
| 649 add(field, listener); | 649 add(field, listener); |
| 650 } | 650 } |
| 651 } | 651 } |
| 652 } | 652 } |
| 653 | 653 |
| 654 class CompilationUnitElementX extends ElementX | 654 class CompilationUnitElementX extends ElementX |
| 655 with CompilationUnitElementCommon |
| 655 implements CompilationUnitElement { | 656 implements CompilationUnitElement { |
| 656 final Script script; | 657 final Script script; |
| 657 PartOf partTag; | 658 PartOf partTag; |
| 658 Link<Element> localMembers = const Link<Element>(); | 659 Link<Element> localMembers = const Link<Element>(); |
| 659 | 660 |
| 660 CompilationUnitElementX(Script script, LibraryElementX library) | 661 CompilationUnitElementX(Script script, LibraryElementX library) |
| 661 : this.script = script, | 662 : this.script = script, |
| 662 super(script.name, | 663 super(script.name, |
| 663 ElementKind.COMPILATION_UNIT, | 664 ElementKind.COMPILATION_UNIT, |
| 664 library) { | 665 library) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 listener.reportWarning(library, | 712 listener.reportWarning(library, |
| 712 MessageKind.MISSING_LIBRARY_NAME, | 713 MessageKind.MISSING_LIBRARY_NAME, |
| 713 {'libraryName': actualName}); | 714 {'libraryName': actualName}); |
| 714 listener.reportInfo(tag.name, | 715 listener.reportInfo(tag.name, |
| 715 MessageKind.THIS_IS_THE_PART_OF_TAG); | 716 MessageKind.THIS_IS_THE_PART_OF_TAG); |
| 716 } | 717 } |
| 717 } | 718 } |
| 718 | 719 |
| 719 bool get hasMembers => !localMembers.isEmpty; | 720 bool get hasMembers => !localMembers.isEmpty; |
| 720 | 721 |
| 721 int compareTo(CompilationUnitElement other) { | |
| 722 if (this == other) return 0; | |
| 723 return '${script.readableUri}'.compareTo('${other.script.readableUri}'); | |
| 724 } | |
| 725 | |
| 726 Element get analyzableElement => library; | 722 Element get analyzableElement => library; |
| 727 | 723 |
| 728 accept(ElementVisitor visitor, arg) { | 724 accept(ElementVisitor visitor, arg) { |
| 729 return visitor.visitCompilationUnitElement(this, arg); | 725 return visitor.visitCompilationUnitElement(this, arg); |
| 730 } | 726 } |
| 731 } | 727 } |
| 732 | 728 |
| 733 class Importers { | 729 class Importers { |
| 734 Map<Element, Link<Import>> importers = new Map<Element, Link<Import>>(); | 730 Map<Element, Link<Import>> importers = new Map<Element, Link<Import>>(); |
| 735 | 731 |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 | 1059 |
| 1064 /** | 1060 /** |
| 1065 * Returns the library name, which is either the name given in the library tag | 1061 * Returns the library name, which is either the name given in the library tag |
| 1066 * or the empty string if there is no library tag. | 1062 * or the empty string if there is no library tag. |
| 1067 */ | 1063 */ |
| 1068 String getLibraryName() { | 1064 String getLibraryName() { |
| 1069 if (libraryTag == null) return ''; | 1065 if (libraryTag == null) return ''; |
| 1070 return libraryTag.name.toString(); | 1066 return libraryTag.name.toString(); |
| 1071 } | 1067 } |
| 1072 | 1068 |
| 1073 /** | |
| 1074 * Returns the library name (as defined by the library tag) or for script | |
| 1075 * (which have no library tag) the script file name. The latter case is used | |
| 1076 * to private 'library name' for scripts to use for instance in dartdoc. | |
| 1077 * | |
| 1078 * Note: the returned filename will still be escaped ("a%20b.dart" instead of | |
| 1079 * "a b.dart"). | |
| 1080 */ | |
| 1081 String getLibraryOrScriptName() { | |
| 1082 if (libraryTag != null) { | |
| 1083 return libraryTag.name.toString(); | |
| 1084 } else { | |
| 1085 // Use the file name as script name. | |
| 1086 String path = canonicalUri.path; | |
| 1087 return path.substring(path.lastIndexOf('/') + 1); | |
| 1088 } | |
| 1089 } | |
| 1090 | |
| 1091 Scope buildScope() => new LibraryScope(this); | 1069 Scope buildScope() => new LibraryScope(this); |
| 1092 | 1070 |
| 1093 String toString() { | 1071 String toString() { |
| 1094 if (origin != null) { | 1072 if (origin != null) { |
| 1095 return 'patch library(${canonicalUri})'; | 1073 return 'patch library(${canonicalUri})'; |
| 1096 } else if (patch != null) { | 1074 } else if (patch != null) { |
| 1097 return 'origin library(${canonicalUri})'; | 1075 return 'origin library(${canonicalUri})'; |
| 1098 } else { | 1076 } else { |
| 1099 return 'library(${canonicalUri})'; | 1077 return 'library(${canonicalUri})'; |
| 1100 } | 1078 } |
| 1101 } | 1079 } |
| 1102 | 1080 |
| 1103 int compareTo(LibraryElement other) { | |
| 1104 if (this == other) return 0; | |
| 1105 return getLibraryOrScriptName().compareTo(other.getLibraryOrScriptName()); | |
| 1106 } | |
| 1107 | |
| 1108 accept(ElementVisitor visitor, arg) { | 1081 accept(ElementVisitor visitor, arg) { |
| 1109 return visitor.visitLibraryElement(this, arg); | 1082 return visitor.visitLibraryElement(this, arg); |
| 1110 } | 1083 } |
| 1111 | 1084 |
| 1112 // TODO(johnniwinther): Remove these when issue 18630 is fixed. | 1085 // TODO(johnniwinther): Remove these when issue 18630 is fixed. |
| 1113 LibraryElementX get patch => super.patch; | 1086 LibraryElementX get patch => super.patch; |
| 1114 LibraryElementX get origin => super.origin; | 1087 LibraryElementX get origin => super.origin; |
| 1115 } | 1088 } |
| 1116 | 1089 |
| 1117 class PrefixElementX extends ElementX implements PrefixElement { | 1090 class PrefixElementX extends ElementX implements PrefixElement { |
| (...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2187 } | 2160 } |
| 2188 // TODO(johnniwinther): Ensure that the function signature (and with it the | 2161 // TODO(johnniwinther): Ensure that the function signature (and with it the |
| 2189 // function type) substitutes type variables correctly. | 2162 // function type) substitutes type variables correctly. |
| 2190 definingConstructor.computeType(compiler); | 2163 definingConstructor.computeType(compiler); |
| 2191 functionSignatureCache = definingConstructor.functionSignature; | 2164 functionSignatureCache = definingConstructor.functionSignature; |
| 2192 typeCache = definingConstructor.type; | 2165 typeCache = definingConstructor.type; |
| 2193 return functionSignatureCache; | 2166 return functionSignatureCache; |
| 2194 } | 2167 } |
| 2195 | 2168 |
| 2196 accept(ElementVisitor visitor, arg) { | 2169 accept(ElementVisitor visitor, arg) { |
| 2197 return visitor.visitFunctionElement(this, arg); | 2170 return visitor.visitConstructorElement(this, arg); |
| 2198 } | 2171 } |
| 2199 } | 2172 } |
| 2200 | 2173 |
| 2201 abstract class TypeDeclarationElementX<T extends GenericType> | 2174 abstract class TypeDeclarationElementX<T extends GenericType> |
| 2202 implements TypeDeclarationElement { | 2175 implements TypeDeclarationElement { |
| 2203 /** | 2176 /** |
| 2204 * The `this type` for this type declaration. | 2177 * The `this type` for this type declaration. |
| 2205 * | 2178 * |
| 2206 * The type of [:this:] is the generic type based on this element in which | 2179 * The type of [:this:] is the generic type based on this element in which |
| 2207 * the type arguments are the declared type variables. For instance, | 2180 * the type arguments are the declared type variables. For instance, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2268 * Creates the type variables, their type and corresponding element, for the | 2241 * Creates the type variables, their type and corresponding element, for the |
| 2269 * type variables declared in [parameter] on [element]. The bounds of the type | 2242 * type variables declared in [parameter] on [element]. The bounds of the type |
| 2270 * variables are not set until [element] has been resolved. | 2243 * variables are not set until [element] has been resolved. |
| 2271 */ | 2244 */ |
| 2272 List<DartType> createTypeVariables(NodeList parameters) { | 2245 List<DartType> createTypeVariables(NodeList parameters) { |
| 2273 if (parameters == null) return const <DartType>[]; | 2246 if (parameters == null) return const <DartType>[]; |
| 2274 | 2247 |
| 2275 // Create types and elements for type variable. | 2248 // Create types and elements for type variable. |
| 2276 Link<Node> nodes = parameters.nodes; | 2249 Link<Node> nodes = parameters.nodes; |
| 2277 List<DartType> arguments = | 2250 List<DartType> arguments = |
| 2278 new List.generate(nodes.slowLength(), (_) { | 2251 new List.generate(nodes.slowLength(), (int index) { |
| 2279 TypeVariable node = nodes.head; | 2252 TypeVariable node = nodes.head; |
| 2280 String variableName = node.name.source; | 2253 String variableName = node.name.source; |
| 2281 nodes = nodes.tail; | 2254 nodes = nodes.tail; |
| 2282 TypeVariableElementX variableElement = | 2255 TypeVariableElementX variableElement = |
| 2283 new TypeVariableElementX(variableName, this, node); | 2256 new TypeVariableElementX(variableName, this, index, node); |
| 2284 TypeVariableType variableType = new TypeVariableType(variableElement); | 2257 TypeVariableType variableType = new TypeVariableType(variableElement); |
| 2285 variableElement.typeCache = variableType; | 2258 variableElement.typeCache = variableType; |
| 2286 return variableType; | 2259 return variableType; |
| 2287 }, growable: false); | 2260 }, growable: false); |
| 2288 return arguments; | 2261 return arguments; |
| 2289 } | 2262 } |
| 2290 | 2263 |
| 2291 bool get isResolved => resolutionState == STATE_DONE; | 2264 bool get isResolved => resolutionState == STATE_DONE; |
| 2292 | 2265 |
| 2293 int get resolutionState; | 2266 int get resolutionState; |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2753 return result; | 2726 return result; |
| 2754 } | 2727 } |
| 2755 | 2728 |
| 2756 bool get isSwitch => statement is SwitchStatement; | 2729 bool get isSwitch => statement is SwitchStatement; |
| 2757 | 2730 |
| 2758 String toString() => 'Target:$statement'; | 2731 String toString() => 'Target:$statement'; |
| 2759 } | 2732 } |
| 2760 | 2733 |
| 2761 class TypeVariableElementX extends ElementX with AstElementMixin | 2734 class TypeVariableElementX extends ElementX with AstElementMixin |
| 2762 implements TypeVariableElement { | 2735 implements TypeVariableElement { |
| 2736 final int index; |
| 2763 final Node node; | 2737 final Node node; |
| 2764 TypeVariableType typeCache; | 2738 TypeVariableType typeCache; |
| 2765 DartType boundCache; | 2739 DartType boundCache; |
| 2766 | 2740 |
| 2767 TypeVariableElementX(String name, TypeDeclarationElement enclosing, this.node) | 2741 TypeVariableElementX(String name, |
| 2742 TypeDeclarationElement enclosing, |
| 2743 this.index, |
| 2744 this.node) |
| 2768 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | 2745 : super(name, ElementKind.TYPE_VARIABLE, enclosing); |
| 2769 | 2746 |
| 2770 TypeDeclarationElement get typeDeclaration => enclosingElement; | 2747 TypeDeclarationElement get typeDeclaration => enclosingElement; |
| 2771 | 2748 |
| 2772 TypeVariableType computeType(compiler) => type; | 2749 TypeVariableType computeType(compiler) => type; |
| 2773 | 2750 |
| 2774 TypeVariableType get type { | 2751 TypeVariableType get type { |
| 2775 assert(invariant(this, typeCache != null, | 2752 assert(invariant(this, typeCache != null, |
| 2776 message: "Type has not been set on $this.")); | 2753 message: "Type has not been set on $this.")); |
| 2777 return typeCache; | 2754 return typeCache; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2915 AstElement get definingElement; | 2892 AstElement get definingElement; |
| 2916 | 2893 |
| 2917 bool get hasResolvedAst => definingElement.hasTreeElements; | 2894 bool get hasResolvedAst => definingElement.hasTreeElements; |
| 2918 | 2895 |
| 2919 ResolvedAst get resolvedAst { | 2896 ResolvedAst get resolvedAst { |
| 2920 return new ResolvedAst(declaration, | 2897 return new ResolvedAst(declaration, |
| 2921 definingElement.node, definingElement.treeElements); | 2898 definingElement.node, definingElement.treeElements); |
| 2922 } | 2899 } |
| 2923 | 2900 |
| 2924 } | 2901 } |
| OLD | NEW |