Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.operators; | 5 library dart2js.operators; |
| 6 | 6 |
| 7 import '../elements/elements.dart'; | |
| 8 | |
| 7 enum UnaryOperatorKind { | 9 enum UnaryOperatorKind { |
| 8 NOT, | 10 NOT, |
| 9 NEGATE, | 11 NEGATE, |
| 10 COMPLEMENT, | 12 COMPLEMENT, |
| 11 } | 13 } |
| 12 | 14 |
| 13 class UnaryOperator { | 15 class UnaryOperator { |
| 14 final UnaryOperatorKind kind; | 16 final UnaryOperatorKind kind; |
| 15 final String name; | 17 final String name; |
| 16 final String selectorName; | 18 final String selectorName; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 36 static UnaryOperator parse(String value) { | 38 static UnaryOperator parse(String value) { |
| 37 switch (value) { | 39 switch (value) { |
| 38 case '!': return NOT; | 40 case '!': return NOT; |
| 39 case '-': return NEGATE; | 41 case '-': return NEGATE; |
| 40 case '~': return COMPLEMENT; | 42 case '~': return COMPLEMENT; |
| 41 default: return null; | 43 default: return null; |
| 42 } | 44 } |
| 43 } | 45 } |
| 44 } | 46 } |
| 45 | 47 |
| 46 | |
| 47 enum BinaryOperatorKind { | 48 enum BinaryOperatorKind { |
| 48 EQ, | 49 EQ, |
| 49 NOT_EQ, | 50 NOT_EQ, |
| 50 INDEX, | 51 INDEX, |
| 51 ADD, | 52 ADD, |
| 52 SUB, | 53 SUB, |
| 53 MUL, | 54 MUL, |
| 54 DIV, | 55 DIV, |
| 55 IDIV, | 56 IDIV, |
| 56 MOD, | 57 MOD, |
| 57 SHL, | 58 SHL, |
| 58 SHR, | 59 SHR, |
| 59 GTEQ, | 60 GTEQ, |
| 60 GT, | 61 GT, |
| 61 LTEQ, | 62 LTEQ, |
| 62 LT, | 63 LT, |
| 63 AND, | 64 AND, |
| 64 OR, | 65 OR, |
| 65 XOR, | 66 XOR, |
| 67 LOGICAL_AND, | |
| 68 LOGICAL_OR, | |
| 66 } | 69 } |
| 67 | 70 |
| 68 class BinaryOperator { | 71 class BinaryOperator { |
| 69 final BinaryOperatorKind kind; | 72 final BinaryOperatorKind kind; |
| 70 final String name; | 73 final String name; |
| 71 | 74 |
| 72 const BinaryOperator._(this.kind, this.name); | 75 const BinaryOperator._(this.kind, this.name); |
| 73 | 76 |
| 77 /// `true` if this operator can be implemented through an `operator [name]` | |
| 78 /// method. | |
| 74 bool get isUserDefinable => true; | 79 bool get isUserDefinable => true; |
| 80 | |
| 75 String get selectorName => name; | 81 String get selectorName => name; |
| 76 | 82 |
| 77 String toString() => name; | 83 String toString() => name; |
| 78 | 84 |
| 79 /// The == operator. | 85 /// The == operator. |
| 80 static const BinaryOperator EQ = | 86 static const BinaryOperator EQ = |
| 81 const BinaryOperator._(BinaryOperatorKind.EQ, '=='); | 87 const BinaryOperator._(BinaryOperatorKind.EQ, '=='); |
| 82 | 88 |
| 83 /// The != operator. | 89 /// The != operator. |
| 84 static const BinaryOperator NOT_EQ = const _NotEqualsOperator(); | 90 static const BinaryOperator NOT_EQ = const _NotEqualsOperator(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 const BinaryOperator._(BinaryOperatorKind.AND, '&'); | 146 const BinaryOperator._(BinaryOperatorKind.AND, '&'); |
| 141 | 147 |
| 142 /// The binary | operator. | 148 /// The binary | operator. |
| 143 static const BinaryOperator OR = | 149 static const BinaryOperator OR = |
| 144 const BinaryOperator._(BinaryOperatorKind.OR, '|'); | 150 const BinaryOperator._(BinaryOperatorKind.OR, '|'); |
| 145 | 151 |
| 146 /// The binary ^ operator. | 152 /// The binary ^ operator. |
| 147 static const BinaryOperator XOR = | 153 static const BinaryOperator XOR = |
| 148 const BinaryOperator._(BinaryOperatorKind.XOR, '^'); | 154 const BinaryOperator._(BinaryOperatorKind.XOR, '^'); |
| 149 | 155 |
| 156 /// The logical && operator. | |
| 157 static const BinaryOperator LOGICAL_AND = | |
| 158 const _LogicalOperator(BinaryOperatorKind.LOGICAL_AND, '&&'); | |
| 159 | |
| 160 /// The binary | operator. | |
| 161 static const BinaryOperator LOGICAL_OR = | |
| 162 const _LogicalOperator(BinaryOperatorKind.LOGICAL_OR, '||'); | |
| 163 | |
| 150 static BinaryOperator parse(String value) { | 164 static BinaryOperator parse(String value) { |
| 151 switch (value) { | 165 switch (value) { |
| 152 case '==': return EQ; | 166 case '==': return EQ; |
| 153 case '!=': return NOT_EQ; | 167 case '!=': return NOT_EQ; |
| 154 case '[]': return INDEX; | 168 case '[]': return INDEX; |
| 155 case '*': return MUL; | 169 case '*': return MUL; |
| 156 case '/': return DIV; | 170 case '/': return DIV; |
| 157 case '%': return MOD; | 171 case '%': return MOD; |
| 158 case '~/': return IDIV; | 172 case '~/': return IDIV; |
| 159 case '+': return ADD; | 173 case '+': return ADD; |
| 160 case '-': return SUB; | 174 case '-': return SUB; |
| 161 case '<<': return SHL; | 175 case '<<': return SHL; |
| 162 case '>>': return SHR; | 176 case '>>': return SHR; |
| 163 case '>=': return GTEQ; | 177 case '>=': return GTEQ; |
| 164 case '>': return GT; | 178 case '>': return GT; |
| 165 case '<=': return LTEQ; | 179 case '<=': return LTEQ; |
| 166 case '<': return LT; | 180 case '<': return LT; |
| 167 case '&': return AND; | 181 case '&': return AND; |
| 168 case '^': return XOR; | 182 case '^': return XOR; |
| 169 case '|': return OR; | 183 case '|': return OR; |
| 184 case '&&': return LOGICAL_AND; | |
| 185 case '||': return LOGICAL_OR; | |
| 170 default: return null; | 186 default: return null; |
| 171 } | 187 } |
| 172 } | 188 } |
| 173 } | 189 } |
| 174 | 190 |
| 175 /// The operator !=, which is not user definable operator but instead is a negat ion | 191 /// The operator !=, which is not user definable operator but instead is a |
| 192 /// negation of a call to user definable operator, namely ==. | |
| 176 class _NotEqualsOperator extends BinaryOperator { | 193 class _NotEqualsOperator extends BinaryOperator { |
| 177 const _NotEqualsOperator() : super._(BinaryOperatorKind.NOT_EQ, '!='); | 194 const _NotEqualsOperator() : super._(BinaryOperatorKind.NOT_EQ, '!='); |
| 178 | 195 |
| 179 bool get isUserDefinable => false; | 196 bool get isUserDefinable => false; |
| 180 | 197 |
| 181 String get selectorName => '=='; | 198 String get selectorName => '=='; |
| 182 } | 199 } |
| 183 | 200 |
| 201 /// The operators && and || which are not user definable operators but control | |
|
karlklose
2015/04/17 13:27:38
I don't think they are usually called control-stru
| |
| 202 /// structures. | |
| 203 class _LogicalOperator extends BinaryOperator { | |
| 204 const _LogicalOperator(BinaryOperatorKind kind, String name) | |
| 205 : super._(kind, name); | |
| 206 | |
| 207 bool get isUserDefinable => false; | |
| 208 | |
| 209 String get selectorName => null; | |
| 210 } | |
| 211 | |
| 184 enum AssignmentOperatorKind { | 212 enum AssignmentOperatorKind { |
| 185 ASSIGN, | 213 ASSIGN, |
| 186 ADD, | 214 ADD, |
| 187 SUB, | 215 SUB, |
| 188 MUL, | 216 MUL, |
| 189 DIV, | 217 DIV, |
| 190 IDIV, | 218 IDIV, |
| 191 MOD, | 219 MOD, |
| 192 SHL, | 220 SHL, |
| 193 SHR, | 221 SHR, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 const IncDecOperator._(IncDecOperatorKind.DEC, '--', BinaryOperator.SUB); | 343 const IncDecOperator._(IncDecOperatorKind.DEC, '--', BinaryOperator.SUB); |
| 316 | 344 |
| 317 static IncDecOperator parse(String value) { | 345 static IncDecOperator parse(String value) { |
| 318 switch (value) { | 346 switch (value) { |
| 319 case '++': return INC; | 347 case '++': return INC; |
| 320 case '--': return DEC; | 348 case '--': return DEC; |
| 321 default: return null; | 349 default: return null; |
| 322 } | 350 } |
| 323 } | 351 } |
| 324 } | 352 } |
| OLD | NEW |