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

Unified Diff: pkg/compiler/lib/src/serialization/element_serialization.dart

Issue 2060183002: Serialize metadata (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comment. Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/patch_parser.dart ('k') | pkg/compiler/lib/src/serialization/equivalence.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/serialization/element_serialization.dart
diff --git a/pkg/compiler/lib/src/serialization/element_serialization.dart b/pkg/compiler/lib/src/serialization/element_serialization.dart
index b115ae0ed0f15e4f153bda21c9a48decc1d5167e..8a2ad83eab4a14c05c820c4d7ba58447fbf2e8d2 100644
--- a/pkg/compiler/lib/src/serialization/element_serialization.dart
+++ b/pkg/compiler/lib/src/serialization/element_serialization.dart
@@ -120,6 +120,23 @@ class SerializerUtil {
}
}
+ /// Serialize the metadata of [element] into [encoder].
+ static void serializeMetadata(Element element, ObjectEncoder encoder) {
+ if (element.metadata.isNotEmpty) {
+ ListEncoder list = encoder.createList(Key.METADATA);
+ for (MetadataAnnotation metadata in element.metadata) {
+ ObjectEncoder object = list.createObject();
+ object.setElement(Key.ELEMENT, metadata.annotatedElement);
+ SourceSpan sourcePosition = metadata.sourcePosition;
+ // TODO(johnniwinther): What is the base URI here?
+ object.setUri(Key.URI, sourcePosition.uri, sourcePosition.uri);
+ object.setInt(Key.OFFSET, sourcePosition.begin);
+ object.setInt(Key.LENGTH, sourcePosition.end - sourcePosition.begin);
+ object.setConstant(Key.CONSTANT, metadata.constant);
+ }
+ }
+ }
+
/// Serialize the parent relation for [element] into [encoder], i.e library,
/// enclosing class, and compilation unit references.
static void serializeParentRelation(Element element, ObjectEncoder encoder) {
@@ -225,6 +242,7 @@ class LibrarySerializer implements ElementSerializer {
void serialize(LibraryElement element, ObjectEncoder encoder,
SerializedElementKind kind) {
+ SerializerUtil.serializeMetadata(element, encoder);
encoder.setUri(
Key.CANONICAL_URI, element.canonicalUri, element.canonicalUri);
encoder.setString(Key.LIBRARY_NAME, element.libraryName);
@@ -252,6 +270,7 @@ class CompilationUnitSerializer implements ElementSerializer {
void serialize(CompilationUnitElement element, ObjectEncoder encoder,
SerializedElementKind kind) {
+ SerializerUtil.serializeMetadata(element, encoder);
encoder.setElement(Key.LIBRARY, element.library);
encoder.setUri(
Key.URI, element.library.canonicalUri, element.script.resourceUri);
@@ -299,6 +318,7 @@ class ClassSerializer implements ElementSerializer {
void serialize(
ClassElement element, ObjectEncoder encoder, SerializedElementKind kind) {
+ SerializerUtil.serializeMetadata(element, encoder);
encoder.setElement(Key.LIBRARY, element.library);
encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit);
encoder.setString(Key.NAME, element.name);
@@ -307,6 +327,7 @@ class ClassSerializer implements ElementSerializer {
encoder.setBool(Key.IS_ABSTRACT, element.isAbstract);
SerializerUtil.serializeMembers(getMembers(element), encoder);
encoder.setBool(Key.IS_PROXY, element.isProxy);
+ encoder.setBool(Key.IS_INJECTED, element.isInjected);
if (kind == SerializedElementKind.ENUM) {
EnumClassElement enumClass = element;
encoder.setElements(Key.FIELDS, enumClass.enumValues);
@@ -368,12 +389,14 @@ class ConstructorSerializer implements ElementSerializer {
if (kind == SerializedElementKind.FORWARDING_CONSTRUCTOR) {
encoder.setElement(Key.ELEMENT, element.definingConstructor);
} else {
+ SerializerUtil.serializeMetadata(element, encoder);
encoder.setType(Key.TYPE, element.type);
encoder.setString(Key.NAME, element.name);
SerializerUtil.serializePosition(element, encoder);
SerializerUtil.serializeParameters(element, encoder);
encoder.setBool(Key.IS_CONST, element.isConst);
encoder.setBool(Key.IS_EXTERNAL, element.isExternal);
+ encoder.setBool(Key.IS_INJECTED, element.isInjected);
if (element.isConst && !element.isFromEnvironmentConstructor) {
ConstantConstructor constantConstructor = element.constantConstructor;
ObjectEncoder constantEncoder = encoder.createObject(Key.CONSTRUCTOR);
@@ -419,10 +442,12 @@ class FieldSerializer implements ElementSerializer {
void serialize(
FieldElement element, ObjectEncoder encoder, SerializedElementKind kind) {
encoder.setString(Key.NAME, element.name);
+ SerializerUtil.serializeMetadata(element, encoder);
SerializerUtil.serializePosition(element, encoder);
encoder.setType(Key.TYPE, element.type);
encoder.setBool(Key.IS_FINAL, element.isFinal);
encoder.setBool(Key.IS_CONST, element.isConst);
+ encoder.setBool(Key.IS_INJECTED, element.isInjected);
ConstantExpression constant = element.constant;
if (constant != null) {
encoder.setConstant(Key.CONSTANT, constant);
@@ -469,6 +494,7 @@ class FunctionSerializer implements ElementSerializer {
void serialize(FunctionElement element, ObjectEncoder encoder,
SerializedElementKind kind) {
encoder.setString(Key.NAME, element.name);
+ SerializerUtil.serializeMetadata(element, encoder);
SerializerUtil.serializePosition(element, encoder);
SerializerUtil.serializeParameters(element, encoder);
encoder.setType(Key.TYPE, element.type);
@@ -479,6 +505,7 @@ class FunctionSerializer implements ElementSerializer {
SerializerUtil.serializeParentRelation(element, encoder);
encoder.setBool(Key.IS_EXTERNAL, element.isExternal);
encoder.setBool(Key.IS_ABSTRACT, element.isAbstract);
+ encoder.setBool(Key.IS_INJECTED, element.isInjected);
if (element.isLocal) {
LocalFunctionElement localFunction = element;
encoder.setElement(
@@ -500,6 +527,7 @@ class TypedefSerializer implements ElementSerializer {
void serialize(TypedefElement element, ObjectEncoder encoder,
SerializedElementKind kind) {
encoder.setString(Key.NAME, element.name);
+ SerializerUtil.serializeMetadata(element, encoder);
SerializerUtil.serializePosition(element, encoder);
encoder.setType(Key.ALIAS, element.alias);
encoder.setElement(Key.LIBRARY, element.library);
@@ -522,6 +550,7 @@ class TypeVariableSerializer implements ElementSerializer {
SerializedElementKind kind) {
encoder.setElement(Key.TYPE_DECLARATION, element.typeDeclaration);
encoder.setString(Key.NAME, element.name);
+ SerializerUtil.serializeMetadata(element, encoder);
SerializerUtil.serializePosition(element, encoder);
encoder.setType(Key.TYPE, element.type);
encoder.setInt(Key.INDEX, element.index);
@@ -545,6 +574,7 @@ class ParameterSerializer implements ElementSerializer {
SerializedElementKind kind) {
encoder.setElement(Key.FUNCTION, element.functionDeclaration);
encoder.setString(Key.NAME, element.name);
+ SerializerUtil.serializeMetadata(element, encoder);
SerializerUtil.serializePosition(element, encoder);
encoder.setType(Key.TYPE, element.type);
encoder.setBool(Key.IS_OPTIONAL, element.isOptional);
@@ -573,6 +603,7 @@ class LocalVariableSerializer implements ElementSerializer {
void serialize(LocalVariableElement element, ObjectEncoder encoder,
SerializedElementKind kind) {
encoder.setString(Key.NAME, element.name);
+ SerializerUtil.serializeMetadata(element, encoder);
SerializerUtil.serializePosition(element, encoder);
encoder.setType(Key.TYPE, element.type);
encoder.setBool(Key.IS_FINAL, element.isFinal);
@@ -597,6 +628,7 @@ class ImportSerializer implements ElementSerializer {
void serialize(ImportElement element, ObjectEncoder encoder,
SerializedElementKind kind) {
+ SerializerUtil.serializeMetadata(element, encoder);
encoder.setElement(Key.LIBRARY, element.library);
encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit);
encoder.setElement(Key.LIBRARY_DEPENDENCY, element.importedLibrary);
@@ -621,6 +653,7 @@ class ExportSerializer implements ElementSerializer {
void serialize(ExportElement element, ObjectEncoder encoder,
SerializedElementKind kind) {
+ SerializerUtil.serializeMetadata(element, encoder);
encoder.setElement(Key.LIBRARY, element.library);
encoder.setElement(Key.COMPILATION_UNIT, element.compilationUnit);
encoder.setElement(Key.LIBRARY_DEPENDENCY, element.exportedLibrary);
« no previous file with comments | « pkg/compiler/lib/src/patch_parser.dart ('k') | pkg/compiler/lib/src/serialization/equivalence.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698