Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: pkg/compiler/lib/src/elements/modelx.dart

Issue 1192103002: Support serialization of the compiler backbone. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 field.getter = accessor; 644 field.getter = accessor;
645 } else { 645 } else {
646 field.setter = accessor; 646 field.setter = accessor;
647 } 647 }
648 add(field, listener); 648 add(field, listener);
649 } 649 }
650 } 650 }
651 } 651 }
652 652
653 class CompilationUnitElementX extends ElementX 653 class CompilationUnitElementX extends ElementX
654 with CompilationUnitElementCommon
654 implements CompilationUnitElement { 655 implements CompilationUnitElement {
655 final Script script; 656 final Script script;
656 PartOf partTag; 657 PartOf partTag;
657 Link<Element> localMembers = const Link<Element>(); 658 Link<Element> localMembers = const Link<Element>();
658 659
659 CompilationUnitElementX(Script script, LibraryElementX library) 660 CompilationUnitElementX(Script script, LibraryElementX library)
660 : this.script = script, 661 : this.script = script,
661 super(script.name, 662 super(script.name,
662 ElementKind.COMPILATION_UNIT, 663 ElementKind.COMPILATION_UNIT,
663 library) { 664 library) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 listener.reportWarning(library, 711 listener.reportWarning(library,
711 MessageKind.MISSING_LIBRARY_NAME, 712 MessageKind.MISSING_LIBRARY_NAME,
712 {'libraryName': actualName}); 713 {'libraryName': actualName});
713 listener.reportInfo(tag.name, 714 listener.reportInfo(tag.name,
714 MessageKind.THIS_IS_THE_PART_OF_TAG); 715 MessageKind.THIS_IS_THE_PART_OF_TAG);
715 } 716 }
716 } 717 }
717 718
718 bool get hasMembers => !localMembers.isEmpty; 719 bool get hasMembers => !localMembers.isEmpty;
719 720
720 int compareTo(CompilationUnitElement other) {
721 if (this == other) return 0;
722 return '${script.readableUri}'.compareTo('${other.script.readableUri}');
723 }
724
725 Element get analyzableElement => library; 721 Element get analyzableElement => library;
726 722
727 accept(ElementVisitor visitor, arg) { 723 accept(ElementVisitor visitor, arg) {
728 return visitor.visitCompilationUnitElement(this, arg); 724 return visitor.visitCompilationUnitElement(this, arg);
729 } 725 }
730 } 726 }
731 727
732 class Importers { 728 class Importers {
733 Map<Element, Link<Import>> importers = new Map<Element, Link<Import>>(); 729 Map<Element, Link<Import>> importers = new Map<Element, Link<Import>>();
734 730
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 1058
1063 /** 1059 /**
1064 * Returns the library name, which is either the name given in the library tag 1060 * Returns the library name, which is either the name given in the library tag
1065 * or the empty string if there is no library tag. 1061 * or the empty string if there is no library tag.
1066 */ 1062 */
1067 String getLibraryName() { 1063 String getLibraryName() {
1068 if (libraryTag == null) return ''; 1064 if (libraryTag == null) return '';
1069 return libraryTag.name.toString(); 1065 return libraryTag.name.toString();
1070 } 1066 }
1071 1067
1072 /**
1073 * Returns the library name (as defined by the library tag) or for script
1074 * (which have no library tag) the script file name. The latter case is used
1075 * to private 'library name' for scripts to use for instance in dartdoc.
1076 *
1077 * Note: the returned filename will still be escaped ("a%20b.dart" instead of
1078 * "a b.dart").
1079 */
1080 String getLibraryOrScriptName() {
1081 if (libraryTag != null) {
1082 return libraryTag.name.toString();
1083 } else {
1084 // Use the file name as script name.
1085 String path = canonicalUri.path;
1086 return path.substring(path.lastIndexOf('/') + 1);
1087 }
1088 }
1089
1090 Scope buildScope() => new LibraryScope(this); 1068 Scope buildScope() => new LibraryScope(this);
1091 1069
1092 String toString() { 1070 String toString() {
1093 if (origin != null) { 1071 if (origin != null) {
1094 return 'patch library(${canonicalUri})'; 1072 return 'patch library(${canonicalUri})';
1095 } else if (patch != null) { 1073 } else if (patch != null) {
1096 return 'origin library(${canonicalUri})'; 1074 return 'origin library(${canonicalUri})';
1097 } else { 1075 } else {
1098 return 'library(${canonicalUri})'; 1076 return 'library(${canonicalUri})';
1099 } 1077 }
1100 } 1078 }
1101 1079
1102 int compareTo(LibraryElement other) {
1103 if (this == other) return 0;
1104 return getLibraryOrScriptName().compareTo(other.getLibraryOrScriptName());
1105 }
1106
1107 accept(ElementVisitor visitor, arg) { 1080 accept(ElementVisitor visitor, arg) {
1108 return visitor.visitLibraryElement(this, arg); 1081 return visitor.visitLibraryElement(this, arg);
1109 } 1082 }
1110 1083
1111 // TODO(johnniwinther): Remove these when issue 18630 is fixed. 1084 // TODO(johnniwinther): Remove these when issue 18630 is fixed.
1112 LibraryElementX get patch => super.patch; 1085 LibraryElementX get patch => super.patch;
1113 LibraryElementX get origin => super.origin; 1086 LibraryElementX get origin => super.origin;
1114 } 1087 }
1115 1088
1116 class PrefixElementX extends ElementX implements PrefixElement { 1089 class PrefixElementX extends ElementX implements PrefixElement {
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 } 2140 }
2168 // TODO(johnniwinther): Ensure that the function signature (and with it the 2141 // TODO(johnniwinther): Ensure that the function signature (and with it the
2169 // function type) substitutes type variables correctly. 2142 // function type) substitutes type variables correctly.
2170 definingConstructor.computeType(compiler); 2143 definingConstructor.computeType(compiler);
2171 functionSignatureCache = definingConstructor.functionSignature; 2144 functionSignatureCache = definingConstructor.functionSignature;
2172 typeCache = definingConstructor.type; 2145 typeCache = definingConstructor.type;
2173 return functionSignatureCache; 2146 return functionSignatureCache;
2174 } 2147 }
2175 2148
2176 accept(ElementVisitor visitor, arg) { 2149 accept(ElementVisitor visitor, arg) {
2177 return visitor.visitFunctionElement(this, arg); 2150 return visitor.visitConstructorElement(this, arg);
2178 } 2151 }
2179 } 2152 }
2180 2153
2181 abstract class TypeDeclarationElementX<T extends GenericType> 2154 abstract class TypeDeclarationElementX<T extends GenericType>
2182 implements TypeDeclarationElement { 2155 implements TypeDeclarationElement {
2183 /** 2156 /**
2184 * The `this type` for this type declaration. 2157 * The `this type` for this type declaration.
2185 * 2158 *
2186 * The type of [:this:] is the generic type based on this element in which 2159 * The type of [:this:] is the generic type based on this element in which
2187 * the type arguments are the declared type variables. For instance, 2160 * the type arguments are the declared type variables. For instance,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2248 * Creates the type variables, their type and corresponding element, for the 2221 * Creates the type variables, their type and corresponding element, for the
2249 * type variables declared in [parameter] on [element]. The bounds of the type 2222 * type variables declared in [parameter] on [element]. The bounds of the type
2250 * variables are not set until [element] has been resolved. 2223 * variables are not set until [element] has been resolved.
2251 */ 2224 */
2252 List<DartType> createTypeVariables(NodeList parameters) { 2225 List<DartType> createTypeVariables(NodeList parameters) {
2253 if (parameters == null) return const <DartType>[]; 2226 if (parameters == null) return const <DartType>[];
2254 2227
2255 // Create types and elements for type variable. 2228 // Create types and elements for type variable.
2256 Link<Node> nodes = parameters.nodes; 2229 Link<Node> nodes = parameters.nodes;
2257 List<DartType> arguments = 2230 List<DartType> arguments =
2258 new List.generate(nodes.slowLength(), (_) { 2231 new List.generate(nodes.slowLength(), (int index) {
2259 TypeVariable node = nodes.head; 2232 TypeVariable node = nodes.head;
2260 String variableName = node.name.source; 2233 String variableName = node.name.source;
2261 nodes = nodes.tail; 2234 nodes = nodes.tail;
2262 TypeVariableElementX variableElement = 2235 TypeVariableElementX variableElement =
2263 new TypeVariableElementX(variableName, this, node); 2236 new TypeVariableElementX(variableName, this, index, node);
2264 TypeVariableType variableType = new TypeVariableType(variableElement); 2237 TypeVariableType variableType = new TypeVariableType(variableElement);
2265 variableElement.typeCache = variableType; 2238 variableElement.typeCache = variableType;
2266 return variableType; 2239 return variableType;
2267 }, growable: false); 2240 }, growable: false);
2268 return arguments; 2241 return arguments;
2269 } 2242 }
2270 2243
2271 bool get isResolved => resolutionState == STATE_DONE; 2244 bool get isResolved => resolutionState == STATE_DONE;
2272 2245
2273 int get resolutionState; 2246 int get resolutionState;
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
2733 return result; 2706 return result;
2734 } 2707 }
2735 2708
2736 bool get isSwitch => statement is SwitchStatement; 2709 bool get isSwitch => statement is SwitchStatement;
2737 2710
2738 String toString() => 'Target:$statement'; 2711 String toString() => 'Target:$statement';
2739 } 2712 }
2740 2713
2741 class TypeVariableElementX extends ElementX with AstElementMixin 2714 class TypeVariableElementX extends ElementX with AstElementMixin
2742 implements TypeVariableElement { 2715 implements TypeVariableElement {
2716 final int index;
2743 final Node node; 2717 final Node node;
2744 TypeVariableType typeCache; 2718 TypeVariableType typeCache;
2745 DartType boundCache; 2719 DartType boundCache;
2746 2720
2747 TypeVariableElementX(String name, TypeDeclarationElement enclosing, this.node) 2721 TypeVariableElementX(String name,
2722 TypeDeclarationElement enclosing,
2723 this.index,
2724 this.node)
2748 : super(name, ElementKind.TYPE_VARIABLE, enclosing); 2725 : super(name, ElementKind.TYPE_VARIABLE, enclosing);
2749 2726
2750 TypeDeclarationElement get typeDeclaration => enclosingElement; 2727 TypeDeclarationElement get typeDeclaration => enclosingElement;
2751 2728
2752 TypeVariableType computeType(compiler) => type; 2729 TypeVariableType computeType(compiler) => type;
2753 2730
2754 TypeVariableType get type { 2731 TypeVariableType get type {
2755 assert(invariant(this, typeCache != null, 2732 assert(invariant(this, typeCache != null,
2756 message: "Type has not been set on $this.")); 2733 message: "Type has not been set on $this."));
2757 return typeCache; 2734 return typeCache;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
2895 AstElement get definingElement; 2872 AstElement get definingElement;
2896 2873
2897 bool get hasResolvedAst => definingElement.hasTreeElements; 2874 bool get hasResolvedAst => definingElement.hasTreeElements;
2898 2875
2899 ResolvedAst get resolvedAst { 2876 ResolvedAst get resolvedAst {
2900 return new ResolvedAst(declaration, 2877 return new ResolvedAst(declaration,
2901 definingElement.node, definingElement.treeElements); 2878 definingElement.node, definingElement.treeElements);
2902 } 2879 }
2903 2880
2904 } 2881 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698