29.04.2014 - Version 0.4.0_prealpha. PICodeParser, namespace PICodeInfo, new tool "pip_cmg" in dir "code_model_generator". New feature in PIIODevice - "createFromFullPath", all parameters of all I/O devices now works with PIObjects`s properties.
This commit is contained in:
140
main.cpp
140
main.cpp
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Test program
|
||||
Copyright (C) 2013 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2014 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -55,23 +55,147 @@ 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 "picode.h"
|
||||
#include "picodeparser.h"
|
||||
|
||||
#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;
|
||||
}
|
||||
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";
|
||||
}
|
||||
s.restoreControl();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char * argv[]) {
|
||||
//piCout << (S(1,2));
|
||||
//(1,2));
|
||||
//CodeParser cd;
|
||||
//cd.parseFile("test.cpp");
|
||||
PIString s("this\t :is \n(SPARTA)!");
|
||||
piCout << s.findCWord("this");
|
||||
piCout << s.findCWord("is");
|
||||
piCout << s.findCWord("SPARTA");
|
||||
piCout << s.findCWord("SPARTA!");
|
||||
if (argc < 2) return 0;
|
||||
PICodeParser cd;
|
||||
//cd.includeDirectory("../qpicalculator");
|
||||
cd.parseFile(argv[1]);
|
||||
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>();
|
||||
//PIFile::remove("ki");
|
||||
/*PIConfig conf("protocols_commod.conf");
|
||||
piCout << conf.allTree();
|
||||
conf.setValue("rmd.123", 456);*/
|
||||
piCout << PIString("1.1").toFloat();
|
||||
piCout << PIString("1,1").toFloat();
|
||||
|
||||
/*PITimer tm;
|
||||
piCout << tm.debug() << tm.properties();
|
||||
tm.setDebug(false);
|
||||
piCout << tm.debug() << tm.properties();
|
||||
tm.setDebug(true);
|
||||
piCout << tm.debug() << tm.properties();*/
|
||||
|
||||
//PIObject * ser = (PIObject * )PIIODevice::createFromFullPath("file://OM2:38400:7");
|
||||
//piCout << ser << NewLine << ser->properties();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user