00001 #include "While.h"
00002
00003 namespace xi {
00004
00005 WhileConstruct::WhileConstruct(SdagConstruct* pred, SdagConstruct* body)
00006 : BlockConstruct(SWHILE, 0, pred, 0, 0, 0, body, 0) {
00007 label_str = "while";
00008 }
00009
00010 void WhileConstruct::generateCode(XStr& decls, XStr& defs, Entry* entry) {
00011 generateClosureSignature(decls, defs, entry, false, "void", label, false, encapState);
00012
00013 int indent = unravelClosuresBegin(defs);
00014 indentBy(defs, indent);
00015 defs << "if (" << con1->text << ") {\n";
00016 indentBy(defs, indent + 1);
00017 generateCall(defs, encapStateChild, encapStateChild, constructs->front()->label);
00018 indentBy(defs, indent);
00019 defs << "} else {\n";
00020 indentBy(defs, indent + 1);
00021 generateCall(defs, encapState, encapState, next->label, nextBeginOrEnd ? 0 : "_end");
00022 indentBy(defs, indent);
00023 defs << "}\n";
00024 unravelClosuresEnd(defs);
00025 endMethod(defs);
00026
00027 generateClosureSignature(decls, defs, entry, false, "void", label, true,
00028 encapStateChild);
00029 indent = unravelClosuresBegin(defs);
00030 indentBy(defs, indent);
00031 defs << "if (" << con1->text << ") {\n";
00032 indentBy(defs, indent + 1);
00033 generateCall(defs, encapStateChild, encapStateChild, constructs->front()->label);
00034 indentBy(defs, indent);
00035 defs << "} else {\n";
00036 indentBy(defs, indent + 1);
00037 generateCall(defs, encapState, encapState, next->label, nextBeginOrEnd ? 0 : "_end");
00038 indentBy(defs, indent);
00039 defs << "}\n";
00040 unravelClosuresEnd(defs);
00041 endMethod(defs);
00042
00043 generateChildrenCode(decls, defs, entry);
00044 }
00045
00046 void WhileConstruct::numberNodes(void) {
00047 nodeNum = numWhiles++;
00048 SdagConstruct::numberNodes();
00049 }
00050
00051 }