| 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 */ | 136 */ |
| 137 EntityRefBuilder serializeConstructorRef(DartType type, Identifier typeName, | 137 EntityRefBuilder serializeConstructorRef(DartType type, Identifier typeName, |
| 138 TypeArgumentList typeArguments, SimpleIdentifier name); | 138 TypeArgumentList typeArguments, SimpleIdentifier name); |
| 139 | 139 |
| 140 /** | 140 /** |
| 141 * Return [EntityRefBuilder] that corresponds to the given [identifier]. | 141 * Return [EntityRefBuilder] that corresponds to the given [identifier]. |
| 142 */ | 142 */ |
| 143 EntityRefBuilder serializeIdentifier(Identifier identifier); | 143 EntityRefBuilder serializeIdentifier(Identifier identifier); |
| 144 | 144 |
| 145 /** | 145 /** |
| 146 * Return a pair of ints showing how the given [functionExpression] is nested |
| 147 * within the constant currently being serialized. The first int indicates |
| 148 * how many levels of function nesting must be popped in order to reach the |
| 149 * parent of the [functionExpression]. The second int is the index of the |
| 150 * [functionExpression] within its parent element. |
| 151 * |
| 152 * If the constant being summarized is in a context where local function |
| 153 * references are not allowed, return `null`. |
| 154 */ |
| 155 List<int> serializeFunctionExpression(FunctionExpression functionExpression); |
| 156 |
| 157 /** |
| 146 * Return [EntityRefBuilder] that corresponds to the given [expr], which | 158 * Return [EntityRefBuilder] that corresponds to the given [expr], which |
| 147 * must be a sequence of identifiers. | 159 * must be a sequence of identifiers. |
| 148 */ | 160 */ |
| 149 EntityRefBuilder serializeIdentifierSequence(Expression expr); | 161 EntityRefBuilder serializeIdentifierSequence(Expression expr); |
| 150 | 162 |
| 151 void serializeInstanceCreation( | 163 void serializeInstanceCreation( |
| 152 EntityRefBuilder constructor, ArgumentList argumentList) { | 164 EntityRefBuilder constructor, ArgumentList argumentList) { |
| 153 _serializeArguments(argumentList); | 165 _serializeArguments(argumentList); |
| 154 references.add(constructor); | 166 references.add(constructor); |
| 155 operations.add(UnlinkedConstOperation.invokeConstructor); | 167 operations.add(UnlinkedConstOperation.invokeConstructor); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 isValidConst = false; | 308 isValidConst = false; |
| 297 _serialize(expr.target); | 309 _serialize(expr.target); |
| 298 _serialize(expr.index); | 310 _serialize(expr.index); |
| 299 operations.add(UnlinkedConstOperation.extractIndex); | 311 operations.add(UnlinkedConstOperation.extractIndex); |
| 300 } else if (expr is AssignmentExpression) { | 312 } else if (expr is AssignmentExpression) { |
| 301 _serializeAssignment(expr); | 313 _serializeAssignment(expr); |
| 302 } else if (expr is CascadeExpression) { | 314 } else if (expr is CascadeExpression) { |
| 303 _serializeCascadeExpression(expr); | 315 _serializeCascadeExpression(expr); |
| 304 } else if (expr is FunctionExpression) { | 316 } else if (expr is FunctionExpression) { |
| 305 isValidConst = false; | 317 isValidConst = false; |
| 306 // TODO(scheglov) implement | 318 List<int> indices = serializeFunctionExpression(expr); |
| 307 operations.add(UnlinkedConstOperation.pushNull); | 319 if (indices != null) { |
| 320 ints.addAll(serializeFunctionExpression(expr)); |
| 321 operations.add(UnlinkedConstOperation.pushLocalFunctionReference); |
| 322 } else { |
| 323 // Invalid expression; just push null. |
| 324 operations.add(UnlinkedConstOperation.pushNull); |
| 325 } |
| 308 } else if (expr is FunctionExpressionInvocation) { | 326 } else if (expr is FunctionExpressionInvocation) { |
| 309 isValidConst = false; | 327 isValidConst = false; |
| 310 // TODO(scheglov) implement | 328 // TODO(scheglov) implement |
| 311 operations.add(UnlinkedConstOperation.pushNull); | 329 operations.add(UnlinkedConstOperation.pushNull); |
| 312 } else if (expr is AsExpression) { | 330 } else if (expr is AsExpression) { |
| 313 isValidConst = false; | 331 isValidConst = false; |
| 314 _serialize(expr.expression); | 332 _serialize(expr.expression); |
| 315 references.add(serializeTypeName(expr.type)); | 333 references.add(serializeTypeName(expr.type)); |
| 316 operations.add(UnlinkedConstOperation.typeCast); | 334 operations.add(UnlinkedConstOperation.typeCast); |
| 317 } else if (expr is IsExpression) { | 335 } else if (expr is IsExpression) { |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 expr = (expr as PrefixedIdentifier).prefix; | 615 expr = (expr as PrefixedIdentifier).prefix; |
| 598 } else if (expr is PropertyAccess) { | 616 } else if (expr is PropertyAccess) { |
| 599 expr = (expr as PropertyAccess).target; | 617 expr = (expr as PropertyAccess).target; |
| 600 } else { | 618 } else { |
| 601 return false; | 619 return false; |
| 602 } | 620 } |
| 603 } | 621 } |
| 604 return false; | 622 return false; |
| 605 } | 623 } |
| 606 } | 624 } |
| OLD | NEW |