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 '../common/resolution.dart' show Resolution, ParsingContext; | 8 import '../common/resolution.dart' show Resolution, ParsingContext; |
9 import '../compiler.dart' show Compiler; | 9 import '../compiler.dart' show Compiler; |
10 import '../constants/constant_constructors.dart'; | 10 import '../constants/constant_constructors.dart'; |
11 import '../constants/constructors.dart'; | 11 import '../constants/constructors.dart'; |
12 import '../constants/expressions.dart'; | 12 import '../constants/expressions.dart'; |
13 import '../dart_types.dart'; | 13 import '../dart_types.dart'; |
14 import '../diagnostics/messages.dart' show MessageTemplate; | 14 import '../diagnostics/messages.dart' show MessageTemplate; |
15 import '../ordered_typeset.dart' show OrderedTypeSet; | 15 import '../ordered_typeset.dart' show OrderedTypeSet; |
16 import '../resolution/class_members.dart' show ClassMemberMixin; | 16 import '../resolution/class_members.dart' show ClassMemberMixin; |
17 import '../resolution/scope.dart' | 17 import '../resolution/scope.dart' |
18 show ClassScope, LibraryScope, Scope, TypeDeclarationScope; | 18 show |
| 19 ClassScope, |
| 20 LibraryScope, |
| 21 Scope, |
| 22 TypeDeclarationScope; |
19 import '../resolution/resolution.dart' show AnalyzableElementX; | 23 import '../resolution/resolution.dart' show AnalyzableElementX; |
20 import '../resolution/tree_elements.dart' show TreeElements; | 24 import '../resolution/tree_elements.dart' show TreeElements; |
21 import '../resolution/typedefs.dart' show TypedefCyclicVisitor; | 25 import '../resolution/typedefs.dart' show TypedefCyclicVisitor; |
22 import '../script.dart'; | 26 import '../script.dart'; |
23 import '../tokens/token.dart' show ErrorToken, Token; | 27 import '../tokens/token.dart' show ErrorToken, Token; |
24 import '../tokens/token_constants.dart' as Tokens show EOF_TOKEN; | 28 import '../tokens/token_constants.dart' as Tokens show EOF_TOKEN; |
25 import '../tree/tree.dart'; | 29 import '../tree/tree.dart'; |
26 import '../util/util.dart'; | 30 import '../util/util.dart'; |
27 | 31 |
28 import 'common.dart'; | 32 import 'common.dart'; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 return visitor.visitErroneousElement(this, arg); | 280 return visitor.visitErroneousElement(this, arg); |
277 } | 281 } |
278 | 282 |
279 @override | 283 @override |
280 get isEffectiveTargetMalformed { | 284 get isEffectiveTargetMalformed { |
281 throw new UnsupportedError("isEffectiveTargetMalformed"); | 285 throw new UnsupportedError("isEffectiveTargetMalformed"); |
282 } | 286 } |
283 | 287 |
284 @override | 288 @override |
285 bool get isFromEnvironmentConstructor => false; | 289 bool get isFromEnvironmentConstructor => false; |
| 290 |
| 291 @override |
| 292 List<DartType> get typeVariables => unsupported(); |
286 } | 293 } |
287 | 294 |
288 /// A constructor that was synthesized to recover from a compile-time error. | 295 /// A constructor that was synthesized to recover from a compile-time error. |
289 class ErroneousConstructorElementX extends ErroneousElementX | 296 class ErroneousConstructorElementX extends ErroneousElementX |
290 with | 297 with |
291 PatchMixin<FunctionElement>, | 298 PatchMixin<FunctionElement>, |
292 AnalyzableElementX, | 299 AnalyzableElementX, |
293 ConstantConstructorMixin | 300 ConstantConstructorMixin |
294 implements ConstructorElementX { | 301 implements ConstructorElementX { |
295 // TODO(ahe): Instead of subclassing [ErroneousElementX], this class should | 302 // TODO(ahe): Instead of subclassing [ErroneousElementX], this class should |
(...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1657 } | 1664 } |
1658 | 1665 |
1659 /// [Element] for a parameter-like element. | 1666 /// [Element] for a parameter-like element. |
1660 class FormalElementX extends ElementX | 1667 class FormalElementX extends ElementX |
1661 with AstElementMixin | 1668 with AstElementMixin |
1662 implements FormalElement { | 1669 implements FormalElement { |
1663 final VariableDefinitions definitions; | 1670 final VariableDefinitions definitions; |
1664 final Identifier identifier; | 1671 final Identifier identifier; |
1665 DartType typeCache; | 1672 DartType typeCache; |
1666 | 1673 |
| 1674 @override |
| 1675 List<DartType> get typeVariables => functionSignature.typeVariables; |
| 1676 |
1667 /** | 1677 /** |
1668 * Function signature for a variable with a function type. The signature is | 1678 * Function signature for a variable with a function type. The signature is |
1669 * kept to provide full information about parameter names through the mirror | 1679 * kept to provide full information about parameter names through the mirror |
1670 * system. | 1680 * system. |
1671 */ | 1681 */ |
1672 FunctionSignature _functionSignatureCache; | 1682 FunctionSignature _functionSignatureCache; |
1673 | 1683 |
1674 FormalElementX(ElementKind elementKind, FunctionTypedElement enclosingElement, | 1684 FormalElementX(ElementKind elementKind, FunctionTypedElement enclosingElement, |
1675 this.definitions, Identifier identifier) | 1685 this.definitions, Identifier identifier) |
1676 : this.identifier = identifier, | 1686 : this.identifier = identifier, |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1886 return getter != null && getter.isAbstract || | 1896 return getter != null && getter.isAbstract || |
1887 setter != null && setter.isAbstract; | 1897 setter != null && setter.isAbstract; |
1888 } | 1898 } |
1889 } | 1899 } |
1890 | 1900 |
1891 // TODO(johnniwinther): [FunctionSignature] should be merged with | 1901 // TODO(johnniwinther): [FunctionSignature] should be merged with |
1892 // [FunctionType]. | 1902 // [FunctionType]. |
1893 // TODO(karlklose): all these lists should have element type [FormalElement]. | 1903 // TODO(karlklose): all these lists should have element type [FormalElement]. |
1894 class FunctionSignatureX extends FunctionSignatureCommon | 1904 class FunctionSignatureX extends FunctionSignatureCommon |
1895 implements FunctionSignature { | 1905 implements FunctionSignature { |
| 1906 final List<DartType> typeVariables; |
1896 final List<Element> requiredParameters; | 1907 final List<Element> requiredParameters; |
1897 final List<Element> optionalParameters; | 1908 final List<Element> optionalParameters; |
1898 final int requiredParameterCount; | 1909 final int requiredParameterCount; |
1899 final int optionalParameterCount; | 1910 final int optionalParameterCount; |
1900 final bool optionalParametersAreNamed; | 1911 final bool optionalParametersAreNamed; |
1901 final List<Element> orderedOptionalParameters; | 1912 final List<Element> orderedOptionalParameters; |
1902 final FunctionType type; | 1913 final FunctionType type; |
1903 final bool hasOptionalParameters; | 1914 final bool hasOptionalParameters; |
1904 | 1915 |
1905 FunctionSignatureX( | 1916 FunctionSignatureX( |
1906 {this.requiredParameters: const <Element>[], | 1917 {this.typeVariables: const <DartType>[], |
| 1918 this.requiredParameters: const <Element>[], |
1907 this.requiredParameterCount: 0, | 1919 this.requiredParameterCount: 0, |
1908 List<Element> optionalParameters: const <Element>[], | 1920 List<Element> optionalParameters: const <Element>[], |
1909 this.optionalParameterCount: 0, | 1921 this.optionalParameterCount: 0, |
1910 this.optionalParametersAreNamed: false, | 1922 this.optionalParametersAreNamed: false, |
1911 this.orderedOptionalParameters: const <Element>[], | 1923 this.orderedOptionalParameters: const <Element>[], |
1912 this.type}) | 1924 this.type}) |
1913 : optionalParameters = optionalParameters, | 1925 : optionalParameters = optionalParameters, |
1914 hasOptionalParameters = !optionalParameters.isEmpty; | 1926 hasOptionalParameters = !optionalParameters.isEmpty; |
1915 } | 1927 } |
1916 | 1928 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1977 } | 1989 } |
1978 | 1990 |
1979 FunctionType get type { | 1991 FunctionType get type { |
1980 assert(invariant(this, typeCache != null, | 1992 assert(invariant(this, typeCache != null, |
1981 message: "Type has not been computed for $this.")); | 1993 message: "Type has not been computed for $this.")); |
1982 return typeCache; | 1994 return typeCache; |
1983 } | 1995 } |
1984 | 1996 |
1985 FunctionElement asFunctionElement() => this; | 1997 FunctionElement asFunctionElement() => this; |
1986 | 1998 |
| 1999 @override |
| 2000 Scope buildScope() => new TypeDeclarationScope(super.buildScope(), this); |
| 2001 |
1987 String toString() { | 2002 String toString() { |
1988 if (isPatch) { | 2003 if (isPatch) { |
1989 return 'patch ${super.toString()}'; | 2004 return 'patch ${super.toString()}'; |
1990 } else if (isPatched) { | 2005 } else if (isPatched) { |
1991 return 'origin ${super.toString()}'; | 2006 return 'origin ${super.toString()}'; |
1992 } else { | 2007 } else { |
1993 return super.toString(); | 2008 return super.toString(); |
1994 } | 2009 } |
1995 } | 2010 } |
1996 | 2011 |
1997 bool get isAbstract => false; | 2012 bool get isAbstract => false; |
1998 | 2013 |
1999 // A function is defined by the implementation element. | 2014 // A function is defined by the implementation element. |
2000 AstElement get definingElement => implementation; | 2015 AstElement get definingElement => implementation; |
| 2016 |
| 2017 @override |
| 2018 List<DartType> get typeVariables => functionSignature.typeVariables; |
2001 } | 2019 } |
2002 | 2020 |
2003 abstract class FunctionElementX extends BaseFunctionElementX | 2021 abstract class FunctionElementX extends BaseFunctionElementX |
2004 with AnalyzableElementX | 2022 with AnalyzableElementX |
2005 implements MethodElement { | 2023 implements MethodElement { |
2006 FunctionElementX( | 2024 FunctionElementX( |
2007 String name, ElementKind kind, Modifiers modifiers, Element enclosing) | 2025 String name, ElementKind kind, Modifiers modifiers, Element enclosing) |
2008 : super(name, kind, modifiers, enclosing); | 2026 : super(name, kind, modifiers, enclosing); |
2009 | 2027 |
2010 MemberElement get memberContext => this; | 2028 MemberElement get memberContext => this; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2148 } | 2166 } |
2149 } | 2167 } |
2150 | 2168 |
2151 bool get isFromEnvironmentConstructor { | 2169 bool get isFromEnvironmentConstructor { |
2152 return name == 'fromEnvironment' && | 2170 return name == 'fromEnvironment' && |
2153 library.isDartCore && | 2171 library.isDartCore && |
2154 (enclosingClass.name == 'bool' || | 2172 (enclosingClass.name == 'bool' || |
2155 enclosingClass.name == 'int' || | 2173 enclosingClass.name == 'int' || |
2156 enclosingClass.name == 'String'); | 2174 enclosingClass.name == 'String'); |
2157 } | 2175 } |
| 2176 |
| 2177 /// Returns the empty list of type variables by default. |
| 2178 @override |
| 2179 List<DartType> get typeVariables => functionSignature.typeVariables; |
2158 } | 2180 } |
2159 | 2181 |
2160 abstract class ConstructorElementX extends FunctionElementX | 2182 abstract class ConstructorElementX extends FunctionElementX |
2161 with ConstantConstructorMixin | 2183 with ConstantConstructorMixin |
2162 implements ConstructorElement { | 2184 implements ConstructorElement { |
2163 bool isRedirectingGenerative = false; | 2185 bool isRedirectingGenerative = false; |
2164 | 2186 |
2165 ConstructorElementX( | 2187 ConstructorElementX( |
2166 String name, ElementKind kind, Modifiers modifiers, Element enclosing) | 2188 String name, ElementKind kind, Modifiers modifiers, Element enclosing) |
2167 : super(name, kind, modifiers, enclosing); | 2189 : super(name, kind, modifiers, enclosing); |
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3078 | 3100 |
3079 class TypeVariableElementX extends ElementX | 3101 class TypeVariableElementX extends ElementX |
3080 with AstElementMixin | 3102 with AstElementMixin |
3081 implements TypeVariableElement { | 3103 implements TypeVariableElement { |
3082 final int index; | 3104 final int index; |
3083 final Node node; | 3105 final Node node; |
3084 TypeVariableType typeCache; | 3106 TypeVariableType typeCache; |
3085 DartType boundCache; | 3107 DartType boundCache; |
3086 | 3108 |
3087 TypeVariableElementX( | 3109 TypeVariableElementX( |
3088 String name, TypeDeclarationElement enclosing, this.index, this.node) | 3110 String name, GenericElement enclosing, this.index, this.node) |
3089 : super(name, ElementKind.TYPE_VARIABLE, enclosing); | 3111 : super(name, ElementKind.TYPE_VARIABLE, enclosing); |
3090 | 3112 |
3091 TypeDeclarationElement get typeDeclaration => enclosingElement; | 3113 GenericElement get typeDeclaration => enclosingElement; |
3092 | 3114 |
3093 TypeVariableType computeType(Resolution resolution) => type; | 3115 TypeVariableType computeType(Resolution resolution) => type; |
3094 | 3116 |
3095 TypeVariableType get type { | 3117 TypeVariableType get type { |
3096 assert(invariant(this, typeCache != null, | 3118 assert(invariant(this, typeCache != null, |
3097 message: "Type has not been set on $this.")); | 3119 message: "Type has not been set on $this.")); |
3098 return typeCache; | 3120 return typeCache; |
3099 } | 3121 } |
3100 | 3122 |
3101 DartType get bound { | 3123 DartType get bound { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3245 if (definingElement.isField) { | 3267 if (definingElement.isField) { |
3246 FieldElement field = definingElement; | 3268 FieldElement field = definingElement; |
3247 body = field.initializer; | 3269 body = field.initializer; |
3248 } else if (node != null && node.asFunctionExpression() != null) { | 3270 } else if (node != null && node.asFunctionExpression() != null) { |
3249 body = node.asFunctionExpression().body; | 3271 body = node.asFunctionExpression().body; |
3250 } | 3272 } |
3251 return new ParsedResolvedAst( | 3273 return new ParsedResolvedAst( |
3252 declaration, node, body, definingElement.treeElements); | 3274 declaration, node, body, definingElement.treeElements); |
3253 } | 3275 } |
3254 } | 3276 } |
OLD | NEW |