1
|
1
|
|
2 // Compiler implementation of the D programming language
|
|
3 // Copyright (c) 1999-2007 by Digital Mars
|
|
4 // All Rights Reserved
|
|
5 // written by Walter Bright
|
|
6 // http://www.digitalmars.com
|
|
7 // License for redistribution is by either the Artistic License
|
|
8 // in artistic.txt, or the GNU General Public License in gnu.txt.
|
|
9 // See the included readme.txt for details.
|
|
10
|
|
11 #ifndef DMD_EXPRESSION_H
|
|
12 #define DMD_EXPRESSION_H
|
|
13
|
|
14 #include "mars.h"
|
|
15 #include "identifier.h"
|
|
16 #include "lexer.h"
|
|
17 #include "arraytypes.h"
|
|
18
|
|
19 struct Type;
|
|
20 struct Scope;
|
|
21 struct TupleDeclaration;
|
|
22 struct VarDeclaration;
|
|
23 struct FuncDeclaration;
|
|
24 struct FuncLiteralDeclaration;
|
|
25 struct Declaration;
|
|
26 struct CtorDeclaration;
|
|
27 struct NewDeclaration;
|
|
28 struct Dsymbol;
|
|
29 struct Import;
|
|
30 struct Module;
|
|
31 struct ScopeDsymbol;
|
|
32 struct InlineCostState;
|
|
33 struct InlineDoState;
|
|
34 struct InlineScanState;
|
|
35 struct Expression;
|
|
36 struct Declaration;
|
|
37 struct AggregateDeclaration;
|
|
38 struct StructDeclaration;
|
|
39 struct TemplateInstance;
|
|
40 struct TemplateDeclaration;
|
|
41 struct ClassDeclaration;
|
|
42 struct HdrGenState;
|
|
43 struct BinExp;
|
|
44 struct InterState;
|
|
45 struct Symbol; // back end symbol
|
|
46
|
|
47 namespace llvm
|
|
48 {
|
|
49 class ConstantInt;
|
|
50 }
|
|
51
|
|
52 enum TOK;
|
|
53
|
|
54 // Back end
|
|
55 struct IRState;
|
|
56 struct dt_t;
|
|
57
|
|
58 #ifdef IN_GCC
|
|
59 union tree_node; typedef union tree_node elem;
|
|
60 #else
|
|
61 struct elem;
|
|
62 #endif
|
|
63
|
|
64 void initPrecedence();
|
|
65
|
|
66 Expression *resolveProperties(Scope *sc, Expression *e);
|
|
67 void accessCheck(Loc loc, Scope *sc, Expression *e, Declaration *d);
|
|
68 Dsymbol *search_function(AggregateDeclaration *ad, Identifier *funcid);
|
|
69 void inferApplyArgTypes(enum TOK op, Arguments *arguments, Expression *aggr);
|
|
70 void argExpTypesToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *hgs);
|
|
71 void argsToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *hgs);
|
|
72 void expandTuples(Expressions *exps);
|
19
|
73 FuncDeclaration *hasThis(Scope *sc);
|
|
74 Expression *fromConstInitializer(int result, Expression *e);
|
1
|
75
|
|
76 struct Expression : Object
|
|
77 {
|
|
78 Loc loc; // file location
|
|
79 enum TOK op; // handy to minimize use of dynamic_cast
|
|
80 Type *type; // !=NULL means that semantic() has been run
|
|
81 int size; // # of bytes in Expression so we can copy() it
|
|
82
|
|
83 Expression(Loc loc, enum TOK op, int size);
|
|
84 Expression *copy();
|
|
85 virtual Expression *syntaxCopy();
|
|
86 virtual Expression *semantic(Scope *sc);
|
|
87
|
|
88 int dyncast() { return DYNCAST_EXPRESSION; } // kludge for template.isExpression()
|
|
89
|
|
90 void print();
|
|
91 char *toChars();
|
|
92 virtual void dump(int indent);
|
|
93 void error(const char *format, ...);
|
|
94 virtual void rvalue();
|
|
95
|
|
96 static Expression *combine(Expression *e1, Expression *e2);
|
|
97 static Expressions *arraySyntaxCopy(Expressions *exps);
|
|
98
|
|
99 virtual integer_t toInteger();
|
|
100 virtual uinteger_t toUInteger();
|
|
101 virtual real_t toReal();
|
|
102 virtual real_t toImaginary();
|
|
103 virtual complex_t toComplex();
|
|
104 virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
105 virtual void toMangleBuffer(OutBuffer *buf);
|
|
106 virtual Expression *toLvalue(Scope *sc, Expression *e);
|
|
107 virtual Expression *modifiableLvalue(Scope *sc, Expression *e);
|
|
108 Expression *implicitCastTo(Scope *sc, Type *t);
|
|
109 virtual MATCH implicitConvTo(Type *t);
|
|
110 virtual Expression *castTo(Scope *sc, Type *t);
|
|
111 virtual void checkEscape();
|
|
112 void checkScalar();
|
|
113 void checkNoBool();
|
|
114 Expression *checkIntegral();
|
|
115 void checkArithmetic();
|
|
116 void checkDeprecated(Scope *sc, Dsymbol *s);
|
|
117 virtual Expression *checkToBoolean();
|
|
118 Expression *checkToPointer();
|
|
119 Expression *addressOf(Scope *sc);
|
|
120 Expression *deref();
|
|
121 Expression *integralPromotions(Scope *sc);
|
|
122
|
|
123 Expression *toDelegate(Scope *sc, Type *t);
|
|
124 virtual void scanForNestedRef(Scope *sc);
|
|
125
|
|
126 virtual Expression *optimize(int result);
|
|
127 #define WANTflags 1
|
|
128 #define WANTvalue 2
|
|
129 #define WANTinterpret 4
|
|
130
|
|
131 virtual Expression *interpret(InterState *istate);
|
|
132
|
|
133 virtual int isConst();
|
|
134 virtual int isBool(int result);
|
|
135 virtual int isBit();
|
|
136 virtual int checkSideEffect(int flag);
|
|
137
|
|
138 virtual int inlineCost(InlineCostState *ics);
|
|
139 virtual Expression *doInline(InlineDoState *ids);
|
|
140 virtual Expression *inlineScan(InlineScanState *iss);
|
|
141
|
|
142 // For operator overloading
|
|
143 virtual int isCommutative();
|
|
144 virtual Identifier *opId();
|
|
145 virtual Identifier *opId_r();
|
|
146
|
|
147 // Back end
|
|
148 virtual elem *toElem(IRState *irs);
|
|
149 virtual dt_t **toDt(dt_t **pdt);
|
|
150 };
|
|
151
|
|
152 struct IntegerExp : Expression
|
|
153 {
|
|
154 integer_t value;
|
|
155
|
|
156 IntegerExp(Loc loc, integer_t value, Type *type);
|
|
157 IntegerExp(integer_t value);
|
|
158 int equals(Object *o);
|
|
159 Expression *semantic(Scope *sc);
|
|
160 Expression *interpret(InterState *istate);
|
|
161 char *toChars();
|
|
162 void dump(int indent);
|
|
163 integer_t toInteger();
|
|
164 real_t toReal();
|
|
165 real_t toImaginary();
|
|
166 complex_t toComplex();
|
|
167 int isConst();
|
|
168 int isBool(int result);
|
|
169 MATCH implicitConvTo(Type *t);
|
|
170 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
171 void toMangleBuffer(OutBuffer *buf);
|
|
172 Expression *toLvalue(Scope *sc, Expression *e);
|
|
173 elem *toElem(IRState *irs);
|
|
174 dt_t **toDt(dt_t **pdt);
|
|
175 };
|
|
176
|
|
177 struct RealExp : Expression
|
|
178 {
|
|
179 real_t value;
|
|
180
|
|
181 RealExp(Loc loc, real_t value, Type *type);
|
|
182 int equals(Object *o);
|
|
183 Expression *semantic(Scope *sc);
|
|
184 Expression *interpret(InterState *istate);
|
|
185 char *toChars();
|
|
186 integer_t toInteger();
|
|
187 uinteger_t toUInteger();
|
|
188 real_t toReal();
|
|
189 real_t toImaginary();
|
|
190 complex_t toComplex();
|
|
191 Expression *castTo(Scope *sc, Type *t);
|
|
192 int isConst();
|
|
193 int isBool(int result);
|
|
194 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
195 void toMangleBuffer(OutBuffer *buf);
|
|
196 elem *toElem(IRState *irs);
|
|
197 dt_t **toDt(dt_t **pdt);
|
|
198 };
|
|
199
|
|
200 struct ComplexExp : Expression
|
|
201 {
|
|
202 complex_t value;
|
|
203
|
|
204 ComplexExp(Loc loc, complex_t value, Type *type);
|
|
205 int equals(Object *o);
|
|
206 Expression *semantic(Scope *sc);
|
|
207 Expression *interpret(InterState *istate);
|
|
208 char *toChars();
|
|
209 integer_t toInteger();
|
|
210 uinteger_t toUInteger();
|
|
211 real_t toReal();
|
|
212 real_t toImaginary();
|
|
213 complex_t toComplex();
|
|
214 Expression *castTo(Scope *sc, Type *t);
|
|
215 int isConst();
|
|
216 int isBool(int result);
|
|
217 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
218 void toMangleBuffer(OutBuffer *buf);
|
|
219 #ifdef _DH
|
|
220 OutBuffer hexp;
|
|
221 #endif
|
|
222 elem *toElem(IRState *irs);
|
|
223 dt_t **toDt(dt_t **pdt);
|
|
224 };
|
|
225
|
|
226 struct IdentifierExp : Expression
|
|
227 {
|
|
228 Identifier *ident;
|
|
229 Declaration *var;
|
|
230
|
|
231 IdentifierExp(Loc loc, Identifier *ident);
|
|
232 IdentifierExp(Loc loc, Declaration *var);
|
|
233 Expression *semantic(Scope *sc);
|
|
234 char *toChars();
|
|
235 void dump(int indent);
|
|
236 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
237 Expression *toLvalue(Scope *sc, Expression *e);
|
|
238 };
|
|
239
|
|
240 struct DollarExp : IdentifierExp
|
|
241 {
|
|
242 DollarExp(Loc loc);
|
|
243 };
|
|
244
|
|
245 struct DsymbolExp : Expression
|
|
246 {
|
|
247 Dsymbol *s;
|
|
248
|
|
249 DsymbolExp(Loc loc, Dsymbol *s);
|
|
250 Expression *semantic(Scope *sc);
|
|
251 char *toChars();
|
|
252 void dump(int indent);
|
|
253 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
254 Expression *toLvalue(Scope *sc, Expression *e);
|
|
255 };
|
|
256
|
|
257 struct ThisExp : Expression
|
|
258 {
|
|
259 Declaration *var;
|
|
260
|
|
261 ThisExp(Loc loc);
|
|
262 Expression *semantic(Scope *sc);
|
|
263 int isBool(int result);
|
|
264 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
265 Expression *toLvalue(Scope *sc, Expression *e);
|
|
266 void scanForNestedRef(Scope *sc);
|
|
267
|
|
268 int inlineCost(InlineCostState *ics);
|
|
269 Expression *doInline(InlineDoState *ids);
|
|
270 //Expression *inlineScan(InlineScanState *iss);
|
|
271
|
|
272 elem *toElem(IRState *irs);
|
|
273 };
|
|
274
|
|
275 struct SuperExp : ThisExp
|
|
276 {
|
|
277 SuperExp(Loc loc);
|
|
278 Expression *semantic(Scope *sc);
|
|
279 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
280 void scanForNestedRef(Scope *sc);
|
|
281
|
|
282 int inlineCost(InlineCostState *ics);
|
|
283 Expression *doInline(InlineDoState *ids);
|
|
284 //Expression *inlineScan(InlineScanState *iss);
|
|
285 };
|
|
286
|
|
287 struct NullExp : Expression
|
|
288 {
|
|
289 unsigned char committed; // !=0 if type is committed
|
|
290
|
|
291 NullExp(Loc loc);
|
|
292 Expression *semantic(Scope *sc);
|
|
293 int isBool(int result);
|
|
294 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
295 void toMangleBuffer(OutBuffer *buf);
|
|
296 MATCH implicitConvTo(Type *t);
|
|
297 Expression *castTo(Scope *sc, Type *t);
|
|
298 Expression *interpret(InterState *istate);
|
|
299 elem *toElem(IRState *irs);
|
|
300 dt_t **toDt(dt_t **pdt);
|
|
301 };
|
|
302
|
|
303 struct StringExp : Expression
|
|
304 {
|
|
305 void *string; // char, wchar, or dchar data
|
|
306 size_t len; // number of chars, wchars, or dchars
|
|
307 unsigned char sz; // 1: char, 2: wchar, 4: dchar
|
|
308 unsigned char committed; // !=0 if type is committed
|
|
309 unsigned char postfix; // 'c', 'w', 'd'
|
|
310
|
|
311 StringExp(Loc loc, char *s);
|
|
312 StringExp(Loc loc, void *s, size_t len);
|
|
313 StringExp(Loc loc, void *s, size_t len, unsigned char postfix);
|
|
314 //Expression *syntaxCopy();
|
|
315 int equals(Object *o);
|
|
316 char *toChars();
|
|
317 Expression *semantic(Scope *sc);
|
|
318 Expression *interpret(InterState *istate);
|
|
319 StringExp *toUTF8(Scope *sc);
|
|
320 MATCH implicitConvTo(Type *t);
|
|
321 Expression *castTo(Scope *sc, Type *t);
|
|
322 int compare(Object *obj);
|
|
323 int isBool(int result);
|
|
324 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
325 void toMangleBuffer(OutBuffer *buf);
|
|
326 elem *toElem(IRState *irs);
|
|
327 dt_t **toDt(dt_t **pdt);
|
|
328 };
|
|
329
|
|
330 // Tuple
|
|
331
|
|
332 struct TupleExp : Expression
|
|
333 {
|
|
334 Expressions *exps;
|
|
335
|
|
336 TupleExp(Loc loc, Expressions *exps);
|
|
337 TupleExp(Loc loc, TupleDeclaration *tup);
|
|
338 Expression *syntaxCopy();
|
|
339 int equals(Object *o);
|
|
340 Expression *semantic(Scope *sc);
|
|
341 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
342 void scanForNestedRef(Scope *sc);
|
|
343 void checkEscape();
|
|
344 int checkSideEffect(int flag);
|
|
345 Expression *optimize(int result);
|
|
346 Expression *interpret(InterState *istate);
|
|
347 Expression *castTo(Scope *sc, Type *t);
|
|
348
|
|
349 int inlineCost(InlineCostState *ics);
|
|
350 Expression *doInline(InlineDoState *ids);
|
|
351 Expression *inlineScan(InlineScanState *iss);
|
|
352 };
|
|
353
|
|
354 struct ArrayLiteralExp : Expression
|
|
355 {
|
|
356 Expressions *elements;
|
|
357
|
|
358 ArrayLiteralExp(Loc loc, Expressions *elements);
|
|
359 ArrayLiteralExp(Loc loc, Expression *e);
|
|
360
|
|
361 Expression *syntaxCopy();
|
|
362 Expression *semantic(Scope *sc);
|
|
363 int isBool(int result);
|
|
364 elem *toElem(IRState *irs);
|
|
365 int checkSideEffect(int flag);
|
|
366 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
367 void toMangleBuffer(OutBuffer *buf);
|
|
368 void scanForNestedRef(Scope *sc);
|
|
369 Expression *optimize(int result);
|
|
370 Expression *interpret(InterState *istate);
|
|
371 MATCH implicitConvTo(Type *t);
|
|
372 Expression *castTo(Scope *sc, Type *t);
|
|
373 dt_t **toDt(dt_t **pdt);
|
|
374
|
|
375 int inlineCost(InlineCostState *ics);
|
|
376 Expression *doInline(InlineDoState *ids);
|
|
377 Expression *inlineScan(InlineScanState *iss);
|
|
378 };
|
|
379
|
|
380 struct AssocArrayLiteralExp : Expression
|
|
381 {
|
|
382 Expressions *keys;
|
|
383 Expressions *values;
|
|
384
|
|
385 AssocArrayLiteralExp(Loc loc, Expressions *keys, Expressions *values);
|
|
386
|
|
387 Expression *syntaxCopy();
|
|
388 Expression *semantic(Scope *sc);
|
|
389 int isBool(int result);
|
|
390 elem *toElem(IRState *irs);
|
|
391 int checkSideEffect(int flag);
|
|
392 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
393 void toMangleBuffer(OutBuffer *buf);
|
|
394 void scanForNestedRef(Scope *sc);
|
|
395 Expression *optimize(int result);
|
|
396 Expression *interpret(InterState *istate);
|
|
397 MATCH implicitConvTo(Type *t);
|
|
398 Expression *castTo(Scope *sc, Type *t);
|
|
399
|
|
400 int inlineCost(InlineCostState *ics);
|
|
401 Expression *doInline(InlineDoState *ids);
|
|
402 Expression *inlineScan(InlineScanState *iss);
|
|
403 };
|
|
404
|
|
405 struct StructLiteralExp : Expression
|
|
406 {
|
|
407 StructDeclaration *sd; // which aggregate this is for
|
|
408 Expressions *elements; // parallels sd->fields[] with
|
|
409 // NULL entries for fields to skip
|
|
410
|
|
411 Symbol *sym; // back end symbol to initialize with literal
|
|
412 size_t soffset; // offset from start of s
|
|
413 int fillHoles; // fill alignment 'holes' with zero
|
|
414
|
|
415 StructLiteralExp(Loc loc, StructDeclaration *sd, Expressions *elements);
|
|
416
|
|
417 Expression *syntaxCopy();
|
|
418 Expression *semantic(Scope *sc);
|
|
419 Expression *getField(Type *type, unsigned offset);
|
|
420 int getFieldIndex(Type *type, unsigned offset);
|
|
421 elem *toElem(IRState *irs);
|
|
422 int checkSideEffect(int flag);
|
|
423 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
424 void toMangleBuffer(OutBuffer *buf);
|
|
425 void scanForNestedRef(Scope *sc);
|
|
426 Expression *optimize(int result);
|
|
427 Expression *interpret(InterState *istate);
|
|
428 dt_t **toDt(dt_t **pdt);
|
|
429 Expression *toLvalue(Scope *sc, Expression *e);
|
|
430
|
|
431 int inlineCost(InlineCostState *ics);
|
|
432 Expression *doInline(InlineDoState *ids);
|
|
433 Expression *inlineScan(InlineScanState *iss);
|
|
434 };
|
|
435
|
|
436 struct TypeDotIdExp : Expression
|
|
437 {
|
|
438 Identifier *ident;
|
|
439
|
|
440 TypeDotIdExp(Loc loc, Type *type, Identifier *ident);
|
|
441 Expression *syntaxCopy();
|
|
442 Expression *semantic(Scope *sc);
|
|
443 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
444 elem *toElem(IRState *irs);
|
|
445 };
|
|
446
|
|
447 struct TypeExp : Expression
|
|
448 {
|
|
449 TypeExp(Loc loc, Type *type);
|
|
450 Expression *semantic(Scope *sc);
|
|
451 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
452 Expression *optimize(int result);
|
|
453 elem *toElem(IRState *irs);
|
|
454 };
|
|
455
|
|
456 struct ScopeExp : Expression
|
|
457 {
|
|
458 ScopeDsymbol *sds;
|
|
459
|
|
460 ScopeExp(Loc loc, ScopeDsymbol *sds);
|
|
461 Expression *syntaxCopy();
|
|
462 Expression *semantic(Scope *sc);
|
|
463 elem *toElem(IRState *irs);
|
|
464 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
465 };
|
|
466
|
|
467 struct TemplateExp : Expression
|
|
468 {
|
|
469 TemplateDeclaration *td;
|
|
470
|
|
471 TemplateExp(Loc loc, TemplateDeclaration *td);
|
|
472 void rvalue();
|
|
473 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
474 };
|
|
475
|
|
476 struct NewExp : Expression
|
|
477 {
|
|
478 /* thisexp.new(newargs) newtype(arguments)
|
|
479 */
|
|
480 Expression *thisexp; // if !NULL, 'this' for class being allocated
|
|
481 Expressions *newargs; // Array of Expression's to call new operator
|
|
482 Type *newtype;
|
|
483 Expressions *arguments; // Array of Expression's
|
|
484
|
|
485 CtorDeclaration *member; // constructor function
|
|
486 NewDeclaration *allocator; // allocator function
|
|
487 int onstack; // allocate on stack
|
|
488
|
|
489 NewExp(Loc loc, Expression *thisexp, Expressions *newargs,
|
|
490 Type *newtype, Expressions *arguments);
|
|
491 Expression *syntaxCopy();
|
|
492 Expression *semantic(Scope *sc);
|
|
493 elem *toElem(IRState *irs);
|
|
494 int checkSideEffect(int flag);
|
|
495 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
496 void scanForNestedRef(Scope *sc);
|
|
497
|
|
498 //int inlineCost(InlineCostState *ics);
|
|
499 Expression *doInline(InlineDoState *ids);
|
|
500 //Expression *inlineScan(InlineScanState *iss);
|
|
501 };
|
|
502
|
|
503 struct NewAnonClassExp : Expression
|
|
504 {
|
|
505 /* thisexp.new(newargs) class baseclasses { } (arguments)
|
|
506 */
|
|
507 Expression *thisexp; // if !NULL, 'this' for class being allocated
|
|
508 Expressions *newargs; // Array of Expression's to call new operator
|
|
509 ClassDeclaration *cd; // class being instantiated
|
|
510 Expressions *arguments; // Array of Expression's to call class constructor
|
|
511
|
|
512 NewAnonClassExp(Loc loc, Expression *thisexp, Expressions *newargs,
|
|
513 ClassDeclaration *cd, Expressions *arguments);
|
|
514 Expression *syntaxCopy();
|
|
515 Expression *semantic(Scope *sc);
|
|
516 int checkSideEffect(int flag);
|
|
517 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
518 };
|
|
519
|
|
520 // Offset from symbol
|
|
521
|
|
522 struct SymOffExp : Expression
|
|
523 {
|
|
524 Declaration *var;
|
|
525 unsigned offset;
|
|
526
|
|
527 SymOffExp(Loc loc, Declaration *var, unsigned offset);
|
|
528 Expression *semantic(Scope *sc);
|
|
529 void checkEscape();
|
|
530 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
531 int isConst();
|
|
532 int isBool(int result);
|
|
533 Expression *doInline(InlineDoState *ids);
|
|
534 MATCH implicitConvTo(Type *t);
|
|
535 Expression *castTo(Scope *sc, Type *t);
|
|
536 void scanForNestedRef(Scope *sc);
|
|
537
|
|
538 elem *toElem(IRState *irs);
|
|
539 dt_t **toDt(dt_t **pdt);
|
|
540 };
|
|
541
|
|
542 // Variable
|
|
543
|
|
544 struct VarExp : Expression
|
|
545 {
|
|
546 Declaration *var;
|
|
547
|
|
548 VarExp(Loc loc, Declaration *var);
|
|
549 int equals(Object *o);
|
|
550 Expression *semantic(Scope *sc);
|
|
551 Expression *optimize(int result);
|
|
552 Expression *interpret(InterState *istate);
|
|
553 void dump(int indent);
|
|
554 char *toChars();
|
|
555 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
556 void checkEscape();
|
|
557 Expression *toLvalue(Scope *sc, Expression *e);
|
|
558 Expression *modifiableLvalue(Scope *sc, Expression *e);
|
|
559 elem *toElem(IRState *irs);
|
|
560 dt_t **toDt(dt_t **pdt);
|
|
561 void scanForNestedRef(Scope *sc);
|
|
562
|
|
563 int inlineCost(InlineCostState *ics);
|
|
564 Expression *doInline(InlineDoState *ids);
|
|
565 //Expression *inlineScan(InlineScanState *iss);
|
|
566 };
|
|
567
|
|
568 // Function/Delegate literal
|
|
569
|
|
570 struct FuncExp : Expression
|
|
571 {
|
|
572 FuncLiteralDeclaration *fd;
|
|
573
|
|
574 FuncExp(Loc loc, FuncLiteralDeclaration *fd);
|
|
575 Expression *syntaxCopy();
|
|
576 Expression *semantic(Scope *sc);
|
|
577 void scanForNestedRef(Scope *sc);
|
|
578 char *toChars();
|
|
579 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
580 elem *toElem(IRState *irs);
|
|
581
|
|
582 int inlineCost(InlineCostState *ics);
|
|
583 //Expression *doInline(InlineDoState *ids);
|
|
584 //Expression *inlineScan(InlineScanState *iss);
|
|
585 };
|
|
586
|
|
587 // Declaration of a symbol
|
|
588
|
|
589 struct DeclarationExp : Expression
|
|
590 {
|
|
591 Dsymbol *declaration;
|
|
592
|
|
593 DeclarationExp(Loc loc, Dsymbol *declaration);
|
|
594 Expression *syntaxCopy();
|
|
595 Expression *semantic(Scope *sc);
|
|
596 Expression *interpret(InterState *istate);
|
|
597 int checkSideEffect(int flag);
|
|
598 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
599 elem *toElem(IRState *irs);
|
|
600 void scanForNestedRef(Scope *sc);
|
|
601
|
|
602 int inlineCost(InlineCostState *ics);
|
|
603 Expression *doInline(InlineDoState *ids);
|
|
604 Expression *inlineScan(InlineScanState *iss);
|
|
605 };
|
|
606
|
|
607 struct TypeidExp : Expression
|
|
608 {
|
|
609 Type *typeidType;
|
|
610
|
|
611 TypeidExp(Loc loc, Type *typeidType);
|
|
612 Expression *syntaxCopy();
|
|
613 Expression *semantic(Scope *sc);
|
|
614 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
615 };
|
|
616
|
|
617 struct HaltExp : Expression
|
|
618 {
|
|
619 HaltExp(Loc loc);
|
|
620 Expression *semantic(Scope *sc);
|
|
621 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
622 int checkSideEffect(int flag);
|
|
623
|
|
624 elem *toElem(IRState *irs);
|
|
625 };
|
|
626
|
19
|
627 struct IsExp : Expression
|
1
|
628 {
|
|
629 /* is(targ id tok tspec)
|
|
630 * is(targ id == tok2)
|
|
631 */
|
|
632 Type *targ;
|
|
633 Identifier *id; // can be NULL
|
|
634 enum TOK tok; // ':' or '=='
|
|
635 Type *tspec; // can be NULL
|
|
636 enum TOK tok2; // 'struct', 'union', 'typedef', etc.
|
|
637
|
19
|
638 IsExp(Loc loc, Type *targ, Identifier *id, enum TOK tok, Type *tspec, enum TOK tok2);
|
1
|
639 Expression *syntaxCopy();
|
|
640 Expression *semantic(Scope *sc);
|
|
641 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
642 };
|
|
643
|
|
644 /****************************************************************/
|
|
645
|
|
646 struct UnaExp : Expression
|
|
647 {
|
|
648 Expression *e1;
|
|
649
|
|
650 UnaExp(Loc loc, enum TOK op, int size, Expression *e1);
|
|
651 Expression *syntaxCopy();
|
|
652 Expression *semantic(Scope *sc);
|
|
653 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
654 Expression *optimize(int result);
|
|
655 void dump(int indent);
|
|
656 void scanForNestedRef(Scope *sc);
|
|
657 Expression *interpretCommon(InterState *istate, Expression *(*fp)(Type *, Expression *));
|
|
658
|
|
659 int inlineCost(InlineCostState *ics);
|
|
660 Expression *doInline(InlineDoState *ids);
|
|
661 Expression *inlineScan(InlineScanState *iss);
|
|
662
|
|
663 Expression *op_overload(Scope *sc); // doesn't need to be virtual
|
|
664 };
|
|
665
|
|
666 struct BinExp : Expression
|
|
667 {
|
|
668 Expression *e1;
|
|
669 Expression *e2;
|
|
670
|
|
671 BinExp(Loc loc, enum TOK op, int size, Expression *e1, Expression *e2);
|
|
672 Expression *syntaxCopy();
|
|
673 Expression *semantic(Scope *sc);
|
|
674 Expression *semanticp(Scope *sc);
|
|
675 Expression *commonSemanticAssign(Scope *sc);
|
|
676 Expression *commonSemanticAssignIntegral(Scope *sc);
|
|
677 int checkSideEffect(int flag);
|
|
678 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
679 Expression *scaleFactor(Scope *sc);
|
|
680 Expression *typeCombine(Scope *sc);
|
|
681 Expression *optimize(int result);
|
|
682 int isunsigned();
|
|
683 void incompatibleTypes();
|
|
684 void dump(int indent);
|
|
685 void scanForNestedRef(Scope *sc);
|
|
686 Expression *interpretCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *));
|
|
687 Expression *interpretCommon2(InterState *istate, Expression *(*fp)(TOK, Type *, Expression *, Expression *));
|
|
688 Expression *interpretAssignCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *), int post = 0);
|
|
689
|
|
690 int inlineCost(InlineCostState *ics);
|
|
691 Expression *doInline(InlineDoState *ids);
|
|
692 Expression *inlineScan(InlineScanState *iss);
|
|
693
|
|
694 Expression *op_overload(Scope *sc);
|
|
695
|
|
696 elem *toElemBin(IRState *irs, int op);
|
|
697 };
|
|
698
|
|
699 struct BinAssignExp : BinExp
|
|
700 {
|
|
701 BinAssignExp(Loc loc, enum TOK op, int size, Expression *e1, Expression *e2);
|
|
702 int checkSideEffect(int flag);
|
|
703 };
|
|
704
|
|
705 /****************************************************************/
|
|
706
|
|
707 struct CompileExp : UnaExp
|
|
708 {
|
|
709 CompileExp(Loc loc, Expression *e);
|
|
710 Expression *semantic(Scope *sc);
|
|
711 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
712 };
|
|
713
|
|
714 struct FileExp : UnaExp
|
|
715 {
|
|
716 FileExp(Loc loc, Expression *e);
|
|
717 Expression *semantic(Scope *sc);
|
|
718 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
719 };
|
|
720
|
|
721 struct AssertExp : UnaExp
|
|
722 {
|
|
723 Expression *msg;
|
|
724
|
|
725 AssertExp(Loc loc, Expression *e, Expression *msg = NULL);
|
|
726 Expression *syntaxCopy();
|
|
727 Expression *semantic(Scope *sc);
|
|
728 Expression *interpret(InterState *istate);
|
|
729 int checkSideEffect(int flag);
|
|
730 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
731
|
|
732 int inlineCost(InlineCostState *ics);
|
|
733 Expression *doInline(InlineDoState *ids);
|
|
734 Expression *inlineScan(InlineScanState *iss);
|
|
735
|
|
736 elem *toElem(IRState *irs);
|
|
737 };
|
|
738
|
|
739 struct DotIdExp : UnaExp
|
|
740 {
|
|
741 Identifier *ident;
|
|
742
|
|
743 DotIdExp(Loc loc, Expression *e, Identifier *ident);
|
|
744 Expression *semantic(Scope *sc);
|
|
745 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
746 void dump(int i);
|
|
747 };
|
|
748
|
|
749 struct DotTemplateExp : UnaExp
|
|
750 {
|
|
751 TemplateDeclaration *td;
|
|
752
|
|
753 DotTemplateExp(Loc loc, Expression *e, TemplateDeclaration *td);
|
|
754 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
755 };
|
|
756
|
|
757 struct DotVarExp : UnaExp
|
|
758 {
|
|
759 Declaration *var;
|
|
760
|
|
761 DotVarExp(Loc loc, Expression *e, Declaration *var);
|
|
762 Expression *semantic(Scope *sc);
|
|
763 Expression *toLvalue(Scope *sc, Expression *e);
|
|
764 Expression *modifiableLvalue(Scope *sc, Expression *e);
|
|
765 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
766 void dump(int indent);
|
|
767 elem *toElem(IRState *irs);
|
|
768 };
|
|
769
|
|
770 struct DotTemplateInstanceExp : UnaExp
|
|
771 {
|
|
772 TemplateInstance *ti;
|
|
773
|
|
774 DotTemplateInstanceExp(Loc loc, Expression *e, TemplateInstance *ti);
|
|
775 Expression *syntaxCopy();
|
|
776 Expression *semantic(Scope *sc);
|
|
777 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
778 void dump(int indent);
|
|
779 };
|
|
780
|
|
781 struct DelegateExp : UnaExp
|
|
782 {
|
|
783 FuncDeclaration *func;
|
|
784
|
|
785 DelegateExp(Loc loc, Expression *e, FuncDeclaration *func);
|
|
786 Expression *semantic(Scope *sc);
|
|
787 MATCH implicitConvTo(Type *t);
|
|
788 Expression *castTo(Scope *sc, Type *t);
|
|
789 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
790 void dump(int indent);
|
|
791
|
|
792 int inlineCost(InlineCostState *ics);
|
|
793 elem *toElem(IRState *irs);
|
|
794 };
|
|
795
|
|
796 struct DotTypeExp : UnaExp
|
|
797 {
|
|
798 Dsymbol *sym; // symbol that represents a type
|
|
799
|
|
800 DotTypeExp(Loc loc, Expression *e, Dsymbol *sym);
|
|
801 Expression *semantic(Scope *sc);
|
|
802 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
803 elem *toElem(IRState *irs);
|
|
804 };
|
|
805
|
|
806 struct CallExp : UnaExp
|
|
807 {
|
|
808 Expressions *arguments; // function arguments
|
|
809
|
|
810 CallExp(Loc loc, Expression *e, Expressions *exps);
|
|
811 CallExp(Loc loc, Expression *e);
|
|
812 CallExp(Loc loc, Expression *e, Expression *earg1);
|
|
813 CallExp(Loc loc, Expression *e, Expression *earg1, Expression *earg2);
|
|
814
|
|
815 Expression *syntaxCopy();
|
|
816 Expression *semantic(Scope *sc);
|
|
817 Expression *optimize(int result);
|
|
818 Expression *interpret(InterState *istate);
|
|
819 int checkSideEffect(int flag);
|
|
820 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
821 void dump(int indent);
|
|
822 elem *toElem(IRState *irs);
|
|
823 void scanForNestedRef(Scope *sc);
|
|
824 Expression *toLvalue(Scope *sc, Expression *e);
|
|
825
|
|
826 int inlineCost(InlineCostState *ics);
|
|
827 Expression *doInline(InlineDoState *ids);
|
|
828 Expression *inlineScan(InlineScanState *iss);
|
|
829 };
|
|
830
|
|
831 struct AddrExp : UnaExp
|
|
832 {
|
|
833 AddrExp(Loc loc, Expression *e);
|
|
834 Expression *semantic(Scope *sc);
|
|
835 elem *toElem(IRState *irs);
|
|
836 MATCH implicitConvTo(Type *t);
|
|
837 Expression *castTo(Scope *sc, Type *t);
|
|
838 Expression *optimize(int result);
|
|
839 };
|
|
840
|
|
841 struct PtrExp : UnaExp
|
|
842 {
|
|
843 PtrExp(Loc loc, Expression *e);
|
|
844 PtrExp(Loc loc, Expression *e, Type *t);
|
|
845 Expression *semantic(Scope *sc);
|
|
846 Expression *toLvalue(Scope *sc, Expression *e);
|
|
847 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
848 elem *toElem(IRState *irs);
|
|
849 Expression *optimize(int result);
|
|
850 Expression *interpret(InterState *istate);
|
|
851 };
|
|
852
|
|
853 struct NegExp : UnaExp
|
|
854 {
|
|
855 NegExp(Loc loc, Expression *e);
|
|
856 Expression *semantic(Scope *sc);
|
|
857 Expression *optimize(int result);
|
|
858 Expression *interpret(InterState *istate);
|
|
859
|
|
860 // For operator overloading
|
|
861 Identifier *opId();
|
|
862
|
|
863 elem *toElem(IRState *irs);
|
|
864 };
|
|
865
|
|
866 struct UAddExp : UnaExp
|
|
867 {
|
|
868 UAddExp(Loc loc, Expression *e);
|
|
869 Expression *semantic(Scope *sc);
|
|
870
|
|
871 // For operator overloading
|
|
872 Identifier *opId();
|
|
873 };
|
|
874
|
|
875 struct ComExp : UnaExp
|
|
876 {
|
|
877 ComExp(Loc loc, Expression *e);
|
|
878 Expression *semantic(Scope *sc);
|
|
879 Expression *optimize(int result);
|
|
880 Expression *interpret(InterState *istate);
|
|
881
|
|
882 // For operator overloading
|
|
883 Identifier *opId();
|
|
884
|
|
885 elem *toElem(IRState *irs);
|
|
886 };
|
|
887
|
|
888 struct NotExp : UnaExp
|
|
889 {
|
|
890 NotExp(Loc loc, Expression *e);
|
|
891 Expression *semantic(Scope *sc);
|
|
892 Expression *optimize(int result);
|
|
893 Expression *interpret(InterState *istate);
|
|
894 int isBit();
|
|
895 elem *toElem(IRState *irs);
|
|
896 };
|
|
897
|
|
898 struct BoolExp : UnaExp
|
|
899 {
|
|
900 BoolExp(Loc loc, Expression *e, Type *type);
|
|
901 Expression *semantic(Scope *sc);
|
|
902 Expression *optimize(int result);
|
|
903 Expression *interpret(InterState *istate);
|
|
904 int isBit();
|
|
905 elem *toElem(IRState *irs);
|
|
906 };
|
|
907
|
|
908 struct DeleteExp : UnaExp
|
|
909 {
|
|
910 DeleteExp(Loc loc, Expression *e);
|
|
911 Expression *semantic(Scope *sc);
|
|
912 Expression *checkToBoolean();
|
|
913 int checkSideEffect(int flag);
|
|
914 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
915 elem *toElem(IRState *irs);
|
|
916 };
|
|
917
|
|
918 struct CastExp : UnaExp
|
|
919 {
|
|
920 // Possible to cast to one type while painting to another type
|
|
921 Type *to; // type to cast to
|
|
922
|
|
923 CastExp(Loc loc, Expression *e, Type *t);
|
|
924 Expression *syntaxCopy();
|
|
925 Expression *semantic(Scope *sc);
|
|
926 Expression *optimize(int result);
|
|
927 Expression *interpret(InterState *istate);
|
|
928 int checkSideEffect(int flag);
|
|
929 void checkEscape();
|
|
930 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
931 elem *toElem(IRState *irs);
|
|
932
|
|
933 // For operator overloading
|
|
934 Identifier *opId();
|
|
935 };
|
|
936
|
|
937
|
|
938 struct SliceExp : UnaExp
|
|
939 {
|
|
940 Expression *upr; // NULL if implicit 0
|
|
941 Expression *lwr; // NULL if implicit [length - 1]
|
|
942 VarDeclaration *lengthVar;
|
|
943
|
|
944 SliceExp(Loc loc, Expression *e1, Expression *lwr, Expression *upr);
|
|
945 Expression *syntaxCopy();
|
|
946 Expression *semantic(Scope *sc);
|
|
947 void checkEscape();
|
|
948 Expression *toLvalue(Scope *sc, Expression *e);
|
|
949 Expression *modifiableLvalue(Scope *sc, Expression *e);
|
|
950 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
951 Expression *optimize(int result);
|
|
952 Expression *interpret(InterState *istate);
|
|
953 void dump(int indent);
|
|
954 elem *toElem(IRState *irs);
|
|
955 void scanForNestedRef(Scope *sc);
|
|
956
|
|
957 int inlineCost(InlineCostState *ics);
|
|
958 Expression *doInline(InlineDoState *ids);
|
|
959 Expression *inlineScan(InlineScanState *iss);
|
|
960 };
|
|
961
|
|
962 struct ArrayLengthExp : UnaExp
|
|
963 {
|
|
964 ArrayLengthExp(Loc loc, Expression *e1);
|
|
965 Expression *semantic(Scope *sc);
|
|
966 Expression *optimize(int result);
|
|
967 Expression *interpret(InterState *istate);
|
|
968 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
969 elem *toElem(IRState *irs);
|
|
970 };
|
|
971
|
|
972 // e1[a0,a1,a2,a3,...]
|
|
973
|
|
974 struct ArrayExp : UnaExp
|
|
975 {
|
|
976 Expressions *arguments; // Array of Expression's
|
|
977
|
|
978 ArrayExp(Loc loc, Expression *e1, Expressions *arguments);
|
|
979 Expression *syntaxCopy();
|
|
980 Expression *semantic(Scope *sc);
|
|
981 Expression *toLvalue(Scope *sc, Expression *e);
|
|
982 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
983 void scanForNestedRef(Scope *sc);
|
|
984
|
|
985 // For operator overloading
|
|
986 Identifier *opId();
|
|
987
|
|
988 int inlineCost(InlineCostState *ics);
|
|
989 Expression *doInline(InlineDoState *ids);
|
|
990 Expression *inlineScan(InlineScanState *iss);
|
|
991 };
|
|
992
|
|
993 /****************************************************************/
|
|
994
|
|
995 struct DotExp : BinExp
|
|
996 {
|
|
997 DotExp(Loc loc, Expression *e1, Expression *e2);
|
|
998 Expression *semantic(Scope *sc);
|
|
999 };
|
|
1000
|
|
1001 struct CommaExp : BinExp
|
|
1002 {
|
|
1003 CommaExp(Loc loc, Expression *e1, Expression *e2);
|
|
1004 Expression *semantic(Scope *sc);
|
|
1005 void checkEscape();
|
|
1006 Expression *toLvalue(Scope *sc, Expression *e);
|
|
1007 Expression *modifiableLvalue(Scope *sc, Expression *e);
|
|
1008 int isBool(int result);
|
|
1009 int checkSideEffect(int flag);
|
|
1010 Expression *optimize(int result);
|
|
1011 Expression *interpret(InterState *istate);
|
|
1012 elem *toElem(IRState *irs);
|
|
1013 };
|
|
1014
|
|
1015 struct IndexExp : BinExp
|
|
1016 {
|
|
1017 VarDeclaration *lengthVar;
|
|
1018 int modifiable;
|
|
1019
|
|
1020 IndexExp(Loc loc, Expression *e1, Expression *e2);
|
|
1021 Expression *semantic(Scope *sc);
|
|
1022 Expression *toLvalue(Scope *sc, Expression *e);
|
|
1023 Expression *modifiableLvalue(Scope *sc, Expression *e);
|
|
1024 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
1025 Expression *optimize(int result);
|
|
1026 Expression *interpret(InterState *istate);
|
|
1027 Expression *doInline(InlineDoState *ids);
|
|
1028 void scanForNestedRef(Scope *sc);
|
|
1029
|
|
1030 elem *toElem(IRState *irs);
|
|
1031 };
|
|
1032
|
|
1033 /* For both i++ and i--
|
|
1034 */
|
|
1035 struct PostExp : BinExp
|
|
1036 {
|
|
1037 PostExp(enum TOK op, Loc loc, Expression *e);
|
|
1038 Expression *semantic(Scope *sc);
|
|
1039 Expression *interpret(InterState *istate);
|
|
1040 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
1041 Identifier *opId(); // For operator overloading
|
|
1042 elem *toElem(IRState *irs);
|
|
1043 };
|
|
1044
|
|
1045 struct AssignExp : BinExp
|
|
1046 { int ismemset; // !=0 if setting the contents of an array
|
|
1047
|
|
1048 AssignExp(Loc loc, Expression *e1, Expression *e2);
|
|
1049 Expression *semantic(Scope *sc);
|
|
1050 Expression *checkToBoolean();
|
|
1051 Expression *interpret(InterState *istate);
|
|
1052 Identifier *opId(); // For operator overloading
|
|
1053 elem *toElem(IRState *irs);
|
|
1054 };
|
|
1055
|
|
1056 #define ASSIGNEXP(op) \
|
|
1057 struct op##AssignExp : BinExp \
|
|
1058 { \
|
|
1059 op##AssignExp(Loc loc, Expression *e1, Expression *e2); \
|
|
1060 Expression *semantic(Scope *sc); \
|
|
1061 Expression *interpret(InterState *istate); \
|
|
1062 \
|
|
1063 Identifier *opId(); /* For operator overloading */ \
|
|
1064 \
|
|
1065 elem *toElem(IRState *irs); \
|
|
1066 };
|
|
1067
|
|
1068 ASSIGNEXP(Add)
|
|
1069 ASSIGNEXP(Min)
|
|
1070 ASSIGNEXP(Cat)
|
|
1071 ASSIGNEXP(Mul)
|
|
1072 ASSIGNEXP(Div)
|
|
1073 ASSIGNEXP(Mod)
|
|
1074 ASSIGNEXP(Shl)
|
|
1075 ASSIGNEXP(Shr)
|
|
1076 ASSIGNEXP(Ushr)
|
|
1077 ASSIGNEXP(And)
|
|
1078 ASSIGNEXP(Or)
|
|
1079 ASSIGNEXP(Xor)
|
|
1080
|
|
1081 #undef ASSIGNEXP
|
|
1082
|
|
1083 struct AddExp : BinExp
|
|
1084 {
|
|
1085 AddExp(Loc loc, Expression *e1, Expression *e2);
|
|
1086 Expression *semantic(Scope *sc);
|
|
1087 Expression *optimize(int result);
|
|
1088 Expression *interpret(InterState *istate);
|
|
1089
|
|
1090 // For operator overloading
|
|
1091 int isCommutative();
|
|
1092 Identifier *opId();
|
|
1093 Identifier *opId_r();
|
|
1094
|
|
1095 elem *toElem(IRState *irs);
|
|
1096 };
|
|
1097
|
|
1098 struct MinExp : BinExp
|
|
1099 {
|
|
1100 MinExp(Loc loc, Expression *e1, Expression *e2);
|
|
1101 Expression *semantic(Scope *sc);
|
|
1102 Expression *optimize(int result);
|
|
1103 Expression *interpret(InterState *istate);
|
|
1104
|
|
1105 // For operator overloading
|
|
1106 Identifier *opId();
|
|
1107 Identifier *opId_r();
|
|
1108
|
|
1109 elem *toElem(IRState *irs);
|
|
1110 };
|
|
1111
|
|
1112 struct CatExp : BinExp
|
|
1113 {
|
|
1114 CatExp(Loc loc, Expression *e1, Expression *e2);
|
|
1115 Expression *semantic(Scope *sc);
|
|
1116 Expression *optimize(int result);
|
|
1117 Expression *interpret(InterState *istate);
|
|
1118
|
|
1119 // For operator overloading
|
|
1120 Identifier *opId();
|
|
1121 Identifier *opId_r();
|
|
1122
|
|
1123 elem *toElem(IRState *irs);
|
|
1124 };
|
|
1125
|
|
1126 struct MulExp : BinExp
|
|
1127 {
|
|
1128 MulExp(Loc loc, Expression *e1, Expression *e2);
|
|
1129 Expression *semantic(Scope *sc);
|
|
1130 Expression *optimize(int result);
|
|
1131 Expression *interpret(InterState *istate);
|
|
1132
|
|
1133 // For operator overloading
|
|
1134 int isCommutative();
|
|
1135 Identifier *opId();
|
|
1136 Identifier *opId_r();
|
|
1137
|
|
1138 elem *toElem(IRState *irs);
|
|
1139 };
|
|
1140
|
|
1141 struct DivExp : BinExp
|
|
1142 {
|
|
1143 DivExp(Loc loc, Expression *e1, Expression *e2);
|
|
1144 Expression *semantic(Scope *sc);
|
|
1145 Expression *optimize(int result);
|
|
1146 Expression *interpret(InterState *istate);
|
|
1147
|
|
1148 // For operator overloading
|
|
1149 Identifier *opId();
|
|
1150 Identifier *opId_r();
|
|
1151
|
|
1152 elem *toElem(IRState *irs);
|
|
1153 };
|
|
1154
|
|
1155 struct ModExp : BinExp
|
|
1156 {
|
|
1157 ModExp(Loc loc, Expression *e1, Expression *e2);
|
|
1158 Expression *semantic(Scope *sc);
|
|
1159 Expression *optimize(int result);
|
|
1160 Expression *interpret(InterState *istate);
|
|
1161
|
|
1162 // For operator overloading
|
|
1163 Identifier *opId();
|
|
1164 Identifier *opId_r();
|
|
1165
|
|
1166 elem *toElem(IRState *irs);
|
|
1167 };
|
|
1168
|
|
1169 struct ShlExp : BinExp
|
|
1170 {
|
|
1171 ShlExp(Loc loc, Expression *e1, Expression *e2);
|
|
1172 Expression *semantic(Scope *sc);
|
|
1173 Expression *optimize(int result);
|
|
1174 Expression *interpret(InterState *istate);
|
|
1175
|
|
1176 // For operator overloading
|
|
1177 Identifier *opId();
|
|
1178 Identifier *opId_r();
|
|
1179
|
|
1180 elem *toElem(IRState *irs);
|
|
1181 };
|
|
1182
|
|
1183 struct ShrExp : BinExp
|
|
1184 {
|
|
1185 ShrExp(Loc loc, Expression *e1, Expression *e2);
|
|
1186 Expression *semantic(Scope *sc);
|
|
1187 Expression *optimize(int result);
|
|
1188 Expression *interpret(InterState *istate);
|
|
1189
|
|
1190 // For operator overloading
|
|
1191 Identifier *opId();
|
|
1192 Identifier *opId_r();
|
|
1193
|
|
1194 elem *toElem(IRState *irs);
|
|
1195 };
|
|
1196
|
|
1197 struct UshrExp : BinExp
|
|
1198 {
|
|
1199 UshrExp(Loc loc, Expression *e1, Expression *e2);
|
|
1200 Expression *semantic(Scope *sc);
|
|
1201 Expression *optimize(int result);
|
|
1202 Expression *interpret(InterState *istate);
|
|
1203
|
|
1204 // For operator overloading
|
|
1205 Identifier *opId();
|
|
1206 Identifier *opId_r();
|
|
1207
|
|
1208 elem *toElem(IRState *irs);
|
|
1209 };
|
|
1210
|
|
1211 struct AndExp : BinExp
|
|
1212 {
|
|
1213 AndExp(Loc loc, Expression *e1, Expression *e2);
|
|
1214 Expression *semantic(Scope *sc);
|
|
1215 Expression *optimize(int result);
|
|
1216 Expression *interpret(InterState *istate);
|
|
1217
|
|
1218 // For operator overloading
|
|
1219 int isCommutative();
|
|
1220 Identifier *opId();
|
|
1221 Identifier *opId_r();
|
|
1222
|
|
1223 elem *toElem(IRState *irs);
|
|
1224 };
|
|
1225
|
|
1226 struct OrExp : BinExp
|
|
1227 {
|
|
1228 OrExp(Loc loc, Expression *e1, Expression *e2);
|
|
1229 Expression *semantic(Scope *sc);
|
|
1230 Expression *optimize(int result);
|
|
1231 Expression *interpret(InterState *istate);
|
|
1232
|
|
1233 // For operator overloading
|
|
1234 int isCommutative();
|
|
1235 Identifier *opId();
|
|
1236 Identifier *opId_r();
|
|
1237
|
|
1238 elem *toElem(IRState *irs);
|
|
1239 };
|
|
1240
|
|
1241 struct XorExp : BinExp
|
|
1242 {
|
|
1243 XorExp(Loc loc, Expression *e1, Expression *e2);
|
|
1244 Expression *semantic(Scope *sc);
|
|
1245 Expression *optimize(int result);
|
|
1246 Expression *interpret(InterState *istate);
|
|
1247
|
|
1248 // For operator overloading
|
|
1249 int isCommutative();
|
|
1250 Identifier *opId();
|
|
1251 Identifier *opId_r();
|
|
1252
|
|
1253 elem *toElem(IRState *irs);
|
|
1254 };
|
|
1255
|
|
1256 struct OrOrExp : BinExp
|
|
1257 {
|
|
1258 OrOrExp(Loc loc, Expression *e1, Expression *e2);
|
|
1259 Expression *semantic(Scope *sc);
|
|
1260 Expression *checkToBoolean();
|
|
1261 int isBit();
|
|
1262 Expression *optimize(int result);
|
|
1263 Expression *interpret(InterState *istate);
|
|
1264 int checkSideEffect(int flag);
|
|
1265 elem *toElem(IRState *irs);
|
|
1266 };
|
|
1267
|
|
1268 struct AndAndExp : BinExp
|
|
1269 {
|
|
1270 AndAndExp(Loc loc, Expression *e1, Expression *e2);
|
|
1271 Expression *semantic(Scope *sc);
|
|
1272 Expression *checkToBoolean();
|
|
1273 int isBit();
|
|
1274 Expression *optimize(int result);
|
|
1275 Expression *interpret(InterState *istate);
|
|
1276 int checkSideEffect(int flag);
|
|
1277 elem *toElem(IRState *irs);
|
|
1278 };
|
|
1279
|
|
1280 struct CmpExp : BinExp
|
|
1281 {
|
|
1282 CmpExp(enum TOK op, Loc loc, Expression *e1, Expression *e2);
|
|
1283 Expression *semantic(Scope *sc);
|
|
1284 Expression *optimize(int result);
|
|
1285 Expression *interpret(InterState *istate);
|
|
1286 int isBit();
|
|
1287
|
|
1288 // For operator overloading
|
|
1289 int isCommutative();
|
|
1290 Identifier *opId();
|
|
1291
|
|
1292 elem *toElem(IRState *irs);
|
|
1293 };
|
|
1294
|
|
1295 struct InExp : BinExp
|
|
1296 {
|
|
1297 InExp(Loc loc, Expression *e1, Expression *e2);
|
|
1298 Expression *semantic(Scope *sc);
|
|
1299 int isBit();
|
|
1300
|
|
1301 // For operator overloading
|
|
1302 Identifier *opId();
|
|
1303 Identifier *opId_r();
|
|
1304
|
|
1305 elem *toElem(IRState *irs);
|
|
1306 };
|
|
1307
|
|
1308 struct RemoveExp : BinExp
|
|
1309 {
|
|
1310 RemoveExp(Loc loc, Expression *e1, Expression *e2);
|
|
1311 elem *toElem(IRState *irs);
|
|
1312 };
|
|
1313
|
|
1314 // == and !=
|
|
1315
|
|
1316 struct EqualExp : BinExp
|
|
1317 {
|
|
1318 EqualExp(enum TOK op, Loc loc, Expression *e1, Expression *e2);
|
|
1319 Expression *semantic(Scope *sc);
|
|
1320 Expression *optimize(int result);
|
|
1321 Expression *interpret(InterState *istate);
|
|
1322 int isBit();
|
|
1323
|
|
1324 // For operator overloading
|
|
1325 int isCommutative();
|
|
1326 Identifier *opId();
|
|
1327
|
|
1328 elem *toElem(IRState *irs);
|
|
1329 };
|
|
1330
|
|
1331 // === and !===
|
|
1332
|
|
1333 struct IdentityExp : BinExp
|
|
1334 {
|
|
1335 IdentityExp(enum TOK op, Loc loc, Expression *e1, Expression *e2);
|
|
1336 Expression *semantic(Scope *sc);
|
|
1337 int isBit();
|
|
1338 Expression *optimize(int result);
|
|
1339 Expression *interpret(InterState *istate);
|
|
1340 elem *toElem(IRState *irs);
|
|
1341 };
|
|
1342
|
|
1343 /****************************************************************/
|
|
1344
|
|
1345 struct CondExp : BinExp
|
|
1346 {
|
|
1347 Expression *econd;
|
|
1348
|
|
1349 CondExp(Loc loc, Expression *econd, Expression *e1, Expression *e2);
|
|
1350 Expression *syntaxCopy();
|
|
1351 Expression *semantic(Scope *sc);
|
|
1352 Expression *optimize(int result);
|
|
1353 Expression *interpret(InterState *istate);
|
|
1354 void checkEscape();
|
|
1355 Expression *toLvalue(Scope *sc, Expression *e);
|
|
1356 Expression *modifiableLvalue(Scope *sc, Expression *e);
|
|
1357 Expression *checkToBoolean();
|
|
1358 int checkSideEffect(int flag);
|
|
1359 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
1360 MATCH implicitConvTo(Type *t);
|
|
1361 Expression *castTo(Scope *sc, Type *t);
|
|
1362 void scanForNestedRef(Scope *sc);
|
|
1363
|
|
1364 int inlineCost(InlineCostState *ics);
|
|
1365 Expression *doInline(InlineDoState *ids);
|
|
1366 Expression *inlineScan(InlineScanState *iss);
|
|
1367
|
|
1368 elem *toElem(IRState *irs);
|
|
1369 };
|
|
1370
|
|
1371
|
|
1372 /****************************************************************/
|
|
1373
|
|
1374 /* Special values used by the interpreter
|
|
1375 */
|
|
1376 #define EXP_CANT_INTERPRET ((Expression *)1)
|
|
1377 #define EXP_CONTINUE_INTERPRET ((Expression *)2)
|
|
1378 #define EXP_BREAK_INTERPRET ((Expression *)3)
|
|
1379 #define EXP_GOTO_INTERPRET ((Expression *)4)
|
|
1380 #define EXP_VOID_INTERPRET ((Expression *)5)
|
|
1381
|
|
1382 Expression *expType(Type *type, Expression *e);
|
|
1383
|
|
1384 Expression *Neg(Type *type, Expression *e1);
|
|
1385 Expression *Com(Type *type, Expression *e1);
|
|
1386 Expression *Not(Type *type, Expression *e1);
|
|
1387 Expression *Bool(Type *type, Expression *e1);
|
|
1388 Expression *Cast(Type *type, Type *to, Expression *e1);
|
|
1389 Expression *ArrayLength(Type *type, Expression *e1);
|
|
1390 Expression *Ptr(Type *type, Expression *e1);
|
|
1391
|
|
1392 Expression *Add(Type *type, Expression *e1, Expression *e2);
|
|
1393 Expression *Min(Type *type, Expression *e1, Expression *e2);
|
|
1394 Expression *Mul(Type *type, Expression *e1, Expression *e2);
|
|
1395 Expression *Div(Type *type, Expression *e1, Expression *e2);
|
|
1396 Expression *Mod(Type *type, Expression *e1, Expression *e2);
|
|
1397 Expression *Shl(Type *type, Expression *e1, Expression *e2);
|
|
1398 Expression *Shr(Type *type, Expression *e1, Expression *e2);
|
|
1399 Expression *Ushr(Type *type, Expression *e1, Expression *e2);
|
|
1400 Expression *And(Type *type, Expression *e1, Expression *e2);
|
|
1401 Expression *Or(Type *type, Expression *e1, Expression *e2);
|
|
1402 Expression *Xor(Type *type, Expression *e1, Expression *e2);
|
|
1403 Expression *Index(Type *type, Expression *e1, Expression *e2);
|
|
1404 Expression *Cat(Type *type, Expression *e1, Expression *e2);
|
|
1405
|
|
1406 Expression *Equal(enum TOK op, Type *type, Expression *e1, Expression *e2);
|
|
1407 Expression *Cmp(enum TOK op, Type *type, Expression *e1, Expression *e2);
|
|
1408 Expression *Identity(enum TOK op, Type *type, Expression *e1, Expression *e2);
|
|
1409
|
|
1410 Expression *Slice(Type *type, Expression *e1, Expression *lwr, Expression *upr);
|
|
1411
|
|
1412 #endif /* DMD_EXPRESSION_H */
|