OLD | NEW |
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/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
9 import 'package:analyzer/dart/element/type.dart' show DartType; | 9 import 'package:analyzer/dart/element/type.dart' show DartType; |
10 import 'package:analyzer/src/summary/format.dart'; | 10 import 'package:analyzer/src/summary/format.dart'; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 * See [UnlinkedConstBuilder.strings]. | 95 * See [UnlinkedConstBuilder.strings]. |
96 */ | 96 */ |
97 final List<String> strings = <String>[]; | 97 final List<String> strings = <String>[]; |
98 | 98 |
99 /** | 99 /** |
100 * See [UnlinkedConstBuilder.references]. | 100 * See [UnlinkedConstBuilder.references]. |
101 */ | 101 */ |
102 final List<EntityRefBuilder> references = <EntityRefBuilder>[]; | 102 final List<EntityRefBuilder> references = <EntityRefBuilder>[]; |
103 | 103 |
104 /** | 104 /** |
105 * Return `true` if a constructor initializer expression is being serialized | 105 * Return `true` if the given [name] is a parameter reference. |
106 * and the given [name] is a constructor parameter reference. | |
107 */ | 106 */ |
108 bool isConstructorParameterName(String name); | 107 bool isParameterName(String name); |
109 | 108 |
110 /** | 109 /** |
111 * Serialize the given [expr] expression into this serializer state. | 110 * Serialize the given [expr] expression into this serializer state. |
112 */ | 111 */ |
113 void serialize(Expression expr) { | 112 void serialize(Expression expr) { |
114 try { | 113 try { |
115 if (expr is NamedExpression) { | 114 if (expr is NamedExpression) { |
116 NamedExpression namedExpression = expr; | 115 NamedExpression namedExpression = expr; |
117 name = namedExpression.name.label.name; | 116 name = namedExpression.name.label.name; |
118 expr = namedExpression.expression; | 117 expr = namedExpression.expression; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 operations.add(UnlinkedConstOperation.pushFalse); | 259 operations.add(UnlinkedConstOperation.pushFalse); |
261 } | 260 } |
262 } else if (expr is StringLiteral) { | 261 } else if (expr is StringLiteral) { |
263 _serializeString(expr); | 262 _serializeString(expr); |
264 } else if (expr is SymbolLiteral) { | 263 } else if (expr is SymbolLiteral) { |
265 strings.add(expr.components.map((token) => token.lexeme).join('.')); | 264 strings.add(expr.components.map((token) => token.lexeme).join('.')); |
266 operations.add(UnlinkedConstOperation.makeSymbol); | 265 operations.add(UnlinkedConstOperation.makeSymbol); |
267 } else if (expr is NullLiteral) { | 266 } else if (expr is NullLiteral) { |
268 operations.add(UnlinkedConstOperation.pushNull); | 267 operations.add(UnlinkedConstOperation.pushNull); |
269 } else if (expr is Identifier) { | 268 } else if (expr is Identifier) { |
270 if (expr is SimpleIdentifier && isConstructorParameterName(expr.name)) { | 269 if (expr is SimpleIdentifier && isParameterName(expr.name)) { |
271 strings.add(expr.name); | 270 strings.add(expr.name); |
272 operations.add(UnlinkedConstOperation.pushConstructorParameter); | 271 operations.add(UnlinkedConstOperation.pushParameter); |
273 } else { | 272 } else { |
274 references.add(serializeIdentifier(expr)); | 273 references.add(serializeIdentifier(expr)); |
275 operations.add(UnlinkedConstOperation.pushReference); | 274 operations.add(UnlinkedConstOperation.pushReference); |
276 } | 275 } |
277 } else if (expr is InstanceCreationExpression) { | 276 } else if (expr is InstanceCreationExpression) { |
278 if (!expr.isConst) { | 277 if (!expr.isConst) { |
279 isValidConst = false; | 278 isValidConst = false; |
280 } | 279 } |
281 TypeName typeName = expr.constructorName.type; | 280 TypeName typeName = expr.constructorName.type; |
282 serializeInstanceCreation( | 281 serializeInstanceCreation( |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 expr = (expr as PrefixedIdentifier).prefix; | 614 expr = (expr as PrefixedIdentifier).prefix; |
616 } else if (expr is PropertyAccess) { | 615 } else if (expr is PropertyAccess) { |
617 expr = (expr as PropertyAccess).target; | 616 expr = (expr as PropertyAccess).target; |
618 } else { | 617 } else { |
619 return false; | 618 return false; |
620 } | 619 } |
621 } | 620 } |
622 return false; | 621 return false; |
623 } | 622 } |
624 } | 623 } |
OLD | NEW |