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

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

Issue 1585973004: Use constructor args in favor of summary "encode" functions. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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) 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 import 'package:analyzer/src/summary/format.dart'; 5 import 'package:analyzer/src/summary/format.dart';
6 import 'package:analyzer/src/summary/name_filter.dart'; 6 import 'package:analyzer/src/summary/name_filter.dart';
7 7
8 /** 8 /**
9 * Create a [PrelinkedLibraryBuilder] corresponding to the given 9 * Create a [PrelinkedLibraryBuilder] corresponding to the given
10 * [definingUnit], which should be the defining compilation unit for a library. 10 * [definingUnit], which should be the defining compilation unit for a library.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 * it accepts. Otherwise zero. 66 * it accepts. Otherwise zero.
67 */ 67 */
68 final int numTypeParameters; 68 final int numTypeParameters;
69 69
70 _Meaning(this.unit, this.kind, this.dependency, this.numTypeParameters); 70 _Meaning(this.unit, this.kind, this.dependency, this.numTypeParameters);
71 71
72 /** 72 /**
73 * Encode this [_Meaning] as a [PrelinkedExportName], using the given [name]. 73 * Encode this [_Meaning] as a [PrelinkedExportName], using the given [name].
74 */ 74 */
75 PrelinkedExportName encodeExportName(String name) { 75 PrelinkedExportName encodeExportName(String name) {
76 return encodePrelinkedExportName( 76 return new PrelinkedExportNameBuilder(
77 name: name, dependency: dependency, unit: unit, kind: kind); 77 name: name, dependency: dependency, unit: unit, kind: kind);
78 } 78 }
79 79
80 /** 80 /**
81 * Encode this [_Meaning] as a [PrelinkedReference]. 81 * Encode this [_Meaning] as a [PrelinkedReference].
82 */ 82 */
83 PrelinkedReferenceBuilder encodeReference() { 83 PrelinkedReferenceBuilder encodeReference() {
84 return encodePrelinkedReference( 84 return new PrelinkedReferenceBuilder(
85 unit: unit, 85 unit: unit,
86 kind: kind, 86 kind: kind,
87 dependency: dependency, 87 dependency: dependency,
88 numTypeParameters: numTypeParameters); 88 numTypeParameters: numTypeParameters);
89 } 89 }
90 } 90 }
91 91
92 /** 92 /**
93 * A [_Meaning] representing a prefix introduced by an import directive. 93 * A [_Meaning] representing a prefix introduced by an import directive.
94 */ 94 */
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 */ 126 */
127 final Map<String, _Meaning> privateNamespace = <String, _Meaning>{ 127 final Map<String, _Meaning> privateNamespace = <String, _Meaning>{
128 '': new _Meaning(0, PrelinkedReferenceKind.classOrEnum, 0, 0) 128 '': new _Meaning(0, PrelinkedReferenceKind.classOrEnum, 0, 0)
129 }; 129 };
130 130
131 /** 131 /**
132 * List of dependencies of the library being prelinked. This will be output 132 * List of dependencies of the library being prelinked. This will be output
133 * to [PrelinkedLibrary.dependencies]. 133 * to [PrelinkedLibrary.dependencies].
134 */ 134 */
135 final List<PrelinkedDependencyBuilder> dependencies = 135 final List<PrelinkedDependencyBuilder> dependencies =
136 <PrelinkedDependencyBuilder>[encodePrelinkedDependency()]; 136 <PrelinkedDependencyBuilder>[new PrelinkedDependencyBuilder()];
137 137
138 /** 138 /**
139 * Map from the relative URI of a dependent library to the index of the 139 * Map from the relative URI of a dependent library to the index of the
140 * corresponding entry in [dependencies]. 140 * corresponding entry in [dependencies].
141 */ 141 */
142 final Map<String, int> uriToDependency = <String, int>{null: 0}; 142 final Map<String, int> uriToDependency = <String, int>{null: 0};
143 143
144 /** 144 /**
145 * List of public namespaces corresponding to each entry in [dependencies]. 145 * List of public namespaces corresponding to each entry in [dependencies].
146 */ 146 */
(...skipping 12 matching lines...) Expand all
159 */ 159 */
160 Map<String, _Meaning> aggregatePublicNamespace(String relativeUri) { 160 Map<String, _Meaning> aggregatePublicNamespace(String relativeUri) {
161 if (uriToDependency.containsKey(relativeUri)) { 161 if (uriToDependency.containsKey(relativeUri)) {
162 return dependencyToPublicNamespace[uriToDependency[relativeUri]]; 162 return dependencyToPublicNamespace[uriToDependency[relativeUri]];
163 } 163 }
164 assert(dependencies.length == dependencyToPublicNamespace.length); 164 assert(dependencies.length == dependencyToPublicNamespace.length);
165 int dependency = dependencies.length; 165 int dependency = dependencies.length;
166 uriToDependency[relativeUri] = dependency; 166 uriToDependency[relativeUri] = dependency;
167 List<String> unitUris = getUnitUris(relativeUri); 167 List<String> unitUris = getUnitUris(relativeUri);
168 PrelinkedDependencyBuilder prelinkedDependency = 168 PrelinkedDependencyBuilder prelinkedDependency =
169 encodePrelinkedDependency(uri: relativeUri, parts: unitUris.sublist(1)); 169 new PrelinkedDependencyBuilder(
170 uri: relativeUri, parts: unitUris.sublist(1));
170 dependencies.add(prelinkedDependency); 171 dependencies.add(prelinkedDependency);
171 172
172 Map<String, _Meaning> aggregated = <String, _Meaning>{}; 173 Map<String, _Meaning> aggregated = <String, _Meaning>{};
173 174
174 for (int unitNum = 0; unitNum < unitUris.length; unitNum++) { 175 for (int unitNum = 0; unitNum < unitUris.length; unitNum++) {
175 String unitUri = unitUris[unitNum]; 176 String unitUri = unitUris[unitNum];
176 UnlinkedPublicNamespace importedNamespace = getImportCached(unitUri); 177 UnlinkedPublicNamespace importedNamespace = getImportCached(unitUri);
177 if (importedNamespace == null) { 178 if (importedNamespace == null) {
178 continue; 179 continue;
179 } 180 }
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 filterExportNamespace(uri, import.combinators, targetNamespace); 351 filterExportNamespace(uri, import.combinators, targetNamespace);
351 return uriToDependency[uri]; 352 return uriToDependency[uri];
352 } 353 }
353 354
354 /** 355 /**
355 * Produce a [PrelinkedUnit] for the given [unit], by resolving every one of 356 * Produce a [PrelinkedUnit] for the given [unit], by resolving every one of
356 * its references. 357 * its references.
357 */ 358 */
358 PrelinkedUnitBuilder linkUnit(UnlinkedUnit unit) { 359 PrelinkedUnitBuilder linkUnit(UnlinkedUnit unit) {
359 if (unit == null) { 360 if (unit == null) {
360 return encodePrelinkedUnit(); 361 return new PrelinkedUnitBuilder();
361 } 362 }
362 Map<int, Map<String, _Meaning>> prefixNamespaces = 363 Map<int, Map<String, _Meaning>> prefixNamespaces =
363 <int, Map<String, _Meaning>>{}; 364 <int, Map<String, _Meaning>>{};
364 List<PrelinkedReferenceBuilder> references = <PrelinkedReferenceBuilder>[]; 365 List<PrelinkedReferenceBuilder> references = <PrelinkedReferenceBuilder>[];
365 for (int i = 0; i < unit.references.length; i++) { 366 for (int i = 0; i < unit.references.length; i++) {
366 UnlinkedReference reference = unit.references[i]; 367 UnlinkedReference reference = unit.references[i];
367 Map<String, _Meaning> namespace; 368 Map<String, _Meaning> namespace;
368 if (reference.prefixReference != 0) { 369 if (reference.prefixReference != 0) {
369 // Prefix references must always point backward. 370 // Prefix references must always point backward.
370 assert(reference.prefixReference < i); 371 assert(reference.prefixReference < i);
371 namespace = prefixNamespaces[reference.prefixReference]; 372 namespace = prefixNamespaces[reference.prefixReference];
372 // Prefix references must always point to proper prefixes. 373 // Prefix references must always point to proper prefixes.
373 assert(namespace != null); 374 assert(namespace != null);
374 } else { 375 } else {
375 namespace = privateNamespace; 376 namespace = privateNamespace;
376 } 377 }
377 _Meaning meaning = namespace[reference.name]; 378 _Meaning meaning = namespace[reference.name];
378 if (meaning != null) { 379 if (meaning != null) {
379 if (meaning is _PrefixMeaning) { 380 if (meaning is _PrefixMeaning) {
380 prefixNamespaces[i] = meaning.namespace; 381 prefixNamespaces[i] = meaning.namespace;
381 } 382 }
382 references.add(meaning.encodeReference()); 383 references.add(meaning.encodeReference());
383 } else { 384 } else {
384 references.add( 385 references.add(new PrelinkedReferenceBuilder(
385 encodePrelinkedReference(kind: PrelinkedReferenceKind.unresolved)); 386 kind: PrelinkedReferenceKind.unresolved));
386 } 387 }
387 } 388 }
388 return encodePrelinkedUnit(references: references); 389 return new PrelinkedUnitBuilder(references: references);
389 } 390 }
390 391
391 /** 392 /**
392 * Form the [PrelinkedLibrary] for the [definingUnit] that was passed to the 393 * Form the [PrelinkedLibrary] for the [definingUnit] that was passed to the
393 * constructor. 394 * constructor.
394 */ 395 */
395 PrelinkedLibraryBuilder prelink() { 396 PrelinkedLibraryBuilder prelink() {
396 // Gather up the unlinked summaries for all the compilation units in the 397 // Gather up the unlinked summaries for all the compilation units in the
397 // library. 398 // library.
398 List<UnlinkedUnit> units = getUnitUris(null).map(getPartCached).toList(); 399 List<UnlinkedUnit> units = getUnitUris(null).map(getPartCached).toList();
(...skipping 27 matching lines...) Expand all
426 } 427 }
427 } 428 }
428 429
429 // Fill in imported names. 430 // Fill in imported names.
430 List<int> importDependencies = 431 List<int> importDependencies =
431 definingUnit.imports.map(handleImport).toList(); 432 definingUnit.imports.map(handleImport).toList();
432 433
433 // Link each compilation unit. 434 // Link each compilation unit.
434 List<PrelinkedUnitBuilder> linkedUnits = units.map(linkUnit).toList(); 435 List<PrelinkedUnitBuilder> linkedUnits = units.map(linkUnit).toList();
435 436
436 return encodePrelinkedLibrary( 437 return new PrelinkedLibraryBuilder(
437 units: linkedUnits, 438 units: linkedUnits,
438 dependencies: dependencies, 439 dependencies: dependencies,
439 importDependencies: importDependencies, 440 importDependencies: importDependencies,
440 exportNames: exportNames); 441 exportNames: exportNames);
441 } 442 }
442 443
443 /** 444 /**
444 * Resolve [relativeUri] relative to [sourceUri]. Works correctly if 445 * Resolve [relativeUri] relative to [sourceUri]. Works correctly if
445 * [sourceUri] is also relative. 446 * [sourceUri] is also relative.
446 */ 447 */
447 String resolveUri(String sourceUri, String relativeUri) { 448 String resolveUri(String sourceUri, String relativeUri) {
448 if (sourceUri == null) { 449 if (sourceUri == null) {
449 return relativeUri; 450 return relativeUri;
450 } else { 451 } else {
451 return Uri.parse(sourceUri).resolve(relativeUri).toString(); 452 return Uri.parse(sourceUri).resolve(relativeUri).toString();
452 } 453 }
453 } 454 }
454 } 455 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/format.dart ('k') | pkg/analyzer/lib/src/summary/public_namespace_computer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698