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

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

Issue 1391193002: Make computeSignature private to modelx. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 2 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
« no previous file with comments | « pkg/compiler/lib/src/closure.dart ('k') | pkg/compiler/lib/src/resolution/enum_creator.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/resolution.dart' show 7 import '../common/resolution.dart' show
8 Resolution, 8 Resolution,
9 Parsing; 9 Parsing;
10 import '../compiler.dart' show 10 import '../compiler.dart' show
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 get immediateRedirectionTarget => unsupported(); 308 get immediateRedirectionTarget => unsupported();
309 get nestedClosures => unsupported(); 309 get nestedClosures => unsupported();
310 get memberContext => unsupported(); 310 get memberContext => unsupported();
311 get executableContext => unsupported(); 311 get executableContext => unsupported();
312 get isExternal => unsupported(); 312 get isExternal => unsupported();
313 get constantConstructor => null; 313 get constantConstructor => null;
314 314
315 bool get isRedirectingGenerative => unsupported(); 315 bool get isRedirectingGenerative => unsupported();
316 bool get isRedirectingFactory => unsupported(); 316 bool get isRedirectingFactory => unsupported();
317 317
318 computeSignature(Resolution resolution) => unsupported();
319 computeType(Resolution resolution) => unsupported(); 318 computeType(Resolution resolution) => unsupported();
320 319
321 bool get hasFunctionSignature => false; 320 bool get hasFunctionSignature => false;
322 321
323 get effectiveTarget => this; 322 get effectiveTarget => this;
324 323
325 computeEffectiveTargetType(InterfaceType newType) => unsupported(); 324 computeEffectiveTargetType(InterfaceType newType) => unsupported();
326 325
327 get definingConstructor => null; 326 get definingConstructor => null;
328 327
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 } 388 }
390 389
391 get effectiveTargetType { 390 get effectiveTargetType {
392 throw new UnsupportedError("effectiveTargetType"); 391 throw new UnsupportedError("effectiveTargetType");
393 } 392 }
394 393
395 set effectiveTargetType(_) { 394 set effectiveTargetType(_) {
396 throw new UnsupportedError("effectiveTargetType="); 395 throw new UnsupportedError("effectiveTargetType=");
397 } 396 }
398 397
398 void _computeSignature(Resolution resolution) {
399 throw new UnsupportedError("_computeSignature");
400 }
401
399 get typeCache { 402 get typeCache {
400 throw new UnsupportedError("typeCache"); 403 throw new UnsupportedError("typeCache");
401 } 404 }
402 405
403 set typeCache(_) { 406 set typeCache(_) {
404 throw new UnsupportedError("typeCache="); 407 throw new UnsupportedError("typeCache=");
405 } 408 }
406 409
407 get immediateRedirectionTarget { 410 get immediateRedirectionTarget {
408 throw new UnsupportedError("immediateRedirectionTarget"); 411 throw new UnsupportedError("immediateRedirectionTarget");
409 } 412 }
410 413
411 set immediateRedirectionTarget(_) { 414 set immediateRedirectionTarget(_) {
412 throw new UnsupportedError("immediateRedirectionTarget="); 415 throw new UnsupportedError("immediateRedirectionTarget=");
413 } 416 }
414 417
415 get functionSignatureCache { 418 get _functionSignatureCache {
416 throw new UnsupportedError("functionSignatureCache"); 419 throw new UnsupportedError("functionSignatureCache");
417 } 420 }
418 421
419 set functionSignatureCache(_) { 422 set _functionSignatureCache(_) {
420 throw new UnsupportedError("functionSignatureCache="); 423 throw new UnsupportedError("functionSignatureCache=");
421 } 424 }
422 425
426 set functionSignature(_) {
427 throw new UnsupportedError("functionSignature=");
428 }
429
423 get nestedClosures { 430 get nestedClosures {
424 throw new UnsupportedError("nestedClosures"); 431 throw new UnsupportedError("nestedClosures");
425 } 432 }
426 433
427 set nestedClosures(_) { 434 set nestedClosures(_) {
428 throw new UnsupportedError("nestedClosures="); 435 throw new UnsupportedError("nestedClosures=");
429 } 436 }
430 437
431 set redirectionDeferredPrefix(_) { 438 set redirectionDeferredPrefix(_) {
432 throw new UnsupportedError("redirectionDeferredPrefix="); 439 throw new UnsupportedError("redirectionDeferredPrefix=");
(...skipping 1261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 implements FormalElement { 1701 implements FormalElement {
1695 final VariableDefinitions definitions; 1702 final VariableDefinitions definitions;
1696 final Identifier identifier; 1703 final Identifier identifier;
1697 DartType typeCache; 1704 DartType typeCache;
1698 1705
1699 /** 1706 /**
1700 * Function signature for a variable with a function type. The signature is 1707 * Function signature for a variable with a function type. The signature is
1701 * kept to provide full information about parameter names through the mirror 1708 * kept to provide full information about parameter names through the mirror
1702 * system. 1709 * system.
1703 */ 1710 */
1704 FunctionSignature functionSignatureCache; 1711 FunctionSignature _functionSignatureCache;
1705 1712
1706 FormalElementX(ElementKind elementKind, 1713 FormalElementX(ElementKind elementKind,
1707 FunctionTypedElement enclosingElement, 1714 FunctionTypedElement enclosingElement,
1708 this.definitions, 1715 this.definitions,
1709 Identifier identifier) 1716 Identifier identifier)
1710 : this.identifier = identifier, 1717 : this.identifier = identifier,
1711 super(identifier.source, elementKind, enclosingElement); 1718 super(identifier.source, elementKind, enclosingElement);
1712 1719
1713 FunctionTypedElement get functionDeclaration => enclosingElement; 1720 FunctionTypedElement get functionDeclaration => enclosingElement;
1714 1721
1715 Modifiers get modifiers => definitions.modifiers; 1722 Modifiers get modifiers => definitions.modifiers;
1716 1723
1717 Token get position => identifier.getBeginToken(); 1724 Token get position => identifier.getBeginToken();
1718 1725
1719 Node parseNode(Parsing parsing) => definitions; 1726 Node parseNode(Parsing parsing) => definitions;
1720 1727
1721 DartType computeType(Resolution resolution) { 1728 DartType computeType(Resolution resolution) {
1722 assert(invariant(this, type != null, 1729 assert(invariant(this, type != null,
1723 message: "Parameter type has not been set for $this.")); 1730 message: "Parameter type has not been set for $this."));
1724 return type; 1731 return type;
1725 } 1732 }
1726 1733
1727 DartType get type { 1734 DartType get type {
1728 assert(invariant(this, typeCache != null, 1735 assert(invariant(this, typeCache != null,
1729 message: "Parameter type has not been set for $this.")); 1736 message: "Parameter type has not been set for $this."));
1730 return typeCache; 1737 return typeCache;
1731 } 1738 }
1732 1739
1733 FunctionSignature get functionSignature { 1740 FunctionSignature get functionSignature {
1734 assert(invariant(this, typeCache != null, 1741 assert(invariant(this, _functionSignatureCache != null,
1735 message: "Parameter signature has not been set for $this.")); 1742 message: "Parameter signature has not been computed for $this."));
1736 return functionSignatureCache; 1743 return _functionSignatureCache;
1744 }
1745
1746 void set functionSignature(FunctionSignature value) {
1747 assert(invariant(this, _functionSignatureCache == null,
1748 message: "Parameter signature has already been computed for $this."));
1749 _functionSignatureCache = value;
1750 typeCache = _functionSignatureCache.type;
1737 } 1751 }
1738 1752
1739 bool get hasNode => true; 1753 bool get hasNode => true;
1740 1754
1741 VariableDefinitions get node => definitions; 1755 VariableDefinitions get node => definitions;
1742 1756
1743 FunctionType get functionType => type; 1757 FunctionType get functionType => type;
1744 1758
1745 accept(ElementVisitor visitor, arg) { 1759 accept(ElementVisitor visitor, arg) {
1746 return visitor.visitFormalElement(this, arg); 1760 return visitor.visitFormalElement(this, arg);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 } 1960 }
1947 1961
1948 abstract class BaseFunctionElementX 1962 abstract class BaseFunctionElementX
1949 extends ElementX with PatchMixin<FunctionElement>, AstElementMixin 1963 extends ElementX with PatchMixin<FunctionElement>, AstElementMixin
1950 implements FunctionElement { 1964 implements FunctionElement {
1951 DartType typeCache; 1965 DartType typeCache;
1952 final Modifiers modifiers; 1966 final Modifiers modifiers;
1953 1967
1954 List<FunctionElement> nestedClosures = new List<FunctionElement>(); 1968 List<FunctionElement> nestedClosures = new List<FunctionElement>();
1955 1969
1956 FunctionSignature functionSignatureCache; 1970 FunctionSignature _functionSignatureCache;
1957 1971
1958 AsyncMarker asyncMarker = AsyncMarker.SYNC; 1972 AsyncMarker asyncMarker = AsyncMarker.SYNC;
1959 1973
1960 BaseFunctionElementX(String name, 1974 BaseFunctionElementX(String name,
1961 ElementKind kind, 1975 ElementKind kind,
1962 Modifiers this.modifiers, 1976 Modifiers this.modifiers,
1963 Element enclosing) 1977 Element enclosing)
1964 : super(name, kind, enclosing) { 1978 : super(name, kind, enclosing) {
1965 assert(modifiers != null); 1979 assert(modifiers != null);
1966 } 1980 }
1967 1981
1968 bool get isExternal => modifiers.isExternal; 1982 bool get isExternal => modifiers.isExternal;
1969 1983
1970 bool get isInstanceMember { 1984 bool get isInstanceMember {
1971 return isClassMember 1985 return isClassMember
1972 && !isConstructor 1986 && !isConstructor
1973 && !isStatic; 1987 && !isStatic;
1974 } 1988 }
1975 1989
1976 bool get hasFunctionSignature => functionSignatureCache != null; 1990 bool get hasFunctionSignature => _functionSignatureCache != null;
1977 1991
1978 FunctionSignature computeSignature(Resolution resolution) { 1992 void _computeSignature(Resolution resolution) {
1979 if (functionSignatureCache != null) return functionSignatureCache; 1993 if (hasFunctionSignature) return;
1980 functionSignatureCache = resolution.resolveSignature(this); 1994 functionSignature = resolution.resolveSignature(this);
1981 return functionSignatureCache;
1982 } 1995 }
1983 1996
1984 FunctionSignature get functionSignature { 1997 FunctionSignature get functionSignature {
1985 assert(invariant(this, functionSignatureCache != null, 1998 assert(invariant(this, hasFunctionSignature,
1986 message: "Function signature has not been computed for $this.")); 1999 message: "Function signature has not been computed for $this."));
1987 return functionSignatureCache; 2000 return _functionSignatureCache;
2001 }
2002
2003 void set functionSignature(FunctionSignature value) {
2004 // TODO(johnniwinther): Strengthen the invariant to `!hasFunctionSignature`
2005 // when checked mode checks are not enqueued eagerly.
2006 assert(invariant(this, !hasFunctionSignature || type == value.type,
2007 message: "Function signature has already been computed for $this."));
2008 _functionSignatureCache = value;
2009 typeCache = _functionSignatureCache.type;
1988 } 2010 }
1989 2011
1990 List<ParameterElement> get parameters { 2012 List<ParameterElement> get parameters {
1991 // TODO(johnniwinther): Store the list directly, possibly by using List 2013 // TODO(johnniwinther): Store the list directly, possibly by using List
1992 // instead of Link in FunctionSignature. 2014 // instead of Link in FunctionSignature.
1993 List<ParameterElement> list = <ParameterElement>[]; 2015 List<ParameterElement> list = <ParameterElement>[];
1994 functionSignature.forEachParameter((e) => list.add(e)); 2016 functionSignature.forEachParameter((e) => list.add(e));
1995 return list; 2017 return list;
1996 } 2018 }
1997 2019
1998 FunctionType computeType(Resolution resolution) { 2020 FunctionType computeType(Resolution resolution) {
1999 if (typeCache != null) return typeCache; 2021 if (typeCache != null) return typeCache;
2000 typeCache = computeSignature(resolution).type; 2022 _computeSignature(resolution);
2023 assert(invariant(this, typeCache != null,
2024 message: "Type cache expected to be set on $this."));
2001 return typeCache; 2025 return typeCache;
2002 } 2026 }
2003 2027
2004 FunctionType get type { 2028 FunctionType get type {
2005 assert(invariant(this, typeCache != null, 2029 assert(invariant(this, typeCache != null,
2006 message: "Type has not been computed for $this.")); 2030 message: "Type has not been computed for $this."));
2007 return typeCache; 2031 return typeCache;
2008 } 2032 }
2009 2033
2010 FunctionElement asFunctionElement() => this; 2034 FunctionElement asFunctionElement() => this;
(...skipping 25 matching lines...) Expand all
2036 ElementKind kind, 2060 ElementKind kind,
2037 Modifiers modifiers, 2061 Modifiers modifiers,
2038 Element enclosing) 2062 Element enclosing)
2039 : super(name, kind, modifiers, enclosing); 2063 : super(name, kind, modifiers, enclosing);
2040 2064
2041 MemberElement get memberContext => this; 2065 MemberElement get memberContext => this;
2042 2066
2043 void reuseElement() { 2067 void reuseElement() {
2044 super.reuseElement(); 2068 super.reuseElement();
2045 nestedClosures.clear(); 2069 nestedClosures.clear();
2046 functionSignatureCache = null; 2070 _functionSignatureCache = null;
2047 typeCache = null; 2071 typeCache = null;
2048 } 2072 }
2049 } 2073 }
2050 2074
2051 abstract class MethodElementX extends FunctionElementX { 2075 abstract class MethodElementX extends FunctionElementX {
2052 final bool hasBody; 2076 final bool hasBody;
2053 2077
2054 MethodElementX(String name, 2078 MethodElementX(String name,
2055 ElementKind kind, 2079 ElementKind kind,
2056 Modifiers modifiers, 2080 Modifiers modifiers,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2226 2250
2227 class DeferredLoaderGetterElementX extends GetterElementX 2251 class DeferredLoaderGetterElementX extends GetterElementX
2228 implements GetterElement { 2252 implements GetterElement {
2229 final PrefixElement prefix; 2253 final PrefixElement prefix;
2230 2254
2231 DeferredLoaderGetterElementX(PrefixElement prefix) 2255 DeferredLoaderGetterElementX(PrefixElement prefix)
2232 : this.prefix = prefix, 2256 : this.prefix = prefix,
2233 super("loadLibrary", 2257 super("loadLibrary",
2234 Modifiers.EMPTY, 2258 Modifiers.EMPTY,
2235 prefix, 2259 prefix,
2236 false); 2260 false) {
2237 2261 functionSignature = new FunctionSignatureX(type: new FunctionType(this));
2238 FunctionSignature computeSignature(Resolution resolution) {
2239 if (functionSignatureCache != null) return functionSignature;
2240 functionSignatureCache =
2241 new FunctionSignatureX(type: new FunctionType(this));
2242 return functionSignatureCache;
2243 } 2262 }
2244 2263
2245 bool get isClassMember => false; 2264 bool get isClassMember => false;
2246 2265
2247 bool get isSynthesized => true; 2266 bool get isSynthesized => true;
2248 2267
2249 bool get isDeferredLoaderGetter => true; 2268 bool get isDeferredLoaderGetter => true;
2250 2269
2251 bool get isTopLevel => true; 2270 bool get isTopLevel => true;
2252 // By having position null, the enclosing elements location is printed in 2271 // By having position null, the enclosing elements location is printed in
(...skipping 13 matching lines...) Expand all
2266 class ConstructorBodyElementX extends BaseFunctionElementX 2285 class ConstructorBodyElementX extends BaseFunctionElementX
2267 implements ConstructorBodyElement { 2286 implements ConstructorBodyElement {
2268 ConstructorElementX constructor; 2287 ConstructorElementX constructor;
2269 2288
2270 ConstructorBodyElementX(ConstructorElementX constructor) 2289 ConstructorBodyElementX(ConstructorElementX constructor)
2271 : this.constructor = constructor, 2290 : this.constructor = constructor,
2272 super(constructor.name, 2291 super(constructor.name,
2273 ElementKind.GENERATIVE_CONSTRUCTOR_BODY, 2292 ElementKind.GENERATIVE_CONSTRUCTOR_BODY,
2274 Modifiers.EMPTY, 2293 Modifiers.EMPTY,
2275 constructor.enclosingElement) { 2294 constructor.enclosingElement) {
2276 functionSignatureCache = constructor.functionSignature; 2295 functionSignature = constructor.functionSignature;
2277 } 2296 }
2278 2297
2279 bool get hasNode => constructor.hasNode; 2298 bool get hasNode => constructor.hasNode;
2280 2299
2281 FunctionExpression get node => constructor.node; 2300 FunctionExpression get node => constructor.node;
2282 2301
2283 List<MetadataAnnotation> get metadata => constructor.metadata; 2302 List<MetadataAnnotation> get metadata => constructor.metadata;
2284 2303
2285 bool get isInstanceMember => true; 2304 bool get isInstanceMember => true;
2286 2305
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2323 Modifiers.EMPTY, 2342 Modifiers.EMPTY,
2324 enclosing) ; 2343 enclosing) ;
2325 2344
2326 SynthesizedConstructorElementX.forDefault(this.definingConstructor, 2345 SynthesizedConstructorElementX.forDefault(this.definingConstructor,
2327 Element enclosing) 2346 Element enclosing)
2328 : isDefaultConstructor = true, 2347 : isDefaultConstructor = true,
2329 super('', 2348 super('',
2330 ElementKind.GENERATIVE_CONSTRUCTOR, 2349 ElementKind.GENERATIVE_CONSTRUCTOR,
2331 Modifiers.EMPTY, 2350 Modifiers.EMPTY,
2332 enclosing) { 2351 enclosing) {
2333 typeCache = new FunctionType.synthesized(enclosingClass.thisType); 2352 functionSignature = new FunctionSignatureX(
2334 functionSignatureCache = new FunctionSignatureX(type: type); 2353 type: new FunctionType.synthesized(enclosingClass.thisType));
2335 } 2354 }
2336 2355
2337 FunctionExpression parseNode(Parsing parsing) => null; 2356 FunctionExpression parseNode(Parsing parsing) => null;
2338 2357
2339 bool get hasNode => false; 2358 bool get hasNode => false;
2340 2359
2341 FunctionExpression get node => null; 2360 FunctionExpression get node => null;
2342 2361
2343 Token get position => enclosingElement.position; 2362 Token get position => enclosingElement.position;
2344 2363
2345 bool get isSynthesized => true; 2364 bool get isSynthesized => true;
2346 2365
2347 DartType get type { 2366 DartType get type {
2348 if (isDefaultConstructor) { 2367 if (isDefaultConstructor) {
2349 return super.type; 2368 return super.type;
2350 } else { 2369 } else {
2351 // TODO(johnniwinther): Ensure that the function type substitutes type 2370 // TODO(johnniwinther): Ensure that the function type substitutes type
2352 // variables correctly. 2371 // variables correctly.
2353 return definingConstructor.type; 2372 return definingConstructor.type;
2354 } 2373 }
2355 } 2374 }
2356 2375
2357 FunctionSignature computeSignature(Resolution resolution) { 2376 void _computeSignature(Resolution resolution) {
2358 if (functionSignatureCache != null) return functionSignatureCache; 2377 if (hasFunctionSignature) return;
2359 if (definingConstructor.isErroneous) { 2378 if (definingConstructor.isErroneous) {
2360 typeCache = new FunctionType.synthesized(enclosingClass.thisType); 2379 functionSignature = new FunctionSignatureX(
2361 return functionSignatureCache = new FunctionSignatureX(type: type); 2380 type: new FunctionType.synthesized(enclosingClass.thisType));
2362 } 2381 }
2363 // TODO(johnniwinther): Ensure that the function signature (and with it the 2382 // TODO(johnniwinther): Ensure that the function signature (and with it the
2364 // function type) substitutes type variables correctly. 2383 // function type) substitutes type variables correctly.
2365 definingConstructor.computeType(resolution); 2384 definingConstructor.computeType(resolution);
2366 functionSignatureCache = definingConstructor.functionSignature; 2385 functionSignature = definingConstructor.functionSignature;
2367 typeCache = definingConstructor.type;
2368 return functionSignatureCache;
2369 } 2386 }
2370 2387
2371 accept(ElementVisitor visitor, arg) { 2388 accept(ElementVisitor visitor, arg) {
2372 return visitor.visitConstructorElement(this, arg); 2389 return visitor.visitConstructorElement(this, arg);
2373 } 2390 }
2374 } 2391 }
2375 2392
2376 abstract class TypeDeclarationElementX<T extends GenericType> 2393 abstract class TypeDeclarationElementX<T extends GenericType>
2377 implements TypeDeclarationElement { 2394 implements TypeDeclarationElement {
2378 /** 2395 /**
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
3106 AstElement get definingElement; 3123 AstElement get definingElement;
3107 3124
3108 bool get hasResolvedAst => definingElement.hasTreeElements; 3125 bool get hasResolvedAst => definingElement.hasTreeElements;
3109 3126
3110 ResolvedAst get resolvedAst { 3127 ResolvedAst get resolvedAst {
3111 return new ResolvedAst(declaration, 3128 return new ResolvedAst(declaration,
3112 definingElement.node, definingElement.treeElements); 3129 definingElement.node, definingElement.treeElements);
3113 } 3130 }
3114 3131
3115 } 3132 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/closure.dart ('k') | pkg/compiler/lib/src/resolution/enum_creator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698