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

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

Issue 1017573004: Rewrite constants evaluation and checks to avoid using 'is double'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/ast_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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.ast; 8 library engine.ast;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 5043 matching lines...) Expand 10 before | Expand all | Expand 10 after
5054 } 5054 }
5055 } else if (node.operator.type == TokenType.AMPERSAND_AMPERSAND) { 5055 } else if (node.operator.type == TokenType.AMPERSAND_AMPERSAND) {
5056 // boolean or {@code null} 5056 // boolean or {@code null}
5057 if (leftOperand is bool && rightOperand is bool) { 5057 if (leftOperand is bool && rightOperand is bool) {
5058 return leftOperand && rightOperand; 5058 return leftOperand && rightOperand;
5059 } 5059 }
5060 } else if (node.operator.type == TokenType.BANG_EQ) { 5060 } else if (node.operator.type == TokenType.BANG_EQ) {
5061 // numeric, string, boolean, or {@code null} 5061 // numeric, string, boolean, or {@code null}
5062 if (leftOperand is bool && rightOperand is bool) { 5062 if (leftOperand is bool && rightOperand is bool) {
5063 return leftOperand != rightOperand; 5063 return leftOperand != rightOperand;
5064 } else if (leftOperand is int && rightOperand is int) { 5064 } else if (leftOperand is num && rightOperand is num) {
5065 return leftOperand != rightOperand;
5066 } else if (leftOperand is double && rightOperand is double) {
5067 return leftOperand != rightOperand; 5065 return leftOperand != rightOperand;
5068 } else if (leftOperand is String && rightOperand is String) { 5066 } else if (leftOperand is String && rightOperand is String) {
5069 return leftOperand != rightOperand; 5067 return leftOperand != rightOperand;
5070 } 5068 }
5071 } else if (node.operator.type == TokenType.BAR) { 5069 } else if (node.operator.type == TokenType.BAR) {
5072 // integer or {@code null} 5070 // integer or {@code null}
5073 if (leftOperand is int && rightOperand is int) { 5071 if (leftOperand is int && rightOperand is int) {
5074 return leftOperand | rightOperand; 5072 return leftOperand | rightOperand;
5075 } 5073 }
5076 } else if (node.operator.type == TokenType.BAR_BAR) { 5074 } else if (node.operator.type == TokenType.BAR_BAR) {
5077 // boolean or {@code null} 5075 // boolean or {@code null}
5078 if (leftOperand is bool && rightOperand is bool) { 5076 if (leftOperand is bool && rightOperand is bool) {
5079 return leftOperand || rightOperand; 5077 return leftOperand || rightOperand;
5080 } 5078 }
5081 } else if (node.operator.type == TokenType.CARET) { 5079 } else if (node.operator.type == TokenType.CARET) {
5082 // integer or {@code null} 5080 // integer or {@code null}
5083 if (leftOperand is int && rightOperand is int) { 5081 if (leftOperand is int && rightOperand is int) {
5084 return leftOperand ^ rightOperand; 5082 return leftOperand ^ rightOperand;
5085 } 5083 }
5086 } else if (node.operator.type == TokenType.EQ_EQ) { 5084 } else if (node.operator.type == TokenType.EQ_EQ) {
5087 // numeric, string, boolean, or {@code null} 5085 // numeric, string, boolean, or {@code null}
5088 if (leftOperand is bool && rightOperand is bool) { 5086 if (leftOperand is bool && rightOperand is bool) {
5089 return leftOperand == rightOperand; 5087 return leftOperand == rightOperand;
5090 } else if (leftOperand is int && rightOperand is int) { 5088 } else if (leftOperand is num && rightOperand is num) {
5091 return leftOperand == rightOperand;
5092 } else if (leftOperand is double && rightOperand is double) {
5093 return leftOperand == rightOperand; 5089 return leftOperand == rightOperand;
5094 } else if (leftOperand is String && rightOperand is String) { 5090 } else if (leftOperand is String && rightOperand is String) {
5095 return leftOperand == rightOperand; 5091 return leftOperand == rightOperand;
5096 } 5092 }
5097 } else if (node.operator.type == TokenType.GT) { 5093 } else if (node.operator.type == TokenType.GT) {
5098 // numeric or {@code null} 5094 // numeric or {@code null}
5099 if (leftOperand is int && rightOperand is int) { 5095 if (leftOperand is num && rightOperand is num) {
5100 return leftOperand.compareTo(rightOperand) > 0;
5101 } else if (leftOperand is double && rightOperand is double) {
5102 return leftOperand.compareTo(rightOperand) > 0; 5096 return leftOperand.compareTo(rightOperand) > 0;
5103 } 5097 }
5104 } else if (node.operator.type == TokenType.GT_EQ) { 5098 } else if (node.operator.type == TokenType.GT_EQ) {
5105 // numeric or {@code null} 5099 // numeric or {@code null}
5106 if (leftOperand is int && rightOperand is int) { 5100 if (leftOperand is num && rightOperand is num) {
5107 return leftOperand.compareTo(rightOperand) >= 0;
5108 } else if (leftOperand is double && rightOperand is double) {
5109 return leftOperand.compareTo(rightOperand) >= 0; 5101 return leftOperand.compareTo(rightOperand) >= 0;
5110 } 5102 }
5111 } else if (node.operator.type == TokenType.GT_GT) { 5103 } else if (node.operator.type == TokenType.GT_GT) {
5112 // integer or {@code null} 5104 // integer or {@code null}
5113 if (leftOperand is int && rightOperand is int) { 5105 if (leftOperand is int && rightOperand is int) {
5114 return leftOperand >> rightOperand; 5106 return leftOperand >> rightOperand;
5115 } 5107 }
5116 } else if (node.operator.type == TokenType.LT) { 5108 } else if (node.operator.type == TokenType.LT) {
5117 // numeric or {@code null} 5109 // numeric or {@code null}
5118 if (leftOperand is int && rightOperand is int) { 5110 if (leftOperand is num && rightOperand is num) {
5119 return leftOperand.compareTo(rightOperand) < 0;
5120 } else if (leftOperand is double && rightOperand is double) {
5121 return leftOperand.compareTo(rightOperand) < 0; 5111 return leftOperand.compareTo(rightOperand) < 0;
5122 } 5112 }
5123 } else if (node.operator.type == TokenType.LT_EQ) { 5113 } else if (node.operator.type == TokenType.LT_EQ) {
5124 // numeric or {@code null} 5114 // numeric or {@code null}
5125 if (leftOperand is int && rightOperand is int) { 5115 if (leftOperand is num && rightOperand is num) {
5126 return leftOperand.compareTo(rightOperand) <= 0;
5127 } else if (leftOperand is double && rightOperand is double) {
5128 return leftOperand.compareTo(rightOperand) <= 0; 5116 return leftOperand.compareTo(rightOperand) <= 0;
5129 } 5117 }
5130 } else if (node.operator.type == TokenType.LT_LT) { 5118 } else if (node.operator.type == TokenType.LT_LT) {
5131 // integer or {@code null} 5119 // integer or {@code null}
5132 if (leftOperand is int && rightOperand is int) { 5120 if (leftOperand is int && rightOperand is int) {
5133 return leftOperand << rightOperand; 5121 return leftOperand << rightOperand;
5134 } 5122 }
5135 } else if (node.operator.type == TokenType.MINUS) { 5123 } else if (node.operator.type == TokenType.MINUS) {
5136 // numeric or {@code null} 5124 // numeric or {@code null}
5137 if (leftOperand is int && rightOperand is int) { 5125 if (leftOperand is num && rightOperand is num) {
5138 return leftOperand - rightOperand;
5139 } else if (leftOperand is double && rightOperand is double) {
5140 return leftOperand - rightOperand; 5126 return leftOperand - rightOperand;
5141 } 5127 }
5142 } else if (node.operator.type == TokenType.PERCENT) { 5128 } else if (node.operator.type == TokenType.PERCENT) {
5143 // numeric or {@code null} 5129 // numeric or {@code null}
5144 if (leftOperand is int && rightOperand is int) { 5130 if (leftOperand is num && rightOperand is num) {
5145 return leftOperand.remainder(rightOperand); 5131 return leftOperand.remainder(rightOperand);
5146 } else if (leftOperand is double && rightOperand is double) {
5147 return leftOperand % rightOperand;
5148 } 5132 }
5149 } else if (node.operator.type == TokenType.PLUS) { 5133 } else if (node.operator.type == TokenType.PLUS) {
5150 // numeric or {@code null} 5134 // numeric or {@code null}
5151 if (leftOperand is int && rightOperand is int) { 5135 if (leftOperand is num && rightOperand is num) {
5152 return leftOperand + rightOperand;
5153 } else if (leftOperand is double && rightOperand is double) {
5154 return leftOperand + rightOperand; 5136 return leftOperand + rightOperand;
5155 } 5137 }
5156 } else if (node.operator.type == TokenType.STAR) { 5138 } else if (node.operator.type == TokenType.STAR) {
5157 // numeric or {@code null} 5139 // numeric or {@code null}
5158 if (leftOperand is int && rightOperand is int) { 5140 if (leftOperand is num && rightOperand is num) {
5159 return leftOperand * rightOperand;
5160 } else if (leftOperand is double && rightOperand is double) {
5161 return leftOperand * rightOperand; 5141 return leftOperand * rightOperand;
5162 } 5142 }
5163 } else if (node.operator.type == TokenType.SLASH) { 5143 } else if (node.operator.type == TokenType.SLASH) {
5164 // numeric or {@code null} 5144 // numeric or {@code null}
5165 if (leftOperand is int && rightOperand is int) { 5145 if (leftOperand is num && rightOperand is num) {
5166 if (rightOperand != 0) {
5167 return leftOperand ~/ rightOperand;
5168 } else {
5169 return leftOperand.toDouble() / rightOperand.toDouble();
5170 }
5171 } else if (leftOperand is double && rightOperand is double) {
5172 return leftOperand / rightOperand; 5146 return leftOperand / rightOperand;
5173 } 5147 }
5174 } else if (node.operator.type == TokenType.TILDE_SLASH) { 5148 } else if (node.operator.type == TokenType.TILDE_SLASH) {
5175 // numeric or {@code null} 5149 // numeric or {@code null}
5176 if (leftOperand is int && rightOperand is int) { 5150 if (leftOperand is num && rightOperand is num) {
5177 if (rightOperand != 0) {
5178 return leftOperand ~/ rightOperand;
5179 } else {
5180 return 0;
5181 }
5182 } else if (leftOperand is double && rightOperand is double) {
5183 return leftOperand ~/ rightOperand; 5151 return leftOperand ~/ rightOperand;
5184 } 5152 }
5185 } else {} 5153 } else {}
5186 break; 5154 break;
5187 } 5155 }
5188 // TODO(brianwilkerson) This doesn't handle numeric conversions. 5156 // TODO(brianwilkerson) This doesn't handle numeric conversions.
5189 return visitExpression(node); 5157 return visitExpression(node);
5190 } 5158 }
5191 5159
5192 @override 5160 @override
5193 Object visitBooleanLiteral(BooleanLiteral node) => node.value ? true : false; 5161 Object visitBooleanLiteral(BooleanLiteral node) => node.value ? true : false;
5194 5162
5195 @override 5163 @override
5196 Object visitDoubleLiteral(DoubleLiteral node) => node.value; 5164 Object visitDoubleLiteral(DoubleLiteral node) => node.value;
5197 5165
5198 @override 5166 @override
5199 Object visitIntegerLiteral(IntegerLiteral node) => node.value; 5167 Object visitIntegerLiteral(IntegerLiteral node) => node.value;
5200 5168
5201 @override 5169 @override
5202 Object visitInterpolationExpression(InterpolationExpression node) { 5170 Object visitInterpolationExpression(InterpolationExpression node) {
5203 Object value = node.expression.accept(this); 5171 Object value = node.expression.accept(this);
5204 if (value == null || 5172 if (value == null || value is bool || value is String || value is num) {
5205 value is bool ||
5206 value is String ||
5207 value is int ||
5208 value is double) {
5209 return value; 5173 return value;
5210 } 5174 }
5211 return NOT_A_CONSTANT; 5175 return NOT_A_CONSTANT;
5212 } 5176 }
5213 5177
5214 @override 5178 @override
5215 Object visitInterpolationString(InterpolationString node) => node.value; 5179 Object visitInterpolationString(InterpolationString node) => node.value;
5216 5180
5217 @override 5181 @override
5218 Object visitListLiteral(ListLiteral node) { 5182 Object visitListLiteral(ListLiteral node) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
5271 } else if (identical(operand, false)) { 5235 } else if (identical(operand, false)) {
5272 return true; 5236 return true;
5273 } 5237 }
5274 } else if (node.operator.type == TokenType.TILDE) { 5238 } else if (node.operator.type == TokenType.TILDE) {
5275 if (operand is int) { 5239 if (operand is int) {
5276 return ~operand; 5240 return ~operand;
5277 } 5241 }
5278 } else if (node.operator.type == TokenType.MINUS) { 5242 } else if (node.operator.type == TokenType.MINUS) {
5279 if (operand == null) { 5243 if (operand == null) {
5280 return null; 5244 return null;
5281 } else if (operand is int) { 5245 } else if (operand is num) {
5282 return -operand;
5283 } else if (operand is double) {
5284 return -operand; 5246 return -operand;
5285 } 5247 }
5286 } else {} 5248 } else {}
5287 break; 5249 break;
5288 } 5250 }
5289 return NOT_A_CONSTANT; 5251 return NOT_A_CONSTANT;
5290 } 5252 }
5291 5253
5292 @override 5254 @override
5293 Object visitPropertyAccess(PropertyAccess node) => _getConstantValue(null); 5255 Object visitPropertyAccess(PropertyAccess node) => _getConstantValue(null);
(...skipping 14802 matching lines...) Expand 10 before | Expand all | Expand 10 after
20096 } 20058 }
20097 20059
20098 @override 20060 @override
20099 accept(AstVisitor visitor) => visitor.visitYieldStatement(this); 20061 accept(AstVisitor visitor) => visitor.visitYieldStatement(this);
20100 20062
20101 @override 20063 @override
20102 void visitChildren(AstVisitor visitor) { 20064 void visitChildren(AstVisitor visitor) {
20103 _safelyVisitChild(_expression, visitor); 20065 _safelyVisitChild(_expression, visitor);
20104 } 20066 }
20105 } 20067 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/ast_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698