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

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: Rebase and some algorithmic bugs fixed. Created 6 years, 9 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 '../tree/tree.dart'; 8 import '../tree/tree.dart';
9 import '../util/util.dart'; 9 import '../util/util.dart';
10 import '../resolution/resolution.dart'; 10 import '../resolution/resolution.dart';
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 FunctionSignature functionSignature; 1076 FunctionSignature functionSignature;
1077 1077
1078 TypedefType computeType(Compiler compiler) { 1078 TypedefType computeType(Compiler compiler) {
1079 if (thisTypeCache != null) return thisTypeCache; 1079 if (thisTypeCache != null) return thisTypeCache;
1080 Typedef node = parseNode(compiler); 1080 Typedef node = parseNode(compiler);
1081 setThisAndRawTypes(compiler, createTypeVariables(node.typeParameters)); 1081 setThisAndRawTypes(compiler, createTypeVariables(node.typeParameters));
1082 compiler.resolveTypedef(this); 1082 compiler.resolveTypedef(this);
1083 return thisTypeCache; 1083 return thisTypeCache;
1084 } 1084 }
1085 1085
1086 TypedefType createType(Link<DartType> typeArguments) { 1086 TypedefType createType(List<DartType> typeArguments) {
1087 return new TypedefType(this, typeArguments); 1087 return new TypedefType(this, typeArguments);
1088 } 1088 }
1089 1089
1090 Scope buildScope() { 1090 Scope buildScope() {
1091 return new TypeDeclarationScope(enclosingElement.buildScope(), this); 1091 return new TypeDeclarationScope(enclosingElement.buildScope(), this);
1092 } 1092 }
1093 1093
1094 void checkCyclicReference(Compiler compiler) { 1094 void checkCyclicReference(Compiler compiler) {
1095 if (hasBeenCheckedForCycles) return; 1095 if (hasBeenCheckedForCycles) return;
1096 var visitor = new TypedefCyclicVisitor(compiler, this); 1096 var visitor = new TypedefCyclicVisitor(compiler, this);
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after
1794 message: 'This type has not been computed for $this')); 1794 message: 'This type has not been computed for $this'));
1795 return thisTypeCache; 1795 return thisTypeCache;
1796 } 1796 }
1797 1797
1798 T get rawType { 1798 T get rawType {
1799 assert(invariant(this, rawTypeCache != null, 1799 assert(invariant(this, rawTypeCache != null,
1800 message: 'Raw type has not been computed for $this')); 1800 message: 'Raw type has not been computed for $this'));
1801 return rawTypeCache; 1801 return rawTypeCache;
1802 } 1802 }
1803 1803
1804 T createType(Link<DartType> typeArguments); 1804 T createType(List<DartType> typeArguments);
1805 1805
1806 void setThisAndRawTypes(Compiler compiler, Link<DartType> typeParameters) { 1806 void setThisAndRawTypes(Compiler compiler, List<DartType> typeParameters) {
1807 assert(invariant(this, thisTypeCache == null, 1807 assert(invariant(this, thisTypeCache == null,
1808 message: "This type has already been set on $this.")); 1808 message: "This type has already been set on $this."));
1809 assert(invariant(this, rawTypeCache == null, 1809 assert(invariant(this, rawTypeCache == null,
1810 message: "Raw type has already been set on $this.")); 1810 message: "Raw type has already been set on $this."));
1811 thisTypeCache = createType(typeParameters); 1811 thisTypeCache = createType(typeParameters);
1812 if (typeParameters.isEmpty) { 1812 if (typeParameters.isEmpty) {
1813 rawTypeCache = thisTypeCache; 1813 rawTypeCache = thisTypeCache;
1814 } else { 1814 } else {
1815 Link<DartType> dynamicParameters = const Link<DartType>(); 1815 List<DartType> dynamicParameters =
1816 typeParameters.forEach((_) { 1816 new List.filled(typeParameters.length, compiler.types.dynamicType);
1817 dynamicParameters =
1818 dynamicParameters.prepend(compiler.types.dynamicType);
1819 });
1820 rawTypeCache = createType(dynamicParameters); 1817 rawTypeCache = createType(dynamicParameters);
1821 } 1818 }
1822 } 1819 }
1823 1820
1824 Link<DartType> get typeVariables => thisType.typeArguments; 1821 List<DartType> get typeVariables => thisType.typeArguments;
1825 1822
1826 /** 1823 /**
1827 * Creates the type variables, their type and corresponding element, for the 1824 * Creates the type variables, their type and corresponding element, for the
1828 * type variables declared in [parameter] on [element]. The bounds of the type 1825 * type variables declared in [parameter] on [element]. The bounds of the type
1829 * variables are not set until [element] has been resolved. 1826 * variables are not set until [element] has been resolved.
1830 */ 1827 */
1831 Link<DartType> createTypeVariables(NodeList parameters) { 1828 List<DartType> createTypeVariables(NodeList parameters) {
1832 if (parameters == null) return const Link<DartType>(); 1829 if (parameters == null) return const <DartType>[];
1833 1830
1834 // Create types and elements for type variable. 1831 // Create types and elements for type variable.
1835 LinkBuilder<DartType> arguments = new LinkBuilder<DartType>(); 1832 Link<Node> nodes = parameters.nodes;
1836 for (Link<Node> link = parameters.nodes; !link.isEmpty; link = link.tail) { 1833 List<DartType> arguments =
1837 TypeVariable node = link.head; 1834 new List.generate(nodes.slowLength(), (_) {
1835 TypeVariable node = nodes.head;
1838 String variableName = node.name.source; 1836 String variableName = node.name.source;
1837 nodes = nodes.tail;
1839 TypeVariableElementX variableElement = 1838 TypeVariableElementX variableElement =
1840 new TypeVariableElementX(variableName, this, node); 1839 new TypeVariableElementX(variableName, this, node);
1841 TypeVariableType variableType = new TypeVariableType(variableElement); 1840 TypeVariableType variableType = new TypeVariableType(variableElement);
1842 variableElement.typeCache = variableType; 1841 variableElement.typeCache = variableType;
1843 arguments.addLast(variableType); 1842 return variableType;
1844 } 1843 });
Johnni Winther 2014/07/01 11:03:50 Add `, growable: false` ?
karlklose 2014/07/01 13:32:06 Done.
1845 return arguments.toLink(); 1844 return arguments;
1846 } 1845 }
1847 } 1846 }
1848 1847
1849 abstract class BaseClassElementX extends ElementX 1848 abstract class BaseClassElementX extends ElementX
1850 with AnalyzableElement, TypeDeclarationElementX<InterfaceType> 1849 with AnalyzableElement, TypeDeclarationElementX<InterfaceType>
1851 implements ClassElement { 1850 implements ClassElement {
1852 final int id; 1851 final int id;
1853 1852
1854 DartType supertype; 1853 DartType supertype;
1855 Link<DartType> interfaces; 1854 Link<DartType> interfaces;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 1890
1892 bool get isUnnamedMixinApplication => false; 1891 bool get isUnnamedMixinApplication => false;
1893 1892
1894 InterfaceType computeType(Compiler compiler) { 1893 InterfaceType computeType(Compiler compiler) {
1895 if (thisTypeCache == null) { 1894 if (thisTypeCache == null) {
1896 computeThisAndRawType(compiler, computeTypeParameters(compiler)); 1895 computeThisAndRawType(compiler, computeTypeParameters(compiler));
1897 } 1896 }
1898 return thisTypeCache; 1897 return thisTypeCache;
1899 } 1898 }
1900 1899
1901 void computeThisAndRawType(Compiler compiler, Link<DartType> typeVariables) { 1900 void computeThisAndRawType(Compiler compiler, List<DartType> typeVariables) {
1902 if (thisTypeCache == null) { 1901 if (thisTypeCache == null) {
1903 if (origin == null) { 1902 if (origin == null) {
1904 setThisAndRawTypes(compiler, typeVariables); 1903 setThisAndRawTypes(compiler, typeVariables);
1905 } else { 1904 } else {
1906 thisTypeCache = origin.computeType(compiler); 1905 thisTypeCache = origin.computeType(compiler);
1907 rawTypeCache = origin.rawType; 1906 rawTypeCache = origin.rawType;
1908 } 1907 }
1909 } 1908 }
1910 } 1909 }
1911 1910
1912 InterfaceType createType(Link<DartType> typeArguments) { 1911 InterfaceType createType(List<DartType> typeArguments) {
1913 return new InterfaceType(this, typeArguments); 1912 return new InterfaceType(this, typeArguments);
1914 } 1913 }
1915 1914
1916 Link<DartType> computeTypeParameters(Compiler compiler); 1915 List<DartType> computeTypeParameters(Compiler compiler);
1917 1916
1918 /** 1917 /**
1919 * Return [:true:] if this element is the [:Object:] class for the [compiler]. 1918 * Return [:true:] if this element is the [:Object:] class for the [compiler].
1920 */ 1919 */
1921 bool isObject(Compiler compiler) => 1920 bool isObject(Compiler compiler) =>
1922 identical(declaration, compiler.objectClass); 1921 identical(declaration, compiler.objectClass);
1923 1922
1924 void ensureResolved(Compiler compiler) { 1923 void ensureResolved(Compiler compiler) {
1925 if (resolutionState == STATE_NOT_STARTED) { 1924 if (resolutionState == STATE_NOT_STARTED) {
1926 compiler.resolver.resolveClass(this); 1925 compiler.resolver.resolveClass(this);
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
2299 } 2298 }
2300 return false; 2299 return false;
2301 } 2300 }
2302 2301
2303 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) { 2302 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) {
2304 addToScope(constructor, compiler); 2303 addToScope(constructor, compiler);
2305 // The default constructor, although synthetic, is part of a class' API. 2304 // The default constructor, although synthetic, is part of a class' API.
2306 localMembers = localMembers.prepend(constructor); 2305 localMembers = localMembers.prepend(constructor);
2307 } 2306 }
2308 2307
2309 Link<DartType> computeTypeParameters(Compiler compiler) { 2308 List<DartType> computeTypeParameters(Compiler compiler) {
2310 ClassNode node = parseNode(compiler); 2309 ClassNode node = parseNode(compiler);
2311 return createTypeVariables(node.typeParameters); 2310 return createTypeVariables(node.typeParameters);
2312 } 2311 }
2313 2312
2314 Scope buildScope() => new ClassScope(enclosingElement.buildScope(), this); 2313 Scope buildScope() => new ClassScope(enclosingElement.buildScope(), this);
2315 2314
2316 String toString() { 2315 String toString() {
2317 if (origin != null) { 2316 if (origin != null) {
2318 return 'patch ${super.toString()}'; 2317 return 'patch ${super.toString()}';
2319 } else if (patch != null) { 2318 } else if (patch != null) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2393 2392
2394 void addConstructor(FunctionElement constructor) { 2393 void addConstructor(FunctionElement constructor) {
2395 constructors = constructors.prepend(constructor); 2394 constructors = constructors.prepend(constructor);
2396 } 2395 }
2397 2396
2398 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) { 2397 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) {
2399 assert(!hasConstructor); 2398 assert(!hasConstructor);
2400 addConstructor(constructor); 2399 addConstructor(constructor);
2401 } 2400 }
2402 2401
2403 Link<DartType> computeTypeParameters(Compiler compiler) { 2402 List<DartType> computeTypeParameters(Compiler compiler) {
2404 NamedMixinApplication named = node.asNamedMixinApplication(); 2403 NamedMixinApplication named = node.asNamedMixinApplication();
2405 if (named == null) { 2404 if (named == null) {
2406 throw new SpannableAssertionFailure(node, 2405 throw new SpannableAssertionFailure(node,
2407 "Type variables on unnamed mixin applications must be set on " 2406 "Type variables on unnamed mixin applications must be set on "
2408 "creation."); 2407 "creation.");
2409 } 2408 }
2410 return createTypeVariables(named.typeParameters); 2409 return createTypeVariables(named.typeParameters);
2411 } 2410 }
2412 2411
2413 accept(ElementVisitor visitor) => visitor.visitMixinApplicationElement(this); 2412 accept(ElementVisitor visitor) => visitor.visitMixinApplicationElement(this);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
2570 2569
2571 ParameterMetadataAnnotation(Metadata this.metadata); 2570 ParameterMetadataAnnotation(Metadata this.metadata);
2572 2571
2573 Node parseNode(DiagnosticListener listener) => metadata.expression; 2572 Node parseNode(DiagnosticListener listener) => metadata.expression;
2574 2573
2575 Token get beginToken => metadata.getBeginToken(); 2574 Token get beginToken => metadata.getBeginToken();
2576 2575
2577 Token get endToken => metadata.getEndToken(); 2576 Token get endToken => metadata.getEndToken();
2578 } 2577 }
2579 2578
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698