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