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

Side by Side Diff: frog/leg/operations.dart

Issue 9668046: Integer operations might not succeed (division by zero). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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 | tests/co19/co19-leg.status » ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 interface Operation { 5 interface Operation {
6 6
7 } 7 }
8 8
9 interface UnaryOperation extends Operation { 9 interface UnaryOperation extends Operation {
10 /** Returns [:null:] if it was unable to fold the operation. */ 10 /** Returns [:null:] if it was unable to fold the operation. */
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 Constant fold(Constant left, Constant right) { 110 Constant fold(Constant left, Constant right) {
111 if (left.isNum() && right.isNum()) { 111 if (left.isNum() && right.isNum()) {
112 NumConstant leftNum = left; 112 NumConstant leftNum = left;
113 NumConstant rightNum = right; 113 NumConstant rightNum = right;
114 num foldedValue; 114 num foldedValue;
115 if (left.isInt() && right.isInt()) { 115 if (left.isInt() && right.isInt()) {
116 foldedValue = foldInts(leftNum.value, rightNum.value); 116 foldedValue = foldInts(leftNum.value, rightNum.value);
117 } else { 117 } else {
118 foldedValue = foldNums(leftNum.value, rightNum.value); 118 foldedValue = foldNums(leftNum.value, rightNum.value);
119 } 119 }
120 assert(foldedValue != null); 120 // A division by 0 means that we might not have a folded value.
121 if (foldedValue === null) return null;
121 if (left.isInt() && right.isInt() && !isDivide()) { 122 if (left.isInt() && right.isInt() && !isDivide()) {
122 assert(foldedValue is int); 123 assert(foldedValue is int);
123 return new IntConstant(foldedValue); 124 return new IntConstant(foldedValue);
124 } else { 125 } else {
125 return new DoubleConstant(foldedValue); 126 return new DoubleConstant(foldedValue);
126 } 127 }
127 } 128 }
128 } 129 }
129 130
130 bool isDivide() => false; 131 bool isDivide() => false;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 return new BoolConstant(left == right); 245 return new BoolConstant(left == right);
245 } 246 }
246 } 247 }
247 248
248 class IdentityOperation implements BinaryOperation { 249 class IdentityOperation implements BinaryOperation {
249 const IdentityOperation(); 250 const IdentityOperation();
250 Constant fold(Constant left, Constant right) { 251 Constant fold(Constant left, Constant right) {
251 return new BoolConstant(left == right); 252 return new BoolConstant(left == right);
252 } 253 }
253 } 254 }
OLDNEW
« no previous file with comments | « no previous file | tests/co19/co19-leg.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698