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

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

Powered by Google App Engine
This is Rietveld 408576698