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

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

Issue 2987863002: Resynthesize factoring constructor redirects 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/lib/src/kernel/resynthesize.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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 } 564 }
565 if (_kernel != null && _constructors == null) { 565 if (_kernel != null && _constructors == null) {
566 var constructors = _kernel.constructors 566 var constructors = _kernel.constructors
567 .map((k) => new ConstructorElementImpl.forKernel(this, k, null)); 567 .map((k) => new ConstructorElementImpl.forKernel(this, k, null));
568 var factories = _kernel.procedures 568 var factories = _kernel.procedures
569 .where((k) => k.isFactory) 569 .where((k) => k.isFactory)
570 .map((k) => new ConstructorElementImpl.forKernel(this, null, k)); 570 .map((k) => new ConstructorElementImpl.forKernel(this, null, k));
571 _constructors = <ConstructorElement>[] 571 _constructors = <ConstructorElement>[]
572 ..addAll(constructors) 572 ..addAll(constructors)
573 ..addAll(factories); 573 ..addAll(factories);
574 _constructors.sort((a, b) => a.nameOffset - b.nameOffset);
574 } 575 }
575 if (_unlinkedClass != null && _constructors == null) { 576 if (_unlinkedClass != null && _constructors == null) {
576 _constructors = _unlinkedClass.executables 577 _constructors = _unlinkedClass.executables
577 .where((e) => e.kind == UnlinkedExecutableKind.constructor) 578 .where((e) => e.kind == UnlinkedExecutableKind.constructor)
578 .map((e) => new ConstructorElementImpl.forSerialized(e, this)) 579 .map((e) => new ConstructorElementImpl.forSerialized(e, this))
579 .toList(growable: false); 580 .toList(growable: false);
580 // Ensure at least implicit default constructor. 581 // Ensure at least implicit default constructor.
581 if (_constructors.isEmpty) { 582 if (_constructors.isEmpty) {
582 ConstructorElementImpl constructor = new ConstructorElementImpl('', -1); 583 ConstructorElementImpl constructor = new ConstructorElementImpl('', -1);
583 constructor.isSynthetic = true; 584 constructor.isSynthetic = true;
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 void _resynthesizeFieldsAndPropertyAccessors() { 1288 void _resynthesizeFieldsAndPropertyAccessors() {
1288 assert(_fields == null); 1289 assert(_fields == null);
1289 assert(_accessors == null); 1290 assert(_accessors == null);
1290 var explicitFields = <FieldElement>[]; 1291 var explicitFields = <FieldElement>[];
1291 var implicitAccessors = <PropertyAccessorElement>[]; 1292 var implicitAccessors = <PropertyAccessorElement>[];
1292 var explicitAccessors = <PropertyAccessorElement>[]; 1293 var explicitAccessors = <PropertyAccessorElement>[];
1293 var implicitFields = <String, FieldElementImpl>{}; 1294 var implicitFields = <String, FieldElementImpl>{};
1294 if (_kernel != null) { 1295 if (_kernel != null) {
1295 // Build explicit fields and implicit property accessors. 1296 // Build explicit fields and implicit property accessors.
1296 for (var k in _kernel.fields) { 1297 for (var k in _kernel.fields) {
1298 if (k.name.name.startsWith('_redirecting#')) {
1299 continue;
1300 }
1297 var field = new FieldElementImpl.forKernelFactory(this, k); 1301 var field = new FieldElementImpl.forKernelFactory(this, k);
1298 explicitFields.add(field); 1302 explicitFields.add(field);
1299 implicitAccessors.add( 1303 implicitAccessors.add(
1300 new PropertyAccessorElementImpl_ImplicitGetter(field) 1304 new PropertyAccessorElementImpl_ImplicitGetter(field)
1301 ..enclosingElement = this); 1305 ..enclosingElement = this);
1302 if (!field.isConst && !field.isFinal) { 1306 if (!field.isConst && !field.isFinal) {
1303 implicitAccessors.add( 1307 implicitAccessors.add(
1304 new PropertyAccessorElementImpl_ImplicitSetter(field) 1308 new PropertyAccessorElementImpl_ImplicitSetter(field)
1305 ..enclosingElement = this); 1309 ..enclosingElement = this);
1306 } 1310 }
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after
2210 _kernelFactory = null, 2214 _kernelFactory = null,
2211 super.forSerialized(serializedExecutable, enclosingClass); 2215 super.forSerialized(serializedExecutable, enclosingClass);
2212 2216
2213 /** 2217 /**
2214 * Return the constant initializers for this element, which will be empty if 2218 * Return the constant initializers for this element, which will be empty if
2215 * there are no initializers, or `null` if there was an error in the source. 2219 * there are no initializers, or `null` if there was an error in the source.
2216 */ 2220 */
2217 List<ConstructorInitializer> get constantInitializers { 2221 List<ConstructorInitializer> get constantInitializers {
2218 if (_constantInitializers == null) { 2222 if (_constantInitializers == null) {
2219 if (_kernelConstructor != null) { 2223 if (_kernelConstructor != null) {
2220 var context = enclosingUnit._kernelContext; 2224 if (_kernelConstructor.isConst) {
2221 _constantInitializers = _kernelConstructor.initializers 2225 var context = enclosingUnit._kernelContext;
2222 .map((k) => context.getConstructorInitializer(this, k)) 2226 _constantInitializers = _kernelConstructor.initializers
2223 .where((i) => i != null) 2227 .map((k) => context.getConstructorInitializer(this, k))
2224 .toList(); 2228 .where((i) => i != null)
2229 .toList();
2230 } else {
2231 _constantInitializers = const <ConstructorInitializer>[];
2232 }
2225 } 2233 }
2226 if (serializedExecutable != null) { 2234 if (serializedExecutable != null) {
2227 _constantInitializers = serializedExecutable.constantInitializers 2235 _constantInitializers = serializedExecutable.constantInitializers
2228 .map((i) => _buildConstructorInitializer(i)) 2236 .map((i) => _buildConstructorInitializer(i))
2229 .toList(growable: false); 2237 .toList(growable: false);
2230 } 2238 }
2231 } 2239 }
2232 return _constantInitializers; 2240 return _constantInitializers;
2233 } 2241 }
2234 2242
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
2352 } 2360 }
2353 2361
2354 void set periodOffset(int periodOffset) { 2362 void set periodOffset(int periodOffset) {
2355 _assertNotResynthesized(serializedExecutable); 2363 _assertNotResynthesized(serializedExecutable);
2356 _periodOffset = periodOffset; 2364 _periodOffset = periodOffset;
2357 } 2365 }
2358 2366
2359 @override 2367 @override
2360 ConstructorElement get redirectedConstructor { 2368 ConstructorElement get redirectedConstructor {
2361 if (_redirectedConstructor == null) { 2369 if (_redirectedConstructor == null) {
2362 if (_kernelConstructor != null) { 2370 if (_kernelConstructor != null || _kernelFactory != null) {
2363 for (var initializer in _kernelConstructor.initializers) { 2371 _redirectedConstructor = enclosingUnit._kernelContext
2364 if (initializer is kernel.RedirectingInitializer) { 2372 .getRedirectedConstructor(_kernelConstructor, _kernelFactory);
2365 return _redirectedConstructor = enclosingUnit._kernelContext
2366 .getElement(initializer.targetReference)
2367 as ConstructorElementImpl;
2368 }
2369 }
2370 } 2373 }
2371 if (serializedExecutable != null) { 2374 if (serializedExecutable != null) {
2372 if (serializedExecutable.isRedirectedConstructor) { 2375 if (serializedExecutable.isRedirectedConstructor) {
2373 if (serializedExecutable.isFactory) { 2376 if (serializedExecutable.isFactory) {
2374 _redirectedConstructor = enclosingUnit.resynthesizerContext 2377 _redirectedConstructor = enclosingUnit.resynthesizerContext
2375 .resolveConstructorRef(enclosingElement, 2378 .resolveConstructorRef(enclosingElement,
2376 serializedExecutable.redirectedConstructor); 2379 serializedExecutable.redirectedConstructor);
2377 } else { 2380 } else {
2378 _redirectedConstructor = enclosingElement.getNamedConstructor( 2381 _redirectedConstructor = enclosingElement.getNamedConstructor(
2379 serializedExecutable.redirectedConstructorName); 2382 serializedExecutable.redirectedConstructorName);
(...skipping 1711 matching lines...) Expand 10 before | Expand all | Expand 10 after
4091 } 4094 }
4092 if (serializedExecutable != null) { 4095 if (serializedExecutable != null) {
4093 return serializedExecutable.name; 4096 return serializedExecutable.name;
4094 } 4097 }
4095 return super.name; 4098 return super.name;
4096 } 4099 }
4097 4100
4098 @override 4101 @override
4099 int get nameOffset { 4102 int get nameOffset {
4100 int offset = super.nameOffset; 4103 int offset = super.nameOffset;
4104 if (_kernel != null) {
4105 return _kernel.fileOffset;
4106 }
4101 if (offset == 0 && serializedExecutable != null) { 4107 if (offset == 0 && serializedExecutable != null) {
4102 return serializedExecutable.nameOffset; 4108 return serializedExecutable.nameOffset;
4103 } 4109 }
4104 return offset; 4110 return offset;
4105 } 4111 }
4106 4112
4107 @override 4113 @override
4108 List<ParameterElement> get parameters { 4114 List<ParameterElement> get parameters {
4109 if (_parameters == null) { 4115 if (_parameters == null) {
4110 if (_kernel != null) { 4116 if (_kernel != null) {
(...skipping 1780 matching lines...) Expand 10 before | Expand all | Expand 10 after
5891 kernel.Library get library; 5897 kernel.Library get library;
5892 5898
5893 /** 5899 /**
5894 * Return the resynthesized [ConstructorInitializer] for the given Kernel 5900 * Return the resynthesized [ConstructorInitializer] for the given Kernel
5895 * [initializer], or `null` if synthetic. 5901 * [initializer], or `null` if synthetic.
5896 */ 5902 */
5897 ConstructorInitializer getConstructorInitializer( 5903 ConstructorInitializer getConstructorInitializer(
5898 ConstructorElementImpl constructor, kernel.Initializer initializer); 5904 ConstructorElementImpl constructor, kernel.Initializer initializer);
5899 5905
5900 /** 5906 /**
5901 * Return the [Element] referenced by the given [reference].
5902 */
5903 ElementImpl getElement(kernel.Reference reference);
5904
5905 /**
5906 * Return the [Expression] for the given kernel. 5907 * Return the [Expression] for the given kernel.
5907 */ 5908 */
5908 Expression getExpression(kernel.Expression expression); 5909 Expression getExpression(kernel.Expression expression);
5909 5910
5910 /** 5911 /**
5911 * Return the [InterfaceType] for the given Kernel [type], or `null` if the 5912 * Return the [InterfaceType] for the given Kernel [type], or `null` if the
5912 * [type] does not correspond to an [InterfaceType]. 5913 * [type] does not correspond to an [InterfaceType].
5913 */ 5914 */
5914 InterfaceType getInterfaceType(ElementImpl context, kernel.Supertype type); 5915 InterfaceType getInterfaceType(ElementImpl context, kernel.Supertype type);
5915 5916
5916 /** 5917 /**
5917 * Return the [LibraryElement] for the given absolute [uriStr]. 5918 * Return the [LibraryElement] for the given absolute [uriStr].
5918 */ 5919 */
5919 LibraryElement getLibrary(String uriStr); 5920 LibraryElement getLibrary(String uriStr);
5920 5921
5921 /** 5922 /**
5923 * Return the [ConstructorElementImpl] to which the given [kernelConstructor]
5924 * or [kernelFactory] redirects.
5925 */
5926 ConstructorElementImpl getRedirectedConstructor(
5927 kernel.Constructor kernelConstructor, kernel.Procedure kernelFactory);
5928
5929 /**
5922 * Return the [DartType] for the given Kernel [type], or `null` if the [type] 5930 * Return the [DartType] for the given Kernel [type], or `null` if the [type]
5923 * does not correspond to a [DartType]. 5931 * does not correspond to a [DartType].
5924 */ 5932 */
5925 DartType getType(ElementImpl context, kernel.DartType type); 5933 DartType getType(ElementImpl context, kernel.DartType type);
5926 } 5934 }
5927 5935
5928 /** 5936 /**
5929 * A concrete implementation of a [LabelElement]. 5937 * A concrete implementation of a [LabelElement].
5930 */ 5938 */
5931 class LabelElementImpl extends ElementImpl implements LabelElement { 5939 class LabelElementImpl extends ElementImpl implements LabelElement {
(...skipping 2414 matching lines...) Expand 10 before | Expand all | Expand 10 after
8346 /** 8354 /**
8347 * Initialize a newly created method element to have the given [name] and 8355 * Initialize a newly created method element to have the given [name] and
8348 * [nameOffset]. 8356 * [nameOffset].
8349 */ 8357 */
8350 PrefixElementImpl(String name, int nameOffset) 8358 PrefixElementImpl(String name, int nameOffset)
8351 : _unlinkedImport = null, 8359 : _unlinkedImport = null,
8352 _kernel = null, 8360 _kernel = null,
8353 super(name, nameOffset); 8361 super(name, nameOffset);
8354 8362
8355 /** 8363 /**
8364 * Initialize using the given kernel.
8365 */
8366 PrefixElementImpl.forKernel(LibraryElementImpl enclosingLibrary, this._kernel)
8367 : _unlinkedImport = null,
8368 super.forSerialized(enclosingLibrary);
8369
8370 /**
8356 * Initialize a newly created prefix element to have the given [name]. 8371 * Initialize a newly created prefix element to have the given [name].
8357 */ 8372 */
8358 PrefixElementImpl.forNode(Identifier name) 8373 PrefixElementImpl.forNode(Identifier name)
8359 : _unlinkedImport = null, 8374 : _unlinkedImport = null,
8360 _kernel = null, 8375 _kernel = null,
8361 super.forNode(name); 8376 super.forNode(name);
8362 8377
8363 /** 8378 /**
8364 * Initialize using the given serialized information. 8379 * Initialize using the given serialized information.
8365 */ 8380 */
8366 PrefixElementImpl.forSerialized( 8381 PrefixElementImpl.forSerialized(
8367 this._unlinkedImport, LibraryElementImpl enclosingLibrary) 8382 this._unlinkedImport, LibraryElementImpl enclosingLibrary)
8368 : _kernel = null, 8383 : _kernel = null,
8369 super.forSerialized(enclosingLibrary); 8384 super.forSerialized(enclosingLibrary);
8370 8385
8371 /**
8372 * Initialize using the given kernel.
8373 */
8374 PrefixElementImpl.forKernel(LibraryElementImpl enclosingLibrary, this._kernel)
8375 : _unlinkedImport = null,
8376 super.forSerialized(enclosingLibrary);
8377
8378 @override 8386 @override
8379 String get displayName => name; 8387 String get displayName => name;
8380 8388
8381 @override 8389 @override
8382 LibraryElement get enclosingElement => 8390 LibraryElement get enclosingElement =>
8383 super.enclosingElement as LibraryElement; 8391 super.enclosingElement as LibraryElement;
8384 8392
8385 @override 8393 @override
8386 String get identifier => "_${super.identifier}"; 8394 String get identifier => "_${super.identifier}";
8387 8395
(...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after
9624 9632
9625 @override 9633 @override
9626 DartObject computeConstantValue() => null; 9634 DartObject computeConstantValue() => null;
9627 9635
9628 @override 9636 @override
9629 void visitChildren(ElementVisitor visitor) { 9637 void visitChildren(ElementVisitor visitor) {
9630 super.visitChildren(visitor); 9638 super.visitChildren(visitor);
9631 _initializer?.accept(visitor); 9639 _initializer?.accept(visitor);
9632 } 9640 }
9633 } 9641 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/kernel/resynthesize.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698