Merge branch 'master' of https://git.shs.tools/SHS/pip into thread
This commit is contained in:
@@ -311,6 +311,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
|
||||
//piCout << PICoutManipulators::NewLine << "file" << cur_file << pfc;
|
||||
int pl = -1;
|
||||
cur_def_vis = Global;
|
||||
while (!pfc.isEmpty()) {
|
||||
pfc.trim();
|
||||
int nl = pfc.size_s();
|
||||
@@ -407,6 +408,7 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc)
|
||||
}
|
||||
PIString typename_ = cd.left(6).trim();
|
||||
bool is_class = typename_ == s_class;
|
||||
Visibility vis = cur_def_vis;
|
||||
cur_def_vis = (is_class ? Private : Public);
|
||||
PIString cn = cd.mid(6).trim();
|
||||
bool has_name = !cn.isEmpty();
|
||||
@@ -419,6 +421,7 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc)
|
||||
e->type = typename_;
|
||||
e->has_name = has_name;
|
||||
e->parents = parents;
|
||||
e->visibility = vis;
|
||||
e->file = cur_file;
|
||||
entities << e;
|
||||
return e;
|
||||
|
||||
@@ -341,14 +341,31 @@ PIString PIString::fromSystem(const char * s) {
|
||||
PIString PIString::fromUTF8(const char * s) {
|
||||
PIString ret;
|
||||
if (!s) return ret;
|
||||
if (s[0] != '\0') ret.appendFromChars(s, -1, __utf8name__);
|
||||
if (s[0] != '\0') {
|
||||
if ((uchar)s[0] == 0xEF && (uchar)s[1] == 0xBB && (uchar)s[2] == 0xBF) {
|
||||
s += 3;
|
||||
if (s[0] == '\0') return ret;
|
||||
}
|
||||
ret.appendFromChars(s, -1, __utf8name__);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PIString PIString::fromUTF8(const PIByteArray & ba) {
|
||||
PIString ret;
|
||||
if (ba.isNotEmpty()) ret.appendFromChars((const char*)ba.data(), ba.size(), __utf8name__);
|
||||
if (ba.isNotEmpty()) {
|
||||
const char * data = (const char*)ba.data();
|
||||
int size = ba.size();
|
||||
if (ba.size() >= 3) {
|
||||
if (ba[0] == 0xEF && ba[1] == 0xBB && ba[2] == 0xBF) {
|
||||
data += 3;
|
||||
size -= 3;
|
||||
if (size == 0) return ret;
|
||||
}
|
||||
}
|
||||
ret.appendFromChars(data, size, __utf8name__);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -134,10 +134,10 @@ void makeClassInfo(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
ts << "\tpci = " << "classesInfo->value(\"" << e->parent_scope->name << "\", 0);\n";
|
||||
ts << "\tif (pci) pci->children_info << ci;\n";
|
||||
}
|
||||
piForeachC (PICodeParser::Entity * p, e->parents)
|
||||
for (const PICodeParser::Entity * p: e->parents)
|
||||
ts << "\tci->parents << \"" << p->name << "\";\n";
|
||||
if (!e->members.isEmpty()) ts << "\n\tTypeInfo ti;\n";
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
for (const PICodeParser::Member & m: e->members) {
|
||||
ts << "\tti = TypeInfo(\"" << m.name << "\", \"" << m.type << "\"";
|
||||
if (m.attributes != 0) {
|
||||
bool fir = true;
|
||||
@@ -163,7 +163,7 @@ void makeClassInfo(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
}
|
||||
PIString arg;
|
||||
bool has_fi = false;
|
||||
piForeachC (PICodeParser::Member & m, e->functions) {
|
||||
for (const PICodeParser::Member & m: e->functions) {
|
||||
if (e->name.findCWord(m.name) >= 0) continue;
|
||||
if (!has_fi)
|
||||
ts << "\n\tFunctionInfo * fi;\n";
|
||||
@@ -179,7 +179,7 @@ void makeClassInfo(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
}
|
||||
ts << ");\n";
|
||||
//piCout << "write func" << m.name;
|
||||
piForeachC (PIString & a, m.arguments_full) {
|
||||
for (const PIString & a: m.arguments_full) {
|
||||
//piCout << "write arg" << a;
|
||||
ts << "\tfi->arguments << TypeInfo(";
|
||||
arg = a;
|
||||
@@ -220,7 +220,7 @@ void makeEnumInfo(PIIOTextStream & ts, const PICodeParser::Enum * e) {
|
||||
ts << "\tei->meta[\"" << i.key() << "\"] = PIString::fromUTF8(\"" << i.value() << "\");\n";
|
||||
}
|
||||
}
|
||||
piForeachC (PICodeParser::EnumeratorInfo & m, e->members) {
|
||||
for (const PICodeParser::EnumeratorInfo & m: e->members) {
|
||||
ts << "\tei->members << PICodeInfo::EnumeratorInfo(\"" << m.name << "\", " << m.value << ");\n";
|
||||
if (!m.meta.isEmpty()) {
|
||||
auto i = m.meta.makeIterator();
|
||||
@@ -233,12 +233,12 @@ void makeEnumInfo(PIIOTextStream & ts, const PICodeParser::Enum * e) {
|
||||
|
||||
void writeClassStreamMembersOut(PIIOTextStream & ts, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||
PIVector<PICodeParser::Member> ml;
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
for (const PICodeParser::Member & m: e->members) {
|
||||
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||
ml << m;
|
||||
}
|
||||
bool is_union = e->type == "union";
|
||||
piForeachC (PICodeParser::Member & m, ml) {
|
||||
for (const PICodeParser::Member & m: ml) {
|
||||
if (is_union && m.isBitfield())
|
||||
continue;
|
||||
if (m.meta.value("id") == "-") continue;
|
||||
@@ -276,7 +276,7 @@ void writeClassStreamMembersOut(PIIOTextStream & ts, const PICodeParser::Entity
|
||||
break;
|
||||
}
|
||||
if (is_union) return;
|
||||
piForeachC (PICodeParser::Entity * ce, e->children) {
|
||||
for (const PICodeParser::Entity * ce: e->children) {
|
||||
if (ce->has_name) continue;
|
||||
writeClassStreamMembersOut(ts, ce, cnt, simple);
|
||||
}
|
||||
@@ -285,12 +285,12 @@ void writeClassStreamMembersOut(PIIOTextStream & ts, const PICodeParser::Entity
|
||||
|
||||
void writeClassStreamMembersIn(PIIOTextStream & ts, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||
PIVector<PICodeParser::Member> ml;
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
for (const PICodeParser::Member & m: e->members) {
|
||||
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||
ml << m;
|
||||
}
|
||||
bool is_union = e->type == "union";
|
||||
piForeachC (PICodeParser::Member & m, ml) {
|
||||
for (const PICodeParser::Member & m: ml) {
|
||||
if (is_union && m.isBitfield())
|
||||
continue;
|
||||
if (m.meta.value("id") == "-") continue;
|
||||
@@ -340,7 +340,7 @@ void writeClassStreamMembersIn(PIIOTextStream & ts, const PICodeParser::Entity *
|
||||
break;
|
||||
}
|
||||
if (is_union) return;
|
||||
piForeachC (PICodeParser::Entity * ce, e->children) {
|
||||
for (const PICodeParser::Entity * ce: e->children) {
|
||||
if (ce->has_name) continue;
|
||||
writeClassStreamMembersIn(ts, ce, cnt, simple);
|
||||
}
|
||||
@@ -349,7 +349,7 @@ void writeClassStreamMembersIn(PIIOTextStream & ts, const PICodeParser::Entity *
|
||||
|
||||
bool needClassStream(const PICodeParser::Entity * e) {
|
||||
if (e->meta.contains("no-stream")) return false;
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
for (const PICodeParser::Member & m: e->members) {
|
||||
if (m.is_type_ptr || m.isBitfield() || !m.dims.isEmpty() || (m.visibility != PICodeParser::Public))
|
||||
continue;
|
||||
if (m.meta.value("id") == "-") continue;
|
||||
@@ -390,7 +390,7 @@ void makeGetterType(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
if (!needClassStream(e)) return;
|
||||
ts << "\nconst char * getterType" << toCName(e->name) << "(const char * name) {\n";
|
||||
ts << "\tif (!name) return \"\";\n";
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
for (const PICodeParser::Member & m: e->members) {
|
||||
if (m.is_type_ptr || m.isBitfield() || !m.dims.isEmpty() || (m.visibility != PICodeParser::Public))
|
||||
continue;
|
||||
ts << "\tif (strcmp(name, \"" << m.name << "\") == 0) return \"" << m.type << "\";\n";
|
||||
@@ -405,7 +405,7 @@ void makeGetterValue(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
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) {
|
||||
for (const PICodeParser::Member & m: e->members) {
|
||||
if (m.is_type_ptr || m.isBitfield() || !m.dims.isEmpty() || (m.visibility != PICodeParser::Public))
|
||||
continue;
|
||||
ts << "\tif (strcmp(name, \"" << m.name << "\") == 0) {serialize(ret, o->" << m.name << "); return ret;}\n";
|
||||
@@ -417,12 +417,12 @@ void makeGetterValue(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
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)
|
||||
for (const PICodeParser::Entity * e: parser.entities)
|
||||
if (!e->name.startsWith("_PI"))
|
||||
inc_files << e->file;
|
||||
PIString inc_string;
|
||||
PIVector<PIString> incf = inc_files.toVector();
|
||||
piForeachC (PIString & i, incf) {
|
||||
for (const PIString & i: incf) {
|
||||
if ((i != parser.mainFile()) && (streams || texts || getters))
|
||||
inc_string += "\n#include \"" + i + "\"";
|
||||
}
|
||||
@@ -442,7 +442,7 @@ bool writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
if (meta || enums || getters) {
|
||||
if (getters) {
|
||||
ts << "\n\n// Getter funtions\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
for (const PICodeParser::Entity * e: parser.entities) {
|
||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||
makeGetterType(ts, e);
|
||||
makeGetterValue(ts, e);
|
||||
@@ -460,19 +460,19 @@ bool writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
}
|
||||
if (meta) {
|
||||
ts << "\n\n// Classes\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
for (const PICodeParser::Entity * e: parser.entities) {
|
||||
if (e->name.startsWith("_PI")) continue;
|
||||
makeClassInfo(ts, e);
|
||||
}
|
||||
}
|
||||
if (enums) {
|
||||
ts << "\n// Enums\n";
|
||||
piForeachC (PICodeParser::Enum & e, parser.enums)
|
||||
for (const PICodeParser::Enum & e: parser.enums)
|
||||
makeEnumInfo(ts, &e);
|
||||
}
|
||||
if (getters) {
|
||||
ts << "\n// Getters\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
for (const PICodeParser::Entity * e: parser.entities) {
|
||||
if (!needClassStream(e)) continue;
|
||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||
ts << "\t(*accessValueFunctions)[\"" << e->name << "\"] = getterValue" << toCName(e->name) << ";\n";
|
||||
@@ -494,7 +494,7 @@ bool writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
}
|
||||
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())
|
||||
for (const PIString & _a: cli.rawArguments())
|
||||
ts << "// \"" << _a << "\"\n";
|
||||
ts << "\n";
|
||||
ts << "#ifndef " << defname << "\n#define " << defname << "\n\n";
|
||||
@@ -504,8 +504,9 @@ bool writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
ts << inc_string << "\n";
|
||||
if (streams) {
|
||||
ts << "\n\n// Stream operators\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||
for (const PICodeParser::Entity * e: parser.entities) {
|
||||
if (!e->has_name || e->name.startsWith("_PI") ||
|
||||
!(e->visibility == PICodeParser::Global || e->visibility == PICodeParser::Public)) continue;
|
||||
makeClassStream(ts, e);
|
||||
}
|
||||
}
|
||||
@@ -547,12 +548,12 @@ int main(int argc, char * argv[]) {
|
||||
return 0;
|
||||
}
|
||||
piDebug = !cli.hasArgument("quiet");
|
||||
piForeachC (PIString & a, cli.rawArguments()) {
|
||||
for (const PIString & a: cli.rawArguments()) {
|
||||
if (a.startsWith("-I")) parser.includeDirectory(a.mid(2));
|
||||
if (a.startsWith("-D")) parser.addDefine(a.mid(2), PIString());
|
||||
}
|
||||
PIStringList files;
|
||||
piForeachC (PIString & a, cli.optionalArguments())
|
||||
for (const PIString & a: cli.optionalArguments())
|
||||
if (!a.startsWith("-")) files << a;
|
||||
piCout << Cyan << Bold << "Parse files" << files << "...";
|
||||
parser.parseFiles(files, !cli.hasArgument("single"));
|
||||
@@ -570,7 +571,7 @@ int main(int argc, char * argv[]) {
|
||||
bool womain = cli.hasArgument("print");
|
||||
piDebug = true;
|
||||
PIStringList pf(parser.parsedFiles());
|
||||
piForeachC (PIString & f, pf) {
|
||||
for (const PIString & f: pf) {
|
||||
if (!womain || (f != parser.mainFile()))
|
||||
piCout << f;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user