Chromium Code Reviews| 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 '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 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1077 * system. | 1077 * system. |
| 1078 * | 1078 * |
| 1079 * The [functionSignature] is not available until the typedef element has been | 1079 * The [functionSignature] is not available until the typedef element has been |
| 1080 * resolved. | 1080 * resolved. |
| 1081 */ | 1081 */ |
| 1082 FunctionSignature functionSignature; | 1082 FunctionSignature functionSignature; |
| 1083 | 1083 |
| 1084 TypedefType computeType(Compiler compiler) { | 1084 TypedefType computeType(Compiler compiler) { |
| 1085 if (thisType != null) return thisType; | 1085 if (thisType != null) return thisType; |
| 1086 Typedef node = parseNode(compiler); | 1086 Typedef node = parseNode(compiler); |
| 1087 Link<DartType> parameters = | 1087 List<DartType> parameters = |
| 1088 TypeDeclarationElementX.createTypeVariables(this, node.typeParameters); | 1088 TypeDeclarationElementX.createTypeVariables(this, node.typeParameters); |
| 1089 thisType = new TypedefType(this, parameters); | 1089 thisType = new TypedefType(this, parameters); |
| 1090 if (parameters.isEmpty) { | 1090 if (parameters.isEmpty) { |
| 1091 rawType = thisType; | 1091 rawType = thisType; |
| 1092 } else { | 1092 } else { |
| 1093 var dynamicParameters = const Link<DartType>(); | 1093 List<DartType> dynamicParameters =new List<DartType>.generate( |
|
Johnni Winther
2014/02/26 14:01:54
Space after =
karlklose
2014/02/27 09:31:41
Done.
| |
| 1094 parameters.forEach((_) { | 1094 parameters.length, |
| 1095 dynamicParameters = | 1095 (_) => compiler.types.dynamicType); |
| 1096 dynamicParameters.prepend(compiler.types.dynamicType); | |
| 1097 }); | |
| 1098 rawType = new TypedefType(this, dynamicParameters); | 1096 rawType = new TypedefType(this, dynamicParameters); |
| 1099 } | 1097 } |
| 1100 compiler.resolveTypedef(this); | 1098 compiler.resolveTypedef(this); |
| 1101 return thisType; | 1099 return thisType; |
| 1102 } | 1100 } |
| 1103 | 1101 |
| 1104 Link<DartType> get typeVariables => thisType.typeArguments; | 1102 List<DartType> get typeVariables => thisType.typeArguments; |
| 1105 | 1103 |
| 1106 Scope buildScope() { | 1104 Scope buildScope() { |
| 1107 return new TypeDeclarationScope(enclosingElement.buildScope(), this); | 1105 return new TypeDeclarationScope(enclosingElement.buildScope(), this); |
| 1108 } | 1106 } |
| 1109 | 1107 |
| 1110 void checkCyclicReference(Compiler compiler) { | 1108 void checkCyclicReference(Compiler compiler) { |
| 1111 if (hasBeenCheckedForCycles) return; | 1109 if (hasBeenCheckedForCycles) return; |
| 1112 var visitor = new TypedefCyclicVisitor(compiler, this); | 1110 var visitor = new TypedefCyclicVisitor(compiler, this); |
| 1113 computeType(compiler).accept(visitor, null); | 1111 computeType(compiler).accept(visitor, null); |
| 1114 hasBeenCheckedForCycles = true; | 1112 hasBeenCheckedForCycles = true; |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1755 | 1753 |
| 1756 accept(ElementVisitor visitor) => visitor.visitVoidElement(this); | 1754 accept(ElementVisitor visitor) => visitor.visitVoidElement(this); |
| 1757 } | 1755 } |
| 1758 | 1756 |
| 1759 class TypeDeclarationElementX { | 1757 class TypeDeclarationElementX { |
| 1760 /** | 1758 /** |
| 1761 * Creates the type variables, their type and corresponding element, for the | 1759 * Creates the type variables, their type and corresponding element, for the |
| 1762 * type variables declared in [parameter] on [element]. The bounds of the type | 1760 * type variables declared in [parameter] on [element]. The bounds of the type |
| 1763 * variables are not set until [element] has been resolved. | 1761 * variables are not set until [element] has been resolved. |
| 1764 */ | 1762 */ |
| 1765 static Link<DartType> createTypeVariables(TypeDeclarationElement element, | 1763 static List<DartType> createTypeVariables(TypeDeclarationElement element, |
| 1766 NodeList parameters) { | 1764 NodeList parameters) { |
| 1767 if (parameters == null) return const Link<DartType>(); | 1765 if (parameters == null) return const <DartType>[]; |
| 1768 | 1766 |
| 1769 // Create types and elements for type variable. | 1767 // Create types and elements for type variable. |
| 1770 var arguments = new LinkBuilder<DartType>(); | 1768 List<DartType> arguments = <DartType>[]; |
| 1771 for (Link link = parameters.nodes; !link.isEmpty; link = link.tail) { | 1769 for (Link link = parameters.nodes; !link.isEmpty; link = link.tail) { |
| 1772 TypeVariable node = link.head; | 1770 TypeVariable node = link.head; |
| 1773 String variableName = node.name.source; | 1771 String variableName = node.name.source; |
| 1774 TypeVariableElement variableElement = | 1772 TypeVariableElement variableElement = |
| 1775 new TypeVariableElementX(variableName, element, node); | 1773 new TypeVariableElementX(variableName, element, node); |
| 1776 TypeVariableType variableType = new TypeVariableType(variableElement); | 1774 TypeVariableType variableType = new TypeVariableType(variableElement); |
| 1777 variableElement.type = variableType; | 1775 variableElement.type = variableType; |
| 1778 arguments.addLast(variableType); | 1776 arguments.add(variableType); |
| 1779 } | 1777 } |
| 1780 return arguments.toLink(); | 1778 return arguments; |
| 1781 } | 1779 } |
| 1782 } | 1780 } |
| 1783 | 1781 |
| 1784 abstract class BaseClassElementX extends ElementX implements ClassElement { | 1782 abstract class BaseClassElementX extends ElementX implements ClassElement { |
| 1785 final int id; | 1783 final int id; |
| 1786 | 1784 |
| 1787 /** | 1785 /** |
| 1788 * The type of [:this:] for this class declaration. | 1786 * The type of [:this:] for this class declaration. |
| 1789 * | 1787 * |
| 1790 * The type of [:this:] is the interface type based on this element in which | 1788 * The type of [:this:] is the interface type based on this element in which |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1847 int get hashCode => id; | 1845 int get hashCode => id; |
| 1848 ClassElement get patch => super.patch; | 1846 ClassElement get patch => super.patch; |
| 1849 ClassElement get origin => super.origin; | 1847 ClassElement get origin => super.origin; |
| 1850 ClassElement get declaration => super.declaration; | 1848 ClassElement get declaration => super.declaration; |
| 1851 ClassElement get implementation => super.implementation; | 1849 ClassElement get implementation => super.implementation; |
| 1852 | 1850 |
| 1853 bool get hasBackendMembers => !backendMembers.isEmpty; | 1851 bool get hasBackendMembers => !backendMembers.isEmpty; |
| 1854 | 1852 |
| 1855 bool get isUnnamedMixinApplication => false; | 1853 bool get isUnnamedMixinApplication => false; |
| 1856 | 1854 |
| 1857 void computeThisAndRawType(Compiler compiler, Link<DartType> typeVariables) { | 1855 void computeThisAndRawType(Compiler compiler, List<DartType> typeVariables) { |
| 1858 if (thisType == null) { | 1856 if (thisType == null) { |
| 1859 if (origin == null) { | 1857 if (origin == null) { |
| 1860 Link<DartType> parameters = typeVariables; | 1858 List<DartType> parameters = typeVariables; |
| 1861 thisType = new InterfaceType(this, parameters); | 1859 thisType = new InterfaceType(this, parameters); |
| 1862 if (parameters.isEmpty) { | 1860 if (parameters.isEmpty) { |
| 1863 rawTypeCache = thisType; | 1861 rawTypeCache = thisType; |
| 1864 } else { | 1862 } else { |
| 1865 var dynamicParameters = const Link<DartType>(); | 1863 // TODO(karlklose): there is similar code in another place; share. |
| 1866 parameters.forEach((_) { | 1864 List<DartType> dynamicParameters = new List<DartType>.generate( |
| 1867 dynamicParameters = | 1865 parameters.length, |
| 1868 dynamicParameters.prepend(compiler.types.dynamicType); | 1866 (_) => compiler.types.dynamicType); |
| 1869 }); | |
| 1870 rawTypeCache = new InterfaceType(this, dynamicParameters); | 1867 rawTypeCache = new InterfaceType(this, dynamicParameters); |
| 1871 } | 1868 } |
| 1872 } else { | 1869 } else { |
| 1873 thisType = origin.computeType(compiler); | 1870 thisType = origin.computeType(compiler); |
| 1874 rawTypeCache = origin.rawType; | 1871 rawTypeCache = origin.rawType; |
| 1875 } | 1872 } |
| 1876 } | 1873 } |
| 1877 } | 1874 } |
| 1878 | 1875 |
| 1879 // TODO(johnniwinther): Add [thisType] getter similar to [rawType]. | 1876 // TODO(johnniwinther): Add [thisType] getter similar to [rawType]. |
| 1880 InterfaceType computeType(Compiler compiler) { | 1877 InterfaceType computeType(Compiler compiler) { |
| 1881 if (thisType == null) { | 1878 if (thisType == null) { |
| 1882 computeThisAndRawType(compiler, computeTypeParameters(compiler)); | 1879 computeThisAndRawType(compiler, computeTypeParameters(compiler)); |
| 1883 } | 1880 } |
| 1884 return thisType; | 1881 return thisType; |
| 1885 } | 1882 } |
| 1886 | 1883 |
| 1887 InterfaceType get rawType { | 1884 InterfaceType get rawType { |
| 1888 assert(invariant(this, rawTypeCache != null, | 1885 assert(invariant(this, rawTypeCache != null, |
| 1889 message: 'Raw type has not been computed for $this')); | 1886 message: 'Raw type has not been computed for $this')); |
| 1890 return rawTypeCache; | 1887 return rawTypeCache; |
| 1891 } | 1888 } |
| 1892 | 1889 |
| 1893 Link<DartType> computeTypeParameters(Compiler compiler); | 1890 List<DartType> computeTypeParameters(Compiler compiler); |
| 1894 | 1891 |
| 1895 /** | 1892 /** |
| 1896 * Return [:true:] if this element is the [:Object:] class for the [compiler]. | 1893 * Return [:true:] if this element is the [:Object:] class for the [compiler]. |
| 1897 */ | 1894 */ |
| 1898 bool isObject(Compiler compiler) => | 1895 bool isObject(Compiler compiler) => |
| 1899 identical(declaration, compiler.objectClass); | 1896 identical(declaration, compiler.objectClass); |
| 1900 | 1897 |
| 1901 Link<DartType> get typeVariables => thisType.typeArguments; | 1898 List<DartType> get typeVariables => thisType.typeArguments; |
| 1902 | 1899 |
| 1903 ClassElement ensureResolved(Compiler compiler) { | 1900 ClassElement ensureResolved(Compiler compiler) { |
| 1904 if (resolutionState == STATE_NOT_STARTED) { | 1901 if (resolutionState == STATE_NOT_STARTED) { |
| 1905 compiler.resolver.resolveClass(this); | 1902 compiler.resolver.resolveClass(this); |
| 1906 } | 1903 } |
| 1907 return this; | 1904 return this; |
| 1908 } | 1905 } |
| 1909 | 1906 |
| 1910 void setDefaultConstructor(FunctionElement constructor, Compiler compiler); | 1907 void setDefaultConstructor(FunctionElement constructor, Compiler compiler); |
| 1911 | 1908 |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2279 } | 2276 } |
| 2280 return false; | 2277 return false; |
| 2281 } | 2278 } |
| 2282 | 2279 |
| 2283 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) { | 2280 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) { |
| 2284 addToScope(constructor, compiler); | 2281 addToScope(constructor, compiler); |
| 2285 // The default constructor, although synthetic, is part of a class' API. | 2282 // The default constructor, although synthetic, is part of a class' API. |
| 2286 localMembers = localMembers.prepend(constructor); | 2283 localMembers = localMembers.prepend(constructor); |
| 2287 } | 2284 } |
| 2288 | 2285 |
| 2289 Link<DartType> computeTypeParameters(Compiler compiler) { | 2286 List<DartType> computeTypeParameters(Compiler compiler) { |
| 2290 ClassNode node = parseNode(compiler); | 2287 ClassNode node = parseNode(compiler); |
| 2291 return TypeDeclarationElementX.createTypeVariables( | 2288 return TypeDeclarationElementX.createTypeVariables( |
| 2292 this, node.typeParameters); | 2289 this, node.typeParameters); |
| 2293 } | 2290 } |
| 2294 | 2291 |
| 2295 Scope buildScope() => new ClassScope(enclosingElement.buildScope(), this); | 2292 Scope buildScope() => new ClassScope(enclosingElement.buildScope(), this); |
| 2296 | 2293 |
| 2297 String toString() { | 2294 String toString() { |
| 2298 if (origin != null) { | 2295 if (origin != null) { |
| 2299 return 'patch ${super.toString()}'; | 2296 return 'patch ${super.toString()}'; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2374 | 2371 |
| 2375 void addConstructor(FunctionElement constructor) { | 2372 void addConstructor(FunctionElement constructor) { |
| 2376 constructors = constructors.prepend(constructor); | 2373 constructors = constructors.prepend(constructor); |
| 2377 } | 2374 } |
| 2378 | 2375 |
| 2379 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) { | 2376 void setDefaultConstructor(FunctionElement constructor, Compiler compiler) { |
| 2380 assert(!hasConstructor); | 2377 assert(!hasConstructor); |
| 2381 addConstructor(constructor); | 2378 addConstructor(constructor); |
| 2382 } | 2379 } |
| 2383 | 2380 |
| 2384 Link<DartType> computeTypeParameters(Compiler compiler) { | 2381 List<DartType> computeTypeParameters(Compiler compiler) { |
| 2385 NamedMixinApplication named = node.asNamedMixinApplication(); | 2382 NamedMixinApplication named = node.asNamedMixinApplication(); |
| 2386 if (named == null) { | 2383 if (named == null) { |
| 2387 throw new SpannableAssertionFailure(node, | 2384 throw new SpannableAssertionFailure(node, |
| 2388 "Type variables on unnamed mixin applications must be set on " | 2385 "Type variables on unnamed mixin applications must be set on " |
| 2389 "creation."); | 2386 "creation."); |
| 2390 } | 2387 } |
| 2391 return TypeDeclarationElementX.createTypeVariables( | 2388 return TypeDeclarationElementX.createTypeVariables( |
| 2392 this, named.typeParameters); | 2389 this, named.typeParameters); |
| 2393 } | 2390 } |
| 2394 | 2391 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2540 final Metadata metadata; | 2537 final Metadata metadata; |
| 2541 | 2538 |
| 2542 ParameterMetadataAnnotation(Metadata this.metadata); | 2539 ParameterMetadataAnnotation(Metadata this.metadata); |
| 2543 | 2540 |
| 2544 Node parseNode(DiagnosticListener listener) => metadata.expression; | 2541 Node parseNode(DiagnosticListener listener) => metadata.expression; |
| 2545 | 2542 |
| 2546 Token get beginToken => metadata.getBeginToken(); | 2543 Token get beginToken => metadata.getBeginToken(); |
| 2547 | 2544 |
| 2548 Token get endToken => metadata.getEndToken(); | 2545 Token get endToken => metadata.getEndToken(); |
| 2549 } | 2546 } |
| OLD | NEW |