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

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

Issue 2944843002: All strong mode cleaning of dart2js. (Closed)
Patch Set: More issues discovered during testing. Created 3 years, 6 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/names.dart' show Identifiers; 8 import '../common/names.dart' show Identifiers;
9 import '../common/resolution.dart' show Resolution, ParsingContext; 9 import '../common/resolution.dart' show Resolution, ParsingContext;
10 import '../compiler.dart' show Compiler; 10 import '../compiler.dart' show Compiler;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 Iterable<MetadataAnnotation> get metadata => unsupported(); 243 Iterable<MetadataAnnotation> get metadata => unsupported();
244 bool get hasNode => false; 244 bool get hasNode => false;
245 get node => unsupported(); 245 get node => unsupported();
246 get hasResolvedAst => false; 246 get hasResolvedAst => false;
247 get resolvedAst => unsupported(); 247 get resolvedAst => unsupported();
248 get type => unsupported(); 248 get type => unsupported();
249 get cachedNode => unsupported(); 249 get cachedNode => unsupported();
250 get functionSignature => unsupported(); 250 get functionSignature => unsupported();
251 get parameterStructure => unsupported(); 251 get parameterStructure => unsupported();
252 get parameters => unsupported(); 252 get parameters => unsupported();
253 get patch => null; 253 Element get patch => null;
254 get origin => this; 254 Element get origin => this;
255 get immediateRedirectionTarget => unsupported(); 255 get immediateRedirectionTarget => unsupported();
256 get nestedClosures => unsupported(); 256 get nestedClosures => unsupported();
257 get memberContext => unsupported(); 257 get memberContext => unsupported();
258 get executableContext => unsupported(); 258 get executableContext => unsupported();
259 get isExternal => unsupported(); 259 get isExternal => unsupported();
260 get constantConstructor => null; 260 get constantConstructor => null;
261 261
262 bool get isRedirectingGenerative => unsupported(); 262 bool get isRedirectingGenerative => unsupported();
263 bool get isRedirectingFactory => unsupported(); 263 bool get isRedirectingFactory => unsupported();
264 264
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 set _isEffectiveTargetMalformed(_) { 374 set _isEffectiveTargetMalformed(_) {
375 throw new UnsupportedError("_isEffectiveTargetMalformed="); 375 throw new UnsupportedError("_isEffectiveTargetMalformed=");
376 } 376 }
377 377
378 @override 378 @override
379 get isEffectiveTargetMalformed { 379 get isEffectiveTargetMalformed {
380 throw new UnsupportedError("isEffectiveTargetMalformed"); 380 throw new UnsupportedError("isEffectiveTargetMalformed");
381 } 381 }
382 382
383 @override 383 @override
384 void setEffectiveTarget( 384 void setEffectiveTarget(ConstructorElement target, ResolutionDartType type,
385 ConstructorElement target, ResolutionInterfaceType type,
386 {bool isMalformed: false}) { 385 {bool isMalformed: false}) {
387 throw new UnsupportedError("setEffectiveTarget"); 386 throw new UnsupportedError("setEffectiveTarget");
388 } 387 }
389 388
390 @override 389 @override
391 void _computeSignature(Resolution resolution) { 390 void _computeSignature(Resolution resolution) {
392 throw new UnsupportedError("_computeSignature"); 391 throw new UnsupportedError("_computeSignature");
393 } 392 }
394 393
395 @override 394 @override
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 453
455 @override 454 @override
456 get _redirectionDeferredPrefix { 455 get _redirectionDeferredPrefix {
457 throw new UnsupportedError("_redirectionDeferredPrefix"); 456 throw new UnsupportedError("_redirectionDeferredPrefix");
458 } 457 }
459 458
460 @override 459 @override
461 set _redirectionDeferredPrefix(_) { 460 set _redirectionDeferredPrefix(_) {
462 throw new UnsupportedError("_redirectionDeferredPrefix="); 461 throw new UnsupportedError("_redirectionDeferredPrefix=");
463 } 462 }
463
464 // TODO(johnniwinther): Remove this.
465 ConstructorElementX get declaration => super.declaration;
466
467 // TODO(johnniwinther): Remove this.
468 ConstructorElementX get implementation => super.implementation;
469
470 // TODO(johnniwinther): Remove this.
471 ConstructorElementX get origin => super.origin;
472
473 // TODO(johnniwinther): Remove this.
474 ConstructorElementX get patch => super.patch;
475
476 ResolutionFunctionType computeType(Resolution resolution) =>
477 super.computeType(resolution);
464 } 478 }
465 479
466 /// A message attached to a [WarnOnUseElementX]. 480 /// A message attached to a [WarnOnUseElementX].
467 class WrappedMessage { 481 class WrappedMessage {
468 /// The message position. If [:null:] the position of the reference to the 482 /// The message position. If [:null:] the position of the reference to the
469 /// [WarnOnUseElementX] is used. 483 /// [WarnOnUseElementX] is used.
470 final SourceSpan sourceSpan; 484 final SourceSpan sourceSpan;
471 485
472 /** 486 /**
473 * The message to report on resolving a wrapped element. 487 * The message to report on resolving a wrapped element.
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 {'libraryName': actualName}), 821 {'libraryName': actualName}),
808 <DiagnosticMessage>[ 822 <DiagnosticMessage>[
809 reporter.createMessage( 823 reporter.createMessage(
810 tag.name, MessageKind.THIS_IS_THE_PART_OF_TAG), 824 tag.name, MessageKind.THIS_IS_THE_PART_OF_TAG),
811 ]); 825 ]);
812 } 826 }
813 } 827 }
814 828
815 bool get hasMembers => !localMembers.isEmpty; 829 bool get hasMembers => !localMembers.isEmpty;
816 830
817 Element get analyzableElement => library; 831 AnalyzableElement get analyzableElement => library;
818 832
819 accept(ElementVisitor visitor, arg) { 833 accept(ElementVisitor visitor, arg) {
820 return visitor.visitCompilationUnitElement(this, arg); 834 return visitor.visitCompilationUnitElement(this, arg);
821 } 835 }
822 } 836 }
823 837
824 /// Map from [Element] to the [ImportElement]s throught which it was imported. 838 /// Map from [Element] to the [ImportElement]s throught which it was imported.
825 /// 839 ///
826 /// This is used for error reporting and deferred loading. 840 /// This is used for error reporting and deferred loading.
827 class Importers { 841 class Importers {
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 return const <MetadataAnnotation>[]; 1083 return const <MetadataAnnotation>[];
1070 } 1084 }
1071 1085
1072 void set metadata(value) { 1086 void set metadata(value) {
1073 // The metadata is stored on [libraryTag]. 1087 // The metadata is stored on [libraryTag].
1074 throw new SpannableAssertionFailure(this, 'Cannot set metadata on Library'); 1088 throw new SpannableAssertionFailure(this, 'Cannot set metadata on Library');
1075 } 1089 }
1076 1090
1077 CompilationUnitElement get compilationUnit => entryCompilationUnit; 1091 CompilationUnitElement get compilationUnit => entryCompilationUnit;
1078 1092
1079 Element get analyzableElement => this; 1093 AnalyzableElement get analyzableElement => this;
1080 1094
1081 void addCompilationUnit(CompilationUnitElement element) { 1095 void addCompilationUnit(CompilationUnitElement element) {
1082 compilationUnits = compilationUnits.prepend(element); 1096 compilationUnits = compilationUnits.prepend(element);
1083 } 1097 }
1084 1098
1085 void addTag(LibraryTag tag, DiagnosticReporter reporter) { 1099 void addTag(LibraryTag tag, DiagnosticReporter reporter) {
1086 if (tagsCache != null) { 1100 if (tagsCache != null) {
1087 reporter.internalError( 1101 reporter.internalError(
1088 tag, "Library tags for $this have already been computed."); 1102 tag, "Library tags for $this have already been computed.");
1089 } 1103 }
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 return 'origin library(${canonicalUri})'; 1271 return 'origin library(${canonicalUri})';
1258 } else { 1272 } else {
1259 return 'library(${canonicalUri})'; 1273 return 'library(${canonicalUri})';
1260 } 1274 }
1261 } 1275 }
1262 1276
1263 accept(ElementVisitor visitor, arg) { 1277 accept(ElementVisitor visitor, arg) {
1264 return visitor.visitLibraryElement(this, arg); 1278 return visitor.visitLibraryElement(this, arg);
1265 } 1279 }
1266 1280
1267 // TODO(johnniwinther): Remove these when issue 18630 is fixed. 1281 // TODO(johnniwinther): Remove this.
1282 LibraryElementX get declaration => super.declaration;
1283
1284 // TODO(johnniwinther): Remove this.
1285 LibraryElementX get implementation => super.implementation;
1286
1287 // TODO(johnniwinther): Remove this.
1288 LibraryElementX get origin => super.origin;
1289
1290 // TODO(johnniwinther): Remove this.
1268 LibraryElementX get patch => super.patch; 1291 LibraryElementX get patch => super.patch;
1269 LibraryElementX get origin => super.origin;
1270 } 1292 }
1271 1293
1272 class PrefixElementX extends ElementX implements PrefixElement { 1294 class PrefixElementX extends ElementX implements PrefixElement {
1273 Token firstPosition; 1295 Token firstPosition;
1274 1296
1275 final ImportScope importScope = new ImportScope(); 1297 final ImportScope importScope = new ImportScope();
1276 1298
1277 bool get isDeferred => deferredImport != null; 1299 bool get isDeferred => deferredImport != null;
1278 1300
1279 // Only needed for deferred imports. 1301 // Only needed for deferred imports.
(...skipping 25 matching lines...) Expand all
1305 1327
1306 @override 1328 @override
1307 GetterElement get loadLibrary { 1329 GetterElement get loadLibrary {
1308 return isDeferred ? lookupLocalMember(Identifiers.loadLibrary) : null; 1330 return isDeferred ? lookupLocalMember(Identifiers.loadLibrary) : null;
1309 } 1331 }
1310 1332
1311 String toString() => '$kind($name)'; 1333 String toString() => '$kind($name)';
1312 } 1334 }
1313 1335
1314 class TypedefElementX extends ElementX 1336 class TypedefElementX extends ElementX
1315 with 1337 with AstElementMixin, AnalyzableElementX, TypeDeclarationElementX
1316 AstElementMixin,
1317 AnalyzableElementX,
1318 TypeDeclarationElementX<ResolutionTypedefType>
1319 implements TypedefElement { 1338 implements TypedefElement {
1320 Typedef cachedNode; 1339 Typedef cachedNode;
1321 1340
1322 /** 1341 /**
1323 * The type annotation which defines this typedef. 1342 * The type annotation which defines this typedef.
1324 */ 1343 */
1325 ResolutionDartType aliasCache; 1344 ResolutionDartType aliasCache;
1326 1345
1327 ResolutionDartType get alias { 1346 ResolutionDartType get alias {
1328 assert(hasBeenCheckedForCycles, 1347 assert(hasBeenCheckedForCycles,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 computeType(resolution).accept(visitor, null); 1404 computeType(resolution).accept(visitor, null);
1386 hasBeenCheckedForCycles = true; 1405 hasBeenCheckedForCycles = true;
1387 } 1406 }
1388 1407
1389 accept(ElementVisitor visitor, arg) { 1408 accept(ElementVisitor visitor, arg) {
1390 return visitor.visitTypedefElement(this, arg); 1409 return visitor.visitTypedefElement(this, arg);
1391 } 1410 }
1392 1411
1393 // A typedef cannot be patched therefore defines itself. 1412 // A typedef cannot be patched therefore defines itself.
1394 AstElement get definingElement => this; 1413 AstElement get definingElement => this;
1414
1415 ResolutionTypedefType get thisType => super.thisType;
1416
1417 ResolutionTypedefType get rawType => super.rawType;
1395 } 1418 }
1396 1419
1397 // This class holds common information for a list of variable or field 1420 // This class holds common information for a list of variable or field
1398 // declarations. It contains the node, and the type. A [VariableElementX] 1421 // declarations. It contains the node, and the type. A [VariableElementX]
1399 // forwards its [computeType] and [parseNode] methods to this class. 1422 // forwards its [computeType] and [parseNode] methods to this class.
1400 class VariableList implements DeclarationSite { 1423 class VariableList implements DeclarationSite {
1401 VariableDefinitions definitions; 1424 VariableDefinitions definitions;
1402 ResolutionDartType type; 1425 ResolutionDartType type;
1403 final Modifiers modifiers; 1426 final Modifiers modifiers;
1404 List<MetadataAnnotation> metadataInternal; 1427 List<MetadataAnnotation> metadataInternal;
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 return visitor.visitFieldParameterElement(this, arg); 1923 return visitor.visitFieldParameterElement(this, arg);
1901 } 1924 }
1902 1925
1903 MemberElement get memberContext => enclosingElement; 1926 MemberElement get memberContext => enclosingElement;
1904 1927
1905 @override 1928 @override
1906 bool get isFinal => true; 1929 bool get isFinal => true;
1907 1930
1908 @override 1931 @override
1909 bool get isLocal => true; 1932 bool get isLocal => true;
1933
1934 ConstructorElement get functionDeclaration => super.functionDeclaration;
1910 } 1935 }
1911 1936
1912 class ErroneousInitializingFormalElementX extends ParameterElementX 1937 class ErroneousInitializingFormalElementX extends ParameterElementX
1913 implements InitializingFormalElementX { 1938 implements InitializingFormalElementX {
1914 final ErroneousFieldElementX fieldElement; 1939 final ErroneousFieldElementX fieldElement;
1915 1940
1916 ErroneousInitializingFormalElementX( 1941 ErroneousInitializingFormalElementX(
1917 Identifier identifier, Element enclosingElement) 1942 Identifier identifier, Element enclosingElement)
1918 : this.fieldElement = 1943 : this.fieldElement =
1919 new ErroneousFieldElementX(identifier, enclosingElement), 1944 new ErroneousFieldElementX(identifier, enclosingElement),
1920 super(ElementKind.INITIALIZING_FORMAL, enclosingElement, null, 1945 super(ElementKind.INITIALIZING_FORMAL, enclosingElement, null,
1921 identifier, null); 1946 identifier, null);
1922 1947
1923 VariableDefinitions get definitions => fieldElement.node; 1948 VariableDefinitions get definitions => fieldElement.node;
1924 1949
1925 MemberElement get memberContext => enclosingElement; 1950 MemberElement get memberContext => enclosingElement;
1926 1951
1927 bool get isLocal => false; 1952 bool get isLocal => false;
1928 1953
1929 bool get isMalformed => true; 1954 bool get isMalformed => true;
1930 1955
1931 ResolutionDynamicType get type => const ResolutionDynamicType(); 1956 ResolutionDynamicType get type => const ResolutionDynamicType();
1957
1958 ConstructorElement get functionDeclaration => super.functionDeclaration;
1932 } 1959 }
1933 1960
1934 class AbstractFieldElementX extends ElementX 1961 class AbstractFieldElementX extends ElementX
1935 with AbstractFieldElementCommon 1962 with AbstractFieldElementCommon
1936 implements AbstractFieldElement { 1963 implements AbstractFieldElement {
1937 GetterElementX getter; 1964 GetterElementX getter;
1938 SetterElementX setter; 1965 SetterElementX setter;
1939 1966
1940 AbstractFieldElementX(String name, Element enclosing) 1967 AbstractFieldElementX(String name, Element enclosing)
1941 : super(name, ElementKind.ABSTRACT_FIELD, enclosing); 1968 : super(name, ElementKind.ABSTRACT_FIELD, enclosing);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1976 } 2003 }
1977 } 2004 }
1978 2005
1979 accept(ElementVisitor visitor, arg) { 2006 accept(ElementVisitor visitor, arg) {
1980 return visitor.visitAbstractFieldElement(this, arg); 2007 return visitor.visitAbstractFieldElement(this, arg);
1981 } 2008 }
1982 } 2009 }
1983 2010
1984 // TODO(johnniwinther): [FunctionSignature] should be merged with 2011 // TODO(johnniwinther): [FunctionSignature] should be merged with
1985 // [FunctionType]. 2012 // [FunctionType].
1986 // TODO(karlklose): all these lists should have element type [FormalElement].
1987 class FunctionSignatureX extends FunctionSignatureCommon 2013 class FunctionSignatureX extends FunctionSignatureCommon
1988 implements FunctionSignature { 2014 implements FunctionSignature {
1989 final List<ResolutionDartType> typeVariables; 2015 final List<ResolutionDartType> typeVariables;
1990 final List<Element> requiredParameters; 2016 final List<FormalElement> requiredParameters;
1991 final List<Element> optionalParameters; 2017 final List<FormalElement> optionalParameters;
1992 final int requiredParameterCount; 2018 final int requiredParameterCount;
1993 final int optionalParameterCount; 2019 final int optionalParameterCount;
1994 final bool optionalParametersAreNamed; 2020 final bool optionalParametersAreNamed;
1995 final List<Element> orderedOptionalParameters; 2021 final List<FormalElement> orderedOptionalParameters;
1996 final ResolutionFunctionType type; 2022 final ResolutionFunctionType type;
1997 final bool hasOptionalParameters; 2023 final bool hasOptionalParameters;
1998 2024
1999 FunctionSignatureX( 2025 FunctionSignatureX(
2000 {this.typeVariables: const <ResolutionDartType>[], 2026 {this.typeVariables: const <ResolutionDartType>[],
2001 this.requiredParameters: const <Element>[], 2027 this.requiredParameters: const <FormalElement>[],
2002 this.requiredParameterCount: 0, 2028 this.requiredParameterCount: 0,
2003 List<Element> optionalParameters: const <Element>[], 2029 List<Element> optionalParameters: const <FormalElement>[],
2004 this.optionalParameterCount: 0, 2030 this.optionalParameterCount: 0,
2005 this.optionalParametersAreNamed: false, 2031 this.optionalParametersAreNamed: false,
2006 this.orderedOptionalParameters: const <Element>[], 2032 this.orderedOptionalParameters: const <FormalElement>[],
2007 this.type}) 2033 this.type})
2008 : optionalParameters = optionalParameters, 2034 : optionalParameters = optionalParameters,
2009 hasOptionalParameters = !optionalParameters.isEmpty; 2035 hasOptionalParameters = !optionalParameters.isEmpty;
2010 } 2036 }
2011 2037
2012 abstract class BaseFunctionElementX extends ElementX 2038 abstract class BaseFunctionElementX extends ElementX
2013 with PatchMixin<FunctionElement>, AstElementMixin 2039 with PatchMixin<FunctionElement>, AstElementMixin
2014 implements FunctionElement { 2040 implements FunctionElement {
2015 ResolutionDartType typeCache; 2041 ResolutionDartType typeCache;
2016 final Modifiers modifiers; 2042 final Modifiers modifiers;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 } 2123 }
2098 } 2124 }
2099 2125
2100 bool get isAbstract => false; 2126 bool get isAbstract => false;
2101 2127
2102 // A function is defined by the implementation element. 2128 // A function is defined by the implementation element.
2103 AstElement get definingElement => implementation; 2129 AstElement get definingElement => implementation;
2104 2130
2105 @override 2131 @override
2106 List<ResolutionDartType> get typeVariables => functionSignature.typeVariables; 2132 List<ResolutionDartType> get typeVariables => functionSignature.typeVariables;
2133
2134 // TODO(johnniwinther): Remove this.
2135 FunctionElement get declaration => super.declaration;
2136
2137 // TODO(johnniwinther): Remove this.
2138 FunctionElement get implementation => super.implementation;
2139
2140 // TODO(johnniwinther): Remove this.
2141 FunctionElement get origin => super.origin;
2142
2143 // TODO(johnniwinther): Remove this.
2144 FunctionElement get patch => super.patch;
2107 } 2145 }
2108 2146
2109 abstract class FunctionElementX extends BaseFunctionElementX 2147 abstract class FunctionElementX extends BaseFunctionElementX
2110 with AnalyzableElementX 2148 with AnalyzableElementX
2111 implements MethodElement { 2149 implements MethodElement {
2112 FunctionElementX( 2150 FunctionElementX(
2113 String name, ElementKind kind, Modifiers modifiers, Element enclosing) 2151 String name, ElementKind kind, Modifiers modifiers, Element enclosing)
2114 : super(name, kind, modifiers, enclosing); 2152 : super(name, kind, modifiers, enclosing);
2115 2153
2116 MemberElement get memberContext => this; 2154 MemberElement get memberContext => this;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 implements ConstructorElement { 2310 implements ConstructorElement {
2273 bool isRedirectingGenerativeInternal = false; 2311 bool isRedirectingGenerativeInternal = false;
2274 2312
2275 ConstructorElementX( 2313 ConstructorElementX(
2276 String name, ElementKind kind, Modifiers modifiers, Element enclosing) 2314 String name, ElementKind kind, Modifiers modifiers, Element enclosing)
2277 : super(name, kind, modifiers, enclosing); 2315 : super(name, kind, modifiers, enclosing);
2278 2316
2279 ConstructorElement _immediateRedirectionTarget; 2317 ConstructorElement _immediateRedirectionTarget;
2280 PrefixElement _redirectionDeferredPrefix; 2318 PrefixElement _redirectionDeferredPrefix;
2281 2319
2282 ConstructorElementX get patch => super.patch;
2283
2284 bool get isRedirectingGenerative { 2320 bool get isRedirectingGenerative {
2285 if (isPatched) return patch.isRedirectingGenerative; 2321 if (isPatched) return patch.isRedirectingGenerative;
2286 return isRedirectingGenerativeInternal; 2322 return isRedirectingGenerativeInternal;
2287 } 2323 }
2288 2324
2289 bool get isRedirectingFactory => immediateRedirectionTarget != null; 2325 bool get isRedirectingFactory => immediateRedirectionTarget != null;
2290 2326
2291 // TODO(johnniwinther): This should also return true for cyclic redirecting 2327 // TODO(johnniwinther): This should also return true for cyclic redirecting
2292 // generative constructors. 2328 // generative constructors.
2293 bool get isCyclicRedirection => effectiveTarget.isRedirectingFactory; 2329 bool get isCyclicRedirection => effectiveTarget.isRedirectingFactory;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
2404 return _isEffectiveTargetMalformed == true; 2440 return _isEffectiveTargetMalformed == true;
2405 } 2441 }
2406 2442
2407 accept(ElementVisitor visitor, arg) { 2443 accept(ElementVisitor visitor, arg) {
2408 return visitor.visitConstructorElement(this, arg); 2444 return visitor.visitConstructorElement(this, arg);
2409 } 2445 }
2410 2446
2411 ConstructorElement get definingConstructor => null; 2447 ConstructorElement get definingConstructor => null;
2412 2448
2413 ClassElement get enclosingClass => enclosingElement.declaration; 2449 ClassElement get enclosingClass => enclosingElement.declaration;
2450
2451 // TODO(johnniwinther): Remove this.
2452 ConstructorElementX get declaration => super.declaration;
2453
2454 // TODO(johnniwinther): Remove this.
2455 ConstructorElementX get implementation => super.implementation;
2456
2457 // TODO(johnniwinther): Remove this.
2458 ConstructorElementX get origin => super.origin;
2459
2460 // TODO(johnniwinther): Remove this.
2461 ConstructorElementX get patch => super.patch;
2414 } 2462 }
2415 2463
2416 class DeferredLoaderGetterElementX extends GetterElementX 2464 class DeferredLoaderGetterElementX extends GetterElementX {
2417 implements GetterElement {
2418 final PrefixElement prefix; 2465 final PrefixElement prefix;
2419 2466
2420 DeferredLoaderGetterElementX(PrefixElement prefix) 2467 DeferredLoaderGetterElementX(PrefixElement prefix)
2421 : this.prefix = prefix, 2468 : this.prefix = prefix,
2422 super(Identifiers.loadLibrary, Modifiers.EMPTY, prefix, false) { 2469 super(Identifiers.loadLibrary, Modifiers.EMPTY, prefix, false) {
2423 functionSignature = 2470 functionSignature =
2424 new FunctionSignatureX(type: new ResolutionFunctionType(this)); 2471 new FunctionSignatureX(type: new ResolutionFunctionType(this));
2425 } 2472 }
2426 2473
2427 bool get isClassMember => false; 2474 bool get isClassMember => false;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
2533 reporter.internalError(this, '$this.computeType.'); 2580 reporter.internalError(this, '$this.computeType.');
2534 return null; 2581 return null;
2535 } 2582 }
2536 2583
2537 int get sourceOffset => constructor.sourceOffset; 2584 int get sourceOffset => constructor.sourceOffset;
2538 2585
2539 Token get position => constructor.position; 2586 Token get position => constructor.position;
2540 2587
2541 Element get outermostEnclosingMemberOrTopLevel => constructor; 2588 Element get outermostEnclosingMemberOrTopLevel => constructor;
2542 2589
2543 Element get analyzableElement => constructor.analyzableElement; 2590 AnalyzableElement get analyzableElement => constructor.analyzableElement;
2544 2591
2545 accept(ElementVisitor visitor, arg) { 2592 accept(ElementVisitor visitor, arg) {
2546 return visitor.visitConstructorBodyElement(this, arg); 2593 return visitor.visitConstructorBodyElement(this, arg);
2547 } 2594 }
2548 2595
2549 MemberElement get memberContext => constructor; 2596 MemberElement get memberContext => constructor;
2550 } 2597 }
2551 2598
2552 /** 2599 /**
2553 * A constructor that is not defined in the source code but rather implied by 2600 * A constructor that is not defined in the source code but rather implied by
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2589 FunctionExpression get node => null; 2636 FunctionExpression get node => null;
2590 2637
2591 Token get position => enclosingElement.position; 2638 Token get position => enclosingElement.position;
2592 2639
2593 bool get isSynthesized => true; 2640 bool get isSynthesized => true;
2594 2641
2595 bool get hasResolvedAst => true; 2642 bool get hasResolvedAst => true;
2596 2643
2597 ResolvedAst get resolvedAst => _resolvedAst; 2644 ResolvedAst get resolvedAst => _resolvedAst;
2598 2645
2599 ResolutionDartType get type { 2646 ResolutionFunctionType get type {
2600 if (isDefaultConstructor) { 2647 if (isDefaultConstructor) {
2601 return super.type; 2648 return super.type;
2602 } else { 2649 } else {
2603 // TODO(johnniwinther): Ensure that the function type substitutes type 2650 // TODO(johnniwinther): Ensure that the function type substitutes type
2604 // variables correctly. 2651 // variables correctly.
2605 return definingConstructor.type; 2652 return definingConstructor.type;
2606 } 2653 }
2607 } 2654 }
2608 2655
2609 void _computeSignature(Resolution resolution) { 2656 void _computeSignature(Resolution resolution) {
2610 if (hasFunctionSignature) return; 2657 if (hasFunctionSignature) return;
2611 if (definingConstructor.isMalformed) { 2658 if (definingConstructor.isMalformed) {
2612 functionSignature = new FunctionSignatureX( 2659 functionSignature = new FunctionSignatureX(
2613 type: 2660 type:
2614 new ResolutionFunctionType.synthesized(enclosingClass.thisType)); 2661 new ResolutionFunctionType.synthesized(enclosingClass.thisType));
2615 } 2662 }
2616 // TODO(johnniwinther): Ensure that the function signature (and with it the 2663 // TODO(johnniwinther): Ensure that the function signature (and with it the
2617 // function type) substitutes type variables correctly. 2664 // function type) substitutes type variables correctly.
2618 definingConstructor.computeType(resolution); 2665 definingConstructor.computeType(resolution);
2619 functionSignature = definingConstructor.functionSignature; 2666 functionSignature = definingConstructor.functionSignature;
2620 } 2667 }
2621 2668
2622 accept(ElementVisitor visitor, arg) { 2669 accept(ElementVisitor visitor, arg) {
2623 return visitor.visitConstructorElement(this, arg); 2670 return visitor.visitConstructorElement(this, arg);
2624 } 2671 }
2625 } 2672 }
2626 2673
2627 abstract class TypeDeclarationElementX<T extends GenericType> 2674 abstract class TypeDeclarationElementX implements TypeDeclarationElement {
2628 implements TypeDeclarationElement {
2629 /** 2675 /**
2630 * The `this type` for this type declaration. 2676 * The `this type` for this type declaration.
2631 * 2677 *
2632 * The type of [:this:] is the generic type based on this element in which 2678 * The type of [:this:] is the generic type based on this element in which
2633 * the type arguments are the declared type variables. For instance, 2679 * the type arguments are the declared type variables. For instance,
2634 * [:List<E>:] for [:List:] and [:Map<K,V>:] for [:Map:]. 2680 * [:List<E>:] for [:List:] and [:Map<K,V>:] for [:Map:].
2635 * 2681 *
2636 * For a class declaration this is the type of [:this:]. 2682 * For a class declaration this is the type of [:this:].
2637 * 2683 *
2638 * This type is computed in [computeType]. 2684 * This type is computed in [computeType].
2639 */ 2685 */
2640 T thisTypeCache; 2686 GenericType thisTypeCache;
2641 2687
2642 /** 2688 /**
2643 * The raw type for this type declaration. 2689 * The raw type for this type declaration.
2644 * 2690 *
2645 * The raw type is the generic type base on this element in which the type 2691 * The raw type is the generic type base on this element in which the type
2646 * arguments are all [dynamic]. For instance [:List<dynamic>:] for [:List:] 2692 * arguments are all [dynamic]. For instance [:List<dynamic>:] for [:List:]
2647 * and [:Map<dynamic,dynamic>:] for [:Map:]. For non-generic classes [rawType] 2693 * and [:Map<dynamic,dynamic>:] for [:Map:]. For non-generic classes [rawType]
2648 * is the same as [thisType]. 2694 * is the same as [thisType].
2649 * 2695 *
2650 * The [rawType] field is a canonicalization of the raw type and should be 2696 * The [rawType] field is a canonicalization of the raw type and should be
2651 * used to distinguish explicit and implicit uses of the [dynamic] 2697 * used to distinguish explicit and implicit uses of the [dynamic]
2652 * type arguments. For instance should [:List:] be the [rawType] of the 2698 * type arguments. For instance should [:List:] be the [rawType] of the
2653 * [:List:] class element whereas [:List<dynamic>:] should be its own 2699 * [:List:] class element whereas [:List<dynamic>:] should be its own
2654 * instantiation of [ResolutionInterfaceType] with [:dynamic:] as type 2700 * instantiation of [ResolutionInterfaceType] with [:dynamic:] as type
2655 * argument. Using this distinction, we can print the raw type with type 2701 * argument. Using this distinction, we can print the raw type with type
2656 * arguments only when the input source has used explicit type arguments. 2702 * arguments only when the input source has used explicit type arguments.
2657 * 2703 *
2658 * This type is computed together with [thisType] in [computeType]. 2704 * This type is computed together with [thisType] in [computeType].
2659 */ 2705 */
2660 T rawTypeCache; 2706 GenericType rawTypeCache;
2661 2707
2662 T get thisType { 2708 GenericType get thisType {
2663 assert(thisTypeCache != null, 2709 assert(thisTypeCache != null,
2664 failedAt(this, 'This type has not been computed for $this')); 2710 failedAt(this, 'This type has not been computed for $this'));
2665 return thisTypeCache; 2711 return thisTypeCache;
2666 } 2712 }
2667 2713
2668 T get rawType { 2714 GenericType get rawType {
2669 assert(rawTypeCache != null, 2715 assert(rawTypeCache != null,
2670 failedAt(this, 'Raw type has not been computed for $this')); 2716 failedAt(this, 'Raw type has not been computed for $this'));
2671 return rawTypeCache; 2717 return rawTypeCache;
2672 } 2718 }
2673 2719
2674 T createType(List<ResolutionDartType> typeArguments); 2720 GenericType createType(List<ResolutionDartType> typeArguments);
2675 2721
2676 void setThisAndRawTypes(List<ResolutionDartType> typeParameters) { 2722 void setThisAndRawTypes(List<ResolutionDartType> typeParameters) {
2677 assert(thisTypeCache == null, 2723 assert(thisTypeCache == null,
2678 failedAt(this, "This type has already been set on $this.")); 2724 failedAt(this, "This type has already been set on $this."));
2679 assert(rawTypeCache == null, 2725 assert(rawTypeCache == null,
2680 failedAt(this, "Raw type has already been set on $this.")); 2726 failedAt(this, "Raw type has already been set on $this."));
2681 thisTypeCache = createType(typeParameters); 2727 thisTypeCache = createType(typeParameters);
2682 if (typeParameters.isEmpty) { 2728 if (typeParameters.isEmpty) {
2683 rawTypeCache = thisTypeCache; 2729 rawTypeCache = thisTypeCache;
2684 } else { 2730 } else {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2718 bool get isResolved => resolutionState == STATE_DONE; 2764 bool get isResolved => resolutionState == STATE_DONE;
2719 2765
2720 int get resolutionState; 2766 int get resolutionState;
2721 } 2767 }
2722 2768
2723 abstract class BaseClassElementX extends ElementX 2769 abstract class BaseClassElementX extends ElementX
2724 with 2770 with
2725 AstElementMixin, 2771 AstElementMixin,
2726 AnalyzableElementX, 2772 AnalyzableElementX,
2727 ClassElementCommon, 2773 ClassElementCommon,
2728 TypeDeclarationElementX<ResolutionInterfaceType>, 2774 TypeDeclarationElementX,
2729 PatchMixin<ClassElement>, 2775 PatchMixin<ClassElement>,
2730 ClassMemberMixin 2776 ClassMemberMixin
2731 implements ClassElement { 2777 implements ClassElement {
2732 final int id; 2778 final int id;
2733 2779
2734 ResolutionInterfaceType supertype; 2780 ResolutionInterfaceType supertype;
2735 Link<ResolutionDartType> interfaces; 2781 Link<ResolutionDartType> interfaces;
2736 int supertypeLoadState; 2782 int supertypeLoadState;
2737 int resolutionState; 2783 int resolutionState;
2738 bool isProxy = false; 2784 bool isProxy = false;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2816 * Returns the super class, if any. 2862 * Returns the super class, if any.
2817 * 2863 *
2818 * The returned element may not be resolved yet. 2864 * The returned element may not be resolved yet.
2819 */ 2865 */
2820 ClassElement get superclass { 2866 ClassElement get superclass {
2821 assert(supertypeLoadState == STATE_DONE, 2867 assert(supertypeLoadState == STATE_DONE,
2822 failedAt(this, "Superclass has not been computed for $this.")); 2868 failedAt(this, "Superclass has not been computed for $this."));
2823 return supertype == null ? null : supertype.element; 2869 return supertype == null ? null : supertype.element;
2824 } 2870 }
2825 2871
2826 // TODO(johnniwinther): Remove these when issue 18630 is fixed. 2872 // A class declaration is defined by the declaration element.
2827 ClassElement get patch => super.patch; 2873 AstElement get definingElement => declaration;
2874
2875 ResolutionInterfaceType get thisType => super.thisType;
2876
2877 ResolutionInterfaceType get rawType => super.rawType;
2878
2879 // TODO(johnniwinther): Remove this.
2880 ClassElement get declaration => super.declaration;
2881
2882 // TODO(johnniwinther): Remove this.
2883 ClassElement get implementation => super.implementation;
2884
2885 // TODO(johnniwinther): Remove this.
2828 ClassElement get origin => super.origin; 2886 ClassElement get origin => super.origin;
2829 2887
2830 // A class declaration is defined by the declaration element. 2888 // TODO(johnniwinther): Remove this.
2831 AstElement get definingElement => declaration; 2889 ClassElement get patch => super.patch;
2832 } 2890 }
2833 2891
2834 abstract class ClassElementX extends BaseClassElementX { 2892 abstract class ClassElementX extends BaseClassElementX {
2835 Link<Element> localMembersReversed = const Link<Element>(); 2893 Link<Element> localMembersReversed = const Link<Element>();
2836 final ScopeX localScope = new ScopeX(); 2894 final ScopeX localScope = new ScopeX();
2837 2895
2838 Link<Element> localMembersCache; 2896 Link<Element> localMembersCache;
2839 2897
2840 Link<Element> get localMembers { 2898 Link<Element> get localMembers {
2841 if (localMembersCache == null) { 2899 if (localMembersCache == null) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2928 /// static const A c = const A(1); 2986 /// static const A c = const A(1);
2929 /// 2987 ///
2930 /// static const List<A> values = const <A>[b, c]; 2988 /// static const List<A> values = const <A>[b, c];
2931 /// } 2989 /// }
2932 /// 2990 ///
2933 /// where the `A` class is encoded using this element. 2991 /// where the `A` class is encoded using this element.
2934 /// 2992 ///
2935 class EnumClassElementX extends ClassElementX 2993 class EnumClassElementX extends ClassElementX
2936 implements EnumClassElement, DeclarationSite { 2994 implements EnumClassElement, DeclarationSite {
2937 final Enum node; 2995 final Enum node;
2938 List<FieldElement> _enumValues; 2996 List<EnumConstantElement> _enumValues;
2939 2997
2940 EnumClassElementX(String name, Element enclosing, int id, this.node) 2998 EnumClassElementX(String name, Element enclosing, int id, this.node)
2941 : super(name, enclosing, id, STATE_NOT_STARTED); 2999 : super(name, enclosing, id, STATE_NOT_STARTED);
2942 3000
2943 @override 3001 @override
2944 bool get hasNode => true; 3002 bool get hasNode => true;
2945 3003
2946 @override 3004 @override
2947 Token get position => node.name.token; 3005 Token get position => node.name.token;
2948 3006
2949 @override 3007 @override
2950 bool get isEnumClass => true; 3008 bool get isEnumClass => true;
2951 3009
2952 @override 3010 @override
2953 Node parseNode(ParsingContext parsing) => node; 3011 Node parseNode(ParsingContext parsing) => node;
2954 3012
2955 @override 3013 @override
2956 accept(ElementVisitor visitor, arg) { 3014 accept(ElementVisitor visitor, arg) {
2957 return visitor.visitEnumClassElement(this, arg); 3015 return visitor.visitEnumClassElement(this, arg);
2958 } 3016 }
2959 3017
2960 List<ResolutionDartType> computeTypeParameters(ParsingContext parsing) => 3018 List<ResolutionDartType> computeTypeParameters(ParsingContext parsing) =>
2961 const <ResolutionDartType>[]; 3019 const <ResolutionDartType>[];
2962 3020
2963 List<FieldElement> get enumValues { 3021 List<EnumConstantElement> get enumValues {
2964 assert(_enumValues != null, 3022 assert(_enumValues != null,
2965 failedAt(this, "enumValues has not been computed for $this.")); 3023 failedAt(this, "enumValues has not been computed for $this."));
2966 return _enumValues; 3024 return _enumValues;
2967 } 3025 }
2968 3026
2969 void set enumValues(List<FieldElement> values) { 3027 void set enumValues(List<EnumConstantElement> values) {
2970 assert(_enumValues == null, 3028 assert(_enumValues == null,
2971 failedAt(this, "enumValues has already been computed for $this.")); 3029 failedAt(this, "enumValues has already been computed for $this."));
2972 _enumValues = values; 3030 _enumValues = values;
2973 } 3031 }
2974 3032
2975 @override 3033 @override
2976 DeclarationSite get declarationSite => this; 3034 DeclarationSite get declarationSite => this;
2977 } 3035 }
2978 3036
2979 /// This element is used to encode the implicit constructor in an enum class. 3037 /// This element is used to encode the implicit constructor in an enum class.
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
3180 Node definition, 3238 Node definition,
3181 Expression initializer, 3239 Expression initializer,
3182 this.index) 3240 this.index)
3183 : super(name, enumClass, variableList, definition, initializer); 3241 : super(name, enumClass, variableList, definition, initializer);
3184 3242
3185 @override 3243 @override
3186 SourceSpan get sourcePosition { 3244 SourceSpan get sourcePosition {
3187 return new SourceSpan(enclosingClass.sourcePosition.uri, 3245 return new SourceSpan(enclosingClass.sourcePosition.uri,
3188 position.charOffset, position.charEnd); 3246 position.charOffset, position.charEnd);
3189 } 3247 }
3248
3249 EnumClassElement get enclosingClass => super.enclosingClass;
3190 } 3250 }
3191 3251
3192 abstract class MixinApplicationElementX extends BaseClassElementX 3252 abstract class MixinApplicationElementX extends BaseClassElementX
3193 with MixinApplicationElementCommon 3253 with MixinApplicationElementCommon
3194 implements MixinApplicationElement { 3254 implements MixinApplicationElement {
3195 Link<ConstructorElement> constructors = new Link<ConstructorElement>(); 3255 Link<ConstructorElement> constructors = new Link<ConstructorElement>();
3196 3256
3197 ResolutionInterfaceType mixinType; 3257 ResolutionInterfaceType mixinType;
3198 3258
3199 MixinApplicationElementX(String name, Element enclosing, int id) 3259 MixinApplicationElementX(String name, Element enclosing, int id)
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
3456 3516
3457 Token get endToken => metadata.getEndToken(); 3517 Token get endToken => metadata.getEndToken();
3458 3518
3459 bool get hasNode => true; 3519 bool get hasNode => true;
3460 3520
3461 Metadata get node => metadata; 3521 Metadata get node => metadata;
3462 } 3522 }
3463 3523
3464 /// Mixin for the implementation of patched elements. 3524 /// Mixin for the implementation of patched elements.
3465 /// 3525 ///
3466 /// See [:patch_parser.dart:] for a description of the terminology. 3526 /// See `patch_parser.dart` for a description of the terminology.
3467 abstract class PatchMixin<E extends Element> implements Element { 3527 abstract class PatchMixin<E extends Element> implements Element {
3468 // TODO(johnniwinther): Use type variables when issue 18630 is fixed. 3528 // TODO(johnniwinther): Use type variables.
3469 Element /*E*/ patch = null; 3529 Element /* E */ patch = null;
3470 Element /*E*/ origin = null; 3530 Element /* E */ origin = null;
3471 3531
3472 bool get isPatch => origin != null; 3532 bool get isPatch => origin != null;
3473 bool get isPatched => patch != null; 3533 bool get isPatched => patch != null;
3474 3534
3475 bool get isImplementation => !isPatched; 3535 bool get isImplementation => !isPatched;
3476 bool get isDeclaration => !isPatch; 3536 bool get isDeclaration => !isPatch;
3477 3537
3478 Element /*E*/ get implementation => isPatched ? patch : this; 3538 Element /* E */ get implementation => isPatched ? patch : this;
3479 Element /*E*/ get declaration => isPatch ? origin : this; 3539 Element /* E */ get declaration => isPatch ? origin : this;
3480 3540
3481 /// Applies a patch to this element. This method must be called at most once. 3541 /// Applies a patch to this element. This method must be called at most once.
3482 void applyPatch(PatchMixin<E> patch) { 3542 void applyPatch(PatchMixin<E> patch) {
3483 assert(this.patch == null, failedAt(this, "Element is patched twice.")); 3543 assert(this.patch == null, failedAt(this, "Element is patched twice."));
3484 assert(this.origin == null, failedAt(this, "Origin element is a patch.")); 3544 assert(this.origin == null, failedAt(this, "Origin element is a patch."));
3485 assert(patch.origin == null, failedAt(patch, "Element is patched twice.")); 3545 assert(patch.origin == null, failedAt(patch, "Element is patched twice."));
3486 assert(patch.patch == null, failedAt(patch, "Patch element is patched.")); 3546 assert(patch.patch == null, failedAt(patch, "Patch element is patched."));
3487 this.patch = patch; 3547 this.patch = patch;
3488 patch.origin = this; 3548 patch.origin = this;
3489 } 3549 }
(...skipping 25 matching lines...) Expand all
3515 body = node.asFunctionExpression().body; 3575 body = node.asFunctionExpression().body;
3516 } 3576 }
3517 return new ParsedResolvedAst( 3577 return new ParsedResolvedAst(
3518 declaration, 3578 declaration,
3519 node, 3579 node,
3520 body, 3580 body,
3521 definingElement.treeElements, 3581 definingElement.treeElements,
3522 definingElement.compilationUnit.script.resourceUri); 3582 definingElement.compilationUnit.script.resourceUri);
3523 } 3583 }
3524 } 3584 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/elements/jumps.dart ('k') | pkg/compiler/lib/src/elements/resolution_types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698