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

Side by Side Diff: pkg/analyzer/lib/src/summary/summarize_const_expr.dart

Issue 1856883002: Serialize assignment expressions. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
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/src/summary/format.dart'; 9 import 'package:analyzer/src/summary/format.dart';
10 import 'package:analyzer/src/summary/idl.dart'; 10 import 'package:analyzer/src/summary/idl.dart';
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 * See [UnlinkedConstBuilder.isInvalid]. 47 * See [UnlinkedConstBuilder.isInvalid].
48 */ 48 */
49 bool isInvalid = false; 49 bool isInvalid = false;
50 50
51 /** 51 /**
52 * See [UnlinkedConstBuilder.operations]. 52 * See [UnlinkedConstBuilder.operations].
53 */ 53 */
54 final List<UnlinkedConstOperation> operations = <UnlinkedConstOperation>[]; 54 final List<UnlinkedConstOperation> operations = <UnlinkedConstOperation>[];
55 55
56 /** 56 /**
57 * See [UnlinkedConstBuilder.assignmentOperators].
58 */
59 final List<UnlinkedExprAssignOperator> assignmentOperators =
60 <UnlinkedExprAssignOperator>[];
61
62 /**
57 * See [UnlinkedConstBuilder.ints]. 63 * See [UnlinkedConstBuilder.ints].
58 */ 64 */
59 final List<int> ints = <int>[]; 65 final List<int> ints = <int>[];
60 66
61 /** 67 /**
62 * See [UnlinkedConstBuilder.doubles]. 68 * See [UnlinkedConstBuilder.doubles].
63 */ 69 */
64 final List<double> doubles = <double>[]; 70 final List<double> doubles = <double>[];
65 71
66 /** 72 /**
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 /** 149 /**
144 * Return the [UnlinkedConstBuilder] that corresponds to the state of this 150 * Return the [UnlinkedConstBuilder] that corresponds to the state of this
145 * serializer. 151 * serializer.
146 */ 152 */
147 UnlinkedConstBuilder toBuilder() { 153 UnlinkedConstBuilder toBuilder() {
148 if (isInvalid) { 154 if (isInvalid) {
149 return new UnlinkedConstBuilder(isInvalid: true); 155 return new UnlinkedConstBuilder(isInvalid: true);
150 } 156 }
151 return new UnlinkedConstBuilder( 157 return new UnlinkedConstBuilder(
152 operations: operations, 158 operations: operations,
159 assignmentOperators: assignmentOperators,
153 ints: ints, 160 ints: ints,
154 doubles: doubles, 161 doubles: doubles,
155 strings: strings, 162 strings: strings,
156 references: references); 163 references: references);
157 } 164 }
158 165
159 void _pushInt(int value) { 166 void _pushInt(int value) {
160 assert(value >= 0); 167 assert(value >= 0);
161 if (value >= (1 << 32)) { 168 if (value >= (1 << 32)) {
162 int numOfComponents = 0; 169 int numOfComponents = 0;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 _serialize(expr.condition); 241 _serialize(expr.condition);
235 _serialize(expr.thenExpression); 242 _serialize(expr.thenExpression);
236 _serialize(expr.elseExpression); 243 _serialize(expr.elseExpression);
237 operations.add(UnlinkedConstOperation.conditional); 244 operations.add(UnlinkedConstOperation.conditional);
238 } else if (expr is PrefixExpression) { 245 } else if (expr is PrefixExpression) {
239 _serializePrefixExpression(expr); 246 _serializePrefixExpression(expr);
240 } else if (expr is PropertyAccess) { 247 } else if (expr is PropertyAccess) {
241 _serializePropertyAccess(expr); 248 _serializePropertyAccess(expr);
242 } else if (expr is ParenthesizedExpression) { 249 } else if (expr is ParenthesizedExpression) {
243 _serialize(expr.expression); 250 _serialize(expr.expression);
251 } else if (expr is AssignmentExpression) {
252 _serializeAssignment(expr);
244 } else { 253 } else {
245 throw new StateError('Unknown expression type: $expr'); 254 throw new StateError('Unknown expression type: $expr');
246 } 255 }
247 } 256 }
248 257
258 void _serializeAssignment(AssignmentExpression expr) {
259 // Push the assignment operator.
260 TokenType operator = expr.operator.type;
261 if (operator == TokenType.EQ) {
262 assignmentOperators.add(UnlinkedExprAssignOperator.assign);
263 } else if (operator == TokenType.QUESTION_QUESTION_EQ) {
264 assignmentOperators.add(UnlinkedExprAssignOperator.ifNull);
265 } else if (operator == TokenType.STAR_EQ) {
266 assignmentOperators.add(UnlinkedExprAssignOperator.multiply);
267 } else if (operator == TokenType.SLASH_EQ) {
268 assignmentOperators.add(UnlinkedExprAssignOperator.divide);
269 } else if (operator == TokenType.TILDE_SLASH_EQ) {
270 assignmentOperators.add(UnlinkedExprAssignOperator.floorDivide);
271 } else if (operator == TokenType.PERCENT_EQ) {
272 assignmentOperators.add(UnlinkedExprAssignOperator.modulo);
273 } else if (operator == TokenType.PLUS_EQ) {
274 assignmentOperators.add(UnlinkedExprAssignOperator.plus);
275 } else if (operator == TokenType.MINUS_EQ) {
276 assignmentOperators.add(UnlinkedExprAssignOperator.minus);
277 } else if (operator == TokenType.LT_LT_EQ) {
278 assignmentOperators.add(UnlinkedExprAssignOperator.shiftLeft);
279 } else if (operator == TokenType.GT_GT_EQ) {
280 assignmentOperators.add(UnlinkedExprAssignOperator.shiftRight);
281 } else if (operator == TokenType.AMPERSAND_EQ) {
282 assignmentOperators.add(UnlinkedExprAssignOperator.bitAnd);
283 } else if (operator == TokenType.CARET_EQ) {
284 assignmentOperators.add(UnlinkedExprAssignOperator.bitXor);
285 } else if (operator == TokenType.BAR_EQ) {
286 assignmentOperators.add(UnlinkedExprAssignOperator.bitOr);
287 } else {
288 throw new StateError('Unknown assignment operator: $operator');
289 }
290 // Push the target and prepare the assignment operation.
291 Expression leftHandSide = expr.leftHandSide;
292 UnlinkedConstOperation assignOperation;
293 if (_isIdentifierSequence(leftHandSide)) {
294 EntityRefBuilder ref = serializeIdentifierSequence(leftHandSide);
295 references.add(ref);
296 assignOperation = UnlinkedConstOperation.assignToRef;
297 } else if (leftHandSide is PropertyAccess) {
298 _serialize(leftHandSide.target);
299 strings.add(leftHandSide.propertyName.name);
300 assignOperation = UnlinkedConstOperation.assignToProperty;
301 } else if (leftHandSide is IndexExpression) {
302 _serialize(leftHandSide.target);
303 _serialize(leftHandSide.index);
304 assignOperation = UnlinkedConstOperation.assignToIndex;
305 } else {
306 throw new StateError('Unsupported LHS: $leftHandSide');
307 }
308 // Push the value.
309 _serialize(expr.rightHandSide);
310 // Push the target-specific assignment operation.
311 operations.add(assignOperation);
312 }
313
249 void _serializeBinaryExpression(BinaryExpression expr) { 314 void _serializeBinaryExpression(BinaryExpression expr) {
250 _serialize(expr.leftOperand); 315 _serialize(expr.leftOperand);
251 _serialize(expr.rightOperand); 316 _serialize(expr.rightOperand);
252 TokenType operator = expr.operator.type; 317 TokenType operator = expr.operator.type;
253 if (operator == TokenType.EQ_EQ) { 318 if (operator == TokenType.EQ_EQ) {
254 operations.add(UnlinkedConstOperation.equal); 319 operations.add(UnlinkedConstOperation.equal);
255 } else if (operator == TokenType.BANG_EQ) { 320 } else if (operator == TokenType.BANG_EQ) {
256 operations.add(UnlinkedConstOperation.notEqual); 321 operations.add(UnlinkedConstOperation.notEqual);
257 } else if (operator == TokenType.AMPERSAND_AMPERSAND) { 322 } else if (operator == TokenType.AMPERSAND_AMPERSAND) {
258 operations.add(UnlinkedConstOperation.and); 323 operations.add(UnlinkedConstOperation.and);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 expr = (expr as PrefixedIdentifier).prefix; 453 expr = (expr as PrefixedIdentifier).prefix;
389 } else if (expr is PropertyAccess) { 454 } else if (expr is PropertyAccess) {
390 expr = (expr as PropertyAccess).target; 455 expr = (expr as PropertyAccess).target;
391 } else { 456 } else {
392 return false; 457 return false;
393 } 458 }
394 } 459 }
395 return false; 460 return false;
396 } 461 }
397 } 462 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/idl.dart ('k') | pkg/analyzer/test/src/summary/summary_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698