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

Side by Side Diff: pkg/analyzer/lib/src/kernel/resynthesize.dart

Issue 3006973002: Resynthesize ?? expressions from Kernel. (Closed)
Patch Set: Created 3 years, 3 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'package:analyzer/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
7 import 'package:analyzer/dart/ast/token.dart'; 7 import 'package:analyzer/dart/ast/token.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/dart/element/type.dart'; 9 import 'package:analyzer/dart/element/type.dart';
10 import 'package:analyzer/src/dart/element/element.dart'; 10 import 'package:analyzer/src/dart/element/element.dart';
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 return AstTestFactory.prefixExpression(TokenType.BANG, operand); 255 return AstTestFactory.prefixExpression(TokenType.BANG, operand);
256 } 256 }
257 257
258 if (expr is kernel.LogicalExpression) { 258 if (expr is kernel.LogicalExpression) {
259 var operator = _toBinaryOperatorTokenType(expr.operator); 259 var operator = _toBinaryOperatorTokenType(expr.operator);
260 var left = build(expr.left); 260 var left = build(expr.left);
261 var right = build(expr.right); 261 var right = build(expr.right);
262 return AstTestFactory.binaryExpression(left, operator, right); 262 return AstTestFactory.binaryExpression(left, operator, right);
263 } 263 }
264 264
265 if (expr is kernel.Let) {
266 var body = expr.body;
267 if (body is kernel.ConditionalExpression) {
268 var condition = body.condition;
269 var otherwiseExpr = body.otherwise;
270 if (condition is kernel.MethodInvocation) {
271 var equalsReceiver = condition.receiver;
272 if (equalsReceiver is kernel.VariableGet &&
273 condition.name.name == '==' &&
274 condition.arguments.positional.length == 1 &&
275 condition.arguments.positional[0] is kernel.NullLiteral &&
276 otherwiseExpr is kernel.VariableGet &&
277 otherwiseExpr.variable == equalsReceiver.variable) {
278 var left = build(expr.variable.initializer);
279 var right = build(body.then);
280 return AstTestFactory.binaryExpression(
281 left, TokenType.QUESTION_QUESTION, right);
282 }
283 }
284 }
285 }
286
265 if (expr is kernel.MethodInvocation) { 287 if (expr is kernel.MethodInvocation) {
266 kernel.Member member = expr.interfaceTarget; 288 kernel.Member member = expr.interfaceTarget;
267 if (member is kernel.Procedure) { 289 if (member is kernel.Procedure) {
268 if (member.kind == kernel.ProcedureKind.Operator) { 290 if (member.kind == kernel.ProcedureKind.Operator) {
269 var left = build(expr.receiver); 291 var left = build(expr.receiver);
270 String operatorName = expr.name.name; 292 String operatorName = expr.name.name;
271 List<kernel.Expression> args = expr.arguments.positional; 293 List<kernel.Expression> args = expr.arguments.positional;
272 if (args.isEmpty) { 294 if (args.isEmpty) {
273 if (operatorName == 'unary-') { 295 if (operatorName == 'unary-') {
274 return AstTestFactory.prefixExpression(TokenType.MINUS, left); 296 return AstTestFactory.prefixExpression(TokenType.MINUS, left);
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 for (var typeParameter in ctx.typeParameters) { 869 for (var typeParameter in ctx.typeParameters) {
848 if (typeParameter.name == name) { 870 if (typeParameter.name == name) {
849 return typeParameter; 871 return typeParameter;
850 } 872 }
851 } 873 }
852 } 874 }
853 } 875 }
854 throw new StateError('Not found $kernelTypeParameter in $context'); 876 throw new StateError('Not found $kernelTypeParameter in $context');
855 } 877 }
856 } 878 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_kernel_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698