version 2.92
pip_cmg
This commit is contained in:
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
|
||||
cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
||||
project(pip)
|
||||
set(pip_MAJOR 2)
|
||||
set(pip_MINOR 91)
|
||||
set(pip_MINOR 92)
|
||||
set(pip_REVISION 0)
|
||||
set(pip_SUFFIX )
|
||||
set(pip_COMPANY SHS)
|
||||
|
||||
@@ -321,7 +321,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
PIString prev_namespace = cur_namespace, ccmn;
|
||||
cur_namespace += pfc.takeCWord() + s_ns;
|
||||
ccmn = pfc.takeRange('{', '}');
|
||||
parseClass(0, ccmn);
|
||||
parseClass(0, ccmn, true);
|
||||
cur_namespace = prev_namespace;
|
||||
continue;
|
||||
}
|
||||
@@ -340,7 +340,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
if (dind < 0 || find < dind) {pfc.cutLeft(6); continue;}
|
||||
ccmn = pfc.left(dind) + s_bo + pfc.mid(dind).takeRange('{', '}') + s_bc;
|
||||
pfc.remove(0, ccmn.size());
|
||||
parseClass(0, ccmn);
|
||||
parseClass(0, ccmn, false);
|
||||
continue;
|
||||
}
|
||||
if (pfc.left(4) == s_enum) {
|
||||
@@ -425,7 +425,7 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc)
|
||||
}
|
||||
|
||||
|
||||
PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
||||
void PICodeParser::parseClass(Entity * parent, PIString & fc, bool is_namespace) {
|
||||
static const PIString s_ns = PIStringAscii("::");
|
||||
static const PIString s_public = PIStringAscii("public");
|
||||
static const PIString s_protected = PIStringAscii("protected");
|
||||
@@ -436,22 +436,31 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
||||
static const PIString s_enum = PIStringAscii("enum");
|
||||
static const PIString s_friend = PIStringAscii("friend");
|
||||
static const PIString s_typedef = PIStringAscii("typedef");
|
||||
static const PIString s_namespace = PIStringAscii("namespace");
|
||||
static const PIString s_template = PIStringAscii("template");
|
||||
Visibility prev_vis = cur_def_vis;
|
||||
int dind = fc.find('{'), find = fc.find(';'), end = 0;
|
||||
if (dind < 0 && find < 0) return PIString();
|
||||
if (dind < 0 || find < dind) return fc.left(find);
|
||||
//piCout << "parse class <****\n" << fc.left(20) << "\n****>";
|
||||
Entity * ce = parseClassDeclaration(fc.takeLeft(dind));
|
||||
if (dind < 0 && find < 0) return;
|
||||
if (dind < 0 || find < dind) {
|
||||
fc.left(find);
|
||||
return;
|
||||
}
|
||||
//piCout << "parse class <****\n" << fc << "\n****>";
|
||||
Entity * ce = parent;
|
||||
if (!is_namespace) {
|
||||
ce = parseClassDeclaration(fc.takeLeft(dind));
|
||||
fc.trim().cutLeft(1).cutRight(1).trim();
|
||||
}
|
||||
//piCout << "found class <****\n" << fc << "\n****>";
|
||||
if (!ce) return PIString();
|
||||
///if (!ce) return PIString();
|
||||
if (ce) {
|
||||
if (parent) parent->children << ce;
|
||||
ce->parent_scope = parent;
|
||||
}
|
||||
int ps = -1;
|
||||
bool def = false;
|
||||
PIString prev_namespace = cur_namespace, stmp;
|
||||
cur_namespace += ce->name + s_ns;
|
||||
if (ce) cur_namespace += ce->name + s_ns;
|
||||
//piCout << "parse class" << ce->name << "namespace" << cur_namespace;
|
||||
//piCout << "\nparse class" << ce->name << "namespace" << cur_namespace;
|
||||
while (!fc.isEmpty()) {
|
||||
@@ -460,6 +469,14 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
||||
if (cw == s_public ) {cur_def_vis = Public; fc.cutLeft(1); continue;}
|
||||
if (cw == s_protected) {cur_def_vis = Protected; fc.cutLeft(1); continue;}
|
||||
if (cw == s_private ) {cur_def_vis = Private; fc.cutLeft(1); continue;}
|
||||
if (cw == s_namespace) {
|
||||
PIString prev_namespace = cur_namespace, ccmn;
|
||||
cur_namespace += fc.takeCWord() + s_ns;
|
||||
ccmn = fc.takeRange('{', '}');
|
||||
parseClass(ce, ccmn, true);
|
||||
cur_namespace = prev_namespace;
|
||||
continue;
|
||||
}
|
||||
if (cw == s_class || cw == s_struct || cw == s_union) {
|
||||
if (isDeclaration(fc, 0, &end)) {
|
||||
fc.cutLeft(end);
|
||||
@@ -470,7 +487,7 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
||||
stmp = fc.takeRange('{', '}');
|
||||
fc.takeSymbol();
|
||||
stmp = cw + ' ' + tmp + '{' + stmp + '}';
|
||||
parseClass(ce, stmp);
|
||||
parseClass(ce, stmp, false);
|
||||
continue;
|
||||
}
|
||||
if (cw == s_enum) {
|
||||
@@ -483,11 +500,13 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
||||
}
|
||||
if (cw == s_friend) {fc.cutLeft(fc.find(';') + 1); continue;}
|
||||
if (cw == s_typedef) {
|
||||
if (ce) {
|
||||
ce->typedefs << parseTypedef(fc.takeLeft(fc.find(';')));
|
||||
typedefs << ce->typedefs.back();
|
||||
typedefs.back().first.insert(0, cur_namespace);
|
||||
if (ce->typedefs.back().first.isEmpty())
|
||||
ce->typedefs.pop_back();
|
||||
}
|
||||
fc.takeSymbol();
|
||||
continue;
|
||||
}
|
||||
@@ -501,7 +520,7 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
||||
}
|
||||
def = !isDeclaration(fc, 0, &end);
|
||||
tmp = (cw + fc.takeLeft(end)).trim();
|
||||
if (!tmp.isEmpty())
|
||||
if (!tmp.isEmpty() && ce)
|
||||
parseMember(ce, tmp);
|
||||
if (def) fc.takeRange('{', '}');
|
||||
else fc.takeSymbol();
|
||||
@@ -510,7 +529,6 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
|
||||
}
|
||||
cur_def_vis = prev_vis;
|
||||
cur_namespace = prev_namespace;
|
||||
return ce->name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ private:
|
||||
bool parseFileContent(PIString & fc, bool main);
|
||||
bool parseDirective(PIString d);
|
||||
Entity * parseClassDeclaration(const PIString & fc);
|
||||
PIString parseClass(Entity * parent, PIString & fc);
|
||||
void parseClass(Entity * parent, PIString & fc, bool is_namespace);
|
||||
MetaMap parseMeta(PIString & fc);
|
||||
bool parseEnum(Entity * parent, const PIString & name, PIString fc, const MetaMap & meta);
|
||||
Typedef parseTypedef(PIString fc);
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "pimap.h"
|
||||
#include "pivector2d.h"
|
||||
|
||||
#define PIP_BINARY_STREAM
|
||||
|
||||
#define BINARY_STREAM_FRIEND(T) \
|
||||
template<typename P> friend PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const T & v); \
|
||||
|
||||
@@ -336,12 +336,12 @@ inline bool operator !=(const PISerial::DeviceInfo & v0, const PISerial::DeviceI
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Store operator
|
||||
//! \~russian Оператор сохранения
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PISerial::DeviceInfo & v) {s << v.vID << v.pID << v.path << v.description << v.manufacturer; return s;}
|
||||
BINARY_STREAM_WRITE(PISerial::DeviceInfo) {s << v.vID << v.pID << v.path << v.description << v.manufacturer; return s;}
|
||||
|
||||
//! \relatesalso PIByteArray
|
||||
//! \~english Restore operator
|
||||
//! \~russian Оператор извлечения
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PISerial::DeviceInfo & v) {s >> v.vID >> v.pID >> v.path >> v.description >> v.manufacturer; return s;}
|
||||
BINARY_STREAM_READ (PISerial::DeviceInfo) {s >> v.vID >> v.pID >> v.path >> v.description >> v.manufacturer; return s;}
|
||||
|
||||
|
||||
#endif // PISERIAL_H
|
||||
|
||||
24
main.cpp
24
main.cpp
@@ -3,11 +3,11 @@
|
||||
#include "pitextstream.h"
|
||||
#include "piiostream.h"
|
||||
//#include "stream.h"
|
||||
//#include "ccm.h"
|
||||
//#include "ccm_.h"
|
||||
//#include "pisystemmonitor_.h"
|
||||
|
||||
using namespace PICoutManipulators;
|
||||
|
||||
/*
|
||||
class File: public PIBinaryStream<File> {
|
||||
public:
|
||||
PIFile file;
|
||||
@@ -25,7 +25,9 @@ public:
|
||||
|
||||
|
||||
struct TS {
|
||||
TS(int v0 = -1, float v1 = -1, PIString v2 = "") {i = v0; f = v1;/* s = v2;*/}
|
||||
TS(int v0 = -1, float v1 = -1, PIString v2 = "") {i = v0; f = v1;
|
||||
// s = v2;
|
||||
}
|
||||
int i;
|
||||
float f;
|
||||
//PIString s;
|
||||
@@ -35,8 +37,20 @@ PICout operator << (PICout c, const TS & v) {c << '{' << v.i << ", " << v.f << '
|
||||
template<typename P> inline PIBinaryStream<P> & operator <<(PIBinaryStream<P> & s, const TS & v) {s << v.i; return s;}
|
||||
template<typename P> inline PIBinaryStream<P> & operator >>(PIBinaryStream<P> & s, TS & v) {s >> v.i; return s;}
|
||||
|
||||
*/
|
||||
int main(int argc, char * argv[]) {
|
||||
PIFile f;
|
||||
/*KMM::NS::Project p, p1;
|
||||
p.sms_path = "mypath";
|
||||
p.time_0 = "0.05";
|
||||
p.time_1 = "10e + 3";
|
||||
PIByteArray ba;
|
||||
ba << p;
|
||||
piCout << ba;
|
||||
piCout << p1.sms_path << p1.time_0 << p1.time_1;
|
||||
ba >> p1;
|
||||
piCout << p1.sms_path << p1.time_0 << p1.time_1;*/
|
||||
|
||||
/*PIFile f;
|
||||
f.open("_test.h", PIIODevice::ReadOnly);
|
||||
PIIOTextStream ts(&f);
|
||||
ts.setEncoding(PIIOTextStream::System);
|
||||
@@ -45,7 +59,7 @@ int main(int argc, char * argv[]) {
|
||||
ts >> v;
|
||||
piCout << v;
|
||||
//piCout << ts.takeCWord();
|
||||
}
|
||||
}*/
|
||||
|
||||
/*PIByteArray ba;
|
||||
PIIOByteArray ioba(&ba);
|
||||
|
||||
@@ -42,8 +42,8 @@ const char help_string[] =
|
||||
"\n"
|
||||
"-S (Stream operators)\n"
|
||||
"Generate store/restore operators with format\n"
|
||||
"PIByteArray & operator <<(PIByteArray & s, const <type> & v);\n"
|
||||
"PIByteArray & operator >>(PIByteArray & s, <type> & v);\n"
|
||||
"BINARY_STREAM_WRITE(<type>);\n"
|
||||
"BINARY_STREAM_READ (<type>);\n"
|
||||
"Only public variables used. All variables stored/restored\n"
|
||||
"using PIChunkStream. IDs are variable number, starting from 1.\n"
|
||||
"You can override ID with PIMETA(id=<ID>). If in class or struct\n"
|
||||
@@ -354,7 +354,7 @@ bool needClassStream(const PICodeParser::Entity * e) {
|
||||
void makeClassStream(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
if (!needClassStream(e)) return;
|
||||
bool simple = e->meta.contains("simple-stream");
|
||||
ts << "\nPIByteArray & operator <<(PIByteArray & s, const " << e->name << " & v) {\n";
|
||||
ts << "\nBINARY_STREAM_WRITE(" << e->name << ") {\n";
|
||||
if (!simple)
|
||||
ts << "\tPIChunkStream cs;\n";
|
||||
int cnt = 0;
|
||||
@@ -362,9 +362,9 @@ void makeClassStream(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
if (!simple)
|
||||
ts << "\ts << cs.data();\n";
|
||||
ts << "\treturn s;\n}\n";
|
||||
ts << "PIByteArray & operator >>(PIByteArray & s, " << e->name << " & v) {\n";
|
||||
ts << "BINARY_STREAM_READ (" << e->name << ") {\n";
|
||||
if (!simple) {
|
||||
ts << "\tif (s.size_s() < 4) return s;\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";
|
||||
@@ -378,20 +378,6 @@ void makeClassStream(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
}
|
||||
|
||||
|
||||
void makeClassStreamHeader(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
if (!needClassStream(e)) return;
|
||||
ts << "\n";
|
||||
PIStringList sl = e->name.split("::");
|
||||
for (int i = 0; i < sl.size_s() - 1; ++i)
|
||||
ts << "namespace " << sl[i] << " {";
|
||||
ts << e->type << " " << sl.back() << ";";
|
||||
if (sl.size_s() > 1) ts << PIString('}').repeat(sl.size_s() - 1);
|
||||
|
||||
ts << "\nPIByteArray & operator <<(PIByteArray & s, const " << e->name << " & v);";
|
||||
ts << "\nPIByteArray & operator >>(PIByteArray & s, " << e->name << " & v);\n";
|
||||
}
|
||||
|
||||
|
||||
void makeGetterType(PIIOTextStream & ts, const PICodeParser::Entity * e) {
|
||||
if (!needClassStream(e)) return;
|
||||
ts << "\nconst char * getterType" << toCName(e->name) << "(const char * name) {\n";
|
||||
@@ -424,7 +410,7 @@ bool writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
PIString defname = "CCM_" + PIString::fromNumber(out.hash()) + "_H";
|
||||
PISet<PIString> inc_files;
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities)
|
||||
if (e->name.find("::") < 0 && !e->name.startsWith("_PI"))
|
||||
if (!e->name.startsWith("_PI"))
|
||||
inc_files << e->file;
|
||||
PIString inc_string;
|
||||
PIVector<PIString> incf = inc_files.toVector();
|
||||
@@ -442,11 +428,8 @@ bool writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
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)
|
||||
ts << "#include <pichunkstream.h>\n";
|
||||
ts << "#include \"" << out << ".h\"";
|
||||
ts << inc_string << "\n";
|
||||
ts << "\nusing namespace PICodeInfo;\n\n";
|
||||
ts << "#include \"" << out << ".h\"\n";
|
||||
ts << "\nusing namespace PICodeInfo;\n";
|
||||
|
||||
if (meta || enums || getters) {
|
||||
if (getters) {
|
||||
@@ -491,13 +474,6 @@ bool writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
ts << "}\n";
|
||||
ts << "\n\nbool __ClassInfo_" << defname << "_Initializer__::_inited_ = false;\n";
|
||||
}
|
||||
if (streams) {
|
||||
ts << "\n\n// Stream operators\n";
|
||||
piForeachC (PICodeParser::Entity * e, parser.entities) {
|
||||
if (!e->has_name || e->name.startsWith("_PI")) continue;
|
||||
makeClassStream(ts, e);
|
||||
}
|
||||
}
|
||||
|
||||
f.close();
|
||||
|
||||
@@ -515,11 +491,14 @@ bool writeModel(PICodeParser & parser, PICLI & cli, const PIString out, bool met
|
||||
ts << "\n";
|
||||
ts << "#ifndef " << defname << "\n#define " << defname << "\n\n";
|
||||
ts << "#include <pivariant.h>\n#include <picodeinfo.h>";
|
||||
if (streams || texts)
|
||||
ts << "\n#include <pichunkstream.h>";
|
||||
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;
|
||||
makeClassStreamHeader(ts, e);
|
||||
makeClassStream(ts, e);
|
||||
}
|
||||
}
|
||||
if (meta || enums || getters) {
|
||||
|
||||
Reference in New Issue
Block a user