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

Unified Diff: pkg/analyzer/lib/src/summary/summarize_elements.dart

Issue 1530503002: Organize summary declarations by unit rather than by library. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/summary/format.dart ('k') | pkg/analyzer/test/src/summary/summary_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/summary/summarize_elements.dart
diff --git a/pkg/analyzer/lib/src/summary/summarize_elements.dart b/pkg/analyzer/lib/src/summary/summarize_elements.dart
index a0777d439b8d51c06b1dd8ef26aec8bf62d2631b..54f8a37930b1c59dc9ad1b25c67cc701cb5e9774 100644
--- a/pkg/analyzer/lib/src/summary/summarize_elements.dart
+++ b/pkg/analyzer/lib/src/summary/summarize_elements.dart
@@ -35,35 +35,9 @@ class _LibrarySerializer {
final TypeProvider typeProvider;
/**
- * List of objects which should be written to [UnlinkedLibrary.classes].
+ * List of objects which should be written to [PrelinkedLibrary.units].
*/
- final List<UnlinkedClassBuilder> classes = <UnlinkedClassBuilder>[];
-
- /**
- * List of objects which should be written to [UnlinkedLibrary.enums].
- */
- final List<UnlinkedEnumBuilder> enums = <UnlinkedEnumBuilder>[];
-
- /**
- * List of objects which should be written to [UnlinkedLibrary.executables].
- */
- final List<UnlinkedExecutableBuilder> executables =
- <UnlinkedExecutableBuilder>[];
-
- /**
- * List of objects which should be written to [UnlinkedLibrary.typedefs].
- */
- final List<UnlinkedTypedefBuilder> typedefs = <UnlinkedTypedefBuilder>[];
-
- /**
- * List of objects which should be written to [UnlinkedLibrary.units].
- */
- final List<UnlinkedUnitBuilder> units = <UnlinkedUnitBuilder>[];
-
- /**
- * List of objects which should be written to [UnlinkedLibrary.variables].
- */
- final List<UnlinkedVariableBuilder> variables = <UnlinkedVariableBuilder>[];
+ final List<PrelinkedUnitBuilder> units = <PrelinkedUnitBuilder>[];
/**
* Map from [LibraryElement] to the index of the entry in the "dependency
@@ -79,12 +53,6 @@ class _LibrarySerializer {
<PrelinkedDependencyBuilder>[];
/**
- * The unlinked portion of the "imports table". This is the list of objects
- * which should be written to [UnlinkedLibrary.imports].
- */
- final List<UnlinkedImportBuilder> unlinkedImports = <UnlinkedImportBuilder>[];
-
- /**
* The prelinked portion of the "imports table". This is the list of ints
* which should be written to [PrelinkedLibrary.imports].
*/
@@ -169,33 +137,46 @@ class _LibrarySerializer {
*/
void addCompilationUnitElements(CompilationUnitElement element, int unitNum) {
UnlinkedUnitBuilder b = new UnlinkedUnitBuilder(ctx);
- if (element.uri != null) {
- b.uri = element.uri;
- }
- units.add(b);
- for (ClassElement cls in element.types) {
- classes.add(serializeClass(cls, unitNum));
- }
- for (ClassElement e in element.enums) {
- enums.add(serializeEnum(e, unitNum));
- }
- for (FunctionTypeAliasElement type in element.functionTypeAliases) {
- typedefs.add(serializeTypedef(type, unitNum));
- }
- for (FunctionElement executable in element.functions) {
- executables.add(serializeExecutable(executable, unitNum));
+ if (unitNum == 0) {
+ // TODO(paulberry): we need to figure out a way to record library, part,
Brian Wilkerson 2015/12/14 23:44:35 We might have discussed this already, but if not i
Paul Berry 2015/12/15 00:29:56 Agreed, that would be a good discussion to have.
+ // import, and export declarations that appear in non-defining
+ // compilation units (even though such declarations are prohibited by the
+ // language), so that if the user makes code changes that cause a
+ // non-defining compilation unit to become a defining compilation unit,
+ // we can create a correct summary by simply re-linking.
+ if (libraryElement.name.isNotEmpty) {
+ b.libraryName = libraryElement.name;
+ }
+ b.exports = libraryElement.exports.map(serializeExport).toList();
+ b.imports = libraryElement.imports.map(serializeImport).toList();
+ b.parts = libraryElement.parts
+ .map(
+ (CompilationUnitElement e) => encodeUnlinkedPart(ctx, uri: e.uri))
+ .toList();
}
+ b.classes = element.types.map(serializeClass).toList();
+ b.enums = element.enums.map(serializeEnum).toList();
+ b.typedefs = element.functionTypeAliases.map(serializeTypedef).toList();
+ List<UnlinkedExecutableBuilder> executables =
+ element.functions.map(serializeExecutable).toList();
for (PropertyAccessorElement accessor in element.accessors) {
if (!accessor.isSynthetic) {
- executables.add(serializeExecutable(accessor, unitNum));
- } else if (accessor.isGetter) {
+ executables.add(serializeExecutable(accessor));
+ }
+ }
+ b.executables = executables;
+ List<UnlinkedVariableBuilder> variables = <UnlinkedVariableBuilder>[];
+ for (PropertyAccessorElement accessor in element.accessors) {
+ if (accessor.isSynthetic && accessor.isGetter) {
PropertyInducingElement variable = accessor.variable;
if (variable != null) {
assert(!variable.isSynthetic);
- variables.add(serializeVariable(variable, unitNum));
+ variables.add(serializeVariable(variable));
}
}
}
+ b.variables = variables;
+ units.add(encodePrelinkedUnit(ctx, unlinked: b));
}
/**
@@ -242,13 +223,11 @@ class _LibrarySerializer {
}
/**
- * Serialize the given [classElement], which exists in the unit numbered
- * [unitNum], creating an [UnlinkedClass].
+ * Serialize the given [classElement], creating an [UnlinkedClass].
*/
- UnlinkedClassBuilder serializeClass(ClassElement classElement, int unitNum) {
+ UnlinkedClassBuilder serializeClass(ClassElement classElement) {
UnlinkedClassBuilder b = new UnlinkedClassBuilder(ctx);
b.name = classElement.name;
- b.unit = unitNum;
b.typeParameters =
classElement.typeParameters.map(serializeTypeParam).toList();
if (classElement.supertype != null && !classElement.supertype.isObject) {
@@ -264,19 +243,19 @@ class _LibrarySerializer {
List<UnlinkedExecutableBuilder> executables = <UnlinkedExecutableBuilder>[];
for (ConstructorElement executable in classElement.constructors) {
if (!executable.isSynthetic) {
- executables.add(serializeExecutable(executable, 0));
+ executables.add(serializeExecutable(executable));
}
}
for (MethodElement executable in classElement.methods) {
- executables.add(serializeExecutable(executable, 0));
+ executables.add(serializeExecutable(executable));
}
for (PropertyAccessorElement accessor in classElement.accessors) {
if (!accessor.isSynthetic) {
- executables.add(serializeExecutable(accessor, 0));
+ executables.add(serializeExecutable(accessor));
} else if (accessor.isGetter) {
PropertyInducingElement field = accessor.variable;
if (field != null && !field.isSynthetic) {
- fields.add(serializeVariable(field, 0));
+ fields.add(serializeVariable(field));
}
}
}
@@ -340,10 +319,9 @@ class _LibrarySerializer {
}
/**
- * Serialize the given [enumElement], which exists in the unit numbered
- * [unitNum], creating an [UnlinkedEnum].
+ * Serialize the given [enumElement], creating an [UnlinkedEnum].
*/
- UnlinkedEnumBuilder serializeEnum(ClassElement enumElement, int unitNum) {
+ UnlinkedEnumBuilder serializeEnum(ClassElement enumElement) {
UnlinkedEnumBuilder b = new UnlinkedEnumBuilder(ctx);
b.name = enumElement.name;
List<UnlinkedEnumValueBuilder> values = <UnlinkedEnumValueBuilder>[];
@@ -353,23 +331,16 @@ class _LibrarySerializer {
}
}
b.values = values;
- b.unit = unitNum;
return b;
}
/**
- * Serialize the given [executableElement], which exists in the unit numbered
- * [unitNum], creating an [UnlinkedExecutable]. For elements declared inside
- * a class, [unitNum] should be zero.
+ * Serialize the given [executableElement], creating an [UnlinkedExecutable].
*/
UnlinkedExecutableBuilder serializeExecutable(
- ExecutableElement executableElement, int unitNum) {
- if (executableElement.enclosingElement is ClassElement) {
- assert(unitNum == 0);
- }
+ ExecutableElement executableElement) {
UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder(ctx);
b.name = executableElement.name;
- b.unit = unitNum;
if (!executableElement.type.returnType.isVoid) {
b.returnType = serializeTypeRef(
executableElement.type.returnType, executableElement);
@@ -409,11 +380,10 @@ class _LibrarySerializer {
}
/**
- * Serialize the given [importElement], adding information about it to
- * the [unlinkedImports] and [prelinkedImports] lists.
+ * Serialize the given [importElement] yielding an [UnlinkedImportBuilder].
+ * Also, add pre-linked information about it to the [prelinkedImports] list.
*/
- void serializeImport(ImportElement importElement) {
- assert(unlinkedImports.length == prelinkedImports.length);
+ UnlinkedImportBuilder serializeImport(ImportElement importElement) {
UnlinkedImportBuilder b = new UnlinkedImportBuilder(ctx);
b.isDeferred = importElement.isDeferred;
b.offset = importElement.nameOffset;
@@ -432,8 +402,8 @@ class _LibrarySerializer {
b.uri = importElement.uri;
}
addTransitiveExportClosure(importElement.importedLibrary);
- unlinkedImports.add(b);
prelinkedImports.add(serializeDependency(importElement.importedLibrary));
+ return b;
}
/**
@@ -443,26 +413,13 @@ class _LibrarySerializer {
PrelinkedLibraryBuilder serializeLibrary() {
UnlinkedLibraryBuilder ub = new UnlinkedLibraryBuilder(ctx);
PrelinkedLibraryBuilder pb = new PrelinkedLibraryBuilder(ctx);
- if (libraryElement.name.isNotEmpty) {
- ub.name = libraryElement.name;
- }
- for (ImportElement importElement in libraryElement.imports) {
- serializeImport(importElement);
- }
- ub.exports = libraryElement.exports.map(serializeExport).toList();
addCompilationUnitElements(libraryElement.definingCompilationUnit, 0);
for (int i = 0; i < libraryElement.parts.length; i++) {
addCompilationUnitElements(libraryElement.parts[i], i + 1);
}
- ub.classes = classes;
- ub.enums = enums;
- ub.executables = executables;
- ub.imports = unlinkedImports;
ub.prefixes = prefixes;
ub.references = unlinkedReferences;
- ub.typedefs = typedefs;
- ub.units = units;
- ub.variables = variables;
+ pb.units = units;
pb.unlinked = ub;
pb.dependencies = dependencies;
pb.importDependencies = prelinkedImports;
@@ -503,14 +460,12 @@ class _LibrarySerializer {
}
/**
- * Serialize the given [typedefElement], which exists in the unit numbered
- * [unitNum], creating an [UnlinkedTypedef].
+ * Serialize the given [typedefElement], creating an [UnlinkedTypedef].
*/
UnlinkedTypedefBuilder serializeTypedef(
- FunctionTypeAliasElement typedefElement, int unitNum) {
+ FunctionTypeAliasElement typedefElement) {
UnlinkedTypedefBuilder b = new UnlinkedTypedefBuilder(ctx);
b.name = typedefElement.name;
- b.unit = unitNum;
b.typeParameters =
typedefElement.typeParameters.map(serializeTypeParam).toList();
if (!typedefElement.returnType.isVoid) {
@@ -608,18 +563,11 @@ class _LibrarySerializer {
}
/**
- * Serialize the given [variable], which exists in the unit numbered
- * [unitNum], creating an [UnlinkedVariable]. For variables declared inside
- * a class (i.e. fields), [unitNum] should be zero.
+ * Serialize the given [variable], creating an [UnlinkedVariable].
*/
- UnlinkedVariableBuilder serializeVariable(
- PropertyInducingElement variable, int unitNum) {
- if (variable.enclosingElement is ClassElement) {
- assert(unitNum == 0);
- }
+ UnlinkedVariableBuilder serializeVariable(PropertyInducingElement variable) {
UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(ctx);
b.name = variable.name;
- b.unit = unitNum;
b.type = serializeTypeRef(variable.type, variable);
b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement;
b.isFinal = variable.isFinal;
« no previous file with comments | « pkg/analyzer/lib/src/summary/format.dart ('k') | pkg/analyzer/test/src/summary/summary_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698