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

Side by Side Diff: pkg/analyzer/lib/src/summary/link.dart

Issue 1839663003: More fixes to summary linking. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Test corner cases involving undefined names Created 4 years, 8 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/summarize_ast_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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 /** 5 /**
6 * This library is capable of producing linked summaries from unlinked 6 * This library is capable of producing linked summaries from unlinked
7 * ones (or prelinked ones). It functions by building a miniature 7 * ones (or prelinked ones). It functions by building a miniature
8 * element model to represent the contents of the summaries, and then 8 * element model to represent the contents of the summaries, and then
9 * scanning the element model to gather linked information and adding 9 * scanning the element model to gather linked information and adding
10 * it to the summary data structures. 10 * it to the summary data structures.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 */ 123 */
124 abstract class ClassElementForLink 124 abstract class ClassElementForLink
125 implements ClassElement, ReferenceableElementForLink { 125 implements ClassElement, ReferenceableElementForLink {
126 Map<String, ReferenceableElementForLink> _containedNames; 126 Map<String, ReferenceableElementForLink> _containedNames;
127 127
128 @override 128 @override
129 ConstructorElementForLink get asConstructor => unnamedConstructor; 129 ConstructorElementForLink get asConstructor => unnamedConstructor;
130 130
131 @override 131 @override
132 ConstVariableNode get asConstVariable { 132 ConstVariableNode get asConstVariable {
133 // TODO(paulberry): implement. 133 // When a class name is used as a constant variable, it doesn't depend on
134 throw new UnimplementedError(); 134 // anything, so it is not necessary to include it in the constant
135 // dependency graph.
136 return null;
135 } 137 }
136 138
137 @override 139 @override
138 List<ConstructorElementForLink> get constructors; 140 List<ConstructorElementForLink> get constructors;
139 141
140 @override 142 @override
141 List<FieldElementForLink> get fields; 143 List<FieldElementForLink> get fields;
142 144
143 /** 145 /**
144 * Indicates whether this is the core class `Object`. 146 * Indicates whether this is the core class `Object`.
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 * Return the element referred to by the given [index] in 436 * Return the element referred to by the given [index] in
435 * [UnlinkedUnit.references]. If the reference is unresolved, 437 * [UnlinkedUnit.references]. If the reference is unresolved,
436 * return [UndefinedElementForLink.instance]. 438 * return [UndefinedElementForLink.instance].
437 */ 439 */
438 ReferenceableElementForLink _resolveRef(int index) { 440 ReferenceableElementForLink _resolveRef(int index) {
439 if (_references[index] == null) { 441 if (_references[index] == null) {
440 UnlinkedReference unlinkedReference = _unlinkedUnit.references[index]; 442 UnlinkedReference unlinkedReference = _unlinkedUnit.references[index];
441 LinkedReference linkedReference = _linkedUnit.references[index]; 443 LinkedReference linkedReference = _linkedUnit.references[index];
442 String name = unlinkedReference.name; 444 String name = unlinkedReference.name;
443 int containingReference = unlinkedReference.prefixReference; 445 int containingReference = unlinkedReference.prefixReference;
444 if (containingReference != 0) { 446 if (containingReference != 0 &&
447 _linkedUnit.references[containingReference].kind !=
448 ReferenceKind.prefix) {
445 _references[index] = 449 _references[index] =
446 _resolveRef(containingReference).getContainedName(name); 450 _resolveRef(containingReference).getContainedName(name);
447 } else if (linkedReference.dependency == 0) { 451 } else if (linkedReference.dependency == 0) {
448 _references[index] = enclosingElement.getContainedName(name); 452 _references[index] = enclosingElement.getContainedName(name);
449 } else { 453 } else {
450 // TODO(paulberry): implement. 454 LibraryElementForLink dependency =
451 throw new UnimplementedError(); 455 enclosingElement._getDependency(linkedReference.dependency);
456 _references[index] = dependency.getContainedName(name);
452 } 457 }
453 } 458 }
454 return _references[index]; 459 return _references[index];
455 } 460 }
456 461
457 /** 462 /**
458 * Resolve an [EntityRef] into a type. If the reference is 463 * Resolve an [EntityRef] into a type. If the reference is
459 * unresolved, return [DynamicTypeImpl.instance]. 464 * unresolved, return [DynamicTypeImpl.instance].
460 * 465 *
461 * TODO(paulberry): or should we have a class representing an 466 * TODO(paulberry): or should we have a class representing an
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 final _Linker _linker; 1105 final _Linker _linker;
1101 1106
1102 /** 1107 /**
1103 * The absolute URI of this library. 1108 * The absolute URI of this library.
1104 */ 1109 */
1105 final Uri _absoluteUri; 1110 final Uri _absoluteUri;
1106 1111
1107 List<UnitElement> _units; 1112 List<UnitElement> _units;
1108 final Map<String, ReferenceableElementForLink> _containedNames = 1113 final Map<String, ReferenceableElementForLink> _containedNames =
1109 <String, ReferenceableElementForLink>{}; 1114 <String, ReferenceableElementForLink>{};
1115 final List<LibraryElementForLink> _dependencies = <LibraryElementForLink>[];
1110 1116
1111 LibraryElementForLink(this._linker, this._absoluteUri); 1117 LibraryElementForLink(this._linker, this._absoluteUri) {
1118 _dependencies.length = _linkedLibrary.dependencies.length;
1119 }
1112 1120
1113 @override 1121 @override
1114 List<UnitElement> get units { 1122 List<UnitElement> get units {
1115 if (_units == null) { 1123 if (_units == null) {
1116 UnlinkedUnit definingUnit = _linker.getUnit(_absoluteUri.toString()); 1124 UnlinkedUnit definingUnit = _linker.getUnit(_absoluteUri.toString());
1117 _units = <UnitElement>[_makeUnitElement(definingUnit, 0)]; 1125 _units = <UnitElement>[_makeUnitElement(definingUnit, 0)];
1118 int numParts = definingUnit.parts.length; 1126 int numParts = definingUnit.parts.length;
1119 for (int i = 0; i < numParts; i++) { 1127 for (int i = 0; i < numParts; i++) {
1120 // TODO(paulberry): make sure we handle the case where Uri.parse fails. 1128 // TODO(paulberry): make sure we handle the case where Uri.parse fails.
1121 // TODO(paulberry): make sure we handle the case where 1129 // TODO(paulberry): make sure we handle the case where
(...skipping 26 matching lines...) Expand all
1148 return element; 1156 return element;
1149 } 1157 }
1150 } 1158 }
1151 return UndefinedElementForLink.instance; 1159 return UndefinedElementForLink.instance;
1152 }); 1160 });
1153 1161
1154 @override 1162 @override
1155 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 1163 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
1156 1164
1157 /** 1165 /**
1166 * Return the [LibraryElement] corresponding to the given dependency [index].
1167 */
1168 LibraryElementForLink _getDependency(int index) {
1169 return _dependencies[index] ??= _linker.getLibrary(resolveRelativeUri(
1170 _absoluteUri, Uri.parse(_linkedLibrary.dependencies[index].uri)));
1171 }
1172
1173 /**
1158 * Create a [UnitElement] for one of the library's compilation 1174 * Create a [UnitElement] for one of the library's compilation
1159 * units. 1175 * units.
1160 */ 1176 */
1161 UnitElement _makeUnitElement(UnlinkedUnit unlinkedUnit, int i); 1177 UnitElement _makeUnitElement(UnlinkedUnit unlinkedUnit, int i);
1162 } 1178 }
1163 1179
1164 /** 1180 /**
1165 * Element representing a library which is part of the build unit 1181 * Element representing a library which is part of the build unit
1166 * being linked. 1182 * being linked.
1167 */ 1183 */
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 1534
1519 /** 1535 /**
1520 * Throw away any information produced by a previous call to [link]. 1536 * Throw away any information produced by a previous call to [link].
1521 */ 1537 */
1522 void unlink() { 1538 void unlink() {
1523 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) { 1539 for (LibraryElementInBuildUnit library in _librariesInBuildUnit) {
1524 library.unlink(); 1540 library.unlink();
1525 } 1541 }
1526 } 1542 }
1527 } 1543 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/summarize_ast_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698