| 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/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 | 10 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } else if (operator == TokenType.PERCENT) { | 181 } else if (operator == TokenType.PERCENT) { |
| 182 operations.add(UnlinkedConstOperation.modulo); | 182 operations.add(UnlinkedConstOperation.modulo); |
| 183 } else { | 183 } else { |
| 184 throw new _ConstExprSerializationError('Unknown operator: $operator'); | 184 throw new _ConstExprSerializationError('Unknown operator: $operator'); |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| 188 void _serializeInstanceCreation(InstanceCreationExpression expr) { | 188 void _serializeInstanceCreation(InstanceCreationExpression expr) { |
| 189 ConstructorName constructor = expr.constructorName; | 189 ConstructorName constructor = expr.constructorName; |
| 190 List<Expression> arguments = expr.argumentList.arguments; | 190 List<Expression> arguments = expr.argumentList.arguments; |
| 191 arguments.forEach(serialize); | 191 // Serialize the arguments. |
| 192 List<String> argumentNames = <String>[]; |
| 193 arguments.forEach((arg) { |
| 194 if (arg is NamedExpression) { |
| 195 argumentNames.add(arg.name.label.name); |
| 196 serialize(arg.expression); |
| 197 } else { |
| 198 serialize(arg); |
| 199 } |
| 200 }); |
| 201 // Add the op-code and numbers of named and positional arguments. |
| 192 operations.add(UnlinkedConstOperation.invokeConstructor); | 202 operations.add(UnlinkedConstOperation.invokeConstructor); |
| 203 ints.add(argumentNames.length); |
| 204 strings.addAll(argumentNames); |
| 205 ints.add(arguments.length - argumentNames.length); |
| 206 // Serialize the reference. |
| 193 references.add(serializeType(constructor.type)); | 207 references.add(serializeType(constructor.type)); |
| 194 if (constructor.name != null) { | 208 if (constructor.name != null) { |
| 195 strings.add(constructor.name.name); | 209 strings.add(constructor.name.name); |
| 196 } else { | 210 } else { |
| 197 strings.add(''); | 211 strings.add(''); |
| 198 } | 212 } |
| 199 // TODO(scheglov) named arguments? | |
| 200 ints.add(arguments.length); | |
| 201 } | 213 } |
| 202 | 214 |
| 203 void _serializeListLiteral(ListLiteral expr) { | 215 void _serializeListLiteral(ListLiteral expr) { |
| 204 List<Expression> elements = expr.elements; | 216 List<Expression> elements = expr.elements; |
| 205 elements.forEach(serialize); | 217 elements.forEach(serialize); |
| 206 TypeName typeArgument; | 218 TypeName typeArgument; |
| 207 if (expr.typeArguments != null && | 219 if (expr.typeArguments != null && |
| 208 expr.typeArguments.arguments.length == 1) { | 220 expr.typeArguments.arguments.length == 1) { |
| 209 typeArgument = expr.typeArguments.arguments[0]; | 221 typeArgument = expr.typeArguments.arguments[0]; |
| 210 } | 222 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 * Error that describes a problem during a constant expression serialization. | 290 * Error that describes a problem during a constant expression serialization. |
| 279 */ | 291 */ |
| 280 class _ConstExprSerializationError { | 292 class _ConstExprSerializationError { |
| 281 final String message; | 293 final String message; |
| 282 | 294 |
| 283 _ConstExprSerializationError(this.message); | 295 _ConstExprSerializationError(this.message); |
| 284 | 296 |
| 285 @override | 297 @override |
| 286 String toString() => message; | 298 String toString() => message; |
| 287 } | 299 } |
| OLD | NEW |