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

Side by Side Diff: lib/compiler/implementation/constant_system_dart.dart

Issue 11033016: Added TODO. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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 | « lib/compiler/implementation/compiler.dart ('k') | lib/compiler/implementation/constants.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 const DART_CONSTANT_SYSTEM = const DartConstantSystem(); 5 const DART_CONSTANT_SYSTEM = const DartConstantSystem();
6 6
7 class BitNotOperation implements UnaryOperation { 7 class BitNotOperation implements UnaryOperation {
8 final SourceString name = const SourceString('~'); 8 final SourceString name = const SourceString('~');
9 bool isUserDefinable() => true; 9 bool isUserDefinable() => true;
10 const BitNotOperation(); 10 const BitNotOperation();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 return DART_CONSTANT_SYSTEM.createBool(!boolConstant.value); 46 return DART_CONSTANT_SYSTEM.createBool(!boolConstant.value);
47 } 47 }
48 return null; 48 return null;
49 } 49 }
50 apply(value) => !value; 50 apply(value) => !value;
51 } 51 }
52 52
53 /** 53 /**
54 * Operations that only work if both arguments are integers. 54 * Operations that only work if both arguments are integers.
55 */ 55 */
56 class BinaryBitOperation implements BinaryOperation { 56 abstract class BinaryBitOperation implements BinaryOperation {
57 bool isUserDefinable() => true; 57 bool isUserDefinable() => true;
58 const BinaryBitOperation(); 58 const BinaryBitOperation();
59 Constant fold(Constant left, Constant right) { 59 Constant fold(Constant left, Constant right) {
60 if (left.isInt() && right.isInt()) { 60 if (left.isInt() && right.isInt()) {
61 IntConstant leftInt = left; 61 IntConstant leftInt = left;
62 IntConstant rightInt = right; 62 IntConstant rightInt = right;
63 int resultValue = foldInts(leftInt.value, rightInt.value); 63 int resultValue = foldInts(leftInt.value, rightInt.value);
64 if (resultValue === null) return null; 64 if (resultValue === null) return null;
65 return DART_CONSTANT_SYSTEM.createInt(resultValue); 65 return DART_CONSTANT_SYSTEM.createInt(resultValue);
66 } 66 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 class ShiftRightOperation extends BinaryBitOperation { 106 class ShiftRightOperation extends BinaryBitOperation {
107 final SourceString name = const SourceString('>>'); 107 final SourceString name = const SourceString('>>');
108 const ShiftRightOperation(); 108 const ShiftRightOperation();
109 int foldInts(int left, int right) { 109 int foldInts(int left, int right) {
110 if (right < 0) return null; 110 if (right < 0) return null;
111 return left >> right; 111 return left >> right;
112 } 112 }
113 apply(left, right) => left >> right; 113 apply(left, right) => left >> right;
114 } 114 }
115 115
116 class BinaryBoolOperation implements BinaryOperation { 116 abstract class BinaryBoolOperation implements BinaryOperation {
117 bool isUserDefinable() => false; 117 bool isUserDefinable() => false;
118 const BinaryBoolOperation(); 118 const BinaryBoolOperation();
119 Constant fold(Constant left, Constant right) { 119 Constant fold(Constant left, Constant right) {
120 if (left.isBool() && right.isBool()) { 120 if (left.isBool() && right.isBool()) {
121 BoolConstant leftBool = left; 121 BoolConstant leftBool = left;
122 BoolConstant rightBool = right; 122 BoolConstant rightBool = right;
123 bool resultValue = foldBools(leftBool.value, rightBool.value); 123 bool resultValue = foldBools(leftBool.value, rightBool.value);
124 return DART_CONSTANT_SYSTEM.createBool(resultValue); 124 return DART_CONSTANT_SYSTEM.createBool(resultValue);
125 } 125 }
126 return null; 126 return null;
127 } 127 }
128 128
129 abstract bool foldBools(bool left, bool right); 129 abstract bool foldBools(bool left, bool right);
130 } 130 }
131 131
132 class BooleanAndOperation extends BinaryBoolOperation { 132 class BooleanAndOperation extends BinaryBoolOperation {
133 final SourceString name = const SourceString('&&'); 133 final SourceString name = const SourceString('&&');
134 const BooleanAndOperation(); 134 const BooleanAndOperation();
135 bool foldBools(bool left, bool right) => left && right; 135 bool foldBools(bool left, bool right) => left && right;
136 apply(left, right) => left && right; 136 apply(left, right) => left && right;
137 } 137 }
138 138
139 class BooleanOrOperation extends BinaryBoolOperation { 139 class BooleanOrOperation extends BinaryBoolOperation {
140 final SourceString name = const SourceString('||'); 140 final SourceString name = const SourceString('||');
141 const BooleanOrOperation(); 141 const BooleanOrOperation();
142 bool foldBools(bool left, bool right) => left || right; 142 bool foldBools(bool left, bool right) => left || right;
143 apply(left, right) => left || right; 143 apply(left, right) => left || right;
144 } 144 }
145 145
146 class ArithmeticNumOperation implements BinaryOperation { 146 abstract class ArithmeticNumOperation implements BinaryOperation {
147 bool isUserDefinable() => true; 147 bool isUserDefinable() => true;
148 const ArithmeticNumOperation(); 148 const ArithmeticNumOperation();
149 Constant fold(Constant left, Constant right) { 149 Constant fold(Constant left, Constant right) {
150 if (left.isNum() && right.isNum()) { 150 if (left.isNum() && right.isNum()) {
151 NumConstant leftNum = left; 151 NumConstant leftNum = left;
152 NumConstant rightNum = right; 152 NumConstant rightNum = right;
153 num foldedValue; 153 num foldedValue;
154 if (left.isInt() && right.isInt()) { 154 if (left.isInt() && right.isInt()) {
155 foldedValue = foldInts(leftNum.value, rightNum.value); 155 foldedValue = foldInts(leftNum.value, rightNum.value);
156 } else { 156 } else {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 NumConstant rightNum = right; 232 NumConstant rightNum = right;
233 double result = leftNum.value + rightNum.value; 233 double result = leftNum.value + rightNum.value;
234 return DART_CONSTANT_SYSTEM.createDouble(result); 234 return DART_CONSTANT_SYSTEM.createDouble(result);
235 } else { 235 } else {
236 return null; 236 return null;
237 } 237 }
238 } 238 }
239 apply(left, right) => left + right; 239 apply(left, right) => left + right;
240 } 240 }
241 241
242 class RelationalNumOperation implements BinaryOperation { 242 abstract class RelationalNumOperation implements BinaryOperation {
243 bool isUserDefinable() => true; 243 bool isUserDefinable() => true;
244 const RelationalNumOperation(); 244 const RelationalNumOperation();
245 Constant fold(Constant left, Constant right) { 245 Constant fold(Constant left, Constant right) {
246 if (left.isNum() && right.isNum()) { 246 if (left.isNum() && right.isNum()) {
247 NumConstant leftNum = left; 247 NumConstant leftNum = left;
248 NumConstant rightNum = right; 248 NumConstant rightNum = right;
249 bool foldedValue = foldNums(leftNum.value, rightNum.value); 249 bool foldedValue = foldNums(leftNum.value, rightNum.value);
250 assert(foldedValue != null); 250 assert(foldedValue != null);
251 return DART_CONSTANT_SYSTEM.createBool(foldedValue); 251 return DART_CONSTANT_SYSTEM.createBool(foldedValue);
252 } 252 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 bool isInt(Constant constant) => constant.isInt(); 362 bool isInt(Constant constant) => constant.isInt();
363 bool isDouble(Constant constant) => constant.isDouble(); 363 bool isDouble(Constant constant) => constant.isDouble();
364 bool isString(Constant constant) => constant.isString(); 364 bool isString(Constant constant) => constant.isString();
365 bool isBool(Constant constant) => constant.isBool(); 365 bool isBool(Constant constant) => constant.isBool();
366 bool isNull(Constant constant) => constant.isNull(); 366 bool isNull(Constant constant) => constant.isNull();
367 367
368 bool isSubtype(Compiler compiler, DartType s, DartType t) { 368 bool isSubtype(Compiler compiler, DartType s, DartType t) {
369 return compiler.types.isSubtype(s, t); 369 return compiler.types.isSubtype(s, t);
370 } 370 }
371 } 371 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/compiler.dart ('k') | lib/compiler/implementation/constants.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698