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

Side by Side Diff: pkg/analyzer/lib/src/dart/ast/utilities.dart

Issue 2586363004: Support + concatenation in constant expressions with strings (Closed)
Patch Set: More tests for constant string concatenation error states Created 3 years, 12 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/dart/ast/utilities_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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.src.dart.ast.utilities; 5 library analyzer.src.dart.ast.utilities;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 10 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
(...skipping 2172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2183 * > </span> 2183 * > </span>
2184 * > * <span> 2184 * > * <span>
2185 * > An expression of one of the forms <i>~e</i>, <i>e<sub>1</sub> ^ 2185 * > An expression of one of the forms <i>~e</i>, <i>e<sub>1</sub> ^
2186 * > e<sub>2</sub></i>, <i>e<sub>1</sub> &amp; e<sub>2</sub></i>, 2186 * > e<sub>2</sub></i>, <i>e<sub>1</sub> &amp; e<sub>2</sub></i>,
2187 * > <i>e<sub>1</sub> | e<sub>2</sub></i>, <i>e<sub>1</sub> &gt;&gt; 2187 * > <i>e<sub>1</sub> | e<sub>2</sub></i>, <i>e<sub>1</sub> &gt;&gt;
2188 * > e<sub>2</sub></i> or <i>e<sub>1</sub> &lt;&lt; e<sub>2</sub></i>, where 2188 * > e<sub>2</sub></i> or <i>e<sub>1</sub> &lt;&lt; e<sub>2</sub></i>, where
2189 * > <i>e</i>, <i>e<sub>1</sub></i> and <i>e<sub>2</sub></i> are constant 2189 * > <i>e</i>, <i>e<sub>1</sub></i> and <i>e<sub>2</sub></i> are constant
2190 * > expressions that evaluate to an integer value or to <b>null</b>. 2190 * > expressions that evaluate to an integer value or to <b>null</b>.
2191 * > </span> 2191 * > </span>
2192 * > * <span> 2192 * > * <span>
2193 * > An expression of one of the forms <i>-e</i>, <i>e<sub>1</sub> + 2193 * > An expression of one of the forms <i>-e</i>, <i>e<sub>1</sub>
2194 * > e<sub>2</sub></i>, <i>e<sub>1</sub> -e<sub>2</sub></i>, 2194 * > -e<sub>2</sub></i>, <i>e<sub>1</sub> * e<sub>2</sub></i>,
2195 * > <i>e<sub>1</sub> * e<sub>2</sub></i>, <i>e<sub>1</sub> / 2195 * > <i>e<sub>1</sub> / e<sub>2</sub></i>, <i>e<sub>1</sub> ~/
2196 * > e<sub>2</sub></i>, <i>e<sub>1</sub> ~/ e<sub>2</sub></i>, 2196 * > e<sub>2</sub></i>, <i>e<sub>1</sub> &gt; e<sub>2</sub></i>,
2197 * > <i>e<sub>1</sub> &gt; e<sub>2</sub></i>, <i>e<sub>1</sub> &lt; 2197 * > <i>e<sub>1</sub> &lt; e<sub>2</sub></i>, <i>e<sub>1</sub> &gt;=
2198 * > e<sub>2</sub></i>, <i>e<sub>1</sub> &gt;= e<sub>2</sub></i>, 2198 * > e<sub>2</sub></i>, <i>e<sub>1</sub> &lt;= e<sub>2</sub></i> or
2199 * > <i>e<sub>1</sub> &lt;= e<sub>2</sub></i> or <i>e<sub>1</sub> % 2199 * > <i>e<sub>1</sub> % e<sub>2</sub></i>, where <i>e</i>,
2200 * > e<sub>2</sub></i>, where <i>e</i>, <i>e<sub>1</sub></i> and 2200 * > <i>e<sub>1</sub></i> and <i>e<sub>2</sub></i> are constant expressions
2201 * > <i>e<sub>2</sub></i> are constant expressions that evaluate to a numeric 2201 * > that evaluate to a numeric value or to <b>null</b>.
2202 * > value or to <b>null</b>. 2202 * > </span>
2203 * > * <span>
2204 * > An expression of one the form <i>e<sub>1</sub> + e<sub>2</sub></i>,
2205 * > <i>e<sub>1</sub> -e<sub>2</sub></i> where <i>e<sub>1</sub> and
2206 * > e<sub>2</sub></i> are constant expressions that evaluate to a numeric or
2207 * > string value or to <b>null</b>.
2203 * > </span> 2208 * > </span>
2204 * > * <span> 2209 * > * <span>
2205 * > An expression of the form <i>e<sub>1</sub> ? e<sub>2</sub> : 2210 * > An expression of the form <i>e<sub>1</sub> ? e<sub>2</sub> :
2206 * > e<sub>3</sub></i> where <i>e<sub>1</sub></i>, <i>e<sub>2</sub></i> and 2211 * > e<sub>3</sub></i> where <i>e<sub>1</sub></i>, <i>e<sub>2</sub></i> and
2207 * > <i>e<sub>3</sub></i> are constant expressions, and <i>e<sub>1</sub></i> 2212 * > <i>e<sub>3</sub></i> are constant expressions, and <i>e<sub>1</sub></i>
2208 * > evaluates to a boolean value. 2213 * > evaluates to a boolean value.
2209 * > </span> 2214 * > </span>
2210 * 2215 *
2216 * However, this comment is now at least a little bit out of sync with the spec.
2217 *
2211 * The values returned by instances of this class are therefore `null` and 2218 * The values returned by instances of this class are therefore `null` and
2212 * instances of the classes `Boolean`, `BigInteger`, `Double`, `String`, and 2219 * instances of the classes `Boolean`, `BigInteger`, `Double`, `String`, and
2213 * `DartObject`. 2220 * `DartObject`.
2214 * 2221 *
2215 * In addition, this class defines several values that can be returned to 2222 * In addition, this class defines several values that can be returned to
2216 * indicate various conditions encountered during evaluation. These are 2223 * indicate various conditions encountered during evaluation. These are
2217 * documented with the static fields that define those values. 2224 * documented with the static fields that define those values.
2218 */ 2225 */
2219 class ConstantEvaluator extends GeneralizingAstVisitor<Object> { 2226 class ConstantEvaluator extends GeneralizingAstVisitor<Object> {
2220 /** 2227 /**
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
2325 if (leftOperand is num && rightOperand is num) { 2332 if (leftOperand is num && rightOperand is num) {
2326 return leftOperand - rightOperand; 2333 return leftOperand - rightOperand;
2327 } 2334 }
2328 } else if (node.operator.type == TokenType.PERCENT) { 2335 } else if (node.operator.type == TokenType.PERCENT) {
2329 // numeric or {@code null} 2336 // numeric or {@code null}
2330 if (leftOperand is num && rightOperand is num) { 2337 if (leftOperand is num && rightOperand is num) {
2331 return leftOperand.remainder(rightOperand); 2338 return leftOperand.remainder(rightOperand);
2332 } 2339 }
2333 } else if (node.operator.type == TokenType.PLUS) { 2340 } else if (node.operator.type == TokenType.PLUS) {
2334 // numeric or {@code null} 2341 // numeric or {@code null}
2335 if (leftOperand is num && rightOperand is num) { 2342 if ((leftOperand is num && rightOperand is num) ||
2343 (leftOperand is String && rightOperand is String)) {
2336 return leftOperand + rightOperand; 2344 return leftOperand + rightOperand;
2337 } 2345 }
2338 } else if (node.operator.type == TokenType.STAR) { 2346 } else if (node.operator.type == TokenType.STAR) {
2339 // numeric or {@code null} 2347 // numeric or {@code null}
2340 if (leftOperand is num && rightOperand is num) { 2348 if (leftOperand is num && rightOperand is num) {
2341 return leftOperand * rightOperand; 2349 return leftOperand * rightOperand;
2342 } 2350 }
2343 } else if (node.operator.type == TokenType.SLASH) { 2351 } else if (node.operator.type == TokenType.SLASH) {
2344 // numeric or {@code null} 2352 // numeric or {@code null}
2345 if (leftOperand is num && rightOperand is num) { 2353 if (leftOperand is num && rightOperand is num) {
(...skipping 6834 matching lines...) Expand 10 before | Expand all | Expand 10 after
9180 if (node.star != null) { 9188 if (node.star != null) {
9181 sink.write("yield* "); 9189 sink.write("yield* ");
9182 } else { 9190 } else {
9183 sink.write("yield "); 9191 sink.write("yield ");
9184 } 9192 }
9185 safelyVisitNode(node.expression); 9193 safelyVisitNode(node.expression);
9186 sink.write(";"); 9194 sink.write(";");
9187 return null; 9195 return null;
9188 } 9196 }
9189 } 9197 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/ast/utilities_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698