/*******************************************************************************
* GenData.cc BEAM Data output
* T.Barnaby, BEAM Ltd, 12/9/03
*******************************************************************************
*/
#define DEBUG 1
#include <stdio.h>
#include <stdarg.h>
#include <strings.h>
#include <GenData.h>
#include <bidl.h>
void GenData::produceInt(Node* n){
BIter i;
BString s;
BList<Node*>* nl;
BString typeName;
switch(n->nodeType()){
case Node::TMODULE:
omodule = n->name();
ofileInt.writeLine(BString("namespace ") + omodule + " {\n");
ofileInt.indentMore();
for(n->nodes().start(i); !n->nodes().isEnd(i); n->nodes().next(i)){
produceInt(n->nodes()[i]);
}
ofileInt.indentLess();
ofileInt.writeLine("}\n");
break;
case Node::TLIST:
for(n->nodes().start(i); !n->nodes().isEnd(i); n->nodes().next(i)){
produceInt(n->nodes()[i]);
}
break;
case Node::TSTRUCT:
typeName = BString("") + n->name();
if((n->nodes().number() == 2) && n->node(1)){
ofileInt.writeLine(BString("class ") + typeName + " : public " + getTypeName(n->node(1), 1) + " {\n");
}
else {
ofileInt.writeLine(BString("class ") + typeName + " {\n");
}
ofileInt.writeLine(BString("class ") + typeName + " {\n");
ofileInt.writeLine("public:\n");
ofileInt.indentMore();
ofileInt.writeLine(typeName + "();\n");
ofileInt.indentLess();
ofileInt.writeLine("public:\n");
ofileInt.indentMore();
nl = &n->node(0)->nodes();
for(nl->start(i); !nl->isEnd(i); nl->next(i)){
s = getTypeName(nl->get(i)->node(0), 1) + "\t";
s = s + nl->get(i)->node(1)->name();
ofileInt.writeLine(s + ";\n");
}
ofileInt.indentLess();
ofileInt.writeLine("};\n\n");
break;
case Node::TENUM:
s = "";
if(n->node(0)){
s = s + n->node(0)->name() + " ";
}
nl = &n->node(1)->nodes();
for(nl->start(i); !nl->isEnd(i); nl->next(i)){
if(s.len())
s += ", ";
s += nl->get(i)->name();
}
ofileInt.writeLine(BString("enum { " + s + "};\n");
break;
default:
break;
}
}
void GenData::produceImp(Node* n){
BString s;
BIter i;
BList<Node*>* nl;
BString typeName;
BString parentTypeName;
switch(n->nodeType()){
case Node::TMODULE:
omodule = n->name();
ofileImp.writeLine(BString("namespace ") + omodule + " {\n");
ofileImp.indentMore();
for(n->nodes().start(i); !n->nodes().isEnd(i); n->nodes().next(i)){
produceImp(n->nodes()[i]);
}
ofileImp.indentLess();
ofileImp.writeLine("}\n");
break;
case Node::TLIST:
for(n->nodes().start(i); !n->nodes().isEnd(i); n->nodes().next(i)){
produceImp(n->nodes()[i]);
}
break;
case Node::TTYPEDOMAIN:
otypeDomain = atoi(n->name());
break;
case Node::TSTRUCT:
typeName = BString("") + n->name();
parentTypeName = "";
if((n->nodes().number() == 2) && n->node(1)){
parentTypeName = getTypeName(n->node(1), 1);
}
ofileImp.writeLine("\n");
ofileImp.writeLine(BString("// ") + typeName + " Object Implementation\n");
if((n->nodes().number() == 2) && n->node(1)){
ofileImp.writeLine(typeName + "::" + typeName + "(){\n");
}
else {
ofileImp.writeLine(typeName + "::" + typeName + "(){\n");
}
ofileImp.indentMore();
ofileImp.indentLess();
ofileImp.writeLine("}\n");
otypeNum++;
break;
default:
break;
}
}
BError GenData::produceHeaderInt(){
BError err;
BString fileName = ofileName + "D.h";
BString fileNameUpper = ofileName + "D_H";
fileNameUpper.toUpper();
ofileInt.printf("/*******************************************************************************\n");
ofileInt.printf(" *\t%s\tProduced by Bidl\n", fileName.retStr());
ofileInt.printf(" *******************************************************************************\n");
ofileInt.printf(" */\n");
ofileInt.printf("\n");
ofileInt.printf("#ifndef %s\n", fileNameUpper.retStr());
ofileInt.printf("#define %s 1\n\n", fileNameUpper.retStr());
ofileInt.printf("#include <Boap.h>\n\n");