comparison dmd2/expression.h @ 758:f04dde6e882c

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