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