23.06.2014 - PICodeParser, PICodeInfo, PIConnection, new binary "pip_cmg"
This commit is contained in:
221
main.cpp
221
main.cpp
@@ -46,90 +46,119 @@ class ElementD: public PIObject {
|
||||
#include "pip.h"
|
||||
#include "pivariant.h"
|
||||
|
||||
/*
|
||||
Test::PIVariant<> * pv;
|
||||
|
||||
|
||||
template <typename T>
|
||||
Test::PIVariant<T> newVariant(const T & v) {return Test::PIVariant<T>(v);}
|
||||
template <typename T>
|
||||
Test::PIVariant<T> * castVariant(Test::__PIVariantBase * v, const T & t) {return static_cast<Test::PIVariant<T> * >(v);}
|
||||
*/
|
||||
|
||||
|
||||
#include "picodeparser.h"
|
||||
#include "pidir.h"
|
||||
#include "piconnection.h"
|
||||
#include <QList>
|
||||
|
||||
#define S(a, b) a#b
|
||||
|
||||
enum TypeFlag {NoFlag, Const = 0x01, Static = 0x02, Mutable = 0x04, Volatile = 0x08, Inline = 0x10, Virtual = 0x20};
|
||||
typedef PIFlags<TypeFlag> TypeFlags;
|
||||
struct TypeInfo {
|
||||
TypeInfo() {flags = 0;}
|
||||
PIString name;
|
||||
PIString type;
|
||||
TypeFlags flags;
|
||||
};
|
||||
struct FunctionInfo {
|
||||
PIString name;
|
||||
TypeInfo return_type;
|
||||
PIVector<TypeInfo> arguments;
|
||||
};
|
||||
struct ClassInfo {
|
||||
PIString name;
|
||||
PIStringList parents;
|
||||
PIVector<TypeInfo> variables;
|
||||
PIVector<FunctionInfo> functions;
|
||||
};
|
||||
inline PICout operator <<(PICout s, const TypeInfo & v) {
|
||||
if (v.flags[Inline]) s << "inline ";
|
||||
if (v.flags[Virtual]) s << "virtual ";
|
||||
if (v.flags[Static]) s << "static ";
|
||||
if (v.flags[Const]) s << "const ";
|
||||
if (v.flags[Mutable]) s << "mutable ";
|
||||
if (v.flags[Volatile]) s << "volatile ";
|
||||
s << v.type;
|
||||
if (!v.name.isEmpty())
|
||||
s << " " << v.name;
|
||||
return s;
|
||||
bool readed(void*, uchar * data, int size) {
|
||||
piCout << Hex << "readed" << PIByteArray(data, size);
|
||||
//piCout << PIString((char*)data, size);
|
||||
return true;
|
||||
}
|
||||
inline PICout operator <<(PICout s, const ClassInfo & v) {
|
||||
s.setControl(0, true);
|
||||
s << "class " << v.name;
|
||||
if (!v.parents.isEmpty()) {
|
||||
s << ": ";
|
||||
bool first = true;
|
||||
piForeachC (PIString & i, v.parents) {
|
||||
if (first) first = false;
|
||||
else s << ", ";
|
||||
s << i;
|
||||
}
|
||||
s << " {\n";
|
||||
piForeachC (FunctionInfo & i, v.functions) {
|
||||
s << Tab << i.return_type << " " << i.name << "(";
|
||||
bool fa = true;
|
||||
piForeachC (TypeInfo & a, i.arguments) {
|
||||
if (fa) fa = false;
|
||||
else s << ", ";
|
||||
s << a;
|
||||
}
|
||||
s << ");\n";
|
||||
}
|
||||
if (!v.functions.isEmpty() && !v.variables.isEmpty())
|
||||
s << "\n";
|
||||
piForeachC (TypeInfo & i, v.variables) {
|
||||
s << Tab << i << ";\n";
|
||||
}
|
||||
s << "}\n";
|
||||
|
||||
class A: public PIObject {
|
||||
PIOBJECT(A)
|
||||
public:
|
||||
EVENT_HANDLER2(void, cr, const PIString &, from, const PIByteArray &, data) {
|
||||
piCout << "A readed" << from << Hex << data;
|
||||
}
|
||||
s.restoreControl();
|
||||
return s;
|
||||
}
|
||||
EVENT_HANDLER2(void, per, uchar *, data, int, size) {
|
||||
piCout << "A readed" << size << ":\"" << PIString((const char *)data, size) << "\"" << NewLine;
|
||||
//piCout << "A readed \"";
|
||||
}
|
||||
};
|
||||
|
||||
class TC: public PIConnection {
|
||||
public:
|
||||
TC() {
|
||||
PIPacketExtractor * pe = addFilter("h&f", addDevice("file://piiodevice.h", PIIODevice::ReadOnly, false), PIPacketExtractor::HeaderAndFooter);
|
||||
pe->setHeader(PIString("//!").toByteArray());
|
||||
pe->setFooter(PIString("\n").toByteArray());
|
||||
pe = addFilter(" h ", "file://piiodevice.h", PIPacketExtractor::Header);
|
||||
addChannel(pe, addDevice("file://out.txt", PIIODevice::WriteOnly));
|
||||
pe->setHeader(PIString("PI").toByteArray());
|
||||
pe->setPayloadSize(3);
|
||||
startAllThreadedReads();
|
||||
}
|
||||
virtual void dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
piCout << "dataReceived" << from << (data.size());
|
||||
}
|
||||
virtual void packetReceived(const PIString & from, const PIByteArray & data) {
|
||||
piCout << "packetReceived" << from << (data.size()) << PIString(data);
|
||||
}
|
||||
virtual bool filterValidatePayload(const PIString & filter_name, uchar * rec, int size) {
|
||||
//piCout << "filterValidatePayload" << filter_name << PIString((char*)rec, size);
|
||||
if (filter_name == " h ") return PIString((char*)rec, size) == "IOD";
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
int main (int argc, char * argv[]) {
|
||||
PIString s("this\t :is \n(SPARTA)!");
|
||||
piCout << s.findCWord("this");
|
||||
piCout << s.findCWord("is");
|
||||
piCout << s.findCWord("SPARTA");
|
||||
piCout << s.findCWord("SPARTA!");
|
||||
/*A a_;
|
||||
PIFile file("piiodevice.h", PIIODevice::ReadOnly);
|
||||
PIByteArray header = PIString("PI").toByteArray();
|
||||
PIByteArray footer = PIString("}").toByteArray();
|
||||
PIPacketExtractor pe(&file);
|
||||
//pe.setPacketData(header.data(), header.size_s(), 10);
|
||||
pe.setSplitMode(PIPacketExtractor::Footer);
|
||||
pe.setHeader(header);
|
||||
pe.setFooter(footer);
|
||||
pe.setPayloadSize(3);
|
||||
pe.setThreadedReadBufferSize(40);
|
||||
//pe.setBufferSize(256);
|
||||
//pe.setPacketData(0, 0, 20);
|
||||
CONNECT2(void, uchar * , int , &pe, packetReceived, &a_, per)
|
||||
pe.startThreadedRead();
|
||||
piMSleep(500);*/
|
||||
|
||||
TC tc;
|
||||
piMSleep(500);
|
||||
piCout << tc.makeConfig();
|
||||
return 0;
|
||||
|
||||
/*tm = PISystemTime::current();
|
||||
for (int i = 0; i < 10000000; ++i) {
|
||||
ql.append(i*10);
|
||||
ql.prepend(i*10 + 1);
|
||||
}
|
||||
piCout << (PISystemTime::current() - tm).toMicroseconds();
|
||||
*/
|
||||
//tm = PISystemTime::current();
|
||||
/*for (int i = 0; i < 100000000; ++i) {
|
||||
pl.append(i*10);
|
||||
pl.prepend(i*10 + 1);
|
||||
}*/
|
||||
//PICodeParser cd_;
|
||||
//cd.includeDirectory("../qpicalculator");
|
||||
//cd_.parseFile("piincludes.h");
|
||||
//piCout << (PISystemTime::current() - tm).toMilliseconds();
|
||||
/*piCout << NewLine;
|
||||
piForeachCA (i, pl)
|
||||
piCout << i;
|
||||
|
||||
pl.remove(1, 2).prepend(111).prepend(222);
|
||||
pl.remove(1, 1);
|
||||
piCout << NewLine;
|
||||
piForeachCA (i, pl)
|
||||
piCout << i;*/
|
||||
/*piCout << NewLine;
|
||||
for (int i = 0; i < pl.size_s(); ++i)
|
||||
piCout << pl[i];
|
||||
*/
|
||||
|
||||
/*PIEthernet eth(PIEthernet::UDP);
|
||||
eth.setReadAddress("192.168.0.30:4001");
|
||||
eth.setSendAddress("192.168.0.50:4001");
|
||||
eth.startThreadedRead(readed);
|
||||
piCout << "Connected";
|
||||
//eth.send(PIString("This is test string!\n").toByteArray());
|
||||
FOREVER_WAIT*/
|
||||
|
||||
if (argc < 2) return 0;
|
||||
PICodeParser cd;
|
||||
//cd.includeDirectory("../qpicalculator");
|
||||
@@ -137,48 +166,6 @@ int main (int argc, char * argv[]) {
|
||||
piForeachC (PICodeParser::Enum & e, cd.enums)
|
||||
piCout << e.name << e.members;
|
||||
|
||||
ClassInfo ci;
|
||||
PICodeParser::Entity * e = cd.findEntityByName("PITimer");
|
||||
if (!e) return 0;
|
||||
ci.name = e->name;
|
||||
piForeachC (PICodeParser::Entity * p, e->parents)
|
||||
ci.parents << p->name;
|
||||
piForeachC (PICodeParser::Member & m, e->members) {
|
||||
TypeInfo ni;
|
||||
ni.name = m.name;
|
||||
ni.type = m.type;
|
||||
if (m.attributes[PICodeParser::Const]) ni.flags |= Const;
|
||||
if (m.attributes[PICodeParser::Static]) ni.flags |= Static;
|
||||
if (m.attributes[PICodeParser::Mutable]) ni.flags |= Mutable;
|
||||
if (m.attributes[PICodeParser::Volatile]) ni.flags |= Volatile;
|
||||
if (m.attributes[PICodeParser::Inline]) ni.flags |= Inline;
|
||||
if (m.attributes[PICodeParser::Virtual]) ni.flags |= Virtual;
|
||||
ci.variables << ni;
|
||||
}
|
||||
piForeachC (PICodeParser::Member & m, e->functions) {
|
||||
FunctionInfo fi;
|
||||
fi.name = m.name;
|
||||
fi.return_type.type = m.type;
|
||||
if (m.attributes[PICodeParser::Const]) fi.return_type.flags |= Const;
|
||||
if (m.attributes[PICodeParser::Static]) fi.return_type.flags |= Static;
|
||||
piForeachC (PIString & a, m.arguments_full) {
|
||||
TypeInfo ni;
|
||||
PIString arg(a);
|
||||
arg.prepend(" ");
|
||||
if (arg.find(" const ") >= 0) {
|
||||
ni.flags |= Const;
|
||||
arg.replaceAll(" const ", " ");
|
||||
}
|
||||
int ts = 0;
|
||||
for (ts = arg.size_s() - 1; ts >= 0; --ts)
|
||||
if (!_isCChar(arg[ts]) && !(arg[ts].isDigit())) break;
|
||||
ni.name = arg.takeRight(arg.size_s() - ts - 1).trim();
|
||||
ni.type = arg.trim();
|
||||
fi.arguments << ni;
|
||||
}
|
||||
ci.functions << fi;
|
||||
}
|
||||
piCout << NewLine << ci;
|
||||
|
||||
//piCout << v.toType<float>();
|
||||
//piCout << v.toType<float>().toType<PIString>();
|
||||
|
||||
Reference in New Issue
Block a user