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

Side by Side Diff: pkg/compiler/lib/src/constant_system_dart.dart

Issue 2561533002: dart2js: Constant folding and specialization for remainder (Closed)
Patch Set: improve range analysis of remainder Created 3 years, 11 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/compiler/lib/src/constants/constant_system.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) 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 library dart2js.constant_system.dart; 5 library dart2js.constant_system.dart;
6 6
7 import 'compiler.dart' show Compiler; 7 import 'compiler.dart' show Compiler;
8 import 'constants/constant_system.dart'; 8 import 'constants/constant_system.dart';
9 import 'constants/values.dart'; 9 import 'constants/values.dart';
10 import 'elements/resolution_types.dart'; 10 import 'elements/resolution_types.dart';
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 const ModuloOperation(); 196 const ModuloOperation();
197 int foldInts(int left, int right) { 197 int foldInts(int left, int right) {
198 if (right == 0) return null; 198 if (right == 0) return null;
199 return left % right; 199 return left % right;
200 } 200 }
201 201
202 num foldNums(num left, num right) => left % right; 202 num foldNums(num left, num right) => left % right;
203 apply(left, right) => left % right; 203 apply(left, right) => left % right;
204 } 204 }
205 205
206 class RemainderOperation extends ArithmeticNumOperation {
207 final String name = 'remainder';
208 const RemainderOperation();
209 // Not a defined constant operation.
210 num foldNums(num left, num right) => null;
211 apply(left, right) => left.remainder(right);
212 }
213
206 class TruncatingDivideOperation extends ArithmeticNumOperation { 214 class TruncatingDivideOperation extends ArithmeticNumOperation {
207 final String name = '~/'; 215 final String name = '~/';
208 const TruncatingDivideOperation(); 216 const TruncatingDivideOperation();
209 int foldInts(int left, int right) { 217 int foldInts(int left, int right) {
210 if (right == 0) return null; 218 if (right == 0) return null;
211 return left ~/ right; 219 return left ~/ right;
212 } 220 }
213 221
214 num foldNums(num left, num right) { 222 num foldNums(num left, num right) {
215 num ratio = left / right; 223 num ratio = left / right;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 final greaterEqual = const GreaterEqualOperation(); 407 final greaterEqual = const GreaterEqualOperation();
400 final greater = const GreaterOperation(); 408 final greater = const GreaterOperation();
401 final identity = const IdentityOperation(); 409 final identity = const IdentityOperation();
402 final ifNull = const IfNullOperation(); 410 final ifNull = const IfNullOperation();
403 final lessEqual = const LessEqualOperation(); 411 final lessEqual = const LessEqualOperation();
404 final less = const LessOperation(); 412 final less = const LessOperation();
405 final modulo = const ModuloOperation(); 413 final modulo = const ModuloOperation();
406 final multiply = const MultiplyOperation(); 414 final multiply = const MultiplyOperation();
407 final negate = const NegateOperation(); 415 final negate = const NegateOperation();
408 final not = const NotOperation(); 416 final not = const NotOperation();
417 final remainder = const RemainderOperation();
409 final shiftLeft = const ShiftLeftOperation(); 418 final shiftLeft = const ShiftLeftOperation();
410 final shiftRight = const ShiftRightOperation(); 419 final shiftRight = const ShiftRightOperation();
411 final subtract = const SubtractOperation(); 420 final subtract = const SubtractOperation();
412 final truncatingDivide = const TruncatingDivideOperation(); 421 final truncatingDivide = const TruncatingDivideOperation();
413 final codeUnitAt = const CodeUnitAtOperation(); 422 final codeUnitAt = const CodeUnitAtOperation();
414 final round = const UnfoldedUnaryOperation('round'); 423 final round = const UnfoldedUnaryOperation('round');
415 424
416 const DartConstantSystem(); 425 const DartConstantSystem();
417 426
418 @override 427 @override
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 bool isInt(ConstantValue constant) => constant.isInt; 471 bool isInt(ConstantValue constant) => constant.isInt;
463 bool isDouble(ConstantValue constant) => constant.isDouble; 472 bool isDouble(ConstantValue constant) => constant.isDouble;
464 bool isString(ConstantValue constant) => constant.isString; 473 bool isString(ConstantValue constant) => constant.isString;
465 bool isBool(ConstantValue constant) => constant.isBool; 474 bool isBool(ConstantValue constant) => constant.isBool;
466 bool isNull(ConstantValue constant) => constant.isNull; 475 bool isNull(ConstantValue constant) => constant.isNull;
467 476
468 bool isSubtype(DartTypes types, DartType s, DartType t) { 477 bool isSubtype(DartTypes types, DartType s, DartType t) {
469 return types.isSubtype(s, t); 478 return types.isSubtype(s, t);
470 } 479 }
471 } 480 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/constants/constant_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698