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

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

Issue 1530303005: Separate prelinked and unlinked parts of summaries. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 serialization.elements; 5 library serialization.elements;
6 6
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/dart/element/type.dart'; 8 import 'package:analyzer/dart/element/type.dart';
9 import 'package:analyzer/src/dart/element/type.dart'; 9 import 'package:analyzer/src/dart/element/type.dart';
10 import 'package:analyzer/src/generated/resolver.dart'; 10 import 'package:analyzer/src/generated/resolver.dart';
11 import 'package:analyzer/src/generated/utilities_dart.dart'; 11 import 'package:analyzer/src/generated/utilities_dart.dart';
12 import 'package:analyzer/src/summary/builder.dart'; 12 import 'package:analyzer/src/summary/builder.dart';
13 import 'package:analyzer/src/summary/format.dart'; 13 import 'package:analyzer/src/summary/format.dart';
14 14
15 /** 15 /**
16 * Serialize all the elements in [lib] to a summary using [ctx] as the context 16 * Serialize all the elements in [lib] to a summary using [ctx] as the context
17 * for building the summary, and using [typeProvider] to find built-in types. 17 * for building the summary, and using [typeProvider] to find built-in types.
18 */ 18 */
19 PrelinkedLibraryBuilder serializeLibrary( 19 LibrarySerializationResult serializeLibrary(
20 BuilderContext ctx, LibraryElement lib, TypeProvider typeProvider) { 20 BuilderContext ctx, LibraryElement lib, TypeProvider typeProvider) {
21 return new _LibrarySerializer(ctx, lib, typeProvider).serializeLibrary(); 21 var serializer = new _LibrarySerializer(ctx, lib, typeProvider);
22 PrelinkedLibraryBuilder prelinked = serializer.serializeLibrary();
23 return new LibrarySerializationResult(
24 prelinked, serializer.unlinkedUnits, serializer.unitUris);
22 } 25 }
23 26
24 /** 27 /**
28 * Data structure holding the result of serializing a [LibraryElement].
29 */
30 class LibrarySerializationResult {
31 /**
32 * Pre-linked information the given library.
33 */
34 final PrelinkedLibraryBuilder prelinked;
35
36 /**
37 * Unlinked information for the compilation units constituting the library.
38 * The zeroth entry in the list is the defining compilation unit; the
39 * remaining entries are the parts, in the order listed in the defining
40 * compilation unit's part declarations.
41 */
42 final List<UnlinkedUnitBuilder> unlinkedUnits;
43
44 /**
45 * Absolute URI of each compilation unit appearing in the library.
46 */
47 final List<String> unitUris;
48
49 LibrarySerializationResult(this.prelinked, this.unlinkedUnits, this.unitUris);
50 }
51
52 /**
25 * Instances of this class keep track of intermediate state during 53 * Instances of this class keep track of intermediate state during
26 * serialization of a single library.` 54 * serialization of a single library.`
27 */ 55 */
28 class _LibrarySerializer { 56 class _LibrarySerializer {
29 /** 57 /**
30 * The library to be serialized. 58 * The library to be serialized.
31 */ 59 */
32 final LibraryElement libraryElement; 60 final LibraryElement libraryElement;
33 61
34 /** 62 /**
35 * The type provider. This is used to locate the library for `dart:core`. 63 * The type provider. This is used to locate the library for `dart:core`.
36 */ 64 */
37 final TypeProvider typeProvider; 65 final TypeProvider typeProvider;
38 66
39 /** 67 /**
40 * List of objects which should be written to [PrelinkedLibrary.units]. 68 * List of objects which should be written to [PrelinkedLibrary.units].
41 */ 69 */
42 final List<PrelinkedUnitBuilder> units = <PrelinkedUnitBuilder>[]; 70 final List<PrelinkedUnitBuilder> prelinkedUnits = <PrelinkedUnitBuilder>[];
71
72 /**
73 * List of unlinked units corresponding to the pre-linked units in
74 * [prelinkedUnits],
75 */
76 final List<UnlinkedUnitBuilder> unlinkedUnits = <UnlinkedUnitBuilder>[];
77
78 /**
79 * List of absolute URIs of the compilation units in the library.
80 */
81 final List<String> unitUris = <String>[];
43 82
44 /** 83 /**
45 * Map from [LibraryElement] to the index of the entry in the "dependency 84 * Map from [LibraryElement] to the index of the entry in the "dependency
46 * table" that refers to it. 85 * table" that refers to it.
47 */ 86 */
48 final Map<LibraryElement, int> dependencyMap = <LibraryElement, int>{}; 87 final Map<LibraryElement, int> dependencyMap = <LibraryElement, int>{};
49 88
50 /** 89 /**
51 * The "dependency table". This is the list of objects which should be 90 * The "dependency table". This is the list of objects which should be
52 * written to [PrelinkedLibrary.dependencies]. 91 * written to [PrelinkedLibrary.dependencies].
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 if (accessor.isSynthetic && accessor.isGetter) { 195 if (accessor.isSynthetic && accessor.isGetter) {
157 PropertyInducingElement variable = accessor.variable; 196 PropertyInducingElement variable = accessor.variable;
158 if (variable != null) { 197 if (variable != null) {
159 assert(!variable.isSynthetic); 198 assert(!variable.isSynthetic);
160 variables.add(serializeVariable(variable)); 199 variables.add(serializeVariable(variable));
161 } 200 }
162 } 201 }
163 } 202 }
164 b.variables = variables; 203 b.variables = variables;
165 b.references = unlinkedReferences; 204 b.references = unlinkedReferences;
166 units.add( 205 unlinkedUnits.add(b);
167 encodePrelinkedUnit(ctx, unlinked: b, references: prelinkedReferences)); 206 prelinkedUnits
207 .add(encodePrelinkedUnit(ctx, references: prelinkedReferences));
208 unitUris.add(element.source.uri.toString());
168 unlinkedReferences = null; 209 unlinkedReferences = null;
169 prelinkedReferences = null; 210 prelinkedReferences = null;
170 } 211 }
171 212
172 /** 213 /**
173 * Add [exportedLibrary] (and the transitive closure of all libraries it 214 * Add [exportedLibrary] (and the transitive closure of all libraries it
174 * exports) to the dependency table ([PrelinkedLibrary.dependencies]). 215 * exports) to the dependency table ([PrelinkedLibrary.dependencies]).
175 */ 216 */
176 void addTransitiveExportClosure(LibraryElement exportedLibrary) { 217 void addTransitiveExportClosure(LibraryElement exportedLibrary) {
177 if (librariesAddedToTransitiveExportClosure.add(exportedLibrary)) { 218 if (librariesAddedToTransitiveExportClosure.add(exportedLibrary)) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 b.uri = importElement.uri; 421 b.uri = importElement.uri;
381 } 422 }
382 addTransitiveExportClosure(importElement.importedLibrary); 423 addTransitiveExportClosure(importElement.importedLibrary);
383 prelinkedImports.add(serializeDependency(importElement.importedLibrary)); 424 prelinkedImports.add(serializeDependency(importElement.importedLibrary));
384 return b; 425 return b;
385 } 426 }
386 427
387 /** 428 /**
388 * Serialize the whole library element into a [PrelinkedLibrary]. Should be 429 * Serialize the whole library element into a [PrelinkedLibrary]. Should be
389 * called exactly once for each instance of [_LibrarySerializer]. 430 * called exactly once for each instance of [_LibrarySerializer].
431 *
432 * The unlinked compilation units are stored in [unlinkedUnits], and their
433 * absolute URIs are stored in [unitUris].
390 */ 434 */
391 PrelinkedLibraryBuilder serializeLibrary() { 435 PrelinkedLibraryBuilder serializeLibrary() {
392 PrelinkedLibraryBuilder pb = new PrelinkedLibraryBuilder(ctx); 436 PrelinkedLibraryBuilder pb = new PrelinkedLibraryBuilder(ctx);
393 addCompilationUnitElements(libraryElement.definingCompilationUnit, 0); 437 addCompilationUnitElements(libraryElement.definingCompilationUnit, 0);
394 for (int i = 0; i < libraryElement.parts.length; i++) { 438 for (int i = 0; i < libraryElement.parts.length; i++) {
395 addCompilationUnitElements(libraryElement.parts[i], i + 1); 439 addCompilationUnitElements(libraryElement.parts[i], i + 1);
396 } 440 }
397 pb.units = units; 441 pb.units = prelinkedUnits;
398 pb.dependencies = dependencies; 442 pb.dependencies = dependencies;
399 pb.importDependencies = prelinkedImports; 443 pb.importDependencies = prelinkedImports;
400 return pb; 444 return pb;
401 } 445 }
402 446
403 /** 447 /**
404 * Serialize the given [parameter] into an [UnlinkedParam]. 448 * Serialize the given [parameter] into an [UnlinkedParam].
405 */ 449 */
406 UnlinkedParamBuilder serializeParam(ParameterElement parameter) { 450 UnlinkedParamBuilder serializeParam(ParameterElement parameter) {
407 UnlinkedParamBuilder b = new UnlinkedParamBuilder(ctx); 451 UnlinkedParamBuilder b = new UnlinkedParamBuilder(ctx);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(ctx); 600 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(ctx);
557 b.name = variable.name; 601 b.name = variable.name;
558 b.type = serializeTypeRef(variable.type, variable); 602 b.type = serializeTypeRef(variable.type, variable);
559 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement; 603 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement;
560 b.isFinal = variable.isFinal; 604 b.isFinal = variable.isFinal;
561 b.isConst = variable.isConst; 605 b.isConst = variable.isConst;
562 b.hasImplicitType = variable.hasImplicitType; 606 b.hasImplicitType = variable.hasImplicitType;
563 return b; 607 return b;
564 } 608 }
565 } 609 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698