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

Side by Side Diff: pkg/compiler/lib/src/serialization/element_serialization.dart

Issue 2065413002: Serialize and process patch metadata (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: 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 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 dart2js.serialization.elements; 5 library dart2js.serialization.elements;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../constants/constructors.dart'; 8 import '../constants/constructors.dart';
9 import '../constants/expressions.dart'; 9 import '../constants/expressions.dart';
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 115 }
116 int length = position.end - position.begin; 116 int length = position.end - position.begin;
117 if (element.name.length != length) { 117 if (element.name.length != length) {
118 encoder.setInt(Key.LENGTH, length); 118 encoder.setInt(Key.LENGTH, length);
119 } 119 }
120 } 120 }
121 } 121 }
122 122
123 /// Serialize the metadata of [element] into [encoder]. 123 /// Serialize the metadata of [element] into [encoder].
124 static void serializeMetadata(Element element, ObjectEncoder encoder) { 124 static void serializeMetadata(Element element, ObjectEncoder encoder) {
125 ListEncoder list;
126
127 void encodeAnnotation(MetadataAnnotation metadata) {
128 ObjectEncoder object = list.createObject();
129 object.setElement(Key.ELEMENT, metadata.annotatedElement);
130 SourceSpan sourcePosition = metadata.sourcePosition;
131 // TODO(johnniwinther): What is the base URI here?
132 object.setUri(Key.URI, sourcePosition.uri, sourcePosition.uri);
133 object.setInt(Key.OFFSET, sourcePosition.begin);
134 object.setInt(Key.LENGTH, sourcePosition.end - sourcePosition.begin);
135 object.setConstant(Key.CONSTANT, metadata.constant);
136 }
137
125 if (element.metadata.isNotEmpty) { 138 if (element.metadata.isNotEmpty) {
126 ListEncoder list = encoder.createList(Key.METADATA); 139 list = encoder.createList(Key.METADATA);
127 for (MetadataAnnotation metadata in element.metadata) { 140 element.metadata.forEach(encodeAnnotation);
128 ObjectEncoder object = list.createObject(); 141 }
129 object.setElement(Key.ELEMENT, metadata.annotatedElement); 142 if (element.isPatched && element.implementation.metadata.isNotEmpty) {
130 SourceSpan sourcePosition = metadata.sourcePosition; 143 list ??= encoder.createList(Key.METADATA);
131 // TODO(johnniwinther): What is the base URI here? 144 element.implementation.metadata.forEach(encodeAnnotation);
132 object.setUri(Key.URI, sourcePosition.uri, sourcePosition.uri);
133 object.setInt(Key.OFFSET, sourcePosition.begin);
134 object.setInt(Key.LENGTH, sourcePosition.end - sourcePosition.begin);
135 object.setConstant(Key.CONSTANT, metadata.constant);
136 }
137 } 145 }
138 } 146 }
139 147
140 /// Serialize the parent relation for [element] into [encoder], i.e library, 148 /// Serialize the parent relation for [element] into [encoder], i.e library,
141 /// enclosing class, and compilation unit references. 149 /// enclosing class, and compilation unit references.
142 static void serializeParentRelation(Element element, ObjectEncoder encoder) { 150 static void serializeParentRelation(Element element, ObjectEncoder encoder) {
143 if (element.enclosingClass != null) { 151 if (element.enclosingClass != null) {
144 encoder.setElement(Key.CLASS, element.enclosingClass); 152 encoder.setElement(Key.CLASS, element.enclosingClass);
145 if (element.enclosingClass.declaration.compilationUnit != 153 if (element.enclosingClass.declaration.compilationUnit !=
146 element.compilationUnit) { 154 element.compilationUnit) {
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 return new LocalVariableElementZ(decoder); 772 return new LocalVariableElementZ(decoder);
765 case SerializedElementKind.EXTERNAL_LIBRARY: 773 case SerializedElementKind.EXTERNAL_LIBRARY:
766 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER: 774 case SerializedElementKind.EXTERNAL_LIBRARY_MEMBER:
767 case SerializedElementKind.EXTERNAL_CLASS_MEMBER: 775 case SerializedElementKind.EXTERNAL_CLASS_MEMBER:
768 case SerializedElementKind.EXTERNAL_CONSTRUCTOR: 776 case SerializedElementKind.EXTERNAL_CONSTRUCTOR:
769 break; 777 break;
770 } 778 }
771 throw new UnsupportedError("Unexpected element kind '${elementKind}."); 779 throw new UnsupportedError("Unexpected element kind '${elementKind}.");
772 } 780 }
773 } 781 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/backend.dart ('k') | tests/compiler/dart2js/serialization/equivalence_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698