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

Side by Side Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 2977963003: Resynthesize factory constructors from Kernel. (Closed)
Patch Set: Created 3 years, 5 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 | « no previous file | pkg/analyzer/test/src/summary/resynthesize_kernel_test.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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 analyzer.src.dart.element.element; 5 library analyzer.src.dart.element.element;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' show min; 8 import 'dart:math' show min;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 543 }
544 return super.codeOffset; 544 return super.codeOffset;
545 } 545 }
546 546
547 @override 547 @override
548 List<ConstructorElement> get constructors { 548 List<ConstructorElement> get constructors {
549 if (isMixinApplication) { 549 if (isMixinApplication) {
550 return _computeMixinAppConstructors(); 550 return _computeMixinAppConstructors();
551 } 551 }
552 if (_kernel != null && _constructors == null) { 552 if (_kernel != null && _constructors == null) {
553 _constructors = _kernel.constructors 553 var constructors = _kernel.constructors
554 .map((k) => new ConstructorElementImpl.forKernel(this, k)) 554 .map((k) => new ConstructorElementImpl.forKernel(this, k, null));
555 .toList(growable: false); 555 var factories = _kernel.procedures
556 .where((k) => k.isFactory)
557 .map((k) => new ConstructorElementImpl.forKernel(this, null, k));
558 _constructors = <ConstructorElement>[]
559 ..addAll(constructors)
560 ..addAll(factories);
556 } 561 }
557 if (_unlinkedClass != null && _constructors == null) { 562 if (_unlinkedClass != null && _constructors == null) {
558 _constructors = _unlinkedClass.executables 563 _constructors = _unlinkedClass.executables
559 .where((e) => e.kind == UnlinkedExecutableKind.constructor) 564 .where((e) => e.kind == UnlinkedExecutableKind.constructor)
560 .map((e) => new ConstructorElementImpl.forSerialized(e, this)) 565 .map((e) => new ConstructorElementImpl.forSerialized(e, this))
561 .toList(growable: false); 566 .toList(growable: false);
562 // Ensure at least implicit default constructor. 567 // Ensure at least implicit default constructor.
563 if (_constructors.isEmpty) { 568 if (_constructors.isEmpty) {
564 ConstructorElementImpl constructor = new ConstructorElementImpl('', -1); 569 ConstructorElementImpl constructor = new ConstructorElementImpl('', -1);
565 constructor.isSynthetic = true; 570 constructor.isSynthetic = true;
(...skipping 1417 matching lines...) Expand 10 before | Expand all | Expand 10 after
1983 1988
1984 /** 1989 /**
1985 * The initializers for this constructor (used for evaluating constant 1990 * The initializers for this constructor (used for evaluating constant
1986 * instance creation expressions). 1991 * instance creation expressions).
1987 */ 1992 */
1988 List<ConstructorInitializer> _constantInitializers; 1993 List<ConstructorInitializer> _constantInitializers;
1989 1994
1990 /** 1995 /**
1991 * The kernel of the element. 1996 * The kernel of the element.
1992 */ 1997 */
1993 final kernel.Constructor _kernel; 1998 final kernel.Constructor _kernelConstructor;
Paul Berry 2017/07/14 20:31:02 It seems unfortunate to bloat the memory footprint
1999
2000 /**
2001 * The kernel of the element.
2002 */
2003 final kernel.Procedure _kernelFactory;
1994 2004
1995 /** 2005 /**
1996 * The offset of the `.` before this constructor name or `null` if not named. 2006 * The offset of the `.` before this constructor name or `null` if not named.
1997 */ 2007 */
1998 int _periodOffset; 2008 int _periodOffset;
1999 2009
2000 /** 2010 /**
2001 * Return the offset of the character immediately following the last character 2011 * Return the offset of the character immediately following the last character
2002 * of this constructor's name, or `null` if not named. 2012 * of this constructor's name, or `null` if not named.
2003 */ 2013 */
2004 int _nameEnd; 2014 int _nameEnd;
2005 2015
2006 /** 2016 /**
2007 * True if this constructor has been found by constant evaluation to be free 2017 * True if this constructor has been found by constant evaluation to be free
2008 * of redirect cycles, and is thus safe to evaluate. 2018 * of redirect cycles, and is thus safe to evaluate.
2009 */ 2019 */
2010 bool _isCycleFree = false; 2020 bool _isCycleFree = false;
2011 2021
2012 /** 2022 /**
2013 * Initialize a newly created constructor element to have the given [name] and 2023 * Initialize a newly created constructor element to have the given [name] and
2014 * [offset]. 2024 * [offset].
2015 */ 2025 */
2016 ConstructorElementImpl(String name, int offset) 2026 ConstructorElementImpl(String name, int offset)
2017 : _kernel = null, 2027 : _kernelConstructor = null,
2028 _kernelFactory = null,
2018 super(name, offset); 2029 super(name, offset);
2019 2030
2020 /** 2031 /**
2021 * Initialize using the given serialized information. 2032 * Initialize using the given serialized information.
2022 */ 2033 */
2023 ConstructorElementImpl.forKernel( 2034 ConstructorElementImpl.forKernel(ClassElementImpl enclosingClass,
2024 ClassElementImpl enclosingClass, this._kernel) 2035 this._kernelConstructor, this._kernelFactory)
2025 : super.forKernel(enclosingClass, _kernel) { 2036 : super.forKernel(enclosingClass, _kernelConstructor ?? _kernelFactory) {
2026 isSynthetic = _kernel.isSyntheticDefault; 2037 isSynthetic = _kernelConstructor?.isSyntheticDefault ?? false;
2027 } 2038 }
2028 2039
2029 /** 2040 /**
2030 * Initialize a newly created constructor element to have the given [name]. 2041 * Initialize a newly created constructor element to have the given [name].
2031 */ 2042 */
2032 ConstructorElementImpl.forNode(Identifier name) 2043 ConstructorElementImpl.forNode(Identifier name)
2033 : _kernel = null, 2044 : _kernelConstructor = null,
2045 _kernelFactory = null,
2034 super.forNode(name); 2046 super.forNode(name);
2035 2047
2036 /** 2048 /**
2037 * Initialize using the given serialized information. 2049 * Initialize using the given serialized information.
2038 */ 2050 */
2039 ConstructorElementImpl.forSerialized( 2051 ConstructorElementImpl.forSerialized(
2040 UnlinkedExecutable serializedExecutable, ClassElementImpl enclosingClass) 2052 UnlinkedExecutable serializedExecutable, ClassElementImpl enclosingClass)
2041 : _kernel = null, 2053 : _kernelConstructor = null,
2054 _kernelFactory = null,
2042 super.forSerialized(serializedExecutable, enclosingClass); 2055 super.forSerialized(serializedExecutable, enclosingClass);
2043 2056
2044 /** 2057 /**
2045 * Return the constant initializers for this element, which will be empty if 2058 * Return the constant initializers for this element, which will be empty if
2046 * there are no initializers, or `null` if there was an error in the source. 2059 * there are no initializers, or `null` if there was an error in the source.
2047 */ 2060 */
2048 List<ConstructorInitializer> get constantInitializers { 2061 List<ConstructorInitializer> get constantInitializers {
2049 if (serializedExecutable != null && _constantInitializers == null) { 2062 if (serializedExecutable != null && _constantInitializers == null) {
2050 _constantInitializers ??= serializedExecutable.constantInitializers 2063 _constantInitializers ??= serializedExecutable.constantInitializers
2051 .map((i) => _buildConstructorInitializer(i)) 2064 .map((i) => _buildConstructorInitializer(i))
(...skipping 19 matching lines...) Expand all
2071 /** 2084 /**
2072 * Set whether this constructor represents a factory method. 2085 * Set whether this constructor represents a factory method.
2073 */ 2086 */
2074 void set factory(bool isFactory) { 2087 void set factory(bool isFactory) {
2075 _assertNotResynthesized(serializedExecutable); 2088 _assertNotResynthesized(serializedExecutable);
2076 setModifier(Modifier.FACTORY, isFactory); 2089 setModifier(Modifier.FACTORY, isFactory);
2077 } 2090 }
2078 2091
2079 @override 2092 @override
2080 bool get isConst { 2093 bool get isConst {
2081 if (_kernel != null) { 2094 if (_kernelConstructor != null) {
2082 return _kernel.isConst; 2095 return _kernelConstructor.isConst;
2096 }
2097 if (_kernelFactory != null) {
2098 return _kernelFactory.isConst;
2083 } 2099 }
2084 if (serializedExecutable != null) { 2100 if (serializedExecutable != null) {
2085 return serializedExecutable.isConst; 2101 return serializedExecutable.isConst;
2086 } 2102 }
2087 return hasModifier(Modifier.CONST); 2103 return hasModifier(Modifier.CONST);
2088 } 2104 }
2089 2105
2090 /** 2106 /**
2091 * Set whether this constructor represents a 'const' constructor. 2107 * Set whether this constructor represents a 'const' constructor.
2092 */ 2108 */
(...skipping 29 matching lines...) Expand all
2122 if (parameter.parameterKind == ParameterKind.REQUIRED) { 2138 if (parameter.parameterKind == ParameterKind.REQUIRED) {
2123 return false; 2139 return false;
2124 } 2140 }
2125 } 2141 }
2126 // OK, can be used as default constructor 2142 // OK, can be used as default constructor
2127 return true; 2143 return true;
2128 } 2144 }
2129 2145
2130 @override 2146 @override
2131 bool get isFactory { 2147 bool get isFactory {
2148 if (_kernelConstructor != null) return false;
2149 if (_kernelFactory != null) return true;
2132 if (serializedExecutable != null) { 2150 if (serializedExecutable != null) {
2133 return serializedExecutable.isFactory; 2151 return serializedExecutable.isFactory;
2134 } 2152 }
2135 return hasModifier(Modifier.FACTORY); 2153 return hasModifier(Modifier.FACTORY);
2136 } 2154 }
2137 2155
2138 @override 2156 @override
2139 bool get isStatic => false; 2157 bool get isStatic => false;
2140 2158
2141 @override 2159 @override
(...skipping 6858 matching lines...) Expand 10 before | Expand all | Expand 10 after
9000 9018
9001 @override 9019 @override
9002 DartObject computeConstantValue() => null; 9020 DartObject computeConstantValue() => null;
9003 9021
9004 @override 9022 @override
9005 void visitChildren(ElementVisitor visitor) { 9023 void visitChildren(ElementVisitor visitor) {
9006 super.visitChildren(visitor); 9024 super.visitChildren(visitor);
9007 _initializer?.accept(visitor); 9025 _initializer?.accept(visitor);
9008 } 9026 }
9009 } 9027 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698