move to PIIOTextStream
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "picli.h"
|
||||
#include "picodeparser.h"
|
||||
#include "piiostream.h"
|
||||
|
||||
using namespace PICoutManipulators;
|
||||
|
||||
@@ -118,69 +119,69 @@ PIString toCName(const PIString &s) {
|
||||
}
|
||||
|
||||
|
||||
void makeClassInfo(PIFile & f, const PICodeParser::Entity * e) {
|
||||
f << "\n\t{\n\tClassInfo * ci = new ClassInfo();\n";
|
||||
f << "\tci->type = \"" << e->type << "\";\n";
|
||||
f << "\tci->name = \"" << e->name << "\";\n";
|
||||
f << "\tci->has_name = " << (e->has_name ? "true" : "false") << ";\n";
|
||||
void makeClassInfo(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
ts << "\n\t{\n\tClassInfo * ci = new ClassInfo();\n";
|
||||
ts << "\tci->type = \"" << e->type << "\";\n";
|
||||
ts << "\tci->name = \"" << e->name << "\";\n";
|
||||
ts << "\tci->has_name = " << (e->has_name ? "true" : "false") << ";\n";
|
||||
if (!e->meta.isEmpty()) {
|
||||
auto i = e->meta.makeIterator();
|
||||
while (i.next())
|
||||
f << "\tci->meta[\"" << i.key() << "\"] = PIString::fromUTF8(\"" << i.value() << "\");\n";
|
||||
ts << "\tci->meta[\"" << i.key() << "\"] = PIString::fromUTF8(\"" << i.value() << "\");\n";
|
||||
}
|
||||
f << "\t(*classesInfo)[ci->name] = ci;\n";
|
||||
ts << "\t(*classesInfo)[ci->name] = ci;\n";
|
||||
if (e->parent_scope) {
|
||||
f << "\tpci = " << "classesInfo->value(\"" << e->parent_scope->name << "\", 0);\n";
|
||||
f << "\tif (pci) pci->children_info << ci;\n";
|
||||
ts << "\tpci = " << "classesInfo->value(\"" << e->parent_scope->name << "\", 0);\n";
|
||||
ts << "\tif (pci) pci->children_info << ci;\n";
|
||||
}
|
||||
piForeachC (PICodeParser::Entity * p, e->parents)
|
||||
f << "\tci->parents << \"" << p->name << "\";\n";
|
||||
if (!e->members.isEmpty()) f << "\n\tTypeInfo ti;\n";
|
||||
ts << "\tci->parents << \"" << p->name << "\";\n";
|
||||
if (!e->members.isEmpty()) ts << "\n\tTypeInfo ti;\n";
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
f << "\tti = TypeInfo(\"" << m.name << "\", \"" << m.type << "\"";
|
||||
ts << "\tti = TypeInfo(\"" << m.name << "\", \"" << m.type << "\"";
|
||||
if (m.attributes != 0) {
|
||||
bool fir = true;
|
||||
f << ", ";
|
||||
if (m.attributes[PICodeParser::Const ]) {if (fir) fir = false; else f << " | "; f << "Const";}
|
||||
if (m.attributes[PICodeParser::Static ]) {if (fir) fir = false; else f << " | "; f << "Static";}
|
||||
if (m.attributes[PICodeParser::Mutable ]) {if (fir) fir = false; else f << " | "; f << "Mutable";}
|
||||
if (m.attributes[PICodeParser::Volatile]) {if (fir) fir = false; else f << " | "; f << "Volatile";}
|
||||
if (m.attributes[PICodeParser::Inline ]) {if (fir) fir = false; else f << " | "; f << "Inline";}
|
||||
if (m.attributes[PICodeParser::Virtual ]) {if (fir) fir = false; else f << " | "; f << "Virtual";}
|
||||
ts << ", ";
|
||||
if (m.attributes[PICodeParser::Const ]) {if (fir) fir = false; else ts << " | "; ts << "Const";}
|
||||
if (m.attributes[PICodeParser::Static ]) {if (fir) fir = false; else ts << " | "; ts << "Static";}
|
||||
if (m.attributes[PICodeParser::Mutable ]) {if (fir) fir = false; else ts << " | "; ts << "Mutable";}
|
||||
if (m.attributes[PICodeParser::Volatile]) {if (fir) fir = false; else ts << " | "; ts << "Volatile";}
|
||||
if (m.attributes[PICodeParser::Inline ]) {if (fir) fir = false; else ts << " | "; ts << "Inline";}
|
||||
if (m.attributes[PICodeParser::Virtual ]) {if (fir) fir = false; else ts << " | "; ts << "Virtual";}
|
||||
} else {
|
||||
if (m.isBitfield())
|
||||
f << ", 0";
|
||||
ts << ", 0";
|
||||
}
|
||||
if (m.isBitfield())
|
||||
f << ", " << m.bits;
|
||||
f << ");\n";
|
||||
ts << ", " << m.bits;
|
||||
ts << ");\n";
|
||||
if (!m.meta.isEmpty()) {
|
||||
for (PICodeParser::MetaMap::const_iterator i = m.meta.begin(); i != m.meta.end(); ++i)
|
||||
f << "\tti.meta[\"" << i.key() << "\"] = PIString::fromUTF8(\"" << i.value() << "\");\n";
|
||||
ts << "\tti.meta[\"" << i.key() << "\"] = PIString::fromUTF8(\"" << i.value() << "\");\n";
|
||||
}
|
||||
f << "\tci->variables << ti;\n";
|
||||
ts << "\tci->variables << ti;\n";
|
||||
}
|
||||
PIString arg;
|
||||
bool has_fi = false;
|
||||
piForeachC (PICodeParser::Member & m, e->functions) {
|
||||
if (e->name.findCWord(m.name) >= 0) continue;
|
||||
if (!has_fi)
|
||||
f << "\n\tFunctionInfo * fi;\n";
|
||||
ts << "\n\tFunctionInfo * fi;\n";
|
||||
has_fi = true;
|
||||
f << "\tci->functions.push_back(FunctionInfo()); fi = &(ci->functions.back());\n";
|
||||
f << "\tfi->name = \"" << m.name << "\";";
|
||||
f << " fi->return_type = TypeInfo(\"\", \"" << m.type << "\"";
|
||||
ts << "\tci->functions.push_back(FunctionInfo()); fi = &(ci->functions.back());\n";
|
||||
ts << "\tfi->name = \"" << m.name << "\";";
|
||||
ts << " fi->return_type = TypeInfo(\"\", \"" << m.type << "\"";
|
||||
if (m.attributes[PICodeParser::Const] || m.attributes[PICodeParser::Static]) {
|
||||
bool fir = true;
|
||||
f << ", ";
|
||||
if (m.attributes[PICodeParser::Const ]) {if (fir) fir = false; else f << " | "; f << "Const";}
|
||||
if (m.attributes[PICodeParser::Static]) {if (fir) fir = false; else f << " | "; f << "Static";}
|
||||
ts << ", ";
|
||||
if (m.attributes[PICodeParser::Const ]) {if (fir) fir = false; else ts << " | "; ts << "Const";}
|
||||
if (m.attributes[PICodeParser::Static]) {if (fir) fir = false; else ts << " | "; ts << "Static";}
|
||||
}
|
||||
f << ");\n";
|
||||
ts << ");\n";
|
||||
//piCout << "write func" << m.name;
|
||||
piForeachC (PIString & a, m.arguments_full) {
|
||||
//piCout << "write arg" << a;
|
||||
f << "\tfi->arguments << TypeInfo(";
|
||||
ts << "\tfi->arguments << TypeInfo(";
|
||||
arg = a;
|
||||
bool con = false;
|
||||
arg.prepend(" ");
|
||||
@@ -189,48 +190,48 @@ void makeClassInfo(PIFile & f, const PICodeParser::Entity * e) {
|
||||
con = true;
|
||||
}
|
||||
arg.trim();
|
||||
int ts = 0;
|
||||
for (ts = arg.size_s() - 1; ts > 0; --ts)
|
||||
if (!_isCChar(arg[ts]) && !(arg[ts].isDigit())) break;
|
||||
f << "\"" << arg.takeRight(arg.size_s() - ts - 1).trim() << "\", ";
|
||||
f << "\"" << arg.trim() << "\"";
|
||||
if (con) f << ", Const";
|
||||
f << ");\n";
|
||||
int i = 0;
|
||||
for (i = arg.size_s() - 1; i > 0; --i)
|
||||
if (!_isCChar(arg[i]) && !(arg[i].isDigit())) break;
|
||||
ts << "\"" << arg.takeRight(arg.size_s() - i - 1).trim() << "\", ";
|
||||
ts << "\"" << arg.trim() << "\"";
|
||||
if (con) ts << ", Const";
|
||||
ts << ");\n";
|
||||
}
|
||||
if (!m.meta.isEmpty()) {
|
||||
for (PICodeParser::MetaMap::const_iterator i = m.meta.begin(); i != m.meta.end(); ++i)
|
||||
f << "\tfi->meta[\"" << i.key() << "\"] = PIString::fromUTF8(\"" << i.value() << "\");\n";
|
||||
ts << "\tfi->meta[\"" << i.key() << "\"] = PIString::fromUTF8(\"" << i.value() << "\");\n";
|
||||
}
|
||||
}
|
||||
f << "\n\t}";
|
||||
ts << "\n\t}";
|
||||
}
|
||||
|
||||
|
||||
void makeEnumInfo(PIFile & f, const PICodeParser::Enum * e) {
|
||||
void makeEnumInfo(PIIOTextStream & ts, const PICodeParser::Enum * e) {
|
||||
if (e->name.isEmpty()) {
|
||||
f << "\n\tei = (*enumsInfo)[\"\"];\n";
|
||||
ts << "\n\tei = (*enumsInfo)[\"\"];\n";
|
||||
} else {
|
||||
f << "\n\tei = new EnumInfo();\n";
|
||||
f << "\t(*enumsInfo)[\"" << e->name << "\"] = ei;\n";
|
||||
f << "\tei->name = \"" << e->name << "\";\n";
|
||||
ts << "\n\tei = new EnumInfo();\n";
|
||||
ts << "\t(*enumsInfo)[\"" << e->name << "\"] = ei;\n";
|
||||
ts << "\tei->name = \"" << e->name << "\";\n";
|
||||
if (!e->meta.isEmpty()) {
|
||||
auto i = e->meta.makeIterator();
|
||||
while (i.next())
|
||||
f << "\tei->meta[\"" << i.key() << "\"] = PIString::fromUTF8(\"" << i.value() << "\");\n";
|
||||
ts << "\tei->meta[\"" << i.key() << "\"] = PIString::fromUTF8(\"" << i.value() << "\");\n";
|
||||
}
|
||||
}
|
||||
piForeachC (PICodeParser::EnumeratorInfo & m, e->members) {
|
||||
f << "\tei->members << PICodeInfo::EnumeratorInfo(\"" << m.name << "\", " << m.value << ");\n";
|
||||
ts << "\tei->members << PICodeInfo::EnumeratorInfo(\"" << m.name << "\", " << m.value << ");\n";
|
||||
if (!m.meta.isEmpty()) {
|
||||
auto i = m.meta.makeIterator();
|
||||
while (i.next())
|
||||
f << "\tei->members.back().meta[\"" << i.key() << "\"] = PIString::fromUTF8(\"" << i.value() << "\");\n";
|
||||
ts << "\tei->members.back().meta[\"" << i.key() << "\"] = PIString::fromUTF8(\"" << i.value() << "\");\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||
void writeClassStreamMembersOut(PIIOTextStream & ts, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||
PIVector<PICodeParser::Member> ml;
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||
@@ -246,15 +247,15 @@ void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int
|
||||
cnt = m.meta.value("id").toInt();
|
||||
if (m.dims.isEmpty()) {
|
||||
if (simple) {
|
||||
f << "\ts << ";
|
||||
ts << "\ts << ";
|
||||
if (parser.isEnum(m.type))
|
||||
f << "(int)";
|
||||
f << "v." << m.name << ";\n";
|
||||
ts << "(int)";
|
||||
ts << "v." << m.name << ";\n";
|
||||
} else {
|
||||
f << "\tcs << cs.chunk(" << cnt << ", ";
|
||||
ts << "\tcs << cs.chunk(" << cnt << ", ";
|
||||
if (parser.isEnum(m.type))
|
||||
f << "(int)";
|
||||
f << "v." << m.name << ");\n";
|
||||
ts << "(int)";
|
||||
ts << "v." << m.name << ");\n";
|
||||
}
|
||||
} else {
|
||||
PIString ptype = m.type.left(m.type.find('[')).trim();
|
||||
@@ -264,11 +265,11 @@ void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int
|
||||
size += m.dims[i];
|
||||
}
|
||||
if (simple) {
|
||||
f << "\tfor (int i = 0; i < " << size << "; ++i)\n";
|
||||
f << "\t\ts << ((const " << ptype << " *)(v." << m.name << "))[i];\n";
|
||||
ts << "\tfor (int i = 0; i < " << size << "; ++i)\n";
|
||||
ts << "\t\ts << ((const " << ptype << " *)(v." << m.name << "))[i];\n";
|
||||
} else {
|
||||
f << "\tcs << cs.chunk(" << cnt << ", PIVector<" << ptype << " >((const " << ptype << " *)(v." << m.name << "), ";
|
||||
f << size << "));\n";
|
||||
ts << "\tcs << cs.chunk(" << cnt << ", PIVector<" << ptype << " >((const " << ptype << " *)(v." << m.name << "), ";
|
||||
ts << size << "));\n";
|
||||
}
|
||||
}
|
||||
if (is_union)
|
||||
@@ -277,12 +278,12 @@ void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int
|
||||
if (is_union) return;
|
||||
piForeachC (PICodeParser::Entity * ce, e->children) {
|
||||
if (ce->has_name) continue;
|
||||
writeClassStreamMembersOut(f, ce, cnt, simple);
|
||||
writeClassStreamMembersOut(ts, ce, cnt, simple);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||
void writeClassStreamMembersIn(PIIOTextStream & ts, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||
PIVector<PICodeParser::Member> ml;
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||
@@ -298,15 +299,15 @@ void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int &
|
||||
cnt = m.meta.value("id").toInt();
|
||||
if (m.dims.isEmpty()) {
|
||||
if (simple) {
|
||||
f << "\ts >> ";
|
||||
ts << "\ts >> ";
|
||||
if (parser.isEnum(m.type))
|
||||
f << "(int&)";
|
||||
f << "v." << m.name << ";\n";
|
||||
ts << "(int&)";
|
||||
ts << "v." << m.name << ";\n";
|
||||
} else {
|
||||
f << "\t\tcase " << cnt << ": cs.get(";
|
||||
ts << "\t\tcase " << cnt << ": cs.get(";
|
||||
if (parser.isEnum(m.type))
|
||||
f << "(int&)";
|
||||
f << "v." << m.name << "); break;\n";
|
||||
ts << "(int&)";
|
||||
ts << "v." << m.name << "); break;\n";
|
||||
}
|
||||
} else {
|
||||
PIString ptype = m.type.left(m.type.find('[')).trim();
|
||||
@@ -316,15 +317,15 @@ void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int &
|
||||
size += m.dims[i];
|
||||
}
|
||||
if (simple) {
|
||||
f << "\tfor (int i = 0; i < " << size << "; ++i)\n";
|
||||
f << "\t\ts >> ((" << ptype << " *)(v." << m.name << "))[i];\n";
|
||||
ts << "\tfor (int i = 0; i < " << size << "; ++i)\n";
|
||||
ts << "\t\ts >> ((" << ptype << " *)(v." << m.name << "))[i];\n";
|
||||
} else {
|
||||
f << "\t\tcase " << cnt << ": {\n\t\t\tPIVector<" << ptype << " > d; cs.get(d);\n";
|
||||
f << "\t\t\tint cnt = piMini(d.size_s(), " << size << ");\n";
|
||||
f << "\t\t\tfor (int i = 0; i < cnt; ++i)\n";
|
||||
f << "\t\t\t\t((" << ptype << " *)(v." << m.name << "))[i] = d[i];\n";
|
||||
f << "\t\t\t}\n";
|
||||
f << "\t\t\tbreak;\n";
|
||||
ts << "\t\tcase " << cnt << ": {\n\t\t\tPIVector<" << ptype << " > d; cs.get(d);\n";
|
||||
ts << "\t\t\tint cnt = piMini(d.size_s(), " << size << ");\n";
|
||||
ts << "\t\t\tfor (int i = 0; i < cnt; ++i)\n";
|
||||
ts << "\t\t\t\t((" << ptype << " *)(v." << m.name << "))[i] = d[i];\n";
|
||||
ts << "\t\t\t}\n";
|
||||
ts << "\t\t\tbreak;\n";
|
||||
}
|
||||
}
|
||||
if (is_union)
|
||||
@@ -333,7 +334,7 @@ void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int &
|
||||
if (is_union) return;
|
||||
piForeachC (PICodeParser::Entity * ce, e->children) {
|
||||
if (ce->has_name) continue;
|
||||
writeClassStreamMembersIn(f, ce, cnt, simple);
|
||||
writeClassStreamMembersIn(ts, ce, cnt, simple);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,76 +351,76 @@ bool needClassStream(const PICodeParser::Entity * e) {
|
||||
}
|
||||
|
||||
|
||||
void makeClassStream(PIFile & f, const PICodeParser::Entity * e) {
|
||||
void makeClassStream(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
if (!needClassStream(e)) return;
|
||||
bool simple = e->meta.contains("simple-stream");
|
||||
f << "\nPIByteArray & operator <<(PIByteArray & s, const " << e->name << " & v) {\n";
|
||||
ts << "\nPIByteArray & operator <<(PIByteArray & s, const " << e->name << " & v) {\n";
|
||||
if (!simple)
|
||||
f << "\tPIChunkStream cs;\n";
|
||||
ts << "\tPIChunkStream cs;\n";
|
||||
int cnt = 0;
|
||||
writeClassStreamMembersOut(f, e, cnt, simple);
|
||||
writeClassStreamMembersOut(ts, e, cnt, simple);
|
||||
if (!simple)
|
||||
f << "\ts << cs.data();\n";
|
||||
f << "\treturn s;\n}\n";
|
||||
f << "PIByteArray & operator >>(PIByteArray & s, " << e->name << " & v) {\n";
|
||||
ts << "\ts << cs.data();\n";
|
||||
ts << "\treturn s;\n}\n";
|
||||
ts << "PIByteArray & operator >>(PIByteArray & s, " << e->name << " & v) {\n";
|
||||
if (!simple) {
|
||||
f << "\tif (s.size_s() < 4) return s;\n";
|
||||
f << "\tPIByteArray csba; s >> csba;\n";
|
||||
f << "\tPIChunkStream cs(csba);\n";
|
||||
f << "\twhile (!cs.atEnd()) {\n";
|
||||
f << "\t\tswitch (cs.read()) {\n";
|
||||
ts << "\tif (s.size_s() < 4) return s;\n";
|
||||
ts << "\tPIByteArray csba; s >> csba;\n";
|
||||
ts << "\tPIChunkStream cs(csba);\n";
|
||||
ts << "\twhile (!cs.atEnd()) {\n";
|
||||
ts << "\t\tswitch (cs.read()) {\n";
|
||||
}
|
||||
cnt = 0;
|
||||
writeClassStreamMembersIn(f, e, cnt, simple);
|
||||
writeClassStreamMembersIn(ts, e, cnt, simple);
|
||||
if (!simple)
|
||||
f << "\t\t}\n\t}\n";
|
||||
f << "\treturn s;\n}\n";
|
||||
ts << "\t\t}\n\t}\n";
|
||||
ts << "\treturn s;\n}\n";
|
||||
}
|
||||
|
||||
|
||||
void makeClassStreamHeader(PIFile & f, const PICodeParser::Entity * e) {
|
||||
void makeClassStreamHeader(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
if (!needClassStream(e)) return;
|
||||
f << "\n";
|
||||
ts << "\n";
|
||||
PIStringList sl = e->name.split("::");
|
||||
for (int i = 0; i < sl.size_s() - 1; ++i)
|
||||
f << "namespace " << sl[i] << " {";
|
||||
f << e->type << " " << sl.back() << ";";
|
||||
if (sl.size_s() > 1) f << PIString('}').repeat(sl.size_s() - 1);
|
||||
ts << "namespace " << sl[i] << " {";
|
||||
ts << e->type << " " << sl.back() << ";";
|
||||
if (sl.size_s() > 1) ts << PIString('}').repeat(sl.size_s() - 1);
|
||||
|
||||
f << "\nPIByteArray & operator <<(PIByteArray & s, const " << e->name << " & v);";
|
||||
f << "\nPIByteArray & operator >>(PIByteArray & s, " << e->name << " & v);\n";
|
||||
ts << "\nPIByteArray & operator <<(PIByteArray & s, const " << e->name << " & v);";
|
||||
ts << "\nPIByteArray & operator >>(PIByteArray & s, " << e->name << " & v);\n";
|
||||
}
|
||||
|
||||
|
||||
void makeGetterType(PIFile & f, const PICodeParser::Entity * e) {
|
||||
void makeGetterType(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
if (!needClassStream(e)) return;
|
||||
f << "\nconst char * getterType" << toCName(e->name) << "(const char * name) {\n";
|
||||
f << "\tif (!name) return \"\";\n";
|
||||
ts << "\nconst char * getterType" << toCName(e->name) << "(const char * name) {\n";
|
||||
ts << "\tif (!name) return \"\";\n";
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
if (m.is_type_ptr || m.isBitfield() || !m.dims.isEmpty() || (m.visibility != PICodeParser::Public))
|
||||
continue;
|
||||
f << "\tif (strcmp(name, \"" << m.name << "\") == 0) return \"" << m.type << "\";\n";
|
||||
ts << "\tif (strcmp(name, \"" << m.name << "\") == 0) return \"" << m.type << "\";\n";
|
||||
}
|
||||
f << "\treturn \"\";\n}\n";
|
||||
ts << "\treturn \"\";\n}\n";
|
||||
}
|
||||
|
||||
|
||||
void makeGetterValue(PIFile & f, const PICodeParser::Entity * e) {
|
||||
void makeGetterValue(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
if (!needClassStream(e)) return;
|
||||
f << "\nPIByteArray getterValue" << toCName(e->name) << "(const void * p, const char * name) {\n";
|
||||
f << "\tPIByteArray ret;\n";
|
||||
f << "\tif (!p || !name) return ret;\n";
|
||||
f << "\t" << e->name << " * o = (" << e->name << "*)p;\n";
|
||||
ts << "\nPIByteArray getterValue" << toCName(e->name) << "(const void * p, const char * name) {\n";
|
||||
ts << "\tPIByteArray ret;\n";
|
||||
ts << "\tif (!p || !name) return ret;\n";
|
||||
ts << "\t" << e->name << " * o = (" << e->name << "*)p;\n";
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
if (m.is_type_ptr || m.isBitfield() || !m.dims.isEmpty() || (m.visibility != PICodeParser::Public))
|
||||
continue;
|
||||
f << "\tif (strcmp(name, \"" << m.name << "\") == 0) {serialize(ret, o->" << m.name << "); return ret;}\n";
|
||||
ts << "\tif (strcmp(name, \"" << m.name << "\") == 0) {serialize(ret, o->" << m.name << "); return ret;}\n";
|
||||
}
|
||||
f << "\treturn ret;\n}\n";
|
||||
ts << "\treturn ret;\n}\n";
|
||||
}
|
||||
|
||||
|
||||
void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool meta, bool enums, bool streams, bool texts, bool getters) {
|
||||
bool writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool meta, bool enums, bool streams, bool texts, bool getters) {
|
||||
PIString defname = "CCM_" + PIString::fromNumber(out.hash()) + "_H";
|
||||
PISet<PIString> inc_files;
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities)
|
||||
@@ -434,63 +435,67 @@ void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
|
||||
PIFile f(out + ".cpp");
|
||||
f.clear();
|
||||
f.open(PIIODevice::WriteOnly);
|
||||
f << "// Generated by \"PIP Code model generator\" " << PIDateTime::current().toString("dd.MM.yyyy hh:mm:ss\n\n");
|
||||
f << "#include <string.h>\n";
|
||||
if (!f.open(PIIODevice::WriteOnly)) {
|
||||
piCout << "Error: can`t open out file" << f.path();
|
||||
return false;
|
||||
}
|
||||
PIIOTextStream ts(&f);
|
||||
ts << "// Generated by \"PIP Code model generator\" " << PIDateTime::current().toString("dd.MM.yyyy hh:mm:ss\n\n");
|
||||
ts << "#include <string.h>\n";
|
||||
if (streams || texts)
|
||||
f << "#include <pichunkstream.h>\n";
|
||||
f << "#include \"" << out << ".h\"";
|
||||
f << inc_string << "\n";
|
||||
f << "\nusing namespace PICodeInfo;\n\n";
|
||||
ts << "#include <pichunkstream.h>\n";
|
||||
ts << "#include \"" << out << ".h\"";
|
||||
ts << inc_string << "\n";
|
||||
ts << "\nusing namespace PICodeInfo;\n\n";
|
||||
|
||||
if (meta || enums || getters) {
|
||||
if (getters) {
|
||||
f << "\n\n// Getter funtions\n";
|
||||
ts << "\n\n// Getter funtions\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||
makeGetterType(f, e);
|
||||
makeGetterValue(f, e);
|
||||
makeGetterType(ts, e);
|
||||
makeGetterValue(ts, e);
|
||||
}
|
||||
}
|
||||
f << "\n\n// Metainformation\n\n__ClassInfo_" << defname << "_Initializer__::__ClassInfo_" << defname << "_Initializer__() {\n";
|
||||
f << "\tif (_inited_) return;\n\t_inited_ = true;\n\n";
|
||||
ts << "\n\n// Metainformation\n\n__ClassInfo_" << defname << "_Initializer__::__ClassInfo_" << defname << "_Initializer__() {\n";
|
||||
ts << "\tif (_inited_) return;\n\t_inited_ = true;\n\n";
|
||||
if (meta) {
|
||||
f << "\tClassInfo * pci = new ClassInfo();\n";
|
||||
f << "\t(*classesInfo)[\"\"] = pci;\n";
|
||||
ts << "\tClassInfo * pci = new ClassInfo();\n";
|
||||
ts << "\t(*classesInfo)[\"\"] = pci;\n";
|
||||
}
|
||||
if (enums && !parser.enums.isEmpty()) {
|
||||
f << "\tEnumInfo * ei;\n";
|
||||
f << "\t(*enumsInfo)[\"\"] = new EnumInfo();\n";
|
||||
ts << "\tEnumInfo * ei;\n";
|
||||
ts << "\t(*enumsInfo)[\"\"] = new EnumInfo();\n";
|
||||
}
|
||||
if (meta) {
|
||||
f << "\n\n// Classes\n";
|
||||
ts << "\n\n// Classes\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
if (e->name.startsWith("_PI")) continue;
|
||||
makeClassInfo(f, e);
|
||||
makeClassInfo(ts, e);
|
||||
}
|
||||
}
|
||||
if (enums) {
|
||||
f << "\n// Enums\n";
|
||||
ts << "\n// Enums\n";
|
||||
piForeachC (PICodeParser::Enum & e, parser.enums)
|
||||
makeEnumInfo(f, &e);
|
||||
makeEnumInfo(ts, &e);
|
||||
}
|
||||
if (getters) {
|
||||
f << "\n// Getters\n";
|
||||
ts << "\n// Getters\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
if (!needClassStream(e)) continue;
|
||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||
f << "\t(*accessValueFunctions)[\"" << e->name << "\"] = getterValue" << toCName(e->name) << ";\n";
|
||||
f << "\t(*accessTypeFunctions)[\"" << e->name << "\"] = getterType" << toCName(e->name) << ";\n";
|
||||
ts << "\t(*accessValueFunctions)[\"" << e->name << "\"] = getterValue" << toCName(e->name) << ";\n";
|
||||
ts << "\t(*accessTypeFunctions)[\"" << e->name << "\"] = getterType" << toCName(e->name) << ";\n";
|
||||
}
|
||||
}
|
||||
f << "}\n";
|
||||
f << "\n\nbool __ClassInfo_" << defname << "_Initializer__::_inited_ = false;\n";
|
||||
ts << "}\n";
|
||||
ts << "\n\nbool __ClassInfo_" << defname << "_Initializer__::_inited_ = false;\n";
|
||||
}
|
||||
if (streams) {
|
||||
f << "\n\n// Stream operators\n";
|
||||
ts << "\n\n// Stream operators\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||
makeClassStream(f, e);
|
||||
makeClassStream(ts, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -499,28 +504,33 @@ void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
|
||||
f.setPath(out + ".h");
|
||||
f.clear();
|
||||
f.open(PIIODevice::WriteOnly);
|
||||
f << "// Generated by \"PIP Code model generator\" " << PIDateTime::current().toString("dd.MM.yyyy hh:mm:ss\n");
|
||||
f << "// Execute command:\n";
|
||||
if (!f.open(PIIODevice::WriteOnly)) {
|
||||
piCout << "Error: can`t open out file" << f.path();
|
||||
return false;
|
||||
}
|
||||
ts << "// Generated by \"PIP Code model generator\" " << PIDateTime::current().toString("dd.MM.yyyy hh:mm:ss\n");
|
||||
ts << "// Execute command:\n";
|
||||
piForeachC (PIString & _a, cli.rawArguments())
|
||||
f << "// \"" << _a << "\"\n";
|
||||
f << "\n";
|
||||
f << "#ifndef " << defname << "\n#define " << defname << "\n\n";
|
||||
f << "#include <pivariant.h>\n#include <picodeinfo.h>";
|
||||
ts << "// \"" << _a << "\"\n";
|
||||
ts << "\n";
|
||||
ts << "#ifndef " << defname << "\n#define " << defname << "\n\n";
|
||||
ts << "#include <pivariant.h>\n#include <picodeinfo.h>";
|
||||
if (streams) {
|
||||
f << "\n\n// Stream operators\n";
|
||||
ts << "\n\n// Stream operators\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||
makeClassStreamHeader(f, e);
|
||||
makeClassStreamHeader(ts, e);
|
||||
}
|
||||
}
|
||||
if (meta || enums || getters) {
|
||||
f << "\n\n// Metainformation\n\nclass __ClassInfo_" << defname << "_Initializer__ {\n";
|
||||
f << "public:\n\t__ClassInfo_" << defname << "_Initializer__();\n\tstatic bool _inited_;\n};\n";
|
||||
f << "\nstatic __ClassInfo_" << defname << "_Initializer__ __classinfo_" << defname.toLowerCase() << "_initializer__;\n";
|
||||
ts << "\n\n// Metainformation\n\nclass __ClassInfo_" << defname << "_Initializer__ {\n";
|
||||
ts << "public:\n\t__ClassInfo_" << defname << "_Initializer__();\n\tstatic bool _inited_;\n};\n";
|
||||
ts << "\nstatic __ClassInfo_" << defname << "_Initializer__ __classinfo_" << defname.toLowerCase() << "_initializer__;\n";
|
||||
}
|
||||
f << "\n\n#endif // " << defname << "\n";
|
||||
ts << "\n\n#endif // " << defname << "\n";
|
||||
f.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -562,11 +572,12 @@ int main(int argc, char * argv[]) {
|
||||
piCout << Cyan << Bold << "Parsing done";
|
||||
piCout << Cyan << Bold << "Writing code model ...";
|
||||
bool all = cli.hasArgument("All");
|
||||
writeModel(parser, cli, cli.argumentValue("output"), cli.hasArgument("Metainfo") || all,
|
||||
cli.hasArgument("Enum") || all,
|
||||
cli.hasArgument("Stream") || all,
|
||||
cli.hasArgument("Text") || all,
|
||||
cli.hasArgument("Getter") || all);
|
||||
if (!writeModel(parser, cli, cli.argumentValue("output"), cli.hasArgument("Metainfo") || all,
|
||||
cli.hasArgument("Enum") || all,
|
||||
cli.hasArgument("Stream") || all,
|
||||
cli.hasArgument("Text") || all,
|
||||
cli.hasArgument("Getter") || all))
|
||||
return 1;
|
||||
piCout << Cyan << Bold << "Writing done";
|
||||
if (cli.hasArgument("print") || cli.hasArgument("Print")) {
|
||||
bool womain = cli.hasArgument("print");
|
||||
|
||||
Reference in New Issue
Block a user