Mercurial > projects > ldc
comparison dmd/expression.h @ 1146:1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
* Added #if IN_DMD versioning around DMD backend specific code in the D1 frontend, D2 is currently broken.
* All part of a greater cleanup scheme.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail.com> |
---|---|
date | Thu, 26 Mar 2009 20:45:53 +0100 |
parents | b30fe7e1dbb9 |
children | 3cf0066e6faf |
comparison
equal
deleted
inserted
replaced
1145:40caa8207b3e | 1146:1860414bf3b7 |
---|---|
40 struct TemplateDeclaration; | 40 struct TemplateDeclaration; |
41 struct ClassDeclaration; | 41 struct ClassDeclaration; |
42 struct HdrGenState; | 42 struct HdrGenState; |
43 struct BinExp; | 43 struct BinExp; |
44 struct InterState; | 44 struct InterState; |
45 struct OverloadSet; | |
46 | |
47 enum TOK; | |
48 | |
49 // Back end | |
50 struct IRState; | |
51 | |
52 #if IN_DMD | |
53 struct dt_t; | |
54 struct elem; | |
45 struct Symbol; // back end symbol | 55 struct Symbol; // back end symbol |
46 struct OverloadSet; | 56 #endif |
57 | |
58 #ifdef IN_GCC | |
59 union tree_node; typedef union tree_node elem; | |
60 #endif | |
61 | |
62 #if IN_LLVM | |
63 struct DValue; | |
64 typedef DValue elem; | |
65 | |
47 namespace llvm | 66 namespace llvm |
48 { | 67 { |
49 class Constant; | 68 class Constant; |
50 class ConstantInt; | 69 class ConstantInt; |
51 } | 70 } |
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 | 71 #endif |
69 | 72 |
70 void initPrecedence(); | 73 void initPrecedence(); |
71 | 74 |
72 Expression *resolveProperties(Scope *sc, Expression *e); | 75 Expression *resolveProperties(Scope *sc, Expression *e); |
157 virtual void buildArrayIdent(OutBuffer *buf, Expressions *arguments); | 160 virtual void buildArrayIdent(OutBuffer *buf, Expressions *arguments); |
158 virtual Expression *buildArrayLoop(Arguments *fparams); | 161 virtual Expression *buildArrayLoop(Arguments *fparams); |
159 | 162 |
160 // Back end | 163 // Back end |
161 virtual elem *toElem(IRState *irs); | 164 virtual elem *toElem(IRState *irs); |
165 #if IN_DMD | |
162 virtual dt_t **toDt(dt_t **pdt); | 166 virtual dt_t **toDt(dt_t **pdt); |
167 #elif IN_LLVM | |
163 // LDC | 168 // LDC |
164 virtual llvm::Constant *toConstElem(IRState *irs); | 169 virtual llvm::Constant *toConstElem(IRState *irs); |
170 #endif | |
165 }; | 171 }; |
166 | 172 |
167 struct IntegerExp : Expression | 173 struct IntegerExp : Expression |
168 { | 174 { |
169 integer_t value; | 175 integer_t value; |
184 MATCH implicitConvTo(Type *t); | 190 MATCH implicitConvTo(Type *t); |
185 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | 191 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
186 void toMangleBuffer(OutBuffer *buf); | 192 void toMangleBuffer(OutBuffer *buf); |
187 Expression *toLvalue(Scope *sc, Expression *e); | 193 Expression *toLvalue(Scope *sc, Expression *e); |
188 elem *toElem(IRState *irs); | 194 elem *toElem(IRState *irs); |
195 #if IN_DMD | |
189 dt_t **toDt(dt_t **pdt); | 196 dt_t **toDt(dt_t **pdt); |
197 #elif IN_LLVM | |
190 // LDC | 198 // LDC |
191 virtual llvm::Constant *toConstElem(IRState *irs); | 199 virtual llvm::Constant *toConstElem(IRState *irs); |
200 #endif | |
192 }; | 201 }; |
193 | 202 |
194 struct RealExp : Expression | 203 struct RealExp : Expression |
195 { | 204 { |
196 real_t value; | 205 real_t value; |
209 int isConst(); | 218 int isConst(); |
210 int isBool(int result); | 219 int isBool(int result); |
211 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | 220 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
212 void toMangleBuffer(OutBuffer *buf); | 221 void toMangleBuffer(OutBuffer *buf); |
213 elem *toElem(IRState *irs); | 222 elem *toElem(IRState *irs); |
223 #if IN_DMD | |
214 dt_t **toDt(dt_t **pdt); | 224 dt_t **toDt(dt_t **pdt); |
225 #elif IN_LLVM | |
215 // LDC | 226 // LDC |
216 virtual llvm::Constant *toConstElem(IRState *irs); | 227 virtual llvm::Constant *toConstElem(IRState *irs); |
228 #endif | |
217 }; | 229 }; |
218 | 230 |
219 struct ComplexExp : Expression | 231 struct ComplexExp : Expression |
220 { | 232 { |
221 complex_t value; | 233 complex_t value; |
237 void toMangleBuffer(OutBuffer *buf); | 249 void toMangleBuffer(OutBuffer *buf); |
238 #ifdef _DH | 250 #ifdef _DH |
239 OutBuffer hexp; | 251 OutBuffer hexp; |
240 #endif | 252 #endif |
241 elem *toElem(IRState *irs); | 253 elem *toElem(IRState *irs); |
254 #if IN_DMD | |
242 dt_t **toDt(dt_t **pdt); | 255 dt_t **toDt(dt_t **pdt); |
256 #elif IN_LLVM | |
243 // LDC | 257 // LDC |
244 virtual llvm::Constant *toConstElem(IRState *irs); | 258 virtual llvm::Constant *toConstElem(IRState *irs); |
259 #endif | |
245 }; | 260 }; |
246 | 261 |
247 struct IdentifierExp : Expression | 262 struct IdentifierExp : Expression |
248 { | 263 { |
249 Identifier *ident; | 264 Identifier *ident; |
316 void toMangleBuffer(OutBuffer *buf); | 331 void toMangleBuffer(OutBuffer *buf); |
317 MATCH implicitConvTo(Type *t); | 332 MATCH implicitConvTo(Type *t); |
318 Expression *castTo(Scope *sc, Type *t); | 333 Expression *castTo(Scope *sc, Type *t); |
319 Expression *interpret(InterState *istate); | 334 Expression *interpret(InterState *istate); |
320 elem *toElem(IRState *irs); | 335 elem *toElem(IRState *irs); |
336 #if IN_DMD | |
321 dt_t **toDt(dt_t **pdt); | 337 dt_t **toDt(dt_t **pdt); |
338 #elif IN_LLVM | |
322 // LDC | 339 // LDC |
323 virtual llvm::Constant *toConstElem(IRState *irs); | 340 virtual llvm::Constant *toConstElem(IRState *irs); |
341 #endif | |
324 }; | 342 }; |
325 | 343 |
326 struct StringExp : Expression | 344 struct StringExp : Expression |
327 { | 345 { |
328 void *string; // char, wchar, or dchar data | 346 void *string; // char, wchar, or dchar data |
346 int isBool(int result); | 364 int isBool(int result); |
347 unsigned charAt(size_t i); | 365 unsigned charAt(size_t i); |
348 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | 366 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
349 void toMangleBuffer(OutBuffer *buf); | 367 void toMangleBuffer(OutBuffer *buf); |
350 elem *toElem(IRState *irs); | 368 elem *toElem(IRState *irs); |
369 #if IN_DMD | |
351 dt_t **toDt(dt_t **pdt); | 370 dt_t **toDt(dt_t **pdt); |
371 #elif IN_LLVM | |
352 // LDC | 372 // LDC |
353 virtual llvm::Constant *toConstElem(IRState *irs); | 373 virtual llvm::Constant *toConstElem(IRState *irs); |
374 #endif | |
354 }; | 375 }; |
355 | 376 |
356 // Tuple | 377 // Tuple |
357 | 378 |
358 struct TupleExp : Expression | 379 struct TupleExp : Expression |
395 void scanForNestedRef(Scope *sc); | 416 void scanForNestedRef(Scope *sc); |
396 Expression *optimize(int result); | 417 Expression *optimize(int result); |
397 Expression *interpret(InterState *istate); | 418 Expression *interpret(InterState *istate); |
398 MATCH implicitConvTo(Type *t); | 419 MATCH implicitConvTo(Type *t); |
399 Expression *castTo(Scope *sc, Type *t); | 420 Expression *castTo(Scope *sc, Type *t); |
421 #if IN_DMD | |
400 dt_t **toDt(dt_t **pdt); | 422 dt_t **toDt(dt_t **pdt); |
401 | 423 #elif IN_LLVM |
402 int inlineCost(InlineCostState *ics); | |
403 Expression *doInline(InlineDoState *ids); | |
404 Expression *inlineScan(InlineScanState *iss); | |
405 // LDC | 424 // LDC |
406 virtual llvm::Constant *toConstElem(IRState *irs); | 425 virtual llvm::Constant *toConstElem(IRState *irs); |
426 #endif | |
427 | |
428 int inlineCost(InlineCostState *ics); | |
429 Expression *doInline(InlineDoState *ids); | |
430 Expression *inlineScan(InlineScanState *iss); | |
407 }; | 431 }; |
408 | 432 |
409 struct AssocArrayLiteralExp : Expression | 433 struct AssocArrayLiteralExp : Expression |
410 { | 434 { |
411 Expressions *keys; | 435 Expressions *keys; |
427 Expression *castTo(Scope *sc, Type *t); | 451 Expression *castTo(Scope *sc, Type *t); |
428 | 452 |
429 int inlineCost(InlineCostState *ics); | 453 int inlineCost(InlineCostState *ics); |
430 Expression *doInline(InlineDoState *ids); | 454 Expression *doInline(InlineDoState *ids); |
431 Expression *inlineScan(InlineScanState *iss); | 455 Expression *inlineScan(InlineScanState *iss); |
456 #if IN_LLVM | |
432 // LDC | 457 // LDC |
433 virtual llvm::Constant *toConstElem(IRState *irs); | 458 virtual llvm::Constant *toConstElem(IRState *irs); |
459 #endif | |
434 }; | 460 }; |
435 | 461 |
436 struct StructLiteralExp : Expression | 462 struct StructLiteralExp : Expression |
437 { | 463 { |
438 StructDeclaration *sd; // which aggregate this is for | 464 StructDeclaration *sd; // which aggregate this is for |
439 Expressions *elements; // parallels sd->fields[] with | 465 Expressions *elements; // parallels sd->fields[] with |
440 // NULL entries for fields to skip | 466 // NULL entries for fields to skip |
441 | 467 |
468 #if IN_DMD | |
442 Symbol *sym; // back end symbol to initialize with literal | 469 Symbol *sym; // back end symbol to initialize with literal |
470 #endif | |
443 size_t soffset; // offset from start of s | 471 size_t soffset; // offset from start of s |
444 int fillHoles; // fill alignment 'holes' with zero | 472 int fillHoles; // fill alignment 'holes' with zero |
445 | 473 |
446 StructLiteralExp(Loc loc, StructDeclaration *sd, Expressions *elements); | 474 StructLiteralExp(Loc loc, StructDeclaration *sd, Expressions *elements); |
447 | 475 |
454 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | 482 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
455 void toMangleBuffer(OutBuffer *buf); | 483 void toMangleBuffer(OutBuffer *buf); |
456 void scanForNestedRef(Scope *sc); | 484 void scanForNestedRef(Scope *sc); |
457 Expression *optimize(int result); | 485 Expression *optimize(int result); |
458 Expression *interpret(InterState *istate); | 486 Expression *interpret(InterState *istate); |
487 #if IN_DMD | |
459 dt_t **toDt(dt_t **pdt); | 488 dt_t **toDt(dt_t **pdt); |
460 Expression *toLvalue(Scope *sc, Expression *e); | 489 #elif IN_LLVM |
461 | |
462 int inlineCost(InlineCostState *ics); | |
463 Expression *doInline(InlineDoState *ids); | |
464 Expression *inlineScan(InlineScanState *iss); | |
465 // LDC | 490 // LDC |
466 virtual llvm::Constant *toConstElem(IRState *irs); | 491 virtual llvm::Constant *toConstElem(IRState *irs); |
492 #endif | |
493 Expression *toLvalue(Scope *sc, Expression *e); | |
494 | |
495 int inlineCost(InlineCostState *ics); | |
496 Expression *doInline(InlineDoState *ids); | |
497 Expression *inlineScan(InlineScanState *iss); | |
498 | |
467 }; | 499 }; |
468 | 500 |
469 struct TypeDotIdExp : Expression | 501 struct TypeDotIdExp : Expression |
470 { | 502 { |
471 Identifier *ident; | 503 Identifier *ident; |
568 MATCH implicitConvTo(Type *t); | 600 MATCH implicitConvTo(Type *t); |
569 Expression *castTo(Scope *sc, Type *t); | 601 Expression *castTo(Scope *sc, Type *t); |
570 void scanForNestedRef(Scope *sc); | 602 void scanForNestedRef(Scope *sc); |
571 | 603 |
572 elem *toElem(IRState *irs); | 604 elem *toElem(IRState *irs); |
605 #if IN_DMD | |
573 dt_t **toDt(dt_t **pdt); | 606 dt_t **toDt(dt_t **pdt); |
607 #endif | |
574 }; | 608 }; |
575 | 609 |
576 // Variable | 610 // Variable |
577 | 611 |
578 struct VarExp : Expression | 612 struct VarExp : Expression |
589 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | 623 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
590 void checkEscape(); | 624 void checkEscape(); |
591 Expression *toLvalue(Scope *sc, Expression *e); | 625 Expression *toLvalue(Scope *sc, Expression *e); |
592 Expression *modifiableLvalue(Scope *sc, Expression *e); | 626 Expression *modifiableLvalue(Scope *sc, Expression *e); |
593 elem *toElem(IRState *irs); | 627 elem *toElem(IRState *irs); |
628 #if IN_DMD | |
594 dt_t **toDt(dt_t **pdt); | 629 dt_t **toDt(dt_t **pdt); |
595 void scanForNestedRef(Scope *sc); | 630 #elif IN_LLVM |
596 | |
597 int inlineCost(InlineCostState *ics); | |
598 Expression *doInline(InlineDoState *ids); | |
599 //Expression *inlineScan(InlineScanState *iss); | |
600 // LDC | 631 // LDC |
601 virtual llvm::Constant *toConstElem(IRState *irs); | 632 virtual llvm::Constant *toConstElem(IRState *irs); |
633 #endif | |
634 void scanForNestedRef(Scope *sc); | |
635 | |
636 int inlineCost(InlineCostState *ics); | |
637 Expression *doInline(InlineDoState *ids); | |
638 //Expression *inlineScan(InlineScanState *iss); | |
602 }; | 639 }; |
603 | 640 |
604 #if DMDV2 | 641 #if DMDV2 |
605 // Overload Set | 642 // Overload Set |
606 | 643 |