PICodeParser entities visibility, check pip_cmg stream operators for public and global visibility
This commit is contained in:
@@ -311,6 +311,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
|||||||
|
|
||||||
//piCout << PICoutManipulators::NewLine << "file" << cur_file << pfc;
|
//piCout << PICoutManipulators::NewLine << "file" << cur_file << pfc;
|
||||||
int pl = -1;
|
int pl = -1;
|
||||||
|
cur_def_vis = Global;
|
||||||
while (!pfc.isEmpty()) {
|
while (!pfc.isEmpty()) {
|
||||||
pfc.trim();
|
pfc.trim();
|
||||||
int nl = pfc.size_s();
|
int nl = pfc.size_s();
|
||||||
@@ -407,6 +408,7 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc)
|
|||||||
}
|
}
|
||||||
PIString typename_ = cd.left(6).trim();
|
PIString typename_ = cd.left(6).trim();
|
||||||
bool is_class = typename_ == s_class;
|
bool is_class = typename_ == s_class;
|
||||||
|
Visibility vis = cur_def_vis;
|
||||||
cur_def_vis = (is_class ? Private : Public);
|
cur_def_vis = (is_class ? Private : Public);
|
||||||
PIString cn = cd.mid(6).trim();
|
PIString cn = cd.mid(6).trim();
|
||||||
bool has_name = !cn.isEmpty();
|
bool has_name = !cn.isEmpty();
|
||||||
@@ -419,6 +421,7 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc)
|
|||||||
e->type = typename_;
|
e->type = typename_;
|
||||||
e->has_name = has_name;
|
e->has_name = has_name;
|
||||||
e->parents = parents;
|
e->parents = parents;
|
||||||
|
e->visibility = vis;
|
||||||
e->file = cur_file;
|
e->file = cur_file;
|
||||||
entities << e;
|
entities << e;
|
||||||
return e;
|
return e;
|
||||||
|
|||||||
@@ -134,10 +134,10 @@ void makeClassInfo(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
|||||||
ts << "\tpci = " << "classesInfo->value(\"" << e->parent_scope->name << "\", 0);\n";
|
ts << "\tpci = " << "classesInfo->value(\"" << e->parent_scope->name << "\", 0);\n";
|
||||||
ts << "\tif (pci) pci->children_info << ci;\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";
|
ts << "\tci->parents << \"" << p->name << "\";\n";
|
||||||
if (!e->members.isEmpty()) ts << "\n\tTypeInfo ti;\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 << "\"";
|
ts << "\tti = TypeInfo(\"" << m.name << "\", \"" << m.type << "\"";
|
||||||
if (m.attributes != 0) {
|
if (m.attributes != 0) {
|
||||||
bool fir = true;
|
bool fir = true;
|
||||||
@@ -163,7 +163,7 @@ void makeClassInfo(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
|||||||
}
|
}
|
||||||
PIString arg;
|
PIString arg;
|
||||||
bool has_fi = false;
|
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 (e->name.findCWord(m.name) >= 0) continue;
|
||||||
if (!has_fi)
|
if (!has_fi)
|
||||||
ts << "\n\tFunctionInfo * fi;\n";
|
ts << "\n\tFunctionInfo * fi;\n";
|
||||||
@@ -179,7 +179,7 @@ void makeClassInfo(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
|||||||
}
|
}
|
||||||
ts << ");\n";
|
ts << ");\n";
|
||||||
//piCout << "write func" << m.name;
|
//piCout << "write func" << m.name;
|
||||||
piForeachC (PIString & a, m.arguments_full) {
|
for (const PIString & a: m.arguments_full) {
|
||||||
//piCout << "write arg" << a;
|
//piCout << "write arg" << a;
|
||||||
ts << "\tfi->arguments << TypeInfo(";
|
ts << "\tfi->arguments << TypeInfo(";
|
||||||
arg = a;
|
arg = a;
|
||||||
@@ -220,7 +220,7 @@ void makeEnumInfo(PIIOTextStream & ts, const PICodeParser::Enum * e) {
|
|||||||
ts << "\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) {
|
for (const PICodeParser::EnumeratorInfo & m: e->members) {
|
||||||
ts << "\tei->members << PICodeInfo::EnumeratorInfo(\"" << m.name << "\", " << m.value << ");\n";
|
ts << "\tei->members << PICodeInfo::EnumeratorInfo(\"" << m.name << "\", " << m.value << ");\n";
|
||||||
if (!m.meta.isEmpty()) {
|
if (!m.meta.isEmpty()) {
|
||||||
auto i = m.meta.makeIterator();
|
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) {
|
void writeClassStreamMembersOut(PIIOTextStream & ts, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||||
PIVector<PICodeParser::Member> ml;
|
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;
|
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||||
ml << m;
|
ml << m;
|
||||||
}
|
}
|
||||||
bool is_union = e->type == "union";
|
bool is_union = e->type == "union";
|
||||||
piForeachC (PICodeParser::Member & m, ml) {
|
for (const PICodeParser::Member & m: ml) {
|
||||||
if (is_union && m.isBitfield())
|
if (is_union && m.isBitfield())
|
||||||
continue;
|
continue;
|
||||||
if (m.meta.value("id") == "-") continue;
|
if (m.meta.value("id") == "-") continue;
|
||||||
@@ -276,7 +276,7 @@ void writeClassStreamMembersOut(PIIOTextStream & ts, const PICodeParser::Entity
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (is_union) return;
|
if (is_union) return;
|
||||||
piForeachC (PICodeParser::Entity * ce, e->children) {
|
for (const PICodeParser::Entity * ce: e->children) {
|
||||||
if (ce->has_name) continue;
|
if (ce->has_name) continue;
|
||||||
writeClassStreamMembersOut(ts, ce, cnt, simple);
|
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) {
|
void writeClassStreamMembersIn(PIIOTextStream & ts, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||||
PIVector<PICodeParser::Member> ml;
|
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;
|
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||||
ml << m;
|
ml << m;
|
||||||
}
|
}
|
||||||
bool is_union = e->type == "union";
|
bool is_union = e->type == "union";
|
||||||
piForeachC (PICodeParser::Member & m, ml) {
|
for (const PICodeParser::Member & m: ml) {
|
||||||
if (is_union && m.isBitfield())
|
if (is_union && m.isBitfield())
|
||||||
continue;
|
continue;
|
||||||
if (m.meta.value("id") == "-") continue;
|
if (m.meta.value("id") == "-") continue;
|
||||||
@@ -340,7 +340,7 @@ void writeClassStreamMembersIn(PIIOTextStream & ts, const PICodeParser::Entity *
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (is_union) return;
|
if (is_union) return;
|
||||||
piForeachC (PICodeParser::Entity * ce, e->children) {
|
for (const PICodeParser::Entity * ce: e->children) {
|
||||||
if (ce->has_name) continue;
|
if (ce->has_name) continue;
|
||||||
writeClassStreamMembersIn(ts, ce, cnt, simple);
|
writeClassStreamMembersIn(ts, ce, cnt, simple);
|
||||||
}
|
}
|
||||||
@@ -349,7 +349,7 @@ void writeClassStreamMembersIn(PIIOTextStream & ts, const PICodeParser::Entity *
|
|||||||
|
|
||||||
bool needClassStream(const PICodeParser::Entity * e) {
|
bool needClassStream(const PICodeParser::Entity * e) {
|
||||||
if (e->meta.contains("no-stream")) return false;
|
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))
|
if (m.is_type_ptr || m.isBitfield() || !m.dims.isEmpty() || (m.visibility != PICodeParser::Public))
|
||||||
continue;
|
continue;
|
||||||
if (m.meta.value("id") == "-") continue;
|
if (m.meta.value("id") == "-") continue;
|
||||||
@@ -390,7 +390,7 @@ void makeGetterType(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
|||||||
if (!needClassStream(e)) return;
|
if (!needClassStream(e)) return;
|
||||||
ts << "\nconst char * getterType" << toCName(e->name) << "(const char * name) {\n";
|
ts << "\nconst char * getterType" << toCName(e->name) << "(const char * name) {\n";
|
||||||
ts << "\tif (!name) return \"\";\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))
|
if (m.is_type_ptr || m.isBitfield() || !m.dims.isEmpty() || (m.visibility != PICodeParser::Public))
|
||||||
continue;
|
continue;
|
||||||
ts << "\tif (strcmp(name, \"" << m.name << "\") == 0) return \"" << m.type << "\";\n";
|
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 << "\tPIByteArray ret;\n";
|
||||||
ts << "\tif (!p || !name) return ret;\n";
|
ts << "\tif (!p || !name) return ret;\n";
|
||||||
ts << "\t" << e->name << " * o = (" << e->name << "*)p;\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))
|
if (m.is_type_ptr || m.isBitfield() || !m.dims.isEmpty() || (m.visibility != PICodeParser::Public))
|
||||||
continue;
|
continue;
|
||||||
ts << "\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";
|
||||||
@@ -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) {
|
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";
|
PIString defname = "CCM_" + PIString::fromNumber(out.hash()) + "_H";
|
||||||
PISet<PIString> inc_files;
|
PISet<PIString> inc_files;
|
||||||
piForeachC (PICodeParser::Entity * e, parser.entities)
|
for (const PICodeParser::Entity * e: parser.entities)
|
||||||
if (!e->name.startsWith("_PI"))
|
if (!e->name.startsWith("_PI"))
|
||||||
inc_files << e->file;
|
inc_files << e->file;
|
||||||
PIString inc_string;
|
PIString inc_string;
|
||||||
PIVector<PIString> incf = inc_files.toVector();
|
PIVector<PIString> incf = inc_files.toVector();
|
||||||
piForeachC (PIString & i, incf) {
|
for (const PIString & i: incf) {
|
||||||
if ((i != parser.mainFile()) && (streams || texts || getters))
|
if ((i != parser.mainFile()) && (streams || texts || getters))
|
||||||
inc_string += "\n#include \"" + i + "\"";
|
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 (meta || enums || getters) {
|
||||||
if (getters) {
|
if (getters) {
|
||||||
ts << "\n\n// Getter funtions\n";
|
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;
|
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||||
makeGetterType(ts, e);
|
makeGetterType(ts, e);
|
||||||
makeGetterValue(ts, e);
|
makeGetterValue(ts, e);
|
||||||
@@ -460,19 +460,19 @@ bool writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
|||||||
}
|
}
|
||||||
if (meta) {
|
if (meta) {
|
||||||
ts << "\n\n// Classes\n";
|
ts << "\n\n// Classes\n";
|
||||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
for (const PICodeParser::Entity * e: parser.entities) {
|
||||||
if (e->name.startsWith("_PI")) continue;
|
if (e->name.startsWith("_PI")) continue;
|
||||||
makeClassInfo(ts, e);
|
makeClassInfo(ts, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (enums) {
|
if (enums) {
|
||||||
ts << "\n// Enums\n";
|
ts << "\n// Enums\n";
|
||||||
piForeachC (PICodeParser::Enum & e, parser.enums)
|
for (const PICodeParser::Enum & e: parser.enums)
|
||||||
makeEnumInfo(ts, &e);
|
makeEnumInfo(ts, &e);
|
||||||
}
|
}
|
||||||
if (getters) {
|
if (getters) {
|
||||||
ts << "\n// Getters\n";
|
ts << "\n// Getters\n";
|
||||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
for (const PICodeParser::Entity * e: parser.entities) {
|
||||||
if (!needClassStream(e)) continue;
|
if (!needClassStream(e)) continue;
|
||||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||||
ts << "\t(*accessValueFunctions)[\"" << e->name << "\"] = getterValue" << toCName(e->name) << ";\n";
|
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 << "// Generated by \"PIP Code model generator\" " << PIDateTime::current().toString("dd.MM.yyyy hh:mm:ss\n");
|
||||||
ts << "// Execute command:\n";
|
ts << "// Execute command:\n";
|
||||||
piForeachC (PIString & _a, cli.rawArguments())
|
for (const PIString & _a: cli.rawArguments())
|
||||||
ts << "// \"" << _a << "\"\n";
|
ts << "// \"" << _a << "\"\n";
|
||||||
ts << "\n";
|
ts << "\n";
|
||||||
ts << "#ifndef " << defname << "\n#define " << defname << "\n\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";
|
ts << inc_string << "\n";
|
||||||
if (streams) {
|
if (streams) {
|
||||||
ts << "\n\n// Stream operators\n";
|
ts << "\n\n// Stream operators\n";
|
||||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
for (const PICodeParser::Entity * e: parser.entities) {
|
||||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
if (!e->has_name || e->name.startsWith("_PI") ||
|
||||||
|
!(e->visibility == PICodeParser::Global || e->visibility == PICodeParser::Public)) continue;
|
||||||
makeClassStream(ts, e);
|
makeClassStream(ts, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -547,12 +548,12 @@ int main(int argc, char * argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
piDebug = !cli.hasArgument("quiet");
|
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("-I")) parser.includeDirectory(a.mid(2));
|
||||||
if (a.startsWith("-D")) parser.addDefine(a.mid(2), PIString());
|
if (a.startsWith("-D")) parser.addDefine(a.mid(2), PIString());
|
||||||
}
|
}
|
||||||
PIStringList files;
|
PIStringList files;
|
||||||
piForeachC (PIString & a, cli.optionalArguments())
|
for (const PIString & a: cli.optionalArguments())
|
||||||
if (!a.startsWith("-")) files << a;
|
if (!a.startsWith("-")) files << a;
|
||||||
piCout << Cyan << Bold << "Parse files" << files << "...";
|
piCout << Cyan << Bold << "Parse files" << files << "...";
|
||||||
parser.parseFiles(files, !cli.hasArgument("single"));
|
parser.parseFiles(files, !cli.hasArgument("single"));
|
||||||
@@ -570,7 +571,7 @@ int main(int argc, char * argv[]) {
|
|||||||
bool womain = cli.hasArgument("print");
|
bool womain = cli.hasArgument("print");
|
||||||
piDebug = true;
|
piDebug = true;
|
||||||
PIStringList pf(parser.parsedFiles());
|
PIStringList pf(parser.parsedFiles());
|
||||||
piForeachC (PIString & f, pf) {
|
for (const PIString & f: pf) {
|
||||||
if (!womain || (f != parser.mainFile()))
|
if (!womain || (f != parser.mainFile()))
|
||||||
piCout << f;
|
piCout << f;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user