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

Side by Side Diff: pkg/compiler/lib/src/resolution/operators.dart

Issue 929113002: Add SemanticVisitor to dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated and extended 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library dart2js.operators;
6
7 enum UnaryOperatorKind {
8 NOT,
9 NEGATE,
10 COMPLEMENT,
11 }
12
13 class UnaryOperator {
14 final UnaryOperatorKind kind;
15 final String name;
16 final String selectorName;
17
18 const UnaryOperator(this.kind, this.name, this.selectorName);
19
20 bool get isUserDefinable => selectorName != null;
21
22 String toString() => name;
23
24 /// The unary ! operator.
25 static const UnaryOperator NOT =
26 const UnaryOperator(UnaryOperatorKind.NOT, '!', null);
27
28 /// The unary - operator.
29 static const UnaryOperator NEGATE =
30 const UnaryOperator(UnaryOperatorKind.NEGATE, '-', 'unary-');
31
32 /// The unary ~ operator.
33 static const UnaryOperator COMPLEMENT =
34 const UnaryOperator(UnaryOperatorKind.COMPLEMENT, '~', '~');
35
36 static UnaryOperator parse(String value) {
37 switch (value) {
38 case '!': return NOT;
39 case '-': return NEGATE;
40 case '~': return COMPLEMENT;
41 default: return null;
42 }
43 }
44 }
45
46
47 enum BinaryOperatorKind {
48 EQ,
49 NOT_EQ,
50 INDEX,
51 ADD,
52 SUB,
53 MUL,
54 DIV,
55 IDIV,
56 MOD,
57 SHL,
58 SHR,
59 GTEQ,
60 GT,
61 LTEQ,
62 LT,
63 AND,
64 OR,
65 XOR,
66 }
67
68 class BinaryOperator {
69 final BinaryOperatorKind kind;
70 final String name;
71
72 const BinaryOperator._(this.kind, this.name);
73
74 bool get isUserDefinable => true;
75 String get selectorName => name;
76
77 String toString() => name;
78
79 /// The == operator.
80 static const BinaryOperator EQ =
81 const BinaryOperator._(BinaryOperatorKind.EQ, '==');
82
83 /// The != operator.
84 static const BinaryOperator NOT_EQ = const _NotEqualsOperator();
85
86 /// The [] operator.
87 static const BinaryOperator INDEX =
88 const BinaryOperator._(BinaryOperatorKind.INDEX, '[]');
89
90 /// The binary + operator.
91 static const BinaryOperator ADD =
92 const BinaryOperator._(BinaryOperatorKind.ADD, '+');
93
94 /// The binary - operator.
95 static const BinaryOperator SUB =
96 const BinaryOperator._(BinaryOperatorKind.SUB, '-');
97
98 /// The binary * operator.
99 static const BinaryOperator MUL =
100 const BinaryOperator._(BinaryOperatorKind.MUL, '*');
101
102 /// The binary / operator.
103 static const BinaryOperator DIV =
104 const BinaryOperator._(BinaryOperatorKind.DIV, '/');
105
106 /// The binary ~/ operator.
107 static const BinaryOperator IDIV =
108 const BinaryOperator._(BinaryOperatorKind.IDIV, '~/');
109
110 /// The binary % operator.
111 static const BinaryOperator MOD =
112 const BinaryOperator._(BinaryOperatorKind.MOD, '%');
113
114 /// The binary << operator.
115 static const BinaryOperator SHL =
116 const BinaryOperator._(BinaryOperatorKind.SHL, '<<');
117
118 /// The binary >> operator.
119 static const BinaryOperator SHR =
120 const BinaryOperator._(BinaryOperatorKind.SHR, '>>');
121
122 /// The binary >= operator.
123 static const BinaryOperator GTEQ =
124 const BinaryOperator._(BinaryOperatorKind.GTEQ, '>=');
125
126 /// The binary > operator.
127 static const BinaryOperator GT =
128 const BinaryOperator._(BinaryOperatorKind.GT, '>');
129
130 /// The binary <= operator.
131 static const BinaryOperator LTEQ =
132 const BinaryOperator._(BinaryOperatorKind.LTEQ, '<=');
133
134 /// The binary < operator.
135 static const BinaryOperator LT =
136 const BinaryOperator._(BinaryOperatorKind.LT, '<');
137
138 /// The binary & operator.
139 static const BinaryOperator AND =
140 const BinaryOperator._(BinaryOperatorKind.AND, '&');
141
142 /// The binary | operator.
143 static const BinaryOperator OR =
144 const BinaryOperator._(BinaryOperatorKind.OR, '|');
145
146 /// The binary ^ operator.
147 static const BinaryOperator XOR =
148 const BinaryOperator._(BinaryOperatorKind.XOR, '^');
149
150 static BinaryOperator parse(String value) {
151 switch (value) {
152 case '==': return EQ;
153 case '!=': return NOT_EQ;
154 case '[]': return INDEX;
155 case '*': return MUL;
156 case '/': return DIV;
157 case '%': return MOD;
158 case '~/': return IDIV;
159 case '+': return ADD;
160 case '-': return SUB;
161 case '<<': return SHL;
162 case '>>': return SHR;
163 case '>=': return GTEQ;
164 case '>': return GT;
165 case '<=': return LTEQ;
166 case '<': return LT;
167 case '&': return AND;
168 case '^': return XOR;
169 case '|': return OR;
170 default: return null;
171 }
172 }
173 }
174
175 /// The operator !=, which is not user definable operator but instead is a negat ion
176 class _NotEqualsOperator extends BinaryOperator {
177 const _NotEqualsOperator() : super._(BinaryOperatorKind.NOT_EQ, '!=');
178
179 bool get isUserDefinable => false;
180
181 String get selectorName => '==';
182 }
183
184 enum AssignmentOperatorKind {
185 ASSIGN,
186 ADD,
187 SUB,
188 MUL,
189 DIV,
190 IDIV,
191 MOD,
192 SHL,
193 SHR,
194 AND,
195 OR,
196 XOR,
197 }
198
199 class AssignmentOperator {
200 final AssignmentOperatorKind kind;
201 final BinaryOperator binaryOperator;
202 final String name;
203 final bool isUserDefinable;
204
205 const AssignmentOperator._(this.kind, this.name, this.binaryOperator,
206 {this.isUserDefinable: true});
207
208 String toString() => name;
209
210 /// The = operator.
211 static const AssignmentOperator ASSIGN =
212 const AssignmentOperator._(AssignmentOperatorKind.ASSIGN, '=',
213 null, isUserDefinable: false);
214
215 /// The += assignment operator.
216 static const AssignmentOperator ADD =
217 const AssignmentOperator._(AssignmentOperatorKind.ADD, '+=',
218 BinaryOperator.ADD);
219
220 /// The -= assignment operator.
221 static const AssignmentOperator SUB =
222 const AssignmentOperator._(AssignmentOperatorKind.SUB, '-=',
223 BinaryOperator.SUB);
224
225 /// The *= assignment operator.
226 static const AssignmentOperator MUL =
227 const AssignmentOperator._(AssignmentOperatorKind.MUL, '*=',
228 BinaryOperator.MUL);
229
230 /// The /= assignment operator.
231 static const AssignmentOperator DIV =
232 const AssignmentOperator._(AssignmentOperatorKind.DIV, '/=',
233 BinaryOperator.DIV);
234
235 /// The ~/= assignment operator.
236 static const AssignmentOperator IDIV =
237 const AssignmentOperator._(AssignmentOperatorKind.IDIV, '~/=',
238 BinaryOperator.IDIV);
239
240 /// The %= assignment operator.
241 static const AssignmentOperator MOD =
242 const AssignmentOperator._(AssignmentOperatorKind.MOD, '%=',
243 BinaryOperator.MOD);
244
245 /// The <<= assignment operator.
246 static const AssignmentOperator SHL =
247 const AssignmentOperator._(AssignmentOperatorKind.SHL, '<<=',
248 BinaryOperator.SHL);
249
250 /// The >>= assignment operator.
251 static const AssignmentOperator SHR =
252 const AssignmentOperator._(AssignmentOperatorKind.SHR, '>>=',
253 BinaryOperator.SHR);
254
255 /// The &= assignment operator.
256 static const AssignmentOperator AND =
257 const AssignmentOperator._(AssignmentOperatorKind.AND, '&=',
258 BinaryOperator.AND);
259
260 /// The |= assignment operator.
261 static const AssignmentOperator OR =
262 const AssignmentOperator._(AssignmentOperatorKind.OR, '|=',
263 BinaryOperator.OR);
264
265 /// The ^= assignment operator.
266 static const AssignmentOperator XOR =
267 const AssignmentOperator._(AssignmentOperatorKind.XOR, '^=',
268 BinaryOperator.XOR);
269
270 static AssignmentOperator parse(String value) {
271 switch (value) {
272 case '=': return ASSIGN;
273 case '*=': return MUL;
274 case '/=': return DIV;
275 case '%=': return MOD;
276 case '~/=': return IDIV;
277 case '+=': return ADD;
278 case '-=': return SUB;
279 case '<<=': return SHL;
280 case '>>=': return SHR;
281 case '&=': return AND;
282 case '^=': return XOR;
283 case '|=': return OR;
284 default: return null;
285 }
286 }
287 }
288
289
290 enum IncDecOperatorKind {
291 INC, DEC
292 }
293
294 class IncDecOperator {
295 final IncDecOperatorKind kind;
296 final String name;
297
298 const IncDecOperator._(this.kind, this.name);
299
300 String toString() => name;
301
302 /// The prefix/postfix ++ operator.
303 static const IncDecOperator INC =
304 const IncDecOperator._(IncDecOperatorKind.INC, '++');
305
306 /// The prefix/postfix -- operator.
307 static const IncDecOperator DEC =
308 const IncDecOperator._(IncDecOperatorKind.DEC, '--');
309
310 static IncDecOperator parse(String value) {
311 switch (value) {
312 case '++': return INC;
313 case '--': return DEC;
314 default: return null;
315 }
316 }
317 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698