comparison dmd/expression.h @ 510:6aee82889553

Merged DMD 1.034, array operations are not yet implemented ;)
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Thu, 14 Aug 2008 06:55:41 +0200
parents 9db9099583ca
children fbb1a366cfbc
comparison
equal deleted inserted replaced
509:337554fd34f1 510:6aee82889553
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 Symbol; // back end symbol 45 struct Symbol; // back end symbol
46 46 struct OverloadSet;
47 namespace llvm 47 namespace llvm
48 { 48 {
49 class Constant; 49 class Constant;
50 class ConstantInt; 50 class ConstantInt;
51 } 51 }
149 // For operator overloading 149 // For operator overloading
150 virtual int isCommutative(); 150 virtual int isCommutative();
151 virtual Identifier *opId(); 151 virtual Identifier *opId();
152 virtual Identifier *opId_r(); 152 virtual Identifier *opId_r();
153 153
154 // For array ops
155 virtual void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
156 virtual Expression *buildArrayLoop(Arguments *fparams);
157
154 // Back end 158 // Back end
155 virtual elem *toElem(IRState *irs); 159 virtual elem *toElem(IRState *irs);
156 virtual dt_t **toDt(dt_t **pdt); 160 virtual dt_t **toDt(dt_t **pdt);
157 // LLVMDC 161 // LLVMDC
158 virtual llvm::Constant *toConstElem(IRState *irs); 162 virtual llvm::Constant *toConstElem(IRState *irs);
592 //Expression *inlineScan(InlineScanState *iss); 596 //Expression *inlineScan(InlineScanState *iss);
593 // LLVMDC 597 // LLVMDC
594 virtual llvm::Constant *toConstElem(IRState *irs); 598 virtual llvm::Constant *toConstElem(IRState *irs);
595 }; 599 };
596 600
601 #if DMDV2
602 // Overload Set
603
604 struct OverExp : Expression
605 {
606 OverloadSet *vars;
607
608 OverExp(OverloadSet *s);
609 int isLvalue();
610 Expression *toLvalue(Scope *sc, Expression *e);
611 };
612 #endif
613
597 // Function/Delegate literal 614 // Function/Delegate literal
598 615
599 struct FuncExp : Expression 616 struct FuncExp : Expression
600 { 617 {
601 FuncLiteralDeclaration *fd; 618 FuncLiteralDeclaration *fd;
640 TypeidExp(Loc loc, Type *typeidType); 657 TypeidExp(Loc loc, Type *typeidType);
641 Expression *syntaxCopy(); 658 Expression *syntaxCopy();
642 Expression *semantic(Scope *sc); 659 Expression *semantic(Scope *sc);
643 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 660 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
644 }; 661 };
662
663 #if DMDV2
664 struct TraitsExp : Expression
665 {
666 Identifier *ident;
667 Objects *args;
668
669 TraitsExp(Loc loc, Identifier *ident, Objects *args);
670 Expression *syntaxCopy();
671 Expression *semantic(Scope *sc);
672 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
673 };
674 #endif
645 675
646 struct HaltExp : Expression 676 struct HaltExp : Expression
647 { 677 {
648 HaltExp(Loc loc); 678 HaltExp(Loc loc);
649 Expression *semantic(Scope *sc); 679 Expression *semantic(Scope *sc);
713 void dump(int indent); 743 void dump(int indent);
714 void scanForNestedRef(Scope *sc); 744 void scanForNestedRef(Scope *sc);
715 Expression *interpretCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *)); 745 Expression *interpretCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *));
716 Expression *interpretCommon2(InterState *istate, Expression *(*fp)(TOK, Type *, Expression *, Expression *)); 746 Expression *interpretCommon2(InterState *istate, Expression *(*fp)(TOK, Type *, Expression *, Expression *));
717 Expression *interpretAssignCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *), int post = 0); 747 Expression *interpretAssignCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *), int post = 0);
748 Expression *arrayOp(Scope *sc);
718 749
719 int inlineCost(InlineCostState *ics); 750 int inlineCost(InlineCostState *ics);
720 Expression *doInline(InlineDoState *ids); 751 Expression *doInline(InlineDoState *ids);
721 Expression *inlineScan(InlineScanState *iss); 752 Expression *inlineScan(InlineScanState *iss);
722 753
885 { 916 {
886 NegExp(Loc loc, Expression *e); 917 NegExp(Loc loc, Expression *e);
887 Expression *semantic(Scope *sc); 918 Expression *semantic(Scope *sc);
888 Expression *optimize(int result); 919 Expression *optimize(int result);
889 Expression *interpret(InterState *istate); 920 Expression *interpret(InterState *istate);
921 void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
922 Expression *buildArrayLoop(Arguments *fparams);
890 923
891 // For operator overloading 924 // For operator overloading
892 Identifier *opId(); 925 Identifier *opId();
893 926
894 elem *toElem(IRState *irs); 927 elem *toElem(IRState *irs);
907 { 940 {
908 ComExp(Loc loc, Expression *e); 941 ComExp(Loc loc, Expression *e);
909 Expression *semantic(Scope *sc); 942 Expression *semantic(Scope *sc);
910 Expression *optimize(int result); 943 Expression *optimize(int result);
911 Expression *interpret(InterState *istate); 944 Expression *interpret(InterState *istate);
945 void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
946 Expression *buildArrayLoop(Arguments *fparams);
912 947
913 // For operator overloading 948 // For operator overloading
914 Identifier *opId(); 949 Identifier *opId();
915 950
916 elem *toElem(IRState *irs); 951 elem *toElem(IRState *irs);
982 Expression *optimize(int result); 1017 Expression *optimize(int result);
983 Expression *interpret(InterState *istate); 1018 Expression *interpret(InterState *istate);
984 void dump(int indent); 1019 void dump(int indent);
985 elem *toElem(IRState *irs); 1020 elem *toElem(IRState *irs);
986 void scanForNestedRef(Scope *sc); 1021 void scanForNestedRef(Scope *sc);
1022 void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
1023 Expression *buildArrayLoop(Arguments *fparams);
987 1024
988 int inlineCost(InlineCostState *ics); 1025 int inlineCost(InlineCostState *ics);
989 Expression *doInline(InlineDoState *ids); 1026 Expression *doInline(InlineDoState *ids);
990 Expression *inlineScan(InlineScanState *iss); 1027 Expression *inlineScan(InlineScanState *iss);
991 }; 1028 };
1079 AssignExp(Loc loc, Expression *e1, Expression *e2); 1116 AssignExp(Loc loc, Expression *e1, Expression *e2);
1080 Expression *semantic(Scope *sc); 1117 Expression *semantic(Scope *sc);
1081 Expression *checkToBoolean(); 1118 Expression *checkToBoolean();
1082 Expression *interpret(InterState *istate); 1119 Expression *interpret(InterState *istate);
1083 Identifier *opId(); // For operator overloading 1120 Identifier *opId(); // For operator overloading
1121 void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
1122 Expression *buildArrayLoop(Arguments *fparams);
1084 elem *toElem(IRState *irs); 1123 elem *toElem(IRState *irs);
1085 }; 1124 };
1086 1125
1087 #define ASSIGNEXP(op) \ 1126 #define ASSIGNEXP(op) \
1088 struct op##AssignExp : BinExp \ 1127 struct op##AssignExp : BinExp \
1089 { \ 1128 { \
1090 op##AssignExp(Loc loc, Expression *e1, Expression *e2); \ 1129 op##AssignExp(Loc loc, Expression *e1, Expression *e2); \
1091 Expression *semantic(Scope *sc); \ 1130 Expression *semantic(Scope *sc); \
1092 Expression *interpret(InterState *istate); \ 1131 Expression *interpret(InterState *istate); \
1132 X(void buildArrayIdent(OutBuffer *buf, Expressions *arguments);) \
1133 X(Expression *buildArrayLoop(Arguments *fparams);) \
1093 \ 1134 \
1094 Identifier *opId(); /* For operator overloading */ \ 1135 Identifier *opId(); /* For operator overloading */ \
1095 \ 1136 \
1096 elem *toElem(IRState *irs); \ 1137 elem *toElem(IRState *irs); \
1097 }; 1138 };
1098 1139
1140 #define X(a) a
1099 ASSIGNEXP(Add) 1141 ASSIGNEXP(Add)
1100 ASSIGNEXP(Min) 1142 ASSIGNEXP(Min)
1101 ASSIGNEXP(Cat)
1102 ASSIGNEXP(Mul) 1143 ASSIGNEXP(Mul)
1103 ASSIGNEXP(Div) 1144 ASSIGNEXP(Div)
1104 ASSIGNEXP(Mod) 1145 ASSIGNEXP(Mod)
1146 ASSIGNEXP(And)
1147 ASSIGNEXP(Or)
1148 ASSIGNEXP(Xor)
1149 #undef X
1150
1151 #define X(a)
1152
1105 ASSIGNEXP(Shl) 1153 ASSIGNEXP(Shl)
1106 ASSIGNEXP(Shr) 1154 ASSIGNEXP(Shr)
1107 ASSIGNEXP(Ushr) 1155 ASSIGNEXP(Ushr)
1108 ASSIGNEXP(And) 1156 ASSIGNEXP(Cat)
1109 ASSIGNEXP(Or) 1157
1110 ASSIGNEXP(Xor) 1158 #undef X
1111
1112 #undef ASSIGNEXP 1159 #undef ASSIGNEXP
1113 1160
1114 struct AddExp : BinExp 1161 struct AddExp : BinExp
1115 { 1162 {
1116 AddExp(Loc loc, Expression *e1, Expression *e2); 1163 AddExp(Loc loc, Expression *e1, Expression *e2);
1117 Expression *semantic(Scope *sc); 1164 Expression *semantic(Scope *sc);
1118 Expression *optimize(int result); 1165 Expression *optimize(int result);
1119 Expression *interpret(InterState *istate); 1166 Expression *interpret(InterState *istate);
1167 void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
1168 Expression *buildArrayLoop(Arguments *fparams);
1120 1169
1121 // For operator overloading 1170 // For operator overloading
1122 int isCommutative(); 1171 int isCommutative();
1123 Identifier *opId(); 1172 Identifier *opId();
1124 Identifier *opId_r(); 1173 Identifier *opId_r();
1133 { 1182 {
1134 MinExp(Loc loc, Expression *e1, Expression *e2); 1183 MinExp(Loc loc, Expression *e1, Expression *e2);
1135 Expression *semantic(Scope *sc); 1184 Expression *semantic(Scope *sc);
1136 Expression *optimize(int result); 1185 Expression *optimize(int result);
1137 Expression *interpret(InterState *istate); 1186 Expression *interpret(InterState *istate);
1187 void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
1188 Expression *buildArrayLoop(Arguments *fparams);
1138 1189
1139 // For operator overloading 1190 // For operator overloading
1140 Identifier *opId(); 1191 Identifier *opId();
1141 Identifier *opId_r(); 1192 Identifier *opId_r();
1142 1193
1161 { 1212 {
1162 MulExp(Loc loc, Expression *e1, Expression *e2); 1213 MulExp(Loc loc, Expression *e1, Expression *e2);
1163 Expression *semantic(Scope *sc); 1214 Expression *semantic(Scope *sc);
1164 Expression *optimize(int result); 1215 Expression *optimize(int result);
1165 Expression *interpret(InterState *istate); 1216 Expression *interpret(InterState *istate);
1217 void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
1218 Expression *buildArrayLoop(Arguments *fparams);
1166 1219
1167 // For operator overloading 1220 // For operator overloading
1168 int isCommutative(); 1221 int isCommutative();
1169 Identifier *opId(); 1222 Identifier *opId();
1170 Identifier *opId_r(); 1223 Identifier *opId_r();
1176 { 1229 {
1177 DivExp(Loc loc, Expression *e1, Expression *e2); 1230 DivExp(Loc loc, Expression *e1, Expression *e2);
1178 Expression *semantic(Scope *sc); 1231 Expression *semantic(Scope *sc);
1179 Expression *optimize(int result); 1232 Expression *optimize(int result);
1180 Expression *interpret(InterState *istate); 1233 Expression *interpret(InterState *istate);
1234 void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
1235 Expression *buildArrayLoop(Arguments *fparams);
1181 1236
1182 // For operator overloading 1237 // For operator overloading
1183 Identifier *opId(); 1238 Identifier *opId();
1184 Identifier *opId_r(); 1239 Identifier *opId_r();
1185 1240
1190 { 1245 {
1191 ModExp(Loc loc, Expression *e1, Expression *e2); 1246 ModExp(Loc loc, Expression *e1, Expression *e2);
1192 Expression *semantic(Scope *sc); 1247 Expression *semantic(Scope *sc);
1193 Expression *optimize(int result); 1248 Expression *optimize(int result);
1194 Expression *interpret(InterState *istate); 1249 Expression *interpret(InterState *istate);
1250 void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
1251 Expression *buildArrayLoop(Arguments *fparams);
1195 1252
1196 // For operator overloading 1253 // For operator overloading
1197 Identifier *opId(); 1254 Identifier *opId();
1198 Identifier *opId_r(); 1255 Identifier *opId_r();
1199 1256
1246 { 1303 {
1247 AndExp(Loc loc, Expression *e1, Expression *e2); 1304 AndExp(Loc loc, Expression *e1, Expression *e2);
1248 Expression *semantic(Scope *sc); 1305 Expression *semantic(Scope *sc);
1249 Expression *optimize(int result); 1306 Expression *optimize(int result);
1250 Expression *interpret(InterState *istate); 1307 Expression *interpret(InterState *istate);
1308 void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
1309 Expression *buildArrayLoop(Arguments *fparams);
1251 1310
1252 // For operator overloading 1311 // For operator overloading
1253 int isCommutative(); 1312 int isCommutative();
1254 Identifier *opId(); 1313 Identifier *opId();
1255 Identifier *opId_r(); 1314 Identifier *opId_r();
1261 { 1320 {
1262 OrExp(Loc loc, Expression *e1, Expression *e2); 1321 OrExp(Loc loc, Expression *e1, Expression *e2);
1263 Expression *semantic(Scope *sc); 1322 Expression *semantic(Scope *sc);
1264 Expression *optimize(int result); 1323 Expression *optimize(int result);
1265 Expression *interpret(InterState *istate); 1324 Expression *interpret(InterState *istate);
1325 void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
1326 Expression *buildArrayLoop(Arguments *fparams);
1266 1327
1267 // For operator overloading 1328 // For operator overloading
1268 int isCommutative(); 1329 int isCommutative();
1269 Identifier *opId(); 1330 Identifier *opId();
1270 Identifier *opId_r(); 1331 Identifier *opId_r();
1276 { 1337 {
1277 XorExp(Loc loc, Expression *e1, Expression *e2); 1338 XorExp(Loc loc, Expression *e1, Expression *e2);
1278 Expression *semantic(Scope *sc); 1339 Expression *semantic(Scope *sc);
1279 Expression *optimize(int result); 1340 Expression *optimize(int result);
1280 Expression *interpret(InterState *istate); 1341 Expression *interpret(InterState *istate);
1342 void buildArrayIdent(OutBuffer *buf, Expressions *arguments);
1343 Expression *buildArrayLoop(Arguments *fparams);
1281 1344
1282 // For operator overloading 1345 // For operator overloading
1283 int isCommutative(); 1346 int isCommutative();
1284 Identifier *opId(); 1347 Identifier *opId();
1285 Identifier *opId_r(); 1348 Identifier *opId_r();
1400 Expression *inlineScan(InlineScanState *iss); 1463 Expression *inlineScan(InlineScanState *iss);
1401 1464
1402 elem *toElem(IRState *irs); 1465 elem *toElem(IRState *irs);
1403 }; 1466 };
1404 1467
1468 #if DMDV2
1469 /****************************************************************/
1470
1471 struct DefaultInitExp : Expression
1472 {
1473 enum TOK subop; // which of the derived classes this is
1474
1475 DefaultInitExp(Loc loc, enum TOK subop, int size);
1476 virtual Expression *resolve(Loc loc, Scope *sc) = 0;
1477 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
1478 };
1479
1480 struct FileInitExp : DefaultInitExp
1481 {
1482 FileInitExp(Loc loc);
1483 Expression *semantic(Scope *sc);
1484 Expression *resolve(Loc loc, Scope *sc);
1485 };
1486
1487 struct LineInitExp : DefaultInitExp
1488 {
1489 LineInitExp(Loc loc);
1490 Expression *semantic(Scope *sc);
1491 Expression *resolve(Loc loc, Scope *sc);
1492 };
1493 #endif
1405 1494
1406 /****************************************************************/ 1495 /****************************************************************/
1407 1496
1408 /* Special values used by the interpreter 1497 /* Special values used by the interpreter
1409 */ 1498 */