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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/elements/modelx.dart

Issue 177963002: Use List instead of Link in the type system. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 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 | Annotate | Revision Log
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 'elements.dart'; 7 import 'elements.dart';
8 import '../helpers/helpers.dart'; 8 import '../helpers/helpers.dart';
9 import '../tree/tree.dart'; 9 import '../tree/tree.dart';
10 import '../util/util.dart'; 10 import '../util/util.dart';
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 ensureResolved(compiler); 1090 ensureResolved(compiler);
1091 return thisTypeCache; 1091 return thisTypeCache;
1092 } 1092 }
1093 1093
1094 void ensureResolved(Compiler compiler) { 1094 void ensureResolved(Compiler compiler) {
1095 if (resolutionState == STATE_NOT_STARTED) { 1095 if (resolutionState == STATE_NOT_STARTED) {
1096 compiler.resolver.resolve(this); 1096 compiler.resolver.resolve(this);
1097 } 1097 }
1098 } 1098 }
1099 1099
1100 TypedefType createType(Link<DartType> typeArguments) { 1100 TypedefType createType(List<DartType> typeArguments) {
1101 return new TypedefType(this, typeArguments); 1101 return new TypedefType(this, typeArguments);
1102 } 1102 }
1103 1103
1104 Scope buildScope() { 1104 Scope buildScope() {
1105 return new TypeDeclarationScope(enclosingElement.buildScope(), this); 1105 return new TypeDeclarationScope(enclosingElement.buildScope(), this);
1106 } 1106 }
1107 1107
1108 void checkCyclicReference(Compiler compiler) { 1108 void checkCyclicReference(Compiler compiler) {
1109 if (hasBeenCheckedForCycles) return; 1109 if (hasBeenCheckedForCycles) return;
1110 var visitor = new TypedefCyclicVisitor(compiler, this); 1110 var visitor = new TypedefCyclicVisitor(compiler, this);
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 message: 'This type has not been computed for $this')); 1837 message: 'This type has not been computed for $this'));
1838 return thisTypeCache; 1838 return thisTypeCache;
1839 } 1839 }
1840 1840
1841 T get rawType { 1841 T get rawType {
1842 assert(invariant(this, rawTypeCache != null, 1842 assert(invariant(this, rawTypeCache != null,
1843 message: 'Raw type has not been computed for $this')); 1843 message: 'Raw type has not been computed for $this'));
1844 return rawTypeCache; 1844 return rawTypeCache;
1845 } 1845 }
1846 1846
1847 T createType(Link<DartType> typeArguments); 1847 T createType(List<DartType> typeArguments);
1848 1848
1849 void setThisAndRawTypes(Compiler compiler, Link<DartType> typeParameters) { 1849 void setThisAndRawTypes(Compiler compiler, List<DartType> typeParameters) {
1850 assert(invariant(this, thisTypeCache == null, 1850 assert(invariant(this, thisTypeCache == null,
1851 message: "This type has already been set on $this.")); 1851 message: "This type has already been set on $this."));
1852 assert(invariant(this, rawTypeCache == null, 1852 assert(invariant(this, rawTypeCache == null,
1853 message: "Raw type has already been set on $this.")); 1853 message: "Raw type has already been set on $this."));
1854 thisTypeCache = createType(typeParameters); 1854 thisTypeCache = createType(typeParameters);
1855 if (typeParameters.isEmpty) { 1855 if (typeParameters.isEmpty) {
1856 rawTypeCache = thisTypeCache; 1856 rawTypeCache = thisTypeCache;
1857 } else { 1857 } else {
1858 Link<DartType> dynamicParameters = const Link<DartType>(); 1858 List<DartType> dynamicParameters =
1859 typeParameters.forEach((_) { 1859 new List.filled(typeParameters.length, const DynamicType());
1860 dynamicParameters =
1861 dynamicParameters.prepend(const DynamicType());
1862 });
1863 rawTypeCache = createType(dynamicParameters); 1860 rawTypeCache = createType(dynamicParameters);
1864 } 1861 }
1865 } 1862 }
1866 1863
1867 Link<DartType> get typeVariables => thisType.typeArguments; 1864 List<DartType> get typeVariables => thisType.typeArguments;
1868 1865
1869 /** 1866 /**
1870 * Creates the type variables, their type and corresponding element, for the 1867 * Creates the type variables, their type and corresponding element, for the
1871 * type variables declared in [parameter] on [element]. The bounds of the type 1868 * type variables declared in [parameter] on [element]. The bounds of the type
1872 * variables are not set until [element] has been resolved. 1869 * variables are not set until [element] has been resolved.
1873 */ 1870 */
1874 Link<DartType> createTypeVariables(NodeList parameters) { 1871 List<DartType> createTypeVariables(NodeList parameters) {
1875 if (parameters == null) return const Link<DartType>(); 1872 if (parameters == null) return const <DartType>[];
1876 1873
1877 // Create types and elements for type variable. 1874 // Create types and elements for type variable.
1878 LinkBuilder<DartType> arguments = new LinkBuilder<DartType>(); 1875 Link<Node> nodes = parameters.nodes;
1879 for (Link<Node> link = parameters.nodes; !link.isEmpty; link = link.tail) { 1876 List<DartType> arguments =
1880 TypeVariable node = link.head; 1877 new List.generate(nodes.slowLength(), (_) {
1878 TypeVariable node = nodes.head;
1881 String variableName = node.name.source; 1879 String variableName = node.name.source;
1880 nodes = nodes.tail;
1882 TypeVariableElementX variableElement = 1881 TypeVariableElementX variableElement =
1883 new TypeVariableElementX(variableName, this, node); 1882 new TypeVariableElementX(variableName, this, node);
1884 TypeVariableType variableType = new TypeVariableType(variableElement); 1883 TypeVariableType variableType = new TypeVariableType(variableElement);
1885 variableElement.typeCache = variableType; 1884 variableElement.typeCache = variableType;
1886 arguments.addLast(variableType); 1885 return variableType;
1887 } 1886 }, growable: false);
1888 return arguments.toLink(); 1887 return arguments;
1889 } 1888 }
1890 1889
1891 bool get isResolved => resolutionState == STATE_DONE; 1890 bool get isResolved => resolutionState == STATE_DONE;
1892 } 1891 }
1893 1892
1894 abstract class BaseClassElementX extends ElementX 1893 abstract class BaseClassElementX extends ElementX
1895 with AstElementMixin, 1894 with AstElementMixin,
1896 AnalyzableElementX, 1895 AnalyzableElementX,
1897 TypeDeclarationElementX<InterfaceType>, 1896 TypeDeclarationElementX<InterfaceType>,
1898 PatchMixin<ClassElement>, 1897 PatchMixin<ClassElement>,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 1931
1933 bool get isUnnamedMixinApplication => false; 1932 bool get isUnnamedMixinApplication => false;
1934 1933
1935 InterfaceType computeType(Compiler compiler) { 1934 InterfaceType computeType(Compiler compiler) {
1936 if (thisTypeCache == null) { 1935 if (thisTypeCache == null) {
1937 computeThisAndRawType(compiler, computeTypeParameters(compiler)); 1936 computeThisAndRawType(compiler, computeTypeParameters(compiler));
1938 } 1937 }
1939 return thisTypeCache; 1938 return thisTypeCache;
1940 } 1939 }
1941 1940
1942 void computeThisAndRawType(Compiler compiler, Link<DartType> typeVariables) { 1941 void computeThisAndRawType(Compiler compiler, List<DartType> typeVariables) {
1943 if (thisTypeCache == null) { 1942 if (thisTypeCache == null) {
1944 if (origin == null) { 1943 if (origin == null) {
1945 setThisAndRawTypes(compiler, typeVariables); 1944 setThisAndRawTypes(compiler, typeVariables);
1946 } else { 1945 } else {
1947 thisTypeCache = origin.computeType(compiler); 1946 thisTypeCache = origin.computeType(compiler);
1948 rawTypeCache = origin.rawType; 1947 rawTypeCache = origin.rawType;
1949 } 1948 }
1950 } 1949 }
1951 } 1950 }
1952 1951
1953 InterfaceType createType(Link<DartType> typeArguments) { 1952 InterfaceType createType(List<DartType> typeArguments) {
1954 return new InterfaceType(this, typeArguments); 1953 return new InterfaceType(this, typeArguments);
1955 } 1954 }
1956 1955
1957 Link<DartType> computeTypeParameters(Compiler compiler); 1956 List<DartType> computeTypeParameters(Compiler compiler);
1958 1957
1959 InterfaceType asInstanceOf(ClassElement cls) { 1958 InterfaceType asInstanceOf(ClassElement cls) {
1960 if (cls == this) return thisType; 1959 if (cls == this) return thisType;
1961 return allSupertypesAndSelf.asInstanceOf(cls); 1960 return allSupertypesAndSelf.asInstanceOf(cls);
1962 } 1961 }
1963 1962
1964 /** 1963 /**
1965 * Return [:true:] if this element is the [:Object:] class for the [compiler]. 1964 * Return [:true:] if this element is the [:Object:] class for the [compiler].
1966 */ 1965 */
1967 bool isObject(Compiler compiler) => 1966 bool isObject(Compiler compiler) =>
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
2343 if (element.isConstructor) return true; 2342 if (element.isConstructor) return true;
2344 } 2343 }
2345 return false; 2344 return false;
2346 } 2345 }
2347 2346
2348 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) { 2347 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) {
2349 // The default constructor, although synthetic, is part of a class' API. 2348 // The default constructor, although synthetic, is part of a class' API.
2350 addMember(constructor, compiler); 2349 addMember(constructor, compiler);
2351 } 2350 }
2352 2351
2353 Link<DartType> computeTypeParameters(Compiler compiler) { 2352 List<DartType> computeTypeParameters(Compiler compiler) {
2354 ClassNode node = parseNode(compiler); 2353 ClassNode node = parseNode(compiler);
2355 return createTypeVariables(node.typeParameters); 2354 return createTypeVariables(node.typeParameters);
2356 } 2355 }
2357 2356
2358 Scope buildScope() => new ClassScope(enclosingElement.buildScope(), this); 2357 Scope buildScope() => new ClassScope(enclosingElement.buildScope(), this);
2359 2358
2360 String toString() { 2359 String toString() {
2361 if (origin != null) { 2360 if (origin != null) {
2362 return 'patch ${super.toString()}'; 2361 return 'patch ${super.toString()}';
2363 } else if (patch != null) { 2362 } else if (patch != null) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
2432 2431
2433 void addConstructor(FunctionElement constructor) { 2432 void addConstructor(FunctionElement constructor) {
2434 constructors = constructors.prepend(constructor); 2433 constructors = constructors.prepend(constructor);
2435 } 2434 }
2436 2435
2437 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) { 2436 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) {
2438 assert(!hasConstructor); 2437 assert(!hasConstructor);
2439 addConstructor(constructor); 2438 addConstructor(constructor);
2440 } 2439 }
2441 2440
2442 Link<DartType> computeTypeParameters(Compiler compiler) { 2441 List<DartType> computeTypeParameters(Compiler compiler) {
2443 NamedMixinApplication named = node.asNamedMixinApplication(); 2442 NamedMixinApplication named = node.asNamedMixinApplication();
2444 if (named == null) { 2443 if (named == null) {
2445 throw new SpannableAssertionFailure(node, 2444 throw new SpannableAssertionFailure(node,
2446 "Type variables on unnamed mixin applications must be set on " 2445 "Type variables on unnamed mixin applications must be set on "
2447 "creation."); 2446 "creation.");
2448 } 2447 }
2449 return createTypeVariables(named.typeParameters); 2448 return createTypeVariables(named.typeParameters);
2450 } 2449 }
2451 2450
2452 accept(ElementVisitor visitor) => visitor.visitMixinApplicationElement(this); 2451 accept(ElementVisitor visitor) => visitor.visitMixinApplicationElement(this);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
2667 AstElement get definingElement; 2666 AstElement get definingElement;
2668 2667
2669 bool get hasResolvedAst => definingElement.hasTreeElements; 2668 bool get hasResolvedAst => definingElement.hasTreeElements;
2670 2669
2671 ResolvedAst get resolvedAst { 2670 ResolvedAst get resolvedAst {
2672 return new ResolvedAst(declaration, 2671 return new ResolvedAst(declaration,
2673 definingElement.node, definingElement.treeElements); 2672 definingElement.node, definingElement.treeElements);
2674 } 2673 }
2675 2674
2676 } 2675 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698