00001 #include "If.h"
00002
00003 using std::list;
00004
00005 namespace xi {
00006
00007 IfConstruct::IfConstruct(SdagConstruct* pred, SdagConstruct* then_body,
00008 SdagConstruct* else_body)
00009 : BlockConstruct(SIF, 0, pred, else_body, 0, 0, then_body, 0) {
00010 label_str = "if";
00011 }
00012
00013 void IfConstruct::generateCode(XStr& decls, XStr& defs, Entry* entry) {
00014 strcpy(nameStr, label->charstar());
00015 generateClosureSignature(decls, defs, entry, false, "void", label, false, encapState);
00016
00017 #if CMK_BIGSIM_CHARM
00018 generateBeginTime(defs);
00019 generateEventBracket(defs, SIF);
00020 #endif
00021
00022 int indent = unravelClosuresBegin(defs);
00023
00024 indentBy(defs, indent);
00025 defs << "if (" << con1->text << ") {\n";
00026 indentBy(defs, indent + 1);
00027 generateCall(defs, encapStateChild, encapStateChild, constructs->front()->label);
00028 indentBy(defs, indent);
00029 defs << "} else {\n";
00030 indentBy(defs, indent + 1);
00031 if (con2 != 0)
00032 generateCall(defs, encapStateChild, encapStateChild, con2->label);
00033 else
00034 generateCall(defs, encapStateChild, encapStateChild, label, "_end");
00035 indentBy(defs, indent);
00036 defs << "}\n";
00037
00038 unravelClosuresEnd(defs);
00039
00040 endMethod(defs);
00041
00042 strcpy(nameStr, label->charstar());
00043 strcat(nameStr, "_end");
00044 generateClosureSignature(decls, defs, entry, false, "void", label, true,
00045 encapStateChild);
00046 #if CMK_BIGSIM_CHARM
00047 generateBeginTime(defs);
00048 generateEventBracket(defs, SIF_END);
00049 #endif
00050 indentBy(defs, 1);
00051 generateCall(defs, encapState, encapState, next->label, nextBeginOrEnd ? 0 : "_end");
00052 endMethod(defs);
00053
00054 if (con2 != 0) con2->generateCode(decls, defs, entry);
00055
00056 generateChildrenCode(decls, defs, entry);
00057 }
00058
00059 void IfConstruct::propagateState(list<EncapState*> encap, list<CStateVar*>& plist,
00060 list<CStateVar*>& wlist, int uniqueVarNum) {
00061 BlockConstruct::propagateState(encap, plist, wlist, uniqueVarNum);
00062 if (con2 != 0) con2->propagateState(encap, plist, wlist, uniqueVarNum);
00063 }
00064
00065 void IfConstruct::numberNodes(void) {
00066 nodeNum = numIfs++;
00067 if (con2 != 0) con2->numberNodes();
00068 SdagConstruct::numberNodes();
00069 }
00070
00071 void IfConstruct::labelNodes() {
00072 SdagConstruct::labelNodes();
00073 if (con2 != 0) con2->labelNodes();
00074 }
00075
00076 }