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

Side by Side Diff: pkg/analyzer/test/src/summary/summary_common.dart

Issue 1859723002: Support for serializing prefix/postfix increment/decrement. (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
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_const_expr.dart ('k') | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analyzer.test.src.summary.summary_common; 5 library analyzer.test.src.summary.summary_common;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/src/dart/scanner/reader.dart'; 10 import 'package:analyzer/src/dart/scanner/reader.dart';
(...skipping 6111 matching lines...) Expand 10 before | Expand all | Expand 10 after
6122 expectedKind: ReferenceKind.unresolved, 6122 expectedKind: ReferenceKind.unresolved,
6123 prefixExpectations: [ 6123 prefixExpectations: [
6124 new _PrefixExpectation(ReferenceKind.unresolved, 'c'), 6124 new _PrefixExpectation(ReferenceKind.unresolved, 'c'),
6125 new _PrefixExpectation(ReferenceKind.unresolved, 'b'), 6125 new _PrefixExpectation(ReferenceKind.unresolved, 'b'),
6126 new _PrefixExpectation( 6126 new _PrefixExpectation(
6127 ReferenceKind.topLevelPropertyAccessor, 'a') 6127 ReferenceKind.topLevelPropertyAccessor, 'a')
6128 ]) 6128 ])
6129 ]); 6129 ]);
6130 } 6130 }
6131 6131
6132 test_expr_assignToRef_postfixDecrement() {
6133 _assertRefPrefixPostfixIncrementDecrement(
6134 'a-- + 2', UnlinkedExprAssignOperator.postfixDecrement);
6135 }
6136
6137 test_expr_assignToRef_postfixIncrement() {
6138 _assertRefPrefixPostfixIncrementDecrement(
6139 'a++ + 2', UnlinkedExprAssignOperator.postfixIncrement);
6140 }
6141
6142 test_expr_assignToRef_prefixDecrement() {
6143 _assertRefPrefixPostfixIncrementDecrement(
6144 '--a + 2', UnlinkedExprAssignOperator.prefixDecrement);
6145 }
6146
6147 test_expr_assignToRef_prefixIncrement() {
6148 _assertRefPrefixPostfixIncrementDecrement(
6149 '++a + 2', UnlinkedExprAssignOperator.prefixIncrement);
6150 }
6151
6132 test_expr_assignToRef_topLevelVariable() { 6152 test_expr_assignToRef_topLevelVariable() {
6133 if (skipNonConstInitializers) { 6153 if (skipNonConstInitializers) {
6134 return; 6154 return;
6135 } 6155 }
6136 UnlinkedVariable variable = serializeVariableText(''' 6156 UnlinkedVariable variable = serializeVariableText('''
6137 int a = 0; 6157 int a = 0;
6138 final v = (a = 1); 6158 final v = (a = 1);
6139 '''); 6159 ''');
6140 _assertUnlinkedConst(variable.constExpr, operators: [ 6160 _assertUnlinkedConst(variable.constExpr, operators: [
6141 UnlinkedConstOperation.pushInt, 6161 UnlinkedConstOperation.pushInt,
(...skipping 2599 matching lines...) Expand 10 before | Expand all | Expand 10 after
8741 expect(p.visibleOffset, expectedVisibleOffset); 8761 expect(p.visibleOffset, expectedVisibleOffset);
8742 expect(p.visibleLength, expectedVisibleLength); 8762 expect(p.visibleLength, expectedVisibleLength);
8743 } 8763 }
8744 8764
8745 void _assertParameterZeroVisibleRange(UnlinkedParam p) { 8765 void _assertParameterZeroVisibleRange(UnlinkedParam p) {
8746 expect(p.visibleOffset, isZero); 8766 expect(p.visibleOffset, isZero);
8747 expect(p.visibleLength, isZero); 8767 expect(p.visibleLength, isZero);
8748 } 8768 }
8749 8769
8750 /** 8770 /**
8771 * Assert that the [expr] of the form `++a + 2` is serialized with the
8772 * [expectedAssignmentOperator].
8773 */
8774 void _assertRefPrefixPostfixIncrementDecrement(
8775 String expr, UnlinkedExprAssignOperator expectedAssignmentOperator) {
8776 if (skipNonConstInitializers) {
8777 return;
8778 }
8779 UnlinkedVariable variable = serializeVariableText('''
8780 int a = 0;
8781 final v = $expr;
8782 ''');
8783 _assertUnlinkedConst(variable.constExpr, operators: [
8784 UnlinkedConstOperation.assignToRef,
8785 UnlinkedConstOperation.pushInt,
8786 UnlinkedConstOperation.add,
8787 ], assignmentOperators: [
8788 expectedAssignmentOperator
8789 ], ints: [
8790 2
8791 ], strings: [], referenceValidators: [
8792 (EntityRef r) => checkTypeRef(r, null, null, 'a',
8793 expectedKind: ReferenceKind.topLevelPropertyAccessor)
8794 ]);
8795 }
8796
8797 /**
8751 * TODO(scheglov) rename "Const" to "Expr" everywhere 8798 * TODO(scheglov) rename "Const" to "Expr" everywhere
8752 */ 8799 */
8753 void _assertUnlinkedConst(UnlinkedConst constExpr, 8800 void _assertUnlinkedConst(UnlinkedConst constExpr,
8754 {bool isInvalid: false, 8801 {bool isInvalid: false,
8755 List<UnlinkedConstOperation> operators: const <UnlinkedConstOperation>[], 8802 List<UnlinkedConstOperation> operators: const <UnlinkedConstOperation>[],
8756 List<UnlinkedExprAssignOperator> assignmentOperators: 8803 List<UnlinkedExprAssignOperator> assignmentOperators:
8757 const <UnlinkedExprAssignOperator>[], 8804 const <UnlinkedExprAssignOperator>[],
8758 List<int> ints: const <int>[], 8805 List<int> ints: const <int>[],
8759 List<double> doubles: const <double>[], 8806 List<double> doubles: const <double>[],
8760 List<String> strings: const <String>[], 8807 List<String> strings: const <String>[],
(...skipping 28 matching lines...) Expand all
8789 class _PrefixExpectation { 8836 class _PrefixExpectation {
8790 final ReferenceKind kind; 8837 final ReferenceKind kind;
8791 final String name; 8838 final String name;
8792 final String absoluteUri; 8839 final String absoluteUri;
8793 final String relativeUri; 8840 final String relativeUri;
8794 final int numTypeParameters; 8841 final int numTypeParameters;
8795 8842
8796 _PrefixExpectation(this.kind, this.name, 8843 _PrefixExpectation(this.kind, this.name,
8797 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); 8844 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0});
8798 } 8845 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_const_expr.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698