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