finish codeparser improvements
pip_cmg now works with new nested entities approach Getters now can access to bitfields
This commit is contained in:
@@ -22,7 +22,8 @@
|
||||
#include "pitranslator.h"
|
||||
|
||||
|
||||
bool writeClassStreamMembersOut(Runtime & rt, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||
bool writeClassStreamMembersOut(Runtime & rt, const PICodeParser::Entity * e, int & cnt, bool simple, PIString var_prefix) {
|
||||
if (var_prefix.isNotEmpty() && !var_prefix.endsWith('.')) var_prefix += ".";
|
||||
PIVector<PICodeParser::Member> ml;
|
||||
for (const PICodeParser::Member & m: e->members) {
|
||||
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||
@@ -31,9 +32,16 @@ bool writeClassStreamMembersOut(Runtime & rt, const PICodeParser::Entity * e, in
|
||||
bool is_union = e->type == "union";
|
||||
PISet<int> used_id;
|
||||
for (const PICodeParser::Member & m: ml) {
|
||||
if (is_union && m.isBitfield()) continue;
|
||||
if (m.isBitfield()) continue;
|
||||
if (m.attributes[PICodeParser::Static]) continue;
|
||||
if (m.meta.value("id") == "-") continue;
|
||||
auto type = findEntity(rt, m.type);
|
||||
if (type) {
|
||||
if (type->is_anonymous) {
|
||||
if (!writeClassStreamMembersOut(rt, type, cnt, simple, var_prefix + m.name)) return false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
++cnt;
|
||||
if (m.meta.contains("id")) cnt = m.meta.value("id").toInt();
|
||||
if (used_id[cnt]) {
|
||||
@@ -44,11 +52,11 @@ bool writeClassStreamMembersOut(Runtime & rt, const PICodeParser::Entity * e, in
|
||||
if (simple) {
|
||||
rt.ts << "\ts << ";
|
||||
if (rt.parser.isEnum(m.type)) rt.ts << "(int)";
|
||||
rt.ts << "v." << m.name << ";\n";
|
||||
rt.ts << "v." << var_prefix << m.name << ";\n";
|
||||
} else {
|
||||
rt.ts << "\tcs.add(" << cnt << ", ";
|
||||
if (rt.parser.isEnum(m.type)) rt.ts << "(int)";
|
||||
rt.ts << "v." << m.name << ");\n";
|
||||
rt.ts << "v." << var_prefix << m.name << ");\n";
|
||||
}
|
||||
} else {
|
||||
PIString ptype = m.type.left(m.type.find('[')).trim();
|
||||
@@ -59,24 +67,22 @@ bool writeClassStreamMembersOut(Runtime & rt, const PICodeParser::Entity * e, in
|
||||
}
|
||||
if (simple) {
|
||||
rt.ts << "\tfor (int i = 0; i < " << size << "; ++i)\n";
|
||||
rt.ts << "\t\ts << ((const " << ptype << " *)(v." << m.name << "))[i];\n";
|
||||
rt.ts << "\t\ts << ((const " << ptype << " *)(" << "v." << var_prefix << m.name << "))[i];\n";
|
||||
} else {
|
||||
rt.ts << "\tcs << cs.chunk(" << cnt << ", PIVector<" << ptype << " >((const " << ptype << " *)(v." << m.name << "), ";
|
||||
rt.ts << "\tcs << cs.chunk(" << cnt << ", PIVector<" << ptype << " >((const " << ptype << " *)(" << "v." << var_prefix
|
||||
<< m.name << "), ";
|
||||
rt.ts << size << "));\n";
|
||||
}
|
||||
}
|
||||
if (is_union) break;
|
||||
}
|
||||
if (is_union) return true;
|
||||
for (const PICodeParser::Entity * ce: e->children) {
|
||||
if (ce->has_name) continue;
|
||||
if (!writeClassStreamMembersOut(rt, ce, cnt, simple)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool writeClassStreamMembersIn(Runtime & rt, const PICodeParser::Entity * e, int & cnt, bool simple) {
|
||||
bool writeClassStreamMembersIn(Runtime & rt, const PICodeParser::Entity * e, int & cnt, bool simple, PIString var_prefix) {
|
||||
if (var_prefix.isNotEmpty() && !var_prefix.endsWith('.')) var_prefix += ".";
|
||||
PIVector<PICodeParser::Member> ml;
|
||||
for (const PICodeParser::Member & m: e->members) {
|
||||
if (m.is_type_ptr || (m.visibility != PICodeParser::Public)) continue;
|
||||
@@ -85,9 +91,16 @@ bool writeClassStreamMembersIn(Runtime & rt, const PICodeParser::Entity * e, int
|
||||
bool is_union = e->type == "union";
|
||||
PISet<int> used_id;
|
||||
for (const PICodeParser::Member & m: ml) {
|
||||
if (is_union && m.isBitfield()) continue;
|
||||
if (m.isBitfield()) continue;
|
||||
if (m.attributes[PICodeParser::Static]) continue;
|
||||
if (m.meta.value("id") == "-") continue;
|
||||
auto type = findEntity(rt, m.type);
|
||||
if (type) {
|
||||
if (type->is_anonymous) {
|
||||
if (!writeClassStreamMembersIn(rt, type, cnt, simple, var_prefix + m.name)) return false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
++cnt;
|
||||
if (m.meta.contains("id")) cnt = m.meta.value("id").toInt();
|
||||
if (used_id[cnt]) {
|
||||
@@ -104,8 +117,8 @@ bool writeClassStreamMembersIn(Runtime & rt, const PICodeParser::Entity * e, int
|
||||
if (is_enum)
|
||||
rt.ts << "i;";
|
||||
else
|
||||
rt.ts << "v." << m.name << ";";
|
||||
if (is_enum) rt.ts << " v." << m.name << " = (" << m.type << ")i;}";
|
||||
rt.ts << "v." << var_prefix << m.name << ";";
|
||||
if (is_enum) rt.ts << " v. << var_prefix" << m.name << " = (" << m.type << ")i;}";
|
||||
rt.ts << "\n";
|
||||
} else {
|
||||
rt.ts << "\t\tcase " << cnt << ":";
|
||||
@@ -114,9 +127,9 @@ bool writeClassStreamMembersIn(Runtime & rt, const PICodeParser::Entity * e, int
|
||||
if (is_enum)
|
||||
rt.ts << "i";
|
||||
else
|
||||
rt.ts << "v." << m.name;
|
||||
rt.ts << "v." << var_prefix << m.name;
|
||||
rt.ts << ");";
|
||||
if (is_enum) rt.ts << " v." << m.name << " = (" << m.type << ")i;}";
|
||||
if (is_enum) rt.ts << " v." << var_prefix << m.name << " = (" << m.type << ")i;}";
|
||||
rt.ts << " break;\n";
|
||||
}
|
||||
} else {
|
||||
@@ -128,12 +141,12 @@ bool writeClassStreamMembersIn(Runtime & rt, const PICodeParser::Entity * e, int
|
||||
}
|
||||
if (simple) {
|
||||
rt.ts << "\tfor (int i = 0; i < " << size << "; ++i)\n";
|
||||
rt.ts << "\t\ts >> ((" << ptype << " *)(v." << m.name << "))[i];\n";
|
||||
rt.ts << "\t\ts >> ((" << ptype << " *)(" << "v." << var_prefix << m.name << "))[i];\n";
|
||||
} else {
|
||||
rt.ts << "\t\tcase " << cnt << ": {\n\t\t\tPIVector<" << ptype << " > d; cs.get(d);\n";
|
||||
rt.ts << "\t\t\tint cnt = piMini(d.size_s(), " << size << ");\n";
|
||||
rt.ts << "\t\t\tfor (int i = 0; i < cnt; ++i)\n";
|
||||
rt.ts << "\t\t\t\t((" << ptype << " *)(v." << m.name << "))[i] = d[i];\n";
|
||||
rt.ts << "\t\t\t\t((" << ptype << " *)(" << "v." << var_prefix << m.name << "))[i] = d[i];\n";
|
||||
rt.ts << "\t\t\t}\n";
|
||||
rt.ts << "\t\t\tbreak;\n";
|
||||
}
|
||||
@@ -141,10 +154,6 @@ bool writeClassStreamMembersIn(Runtime & rt, const PICodeParser::Entity * e, int
|
||||
if (is_union) break;
|
||||
}
|
||||
if (is_union) return true;
|
||||
for (const PICodeParser::Entity * ce: e->children) {
|
||||
if (ce->has_name) continue;
|
||||
if (!writeClassStreamMembersIn(rt, ce, cnt, simple)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user