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

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

Issue 1672413002: Add summary support for annotations. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 library serialization.summarize_const_expr; 5 library serialization.summarize_const_expr;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/scanner.dart'; 8 import 'package:analyzer/src/generated/scanner.dart';
9 import 'package:analyzer/src/summary/format.dart'; 9 import 'package:analyzer/src/summary/format.dart';
10 import 'package:analyzer/src/summary/idl.dart'; 10 import 'package:analyzer/src/summary/idl.dart';
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 _serializeString(expr); 58 _serializeString(expr);
59 } else if (expr is SymbolLiteral) { 59 } else if (expr is SymbolLiteral) {
60 strings.add(expr.components.map((token) => token.lexeme).join('.')); 60 strings.add(expr.components.map((token) => token.lexeme).join('.'));
61 operations.add(UnlinkedConstOperation.makeSymbol); 61 operations.add(UnlinkedConstOperation.makeSymbol);
62 } else if (expr is NullLiteral) { 62 } else if (expr is NullLiteral) {
63 operations.add(UnlinkedConstOperation.pushNull); 63 operations.add(UnlinkedConstOperation.pushNull);
64 } else if (expr is Identifier) { 64 } else if (expr is Identifier) {
65 references.add(serializeIdentifier(expr)); 65 references.add(serializeIdentifier(expr));
66 operations.add(UnlinkedConstOperation.pushReference); 66 operations.add(UnlinkedConstOperation.pushReference);
67 } else if (expr is InstanceCreationExpression) { 67 } else if (expr is InstanceCreationExpression) {
68 _serializeInstanceCreation(expr); 68 serializeInstanceCreation(
69 serializeConstructorName(
70 expr.constructorName.type, expr.constructorName.name),
71 expr.argumentList);
69 } else if (expr is ListLiteral) { 72 } else if (expr is ListLiteral) {
70 _serializeListLiteral(expr); 73 _serializeListLiteral(expr);
71 } else if (expr is MapLiteral) { 74 } else if (expr is MapLiteral) {
72 _serializeMapLiteral(expr); 75 _serializeMapLiteral(expr);
73 } else if (expr is MethodInvocation) { 76 } else if (expr is MethodInvocation) {
74 String name = expr.methodName.name; 77 String name = expr.methodName.name;
75 if (name != 'identical') { 78 if (name != 'identical') {
76 throw new _ConstExprSerializationError( 79 throw new _ConstExprSerializationError(
77 'Only "identity" function invocation is allowed.'); 80 'Only "identity" function invocation is allowed.');
78 } 81 }
(...skipping 23 matching lines...) Expand all
102 operations.add(UnlinkedConstOperation.pushReference); 105 operations.add(UnlinkedConstOperation.pushReference);
103 } 106 }
104 } else if (expr is ParenthesizedExpression) { 107 } else if (expr is ParenthesizedExpression) {
105 serialize(expr.expression); 108 serialize(expr.expression);
106 } else { 109 } else {
107 throw new _ConstExprSerializationError('Unknown expression type: $expr'); 110 throw new _ConstExprSerializationError('Unknown expression type: $expr');
108 } 111 }
109 } 112 }
110 113
111 /** 114 /**
112 * Return [EntityRefBuilder] that corresponds to the given [constructor]. 115 * Serialize the given [annotation] into this serializer state.
113 */ 116 */
114 EntityRefBuilder serializeConstructorName(ConstructorName constructor); 117 void serializeAnnotation(Annotation annotation);
118
119 /**
120 * Return [EntityRefBuilder] that corresponds to the constructor having name
121 * [name] in the class identified by [type].
122 */
123 EntityRefBuilder serializeConstructorName(
124 TypeName type, SimpleIdentifier name);
115 125
116 /** 126 /**
117 * Return [EntityRefBuilder] that corresponds to the given [identifier]. 127 * Return [EntityRefBuilder] that corresponds to the given [identifier].
118 */ 128 */
119 EntityRefBuilder serializeIdentifier(Identifier identifier); 129 EntityRefBuilder serializeIdentifier(Identifier identifier);
120 130
121 /** 131 /**
122 * Return [EntityRefBuilder] that corresponds to the given [access]. 132 * Return [EntityRefBuilder] that corresponds to the given [access].
123 */ 133 */
124 EntityRefBuilder serializePropertyAccess(PropertyAccess access); 134 EntityRefBuilder serializePropertyAccess(PropertyAccess access);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 operations.add(UnlinkedConstOperation.greaterEqual); 212 operations.add(UnlinkedConstOperation.greaterEqual);
203 } else if (operator == TokenType.LT_EQ) { 213 } else if (operator == TokenType.LT_EQ) {
204 operations.add(UnlinkedConstOperation.lessEqual); 214 operations.add(UnlinkedConstOperation.lessEqual);
205 } else if (operator == TokenType.PERCENT) { 215 } else if (operator == TokenType.PERCENT) {
206 operations.add(UnlinkedConstOperation.modulo); 216 operations.add(UnlinkedConstOperation.modulo);
207 } else { 217 } else {
208 throw new _ConstExprSerializationError('Unknown operator: $operator'); 218 throw new _ConstExprSerializationError('Unknown operator: $operator');
209 } 219 }
210 } 220 }
211 221
212 void _serializeInstanceCreation(InstanceCreationExpression expr) { 222 void serializeInstanceCreation(
213 ConstructorName constructor = expr.constructorName; 223 EntityRefBuilder constructor, ArgumentList argumentList) {
214 List<Expression> arguments = expr.argumentList.arguments; 224 List<Expression> arguments = argumentList.arguments;
215 // Serialize the arguments. 225 // Serialize the arguments.
216 List<String> argumentNames = <String>[]; 226 List<String> argumentNames = <String>[];
217 arguments.forEach((arg) { 227 arguments.forEach((arg) {
218 if (arg is NamedExpression) { 228 if (arg is NamedExpression) {
219 argumentNames.add(arg.name.label.name); 229 argumentNames.add(arg.name.label.name);
220 serialize(arg.expression); 230 serialize(arg.expression);
221 } else { 231 } else {
222 serialize(arg); 232 serialize(arg);
223 } 233 }
224 }); 234 });
225 // Add the op-code and numbers of named and positional arguments. 235 // Add the op-code and numbers of named and positional arguments.
226 operations.add(UnlinkedConstOperation.invokeConstructor); 236 operations.add(UnlinkedConstOperation.invokeConstructor);
227 ints.add(argumentNames.length); 237 ints.add(argumentNames.length);
228 strings.addAll(argumentNames); 238 strings.addAll(argumentNames);
229 ints.add(arguments.length - argumentNames.length); 239 ints.add(arguments.length - argumentNames.length);
230 // Serialize the reference. 240 // Serialize the reference.
231 references.add(serializeConstructorName(constructor)); 241 references.add(constructor);
232 } 242 }
233 243
234 void _serializeListLiteral(ListLiteral expr) { 244 void _serializeListLiteral(ListLiteral expr) {
235 List<Expression> elements = expr.elements; 245 List<Expression> elements = expr.elements;
236 elements.forEach(serialize); 246 elements.forEach(serialize);
237 ints.add(elements.length); 247 ints.add(elements.length);
238 if (expr.typeArguments != null && 248 if (expr.typeArguments != null &&
239 expr.typeArguments.arguments.length == 1) { 249 expr.typeArguments.arguments.length == 1) {
240 references.add(serializeType(expr.typeArguments.arguments[0])); 250 references.add(serializeType(expr.typeArguments.arguments[0]));
241 operations.add(UnlinkedConstOperation.makeTypedList); 251 operations.add(UnlinkedConstOperation.makeTypedList);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 * Error that describes a problem during a constant expression serialization. 317 * Error that describes a problem during a constant expression serialization.
308 */ 318 */
309 class _ConstExprSerializationError { 319 class _ConstExprSerializationError {
310 final String message; 320 final String message;
311 321
312 _ConstExprSerializationError(this.message); 322 _ConstExprSerializationError(this.message);
313 323
314 @override 324 @override
315 String toString() => message; 325 String toString() => message;
316 } 326 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_ast.dart ('k') | pkg/analyzer/lib/src/summary/summarize_elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698