git-svn-id: svn://db.shs.com.ru/pip@587 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -30,7 +30,7 @@ if(NOT PIP_VERSION)
|
||||
set(PIP_VERSION ${_VERSION} CACHE STRING "VERSION")
|
||||
if (NOT _PIP_MSG)
|
||||
set(_PIP_MSG 1 CACHE BOOL "msg_pip" FORCE)
|
||||
message(STATUS "Found PIP version ${PIP_VERSION}")
|
||||
message(STATUS "Found PIP version ${PIP_VERSION} (${PIP_LIBRARY})")
|
||||
endif()
|
||||
endif()
|
||||
if(PIP_FIND_VERSION VERSION_GREATER PIP_VERSION)
|
||||
|
||||
27
main.cpp
27
main.cpp
@@ -1,31 +1,10 @@
|
||||
#include "pip.h"
|
||||
#include "pispi.h"
|
||||
#include "picodeparser.h"
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
PICLI cli(argc, argv);
|
||||
cli.setOptionalArgumentsCount(2);
|
||||
cli.addArgument("dev", true);
|
||||
cli.addArgument("speed", true);
|
||||
cli.addArgument("write", true);
|
||||
if (!cli.hasArgument("dev")) {
|
||||
piCout << "no device";
|
||||
return 0;
|
||||
}
|
||||
PIString path = cli.argumentValue("dev");
|
||||
PISPI spi(path, 1000000);
|
||||
piCout << "SPI" << path;
|
||||
//spi.setDebug(true);
|
||||
PIByteArray wba = PIByteArray::fromHex("0000000000000000000000000000000000000000000000000000000000000000");
|
||||
if (cli.hasArgument("speed")) spi.setSpeed(cli.argumentValue("speed").toInt());
|
||||
if (cli.hasArgument("write")) wba = PIByteArray::fromHex(cli.argumentValue("write"));
|
||||
piCout << "try opening..";
|
||||
bool ok = spi.open();
|
||||
piCout << "open" << ok;
|
||||
int r = spi.write(wba);
|
||||
piCout << "write" << r << wba.toHex();
|
||||
PIByteArray ba = spi.readForTime(1);
|
||||
piCout << "read" << ba.toHex();
|
||||
PICodeParser cp;
|
||||
cp.parseFile("cp.h");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ void PICodeParser::parseFiles(const PIStringList & files, bool follow_includes)
|
||||
|
||||
bool PICodeParser::isEnum(const PIString & name) {
|
||||
piForeachC (Enum & e, enums)
|
||||
if (e.name == name)
|
||||
if (e.name == name)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@@ -594,6 +594,11 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
me.is_type_ptr = (me.type.right(1) == "]" || me.type.right(1) == "*");
|
||||
me.type += crepl;
|
||||
me.bits = bits;
|
||||
while (!crepl.isEmpty()) {
|
||||
PIString cdim = crepl.takeRange('[', ']').trim();
|
||||
if (cdim.isEmpty()) break;
|
||||
me.dims << cdim;
|
||||
}
|
||||
//PICout(PICoutManipulators::AddAll) << "var" << me.type << me.name << me.bits;
|
||||
//piCout << "var" << v;
|
||||
parent->members << me;
|
||||
|
||||
@@ -75,6 +75,7 @@ public:
|
||||
PIString name;
|
||||
PIStringList arguments_full;
|
||||
PIStringList arguments_type;
|
||||
PIStringList dims;
|
||||
Visibility visibility;
|
||||
Attributes attributes;
|
||||
bool is_type_ptr;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
using namespace PICoutManipulators;
|
||||
|
||||
PICodeParser parser;
|
||||
|
||||
void usage() {
|
||||
piCout << Bold << "PIP Code model generator";
|
||||
@@ -133,22 +134,98 @@ void makeEnumInfo(PIFile & f, const PICodeParser::Enum * e) {
|
||||
}
|
||||
|
||||
|
||||
void makeClassStream(PIFile & f, const PICodeParser::Entity * e) {
|
||||
PIStringList ml;
|
||||
void writeClassStreamMembersOut(PIFile & f, const PICodeParser::Entity * e, int & cnt) {
|
||||
PIVector<PICodeParser::Member> ml;
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
if (m.is_type_ptr) continue;
|
||||
ml << m.name;
|
||||
ml << m;
|
||||
}
|
||||
if (ml.isEmpty()) return;
|
||||
bool is_union = e->type == "union";
|
||||
piForeachC (PICodeParser::Member & m, ml) {
|
||||
if (is_union && m.isBitfield())
|
||||
continue;
|
||||
++cnt;
|
||||
if (m.dims.isEmpty()) {
|
||||
f << "\tcs << cs.chunk(" << cnt << ", ";
|
||||
if (parser.isEnum(m.type))
|
||||
f << "(int)";
|
||||
f << "v." << m.name << ");\n";
|
||||
} else {
|
||||
PIString ptype = m.type.left(m.type.find('['));
|
||||
f << "\tcs << cs.chunk(" << cnt << ", PIVector<" << ptype << " >((const " << ptype << " *)(v." << m.name << "), ";
|
||||
for (int i = 0; i < m.dims.size_s(); ++i) {
|
||||
if (i > 0) f << " * ";
|
||||
f << m.dims[i];
|
||||
}
|
||||
f << "));\n";
|
||||
}
|
||||
if (is_union)
|
||||
piBreak;
|
||||
}
|
||||
if (is_union) return;
|
||||
piForeachC (PICodeParser::Entity * ce, e->children) {
|
||||
if (ce->has_name) continue;
|
||||
writeClassStreamMembersOut(f, ce, cnt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void writeClassStreamMembersIn(PIFile & f, const PICodeParser::Entity * e, int & cnt) {
|
||||
PIVector<PICodeParser::Member> ml;
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
if (m.is_type_ptr) continue;
|
||||
ml << m;
|
||||
}
|
||||
bool is_union = e->type == "union";
|
||||
piForeachC (PICodeParser::Member & m, ml) {
|
||||
if (is_union && m.isBitfield())
|
||||
continue;
|
||||
++cnt;
|
||||
if (m.dims.isEmpty()) {
|
||||
f << "\t\tcase " << cnt << ": cs.get(";
|
||||
if (parser.isEnum(m.type))
|
||||
f << "(int&)";
|
||||
f << "v." << m.name << "); break;\n";
|
||||
} else {
|
||||
PIString ptype = m.type.left(m.type.find('['));
|
||||
f << "\t\tcase " << cnt << ": {\n\t\t\tPIVector<" << ptype << " > d; cs.get(d);\n";
|
||||
f << "\t\t\tint cnt = piMini(d.size_s(), ";
|
||||
for (int i = 0; i < m.dims.size_s(); ++i) {
|
||||
if (i > 0) f << " * ";
|
||||
f << m.dims[i];
|
||||
}
|
||||
f << ");\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";
|
||||
}
|
||||
if (is_union)
|
||||
piBreak;
|
||||
}
|
||||
if (is_union) return;
|
||||
piForeachC (PICodeParser::Entity * ce, e->children) {
|
||||
if (ce->has_name) continue;
|
||||
writeClassStreamMembersIn(f, ce, cnt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void makeClassStream(PIFile & f, const PICodeParser::Entity * e) {
|
||||
f << "\nPIByteArray & operator <<(PIByteArray & s, const " << e->name << " & v) {\n";
|
||||
f << "\ts";
|
||||
piForeachC (PIString & m, ml)
|
||||
f << " << v." << m << "\n\t";
|
||||
f << ";\n}\nPIByteArray & operator >>(PIByteArray & s, " << e->name << " & v) {\n";
|
||||
f << "\ts";
|
||||
piForeachC (PIString & m, ml)
|
||||
f << " >> v." << m << "\n\t";
|
||||
f << ";\n}\n";
|
||||
f << "\tPIChunkStream cs;\n";
|
||||
int cnt = 0;
|
||||
writeClassStreamMembersOut(f, e, cnt);
|
||||
f << "\ts << cs.data();\n\treturn s;\n}\n";
|
||||
f << "PIByteArray & operator >>(PIByteArray & s, " << e->name << " & v) {\n";
|
||||
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";
|
||||
cnt = 0;
|
||||
writeClassStreamMembersIn(f, e, cnt);
|
||||
f << "\t\t}\n\t}\n";
|
||||
f << "\treturn s;\n}\n";
|
||||
}
|
||||
|
||||
|
||||
@@ -177,15 +254,11 @@ void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
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#include \"" << out << ".h\"\n\nusing namespace PICodeInfo;\n\n";
|
||||
if (streams || texts) {
|
||||
PIVector<PIString> incf = inc_files.toVector();
|
||||
piForeachC (PIString & i, incf) {
|
||||
if (i != parser.mainFile())
|
||||
f << "#include \"" << i << "\"\n";
|
||||
}
|
||||
f << "\n";
|
||||
}
|
||||
f << "#include <string.h>\n";
|
||||
if (streams || texts)
|
||||
f << "#include <pichunkstream.h>\n";
|
||||
f << "#include \"" << out << ".h\"\n";
|
||||
f << "\nusing namespace PICodeInfo;\n\n";
|
||||
/*
|
||||
PIString entry, argtype, rettype, args;
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
@@ -261,7 +334,7 @@ void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
if (streams) {
|
||||
f << "\n\n// Stream operators\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
if (e->name.startsWith("_PI")) continue;
|
||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||
makeClassStream(f, e);
|
||||
}
|
||||
}
|
||||
@@ -279,6 +352,13 @@ void writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
f << "\n";
|
||||
f << "#ifndef " << defname << "\n#define " << defname << "\n\n";
|
||||
f << "#include \"pivariant.h\"\n#include \"picodeinfo.h\"";
|
||||
if (streams || texts) {
|
||||
PIVector<PIString> incf = inc_files.toVector();
|
||||
piForeachC (PIString & i, incf) {
|
||||
if (i != parser.mainFile())
|
||||
f << "\n#include \"" << i << "\"";
|
||||
}
|
||||
}
|
||||
/*
|
||||
f << "\n\n";
|
||||
piForeachC (PICodeParser::Entity * e, ventities)
|
||||
@@ -297,7 +377,7 @@ const PIVariant & arg1 = PIVariant(), const PIVariant & arg2 = PIVariant(), cons
|
||||
if (streams) {
|
||||
f << "\n\n// Stream operators\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
if (e->name.startsWith("_PI")) continue;
|
||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||
makeClassStreamHeader(f, e);
|
||||
}
|
||||
}
|
||||
@@ -326,7 +406,6 @@ int main(int argc, char * argv[]) {
|
||||
return 0;
|
||||
}
|
||||
piDebug = !cli.hasArgument("quiet");
|
||||
PICodeParser parser;
|
||||
piForeachC (PIString & a, cli.rawArguments()) {
|
||||
if (a.startsWith("-I")) parser.includeDirectory(a.mid(2));
|
||||
if (a.startsWith("-D")) parser.addDefine(a.mid(2), PIString());
|
||||
|
||||
Reference in New Issue
Block a user