| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 _serialize(expr.target); | 210 _serialize(expr.target); |
| 211 } | 211 } |
| 212 strings.add(expr.propertyName.name); | 212 strings.add(expr.propertyName.name); |
| 213 operations.add(UnlinkedConstOperation.assignToProperty); | 213 operations.add(UnlinkedConstOperation.assignToProperty); |
| 214 } else if (expr is IndexExpression) { | 214 } else if (expr is IndexExpression) { |
| 215 if (!expr.isCascaded) { | 215 if (!expr.isCascaded) { |
| 216 _serialize(expr.target); | 216 _serialize(expr.target); |
| 217 } | 217 } |
| 218 _serialize(expr.index); | 218 _serialize(expr.index); |
| 219 operations.add(UnlinkedConstOperation.assignToIndex); | 219 operations.add(UnlinkedConstOperation.assignToIndex); |
| 220 } else if (expr is PrefixedIdentifier) { |
| 221 strings.add(expr.prefix.name); |
| 222 operations.add(UnlinkedConstOperation.pushParameter); |
| 223 strings.add(expr.identifier.name); |
| 224 operations.add(UnlinkedConstOperation.assignToProperty); |
| 220 } else { | 225 } else { |
| 221 throw new StateError('Unsupported assignable: $expr'); | 226 throw new StateError('Unsupported assignable: $expr'); |
| 222 } | 227 } |
| 223 } | 228 } |
| 224 | 229 |
| 225 void _pushInt(int value) { | 230 void _pushInt(int value) { |
| 226 assert(value >= 0); | 231 assert(value >= 0); |
| 227 if (value >= (1 << 32)) { | 232 if (value >= (1 << 32)) { |
| 228 int numOfComponents = 0; | 233 int numOfComponents = 0; |
| 229 ints.add(numOfComponents); | 234 ints.add(numOfComponents); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 _serializeString(expr); | 267 _serializeString(expr); |
| 263 } else if (expr is SymbolLiteral) { | 268 } else if (expr is SymbolLiteral) { |
| 264 strings.add(expr.components.map((token) => token.lexeme).join('.')); | 269 strings.add(expr.components.map((token) => token.lexeme).join('.')); |
| 265 operations.add(UnlinkedConstOperation.makeSymbol); | 270 operations.add(UnlinkedConstOperation.makeSymbol); |
| 266 } else if (expr is NullLiteral) { | 271 } else if (expr is NullLiteral) { |
| 267 operations.add(UnlinkedConstOperation.pushNull); | 272 operations.add(UnlinkedConstOperation.pushNull); |
| 268 } else if (expr is Identifier) { | 273 } else if (expr is Identifier) { |
| 269 if (expr is SimpleIdentifier && isParameterName(expr.name)) { | 274 if (expr is SimpleIdentifier && isParameterName(expr.name)) { |
| 270 strings.add(expr.name); | 275 strings.add(expr.name); |
| 271 operations.add(UnlinkedConstOperation.pushParameter); | 276 operations.add(UnlinkedConstOperation.pushParameter); |
| 277 } else if (expr is PrefixedIdentifier && isParameterName(expr.prefix.name)
) { |
| 278 strings.add(expr.prefix.name); |
| 279 operations.add(UnlinkedConstOperation.pushParameter); |
| 280 strings.add(expr.identifier.name); |
| 281 operations.add(UnlinkedConstOperation.extractProperty); |
| 272 } else { | 282 } else { |
| 273 references.add(serializeIdentifier(expr)); | 283 references.add(serializeIdentifier(expr)); |
| 274 operations.add(UnlinkedConstOperation.pushReference); | 284 operations.add(UnlinkedConstOperation.pushReference); |
| 275 } | 285 } |
| 276 } else if (expr is InstanceCreationExpression) { | 286 } else if (expr is InstanceCreationExpression) { |
| 277 if (!expr.isConst) { | 287 if (!expr.isConst) { |
| 278 isValidConst = false; | 288 isValidConst = false; |
| 279 } | 289 } |
| 280 TypeName typeName = expr.constructorName.type; | 290 TypeName typeName = expr.constructorName.type; |
| 281 serializeInstanceCreation( | 291 serializeInstanceCreation( |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 } | 602 } |
| 593 } | 603 } |
| 594 operations.add(UnlinkedConstOperation.concatenate); | 604 operations.add(UnlinkedConstOperation.concatenate); |
| 595 ints.add(interpolation.elements.length); | 605 ints.add(interpolation.elements.length); |
| 596 } | 606 } |
| 597 } | 607 } |
| 598 | 608 |
| 599 /** | 609 /** |
| 600 * Return `true` if the given [expr] is a sequence of identifiers. | 610 * Return `true` if the given [expr] is a sequence of identifiers. |
| 601 */ | 611 */ |
| 602 static bool _isIdentifierSequence(Expression expr) { | 612 bool _isIdentifierSequence(Expression expr) { |
| 603 while (expr != null) { | 613 while (expr != null) { |
| 604 if (expr is SimpleIdentifier) { | 614 if (expr is SimpleIdentifier) { |
| 605 AstNode parent = expr.parent; | 615 AstNode parent = expr.parent; |
| 606 if (parent is MethodInvocation && parent.methodName == expr) { | 616 if (parent is MethodInvocation && parent.methodName == expr) { |
| 607 if (parent.isCascaded) { | 617 if (parent.isCascaded) { |
| 608 return false; | 618 return false; |
| 609 } | 619 } |
| 610 return parent.target == null || _isIdentifierSequence(parent.target); | 620 return parent.target == null || _isIdentifierSequence(parent.target); |
| 611 } | 621 } |
| 622 if (isParameterName(expr.name)) { |
| 623 return false; |
| 624 } |
| 612 return true; | 625 return true; |
| 613 } else if (expr is PrefixedIdentifier) { | 626 } else if (expr is PrefixedIdentifier) { |
| 614 expr = (expr as PrefixedIdentifier).prefix; | 627 expr = (expr as PrefixedIdentifier).prefix; |
| 615 } else if (expr is PropertyAccess) { | 628 } else if (expr is PropertyAccess) { |
| 616 expr = (expr as PropertyAccess).target; | 629 expr = (expr as PropertyAccess).target; |
| 617 } else { | 630 } else { |
| 618 return false; | 631 return false; |
| 619 } | 632 } |
| 620 } | 633 } |
| 621 return false; | 634 return false; |
| 622 } | 635 } |
| 623 } | 636 } |
| OLD | NEW |