root/trunk/src/expression.h

Revision 736, 47.0 kB (checked in by Don Clugston, 2 years ago)

3020 No description is given why function may not be nothrow

Note that this also allows memory allocation inside nothrow functions. Switch statements with missing default are still forbidden.

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