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

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

Issue 1942763002: Rebased and retested version of CL 1915123008. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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 '../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
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 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 } 1665 }
1659 1666
1660 /// [Element] for a parameter-like element. 1667 /// [Element] for a parameter-like element.
1661 class FormalElementX extends ElementX 1668 class FormalElementX extends ElementX
1662 with AstElementMixin 1669 with AstElementMixin
1663 implements FormalElement { 1670 implements FormalElement {
1664 final VariableDefinitions definitions; 1671 final VariableDefinitions definitions;
1665 final Identifier identifier; 1672 final Identifier identifier;
1666 DartType typeCache; 1673 DartType typeCache;
1667 1674
1675 @override
1676 List<DartType> get typeVariables => functionSignature.typeVariables;
1677
1668 /** 1678 /**
1669 * Function signature for a variable with a function type. The signature is 1679 * Function signature for a variable with a function type. The signature is
1670 * kept to provide full information about parameter names through the mirror 1680 * kept to provide full information about parameter names through the mirror
1671 * system. 1681 * system.
1672 */ 1682 */
1673 FunctionSignature _functionSignatureCache; 1683 FunctionSignature _functionSignatureCache;
1674 1684
1675 FormalElementX(ElementKind elementKind, FunctionTypedElement enclosingElement, 1685 FormalElementX(ElementKind elementKind, FunctionTypedElement enclosingElement,
1676 this.definitions, Identifier identifier) 1686 this.definitions, Identifier identifier)
1677 : this.identifier = identifier, 1687 : this.identifier = identifier,
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 return getter != null && getter.isAbstract || 1897 return getter != null && getter.isAbstract ||
1888 setter != null && setter.isAbstract; 1898 setter != null && setter.isAbstract;
1889 } 1899 }
1890 } 1900 }
1891 1901
1892 // TODO(johnniwinther): [FunctionSignature] should be merged with 1902 // TODO(johnniwinther): [FunctionSignature] should be merged with
1893 // [FunctionType]. 1903 // [FunctionType].
1894 // TODO(karlklose): all these lists should have element type [FormalElement]. 1904 // TODO(karlklose): all these lists should have element type [FormalElement].
1895 class FunctionSignatureX extends FunctionSignatureCommon 1905 class FunctionSignatureX extends FunctionSignatureCommon
1896 implements FunctionSignature { 1906 implements FunctionSignature {
1907 final List<DartType> typeVariables;
1897 final List<Element> requiredParameters; 1908 final List<Element> requiredParameters;
1898 final List<Element> optionalParameters; 1909 final List<Element> optionalParameters;
1899 final int requiredParameterCount; 1910 final int requiredParameterCount;
1900 final int optionalParameterCount; 1911 final int optionalParameterCount;
1901 final bool optionalParametersAreNamed; 1912 final bool optionalParametersAreNamed;
1902 final List<Element> orderedOptionalParameters; 1913 final List<Element> orderedOptionalParameters;
1903 final FunctionType type; 1914 final FunctionType type;
1904 final bool hasOptionalParameters; 1915 final bool hasOptionalParameters;
1905 1916
1906 FunctionSignatureX( 1917 FunctionSignatureX(
1907 {this.requiredParameters: const <Element>[], 1918 {this.typeVariables: const <DartType>[],
1919 this.requiredParameters: const <Element>[],
1908 this.requiredParameterCount: 0, 1920 this.requiredParameterCount: 0,
1909 List<Element> optionalParameters: const <Element>[], 1921 List<Element> optionalParameters: const <Element>[],
1910 this.optionalParameterCount: 0, 1922 this.optionalParameterCount: 0,
1911 this.optionalParametersAreNamed: false, 1923 this.optionalParametersAreNamed: false,
1912 this.orderedOptionalParameters: const <Element>[], 1924 this.orderedOptionalParameters: const <Element>[],
1913 this.type}) 1925 this.type})
1914 : optionalParameters = optionalParameters, 1926 : optionalParameters = optionalParameters,
1915 hasOptionalParameters = !optionalParameters.isEmpty; 1927 hasOptionalParameters = !optionalParameters.isEmpty;
1916 } 1928 }
1917 1929
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1978 } 1990 }
1979 1991
1980 FunctionType get type { 1992 FunctionType get type {
1981 assert(invariant(this, typeCache != null, 1993 assert(invariant(this, typeCache != null,
1982 message: "Type has not been computed for $this.")); 1994 message: "Type has not been computed for $this."));
1983 return typeCache; 1995 return typeCache;
1984 } 1996 }
1985 1997
1986 FunctionElement asFunctionElement() => this; 1998 FunctionElement asFunctionElement() => this;
1987 1999
2000 @override
2001 Scope buildScope() => new TypeDeclarationScope(super.buildScope(), this);
2002
1988 String toString() { 2003 String toString() {
1989 if (isPatch) { 2004 if (isPatch) {
1990 return 'patch ${super.toString()}'; 2005 return 'patch ${super.toString()}';
1991 } else if (isPatched) { 2006 } else if (isPatched) {
1992 return 'origin ${super.toString()}'; 2007 return 'origin ${super.toString()}';
1993 } else { 2008 } else {
1994 return super.toString(); 2009 return super.toString();
1995 } 2010 }
1996 } 2011 }
1997 2012
1998 bool get isAbstract => false; 2013 bool get isAbstract => false;
1999 2014
2000 // A function is defined by the implementation element. 2015 // A function is defined by the implementation element.
2001 AstElement get definingElement => implementation; 2016 AstElement get definingElement => implementation;
2017
2018 @override
2019 List<DartType> get typeVariables => functionSignature.typeVariables;
2002 } 2020 }
2003 2021
2004 abstract class FunctionElementX extends BaseFunctionElementX 2022 abstract class FunctionElementX extends BaseFunctionElementX
2005 with AnalyzableElementX 2023 with AnalyzableElementX
2006 implements MethodElement { 2024 implements MethodElement {
2007 FunctionElementX( 2025 FunctionElementX(
2008 String name, ElementKind kind, Modifiers modifiers, Element enclosing) 2026 String name, ElementKind kind, Modifiers modifiers, Element enclosing)
2009 : super(name, kind, modifiers, enclosing); 2027 : super(name, kind, modifiers, enclosing);
2010 2028
2011 MemberElement get memberContext => this; 2029 MemberElement get memberContext => this;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
2149 } 2167 }
2150 } 2168 }
2151 2169
2152 bool get isFromEnvironmentConstructor { 2170 bool get isFromEnvironmentConstructor {
2153 return name == 'fromEnvironment' && 2171 return name == 'fromEnvironment' &&
2154 library.isDartCore && 2172 library.isDartCore &&
2155 (enclosingClass.name == 'bool' || 2173 (enclosingClass.name == 'bool' ||
2156 enclosingClass.name == 'int' || 2174 enclosingClass.name == 'int' ||
2157 enclosingClass.name == 'String'); 2175 enclosingClass.name == 'String');
2158 } 2176 }
2177
2178 /// Returns the empty list of type variables by default.
2179 @override
2180 List<DartType> get typeVariables => functionSignature.typeVariables;
2159 } 2181 }
2160 2182
2161 abstract class ConstructorElementX extends FunctionElementX 2183 abstract class ConstructorElementX extends FunctionElementX
2162 with ConstantConstructorMixin 2184 with ConstantConstructorMixin
2163 implements ConstructorElement { 2185 implements ConstructorElement {
2164 bool isRedirectingGenerative = false; 2186 bool isRedirectingGenerative = false;
2165 2187
2166 ConstructorElementX( 2188 ConstructorElementX(
2167 String name, ElementKind kind, Modifiers modifiers, Element enclosing) 2189 String name, ElementKind kind, Modifiers modifiers, Element enclosing)
2168 : super(name, kind, modifiers, enclosing); 2190 : super(name, kind, modifiers, enclosing);
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
3079 3101
3080 class TypeVariableElementX extends ElementX 3102 class TypeVariableElementX extends ElementX
3081 with AstElementMixin 3103 with AstElementMixin
3082 implements TypeVariableElement { 3104 implements TypeVariableElement {
3083 final int index; 3105 final int index;
3084 final Node node; 3106 final Node node;
3085 TypeVariableType typeCache; 3107 TypeVariableType typeCache;
3086 DartType boundCache; 3108 DartType boundCache;
3087 3109
3088 TypeVariableElementX( 3110 TypeVariableElementX(
3089 String name, TypeDeclarationElement enclosing, this.index, this.node) 3111 String name, GenericElement enclosing, this.index, this.node)
3090 : super(name, ElementKind.TYPE_VARIABLE, enclosing); 3112 : super(name, ElementKind.TYPE_VARIABLE, enclosing);
3091 3113
3092 TypeDeclarationElement get typeDeclaration => enclosingElement; 3114 GenericElement get typeDeclaration => enclosingElement;
3093 3115
3094 TypeVariableType computeType(Resolution resolution) => type; 3116 TypeVariableType computeType(Resolution resolution) => type;
3095 3117
3096 TypeVariableType get type { 3118 TypeVariableType get type {
3097 assert(invariant(this, typeCache != null, 3119 assert(invariant(this, typeCache != null,
3098 message: "Type has not been set on $this.")); 3120 message: "Type has not been set on $this."));
3099 return typeCache; 3121 return typeCache;
3100 } 3122 }
3101 3123
3102 DartType get bound { 3124 DartType get bound {
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
3246 if (definingElement.isField) { 3268 if (definingElement.isField) {
3247 FieldElement field = definingElement; 3269 FieldElement field = definingElement;
3248 body = field.initializer; 3270 body = field.initializer;
3249 } else if (node != null && node.asFunctionExpression() != null) { 3271 } else if (node != null && node.asFunctionExpression() != null) {
3250 body = node.asFunctionExpression().body; 3272 body = node.asFunctionExpression().body;
3251 } 3273 }
3252 return new ParsedResolvedAst( 3274 return new ParsedResolvedAst(
3253 declaration, node, body, definingElement.treeElements); 3275 declaration, node, body, definingElement.treeElements);
3254 } 3276 }
3255 } 3277 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/parser/node_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698