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);
|
|
868 };
|
|
869
|
|
870 struct PtrExp : UnaExp
|
|
871 {
|
|
872 PtrExp(Loc loc, Expression *e);
|
|
873 PtrExp(Loc loc, Expression *e, Type *t);
|
|
874 Expression *semantic(Scope *sc);
|
|
875 Expression *toLvalue(Scope *sc, Expression *e);
|
|
876 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
877 elem *toElem(IRState *irs);
|
|
878 Expression *optimize(int result);
|
|
879 Expression *interpret(InterState *istate);
|
|
880 };
|
|
881
|
|
882 struct NegExp : UnaExp
|
|
883 {
|
|
884 NegExp(Loc loc, Expression *e);
|
|
885 Expression *semantic(Scope *sc);
|
|
886 Expression *optimize(int result);
|
|
887 Expression *interpret(InterState *istate);
|
|
888
|
|
889 // For operator overloading
|
|
890 Identifier *opId();
|
|
891
|
|
892 elem *toElem(IRState *irs);
|
|
893 };
|
|
894
|
|
895 struct UAddExp : UnaExp
|
|
896 {
|
|
897 UAddExp(Loc loc, Expression *e);
|
|
898 Expression *semantic(Scope *sc);
|
|
899
|
|
900 // For operator overloading
|
|
901 Identifier *opId();
|
|
902 };
|
|
903
|
|
904 struct ComExp : UnaExp
|
|
905 {
|
|
906 ComExp(Loc loc, Expression *e);
|
|
907 Expression *semantic(Scope *sc);
|
|
908 Expression *optimize(int result);
|
|
909 Expression *interpret(InterState *istate);
|
|
910
|
|
911 // For operator overloading
|
|
912 Identifier *opId();
|
|
913
|
|
914 elem *toElem(IRState *irs);
|
|
915 };
|
|
916
|
|
917 struct NotExp : UnaExp
|
|
918 {
|
|
919 NotExp(Loc loc, Expression *e);
|
|
920 Expression *semantic(Scope *sc);
|
|
921 Expression *optimize(int result);
|
|
922 Expression *interpret(InterState *istate);
|
|
923 int isBit();
|
|
924 elem *toElem(IRState *irs);
|
|
925 };
|
|
926
|
|
927 struct BoolExp : UnaExp
|
|
928 {
|
|
929 BoolExp(Loc loc, Expression *e, Type *type);
|
|
930 Expression *semantic(Scope *sc);
|
|
931 Expression *optimize(int result);
|
|
932 Expression *interpret(InterState *istate);
|
|
933 int isBit();
|
|
934 elem *toElem(IRState *irs);
|
|
935 };
|
|
936
|
|
937 struct DeleteExp : UnaExp
|
|
938 {
|
|
939 DeleteExp(Loc loc, Expression *e);
|
|
940 Expression *semantic(Scope *sc);
|
|
941 Expression *checkToBoolean();
|
|
942 int checkSideEffect(int flag);
|
|
943 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
944 elem *toElem(IRState *irs);
|
|
945 };
|
|
946
|
|
947 struct CastExp : UnaExp
|
|
948 {
|
|
949 // Possible to cast to one type while painting to another type
|
|
950 Type *to; // type to cast to
|
|
951
|
|
952 CastExp(Loc loc, Expression *e, Type *t);
|
|
953 Expression *syntaxCopy();
|
|
954 Expression *semantic(Scope *sc);
|
|
955 Expression *optimize(int result);
|
|
956 Expression *interpret(InterState *istate);
|
|
957 int checkSideEffect(int flag);
|
|
958 void checkEscape();
|
|
959 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
960 elem *toElem(IRState *irs);
|
|
961
|
|
962 // For operator overloading
|
|
963 Identifier *opId();
|
|
964 };
|
|
965
|
|
966
|
|
967 struct SliceExp : UnaExp
|
|
968 {
|
|
969 Expression *upr; // NULL if implicit 0
|
|
970 Expression *lwr; // NULL if implicit [length - 1]
|
|
971 VarDeclaration *lengthVar;
|
|
972
|
|
973 SliceExp(Loc loc, Expression *e1, Expression *lwr, Expression *upr);
|
|
974 Expression *syntaxCopy();
|
|
975 Expression *semantic(Scope *sc);
|
|
976 void checkEscape();
|
|
977 Expression *toLvalue(Scope *sc, Expression *e);
|
|
978 Expression *modifiableLvalue(Scope *sc, Expression *e);
|
|
979 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
980 Expression *optimize(int result);
|
|
981 Expression *interpret(InterState *istate);
|
|
982 void dump(int indent);
|
|
983 elem *toElem(IRState *irs);
|
|
984 void scanForNestedRef(Scope *sc);
|
|
985
|
|
986 int inlineCost(InlineCostState *ics);
|
|
987 Expression *doInline(InlineDoState *ids);
|
|
988 Expression *inlineScan(InlineScanState *iss);
|
|
989 };
|
|
990
|
|
991 struct ArrayLengthExp : UnaExp
|
|
992 {
|
|
993 ArrayLengthExp(Loc loc, Expression *e1);
|
|
994 Expression *semantic(Scope *sc);
|
|
995 Expression *optimize(int result);
|
|
996 Expression *interpret(InterState *istate);
|
|
997 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
998 elem *toElem(IRState *irs);
|
|
999 };
|
|
1000
|
|
1001 // e1[a0,a1,a2,a3,...]
|
|
1002
|
|
1003 struct ArrayExp : UnaExp
|
|
1004 {
|
|
1005 Expressions *arguments; // Array of Expression's
|
|
1006
|
|
1007 ArrayExp(Loc loc, Expression *e1, Expressions *arguments);
|
|
1008 Expression *syntaxCopy();
|
|
1009 Expression *semantic(Scope *sc);
|
|
1010 Expression *toLvalue(Scope *sc, Expression *e);
|
|
1011 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
1012 void scanForNestedRef(Scope *sc);
|
|
1013
|
|
1014 // For operator overloading
|
|
1015 Identifier *opId();
|
|
1016
|
|
1017 int inlineCost(InlineCostState *ics);
|
|
1018 Expression *doInline(InlineDoState *ids);
|
|
1019 Expression *inlineScan(InlineScanState *iss);
|
|
1020 };
|
|
1021
|
|
1022 /****************************************************************/
|
|
1023
|
|
1024 struct DotExp : BinExp
|
|
1025 {
|
|
1026 DotExp(Loc loc, Expression *e1, Expression *e2);
|
|
1027 Expression *semantic(Scope *sc);
|
|
1028 };
|
|
1029
|
|
1030 struct CommaExp : BinExp
|
|
1031 {
|
|
1032 CommaExp(Loc loc, Expression *e1, Expression *e2);
|
|
1033 Expression *semantic(Scope *sc);
|
|
1034 void checkEscape();
|
|
1035 Expression *toLvalue(Scope *sc, Expression *e);
|
|
1036 Expression *modifiableLvalue(Scope *sc, Expression *e);
|
|
1037 int isBool(int result);
|
|
1038 int checkSideEffect(int flag);
|
|
1039 Expression *optimize(int result);
|
|
1040 Expression *interpret(InterState *istate);
|
|
1041 elem *toElem(IRState *irs);
|
|
1042 };
|
|
1043
|
|
1044 struct IndexExp : BinExp
|
|
1045 {
|
|
1046 VarDeclaration *lengthVar;
|
|
1047 int modifiable;
|
|
1048
|
|
1049 IndexExp(Loc loc, Expression *e1, Expression *e2);
|
|
1050 Expression *semantic(Scope *sc);
|
|
1051 Expression *toLvalue(Scope *sc, Expression *e);
|
|
1052 Expression *modifiableLvalue(Scope *sc, Expression *e);
|
|
1053 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
1054 Expression *optimize(int result);
|
|
1055 Expression *interpret(InterState *istate);
|
|
1056 Expression *doInline(InlineDoState *ids);
|
|
1057 void scanForNestedRef(Scope *sc);
|
|
1058
|
|
1059 elem *toElem(IRState *irs);
|
|
1060 };
|
|
1061
|
|
1062 /* For both i++ and i--
|
|
1063 */
|
|
1064 struct PostExp : BinExp
|
|
1065 {
|
|
1066 PostExp(enum TOK op, Loc loc, Expression *e);
|
|
1067 Expression *semantic(Scope *sc);
|
|
1068 Expression *interpret(InterState *istate);
|
|
1069 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
1070 Identifier *opId(); // For operator overloading
|
|
1071 elem *toElem(IRState *irs);
|
|
1072 };
|
|
1073
|
|
1074 struct AssignExp : BinExp
|
|
1075 { int ismemset; // !=0 if setting the contents of an array
|
|
1076
|
|
1077 AssignExp(Loc loc, Expression *e1, Expression *e2);
|
|
1078 Expression *semantic(Scope *sc);
|
|
1079 Expression *checkToBoolean();
|
|
1080 Expression *interpret(InterState *istate);
|
|
1081 Identifier *opId(); // For operator overloading
|
|
1082 elem *toElem(IRState *irs);
|
|
1083 };
|
|
1084
|
|
1085 #define ASSIGNEXP(op) \
|
|
1086 struct op##AssignExp : BinExp \
|
|
1087 { \
|
|
1088 op##AssignExp(Loc loc, Expression *e1, Expression *e2); \
|
|
1089 Expression *semantic(Scope *sc); \
|
|
1090 Expression *interpret(InterState *istate); \
|
|
1091 \
|
|
1092 Identifier *opId(); /* For operator overloading */ \
|
|
1093 \
|
|
1094 elem *toElem(IRState *irs); \
|
|
1095 };
|
|
1096
|
|
1097 ASSIGNEXP(Add)
|
|
1098 ASSIGNEXP(Min)
|
|
1099 ASSIGNEXP(Cat)
|
|
1100 ASSIGNEXP(Mul)
|
|
1101 ASSIGNEXP(Div)
|
|
1102 ASSIGNEXP(Mod)
|
|
1103 ASSIGNEXP(Shl)
|
|
1104 ASSIGNEXP(Shr)
|
|
1105 ASSIGNEXP(Ushr)
|
|
1106 ASSIGNEXP(And)
|
|
1107 ASSIGNEXP(Or)
|
|
1108 ASSIGNEXP(Xor)
|
|
1109
|
|
1110 #undef ASSIGNEXP
|
|
1111
|
|
1112 struct AddExp : BinExp
|
|
1113 {
|
|
1114 AddExp(Loc loc, Expression *e1, Expression *e2);
|
|
1115 Expression *semantic(Scope *sc);
|
|
1116 Expression *optimize(int result);
|
|
1117 Expression *interpret(InterState *istate);
|
|
1118
|
|
1119 // For operator overloading
|
|
1120 int isCommutative();
|
|
1121 Identifier *opId();
|
|
1122 Identifier *opId_r();
|
|
1123
|
|
1124 elem *toElem(IRState *irs);
|
|
1125
|
|
1126 // LLVMDC
|
|
1127 bool llvmFieldIndex;
|
|
1128 };
|
|
1129
|
|
1130 struct MinExp : BinExp
|
|
1131 {
|
|
1132 MinExp(Loc loc, Expression *e1, Expression *e2);
|
|
1133 Expression *semantic(Scope *sc);
|
|
1134 Expression *optimize(int result);
|
|
1135 Expression *interpret(InterState *istate);
|
|
1136
|
|
1137 // For operator overloading
|
|
1138 Identifier *opId();
|
|
1139 Identifier *opId_r();
|
|
1140
|
|
1141 elem *toElem(IRState *irs);
|
|
1142 };
|
|
1143
|
|
1144 struct CatExp : BinExp
|
|
1145 {
|
|
1146 CatExp(Loc loc, Expression *e1, Expression *e2);
|
|
1147 Expression *semantic(Scope *sc);
|
|
1148 Expression *optimize(int result);
|
|
1149 Expression *interpret(InterState *istate);
|
|
1150
|
|
1151 // For operator overloading
|
|
1152 Identifier *opId();
|
|
1153 Identifier *opId_r();
|
|
1154
|
|
1155 elem *toElem(IRState *irs);
|
|
1156 };
|
|
1157
|
|
1158 struct MulExp : BinExp
|
|
1159 {
|
|
1160 MulExp(Loc loc, Expression *e1, Expression *e2);
|
|
1161 Expression *semantic(Scope *sc);
|
|
1162 Expression *optimize(int result);
|
|
1163 Expression *interpret(InterState *istate);
|
|
1164
|
|
1165 // For operator overloading
|
|
1166 int isCommutative();
|
|
1167 Identifier *opId();
|
|
1168 Identifier *opId_r();
|
|
1169
|
|
1170 elem *toElem(IRState *irs);
|
|
1171 };
|
|
1172
|
|
1173 struct DivExp : BinExp
|
|
1174 {
|
|
1175 DivExp(Loc loc, Expression *e1, Expression *e2);
|
|
1176 Expression *semantic(Scope *sc);
|
|
1177 Expression *optimize(int result);
|
|
1178 Expression *interpret(InterState *istate);
|
|
1179
|
|
1180 // For operator overloading
|
|
1181 Identifier *opId();
|
|
1182 Identifier *opId_r();
|
|
1183
|
|
1184 elem *toElem(IRState *irs);
|
|
1185 };
|
|
1186
|
|
1187 struct ModExp : BinExp
|
|
1188 {
|
|
1189 ModExp(Loc loc, Expression *e1, Expression *e2);
|
|
1190 Expression *semantic(Scope *sc);
|
|
1191 Expression *optimize(int result);
|
|
1192 Expression *interpret(InterState *istate);
|
|
1193
|
|
1194 // For operator overloading
|
|
1195 Identifier *opId();
|
|
1196 Identifier *opId_r();
|
|
1197
|
|
1198 elem *toElem(IRState *irs);
|
|
1199 };
|
|
1200
|
|
1201 struct ShlExp : BinExp
|
|
1202 {
|
|
1203 ShlExp(Loc loc, Expression *e1, Expression *e2);
|
|
1204 Expression *semantic(Scope *sc);
|
|
1205 Expression *optimize(int result);
|
|
1206 Expression *interpret(InterState *istate);
|
|
1207
|
|
1208 // For operator overloading
|
|
1209 Identifier *opId();
|
|
1210 Identifier *opId_r();
|
|
1211
|
|
1212 elem *toElem(IRState *irs);
|
|
1213 };
|
|
1214
|
|
1215 struct ShrExp : BinExp
|
|
1216 {
|
|
1217 ShrExp(Loc loc, Expression *e1, Expression *e2);
|
|
1218 Expression *semantic(Scope *sc);
|
|
1219 Expression *optimize(int result);
|
|
1220 Expression *interpret(InterState *istate);
|
|
1221
|
|
1222 // For operator overloading
|
|
1223 Identifier *opId();
|
|
1224 Identifier *opId_r();
|
|
1225
|
|
1226 elem *toElem(IRState *irs);
|
|
1227 };
|
|
1228
|
|
1229 struct UshrExp : BinExp
|
|
1230 {
|
|
1231 UshrExp(Loc loc, Expression *e1, Expression *e2);
|
|
1232 Expression *semantic(Scope *sc);
|
|
1233 Expression *optimize(int result);
|
|
1234 Expression *interpret(InterState *istate);
|
|
1235
|
|
1236 // For operator overloading
|
|
1237 Identifier *opId();
|
|
1238 Identifier *opId_r();
|
|
1239
|
|
1240 elem *toElem(IRState *irs);
|
|
1241 };
|
|
1242
|
|
1243 struct AndExp : BinExp
|
|
1244 {
|
|
1245 AndExp(Loc loc, Expression *e1, Expression *e2);
|
|
1246 Expression *semantic(Scope *sc);
|
|
1247 Expression *optimize(int result);
|
|
1248 Expression *interpret(InterState *istate);
|
|
1249
|
|
1250 // For operator overloading
|
|
1251 int isCommutative();
|
|
1252 Identifier *opId();
|
|
1253 Identifier *opId_r();
|
|
1254
|
|
1255 elem *toElem(IRState *irs);
|
|
1256 };
|
|
1257
|
|
1258 struct OrExp : BinExp
|
|
1259 {
|
|
1260 OrExp(Loc loc, Expression *e1, Expression *e2);
|
|
1261 Expression *semantic(Scope *sc);
|
|
1262 Expression *optimize(int result);
|
|
1263 Expression *interpret(InterState *istate);
|
|
1264
|
|
1265 // For operator overloading
|
|
1266 int isCommutative();
|
|
1267 Identifier *opId();
|
|
1268 Identifier *opId_r();
|
|
1269
|
|
1270 elem *toElem(IRState *irs);
|
|
1271 };
|
|
1272
|
|
1273 struct XorExp : BinExp
|
|
1274 {
|
|
1275 XorExp(Loc loc, Expression *e1, Expression *e2);
|
|
1276 Expression *semantic(Scope *sc);
|
|
1277 Expression *optimize(int result);
|
|
1278 Expression *interpret(InterState *istate);
|
|
1279
|
|
1280 // For operator overloading
|
|
1281 int isCommutative();
|
|
1282 Identifier *opId();
|
|
1283 Identifier *opId_r();
|
|
1284
|
|
1285 elem *toElem(IRState *irs);
|
|
1286 };
|
|
1287
|
|
1288 struct OrOrExp : BinExp
|
|
1289 {
|
|
1290 OrOrExp(Loc loc, Expression *e1, Expression *e2);
|
|
1291 Expression *semantic(Scope *sc);
|
|
1292 Expression *checkToBoolean();
|
|
1293 int isBit();
|
|
1294 Expression *optimize(int result);
|
|
1295 Expression *interpret(InterState *istate);
|
|
1296 int checkSideEffect(int flag);
|
|
1297 elem *toElem(IRState *irs);
|
|
1298 };
|
|
1299
|
|
1300 struct AndAndExp : BinExp
|
|
1301 {
|
|
1302 AndAndExp(Loc loc, Expression *e1, Expression *e2);
|
|
1303 Expression *semantic(Scope *sc);
|
|
1304 Expression *checkToBoolean();
|
|
1305 int isBit();
|
|
1306 Expression *optimize(int result);
|
|
1307 Expression *interpret(InterState *istate);
|
|
1308 int checkSideEffect(int flag);
|
|
1309 elem *toElem(IRState *irs);
|
|
1310 };
|
|
1311
|
|
1312 struct CmpExp : BinExp
|
|
1313 {
|
|
1314 CmpExp(enum TOK op, Loc loc, Expression *e1, Expression *e2);
|
|
1315 Expression *semantic(Scope *sc);
|
|
1316 Expression *optimize(int result);
|
|
1317 Expression *interpret(InterState *istate);
|
|
1318 int isBit();
|
|
1319
|
|
1320 // For operator overloading
|
|
1321 int isCommutative();
|
|
1322 Identifier *opId();
|
|
1323
|
|
1324 elem *toElem(IRState *irs);
|
|
1325 };
|
|
1326
|
|
1327 struct InExp : BinExp
|
|
1328 {
|
|
1329 InExp(Loc loc, Expression *e1, Expression *e2);
|
|
1330 Expression *semantic(Scope *sc);
|
|
1331 int isBit();
|
|
1332
|
|
1333 // For operator overloading
|
|
1334 Identifier *opId();
|
|
1335 Identifier *opId_r();
|
|
1336
|
|
1337 elem *toElem(IRState *irs);
|
|
1338 };
|
|
1339
|
|
1340 struct RemoveExp : BinExp
|
|
1341 {
|
|
1342 RemoveExp(Loc loc, Expression *e1, Expression *e2);
|
|
1343 elem *toElem(IRState *irs);
|
|
1344 };
|
|
1345
|
|
1346 // == and !=
|
|
1347
|
|
1348 struct EqualExp : BinExp
|
|
1349 {
|
|
1350 EqualExp(enum TOK op, Loc loc, Expression *e1, Expression *e2);
|
|
1351 Expression *semantic(Scope *sc);
|
|
1352 Expression *optimize(int result);
|
|
1353 Expression *interpret(InterState *istate);
|
|
1354 int isBit();
|
|
1355
|
|
1356 // For operator overloading
|
|
1357 int isCommutative();
|
|
1358 Identifier *opId();
|
|
1359
|
|
1360 elem *toElem(IRState *irs);
|
|
1361 };
|
|
1362
|
|
1363 // === and !===
|
|
1364
|
|
1365 struct IdentityExp : BinExp
|
|
1366 {
|
|
1367 IdentityExp(enum TOK op, Loc loc, Expression *e1, Expression *e2);
|
|
1368 Expression *semantic(Scope *sc);
|
|
1369 int isBit();
|
|
1370 Expression *optimize(int result);
|
|
1371 Expression *interpret(InterState *istate);
|
|
1372 elem *toElem(IRState *irs);
|
|
1373 };
|
|
1374
|
|
1375 /****************************************************************/
|
|
1376
|
|
1377 struct CondExp : BinExp
|
|
1378 {
|
|
1379 Expression *econd;
|
|
1380
|
|
1381 CondExp(Loc loc, Expression *econd, Expression *e1, Expression *e2);
|
|
1382 Expression *syntaxCopy();
|
|
1383 Expression *semantic(Scope *sc);
|
|
1384 Expression *optimize(int result);
|
|
1385 Expression *interpret(InterState *istate);
|
|
1386 void checkEscape();
|
|
1387 Expression *toLvalue(Scope *sc, Expression *e);
|
|
1388 Expression *modifiableLvalue(Scope *sc, Expression *e);
|
|
1389 Expression *checkToBoolean();
|
|
1390 int checkSideEffect(int flag);
|
|
1391 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
1392 MATCH implicitConvTo(Type *t);
|
|
1393 Expression *castTo(Scope *sc, Type *t);
|
|
1394 void scanForNestedRef(Scope *sc);
|
|
1395
|
|
1396 int inlineCost(InlineCostState *ics);
|
|
1397 Expression *doInline(InlineDoState *ids);
|
|
1398 Expression *inlineScan(InlineScanState *iss);
|
|
1399
|
|
1400 elem *toElem(IRState *irs);
|
|
1401 };
|
|
1402
|
|
1403
|
|
1404 /****************************************************************/
|
|
1405
|
|
1406 /* Special values used by the interpreter
|
|
1407 */
|
|
1408 #define EXP_CANT_INTERPRET ((Expression *)1)
|
|
1409 #define EXP_CONTINUE_INTERPRET ((Expression *)2)
|
|
1410 #define EXP_BREAK_INTERPRET ((Expression *)3)
|
|
1411 #define EXP_GOTO_INTERPRET ((Expression *)4)
|
|
1412 #define EXP_VOID_INTERPRET ((Expression *)5)
|
|
1413
|
|
1414 Expression *expType(Type *type, Expression *e);
|
|
1415
|
|
1416 Expression *Neg(Type *type, Expression *e1);
|
|
1417 Expression *Com(Type *type, Expression *e1);
|
|
1418 Expression *Not(Type *type, Expression *e1);
|
|
1419 Expression *Bool(Type *type, Expression *e1);
|
|
1420 Expression *Cast(Type *type, Type *to, Expression *e1);
|
|
1421 Expression *ArrayLength(Type *type, Expression *e1);
|
|
1422 Expression *Ptr(Type *type, Expression *e1);
|
|
1423
|
|
1424 Expression *Add(Type *type, Expression *e1, Expression *e2);
|
|
1425 Expression *Min(Type *type, Expression *e1, Expression *e2);
|
|
1426 Expression *Mul(Type *type, Expression *e1, Expression *e2);
|
|
1427 Expression *Div(Type *type, Expression *e1, Expression *e2);
|
|
1428 Expression *Mod(Type *type, Expression *e1, Expression *e2);
|
|
1429 Expression *Shl(Type *type, Expression *e1, Expression *e2);
|
|
1430 Expression *Shr(Type *type, Expression *e1, Expression *e2);
|
|
1431 Expression *Ushr(Type *type, Expression *e1, Expression *e2);
|
|
1432 Expression *And(Type *type, Expression *e1, Expression *e2);
|
|
1433 Expression *Or(Type *type, Expression *e1, Expression *e2);
|
|
1434 Expression *Xor(Type *type, Expression *e1, Expression *e2);
|
|
1435 Expression *Index(Type *type, Expression *e1, Expression *e2);
|
|
1436 Expression *Cat(Type *type, Expression *e1, Expression *e2);
|
|
1437
|
|
1438 Expression *Equal(enum TOK op, Type *type, Expression *e1, Expression *e2);
|
|
1439 Expression *Cmp(enum TOK op, Type *type, Expression *e1, Expression *e2);
|
|
1440 Expression *Identity(enum TOK op, Type *type, Expression *e1, Expression *e2);
|
|
1441
|
|
1442 Expression *Slice(Type *type, Expression *e1, Expression *lwr, Expression *upr);
|
|
1443
|
|
1444 #endif /* DMD_EXPRESSION_H */
|