diff --git a/CMakeLists.txt b/CMakeLists.txt index a64d3245..6b31f081 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake project(PIP) set(PIP_MAJOR 3) set(PIP_MINOR 13) -set(PIP_REVISION 1) +set(PIP_REVISION 2) set(PIP_SUFFIX ) set(PIP_COMPANY SHS) set(PIP_DOMAIN org.SHS) diff --git a/libs/main/code/picodeparser.cpp b/libs/main/code/picodeparser.cpp index 1318bc39..e36e17e9 100644 --- a/libs/main/code/picodeparser.cpp +++ b/libs/main/code/picodeparser.cpp @@ -323,7 +323,7 @@ void PICodeParser::clear() { << "a2" << "n2" << "a3" - << "n3"); + << "n3"); } @@ -445,6 +445,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) { PIString prev_namespace = cur_namespace, ccmn; cur_namespace += pfc.takeCWord() + s_ns; ccmn = pfc.takeRange('{', '}'); + // piCout << "namespace" << cur_namespace; parseClass(0, ccmn, true); cur_namespace = prev_namespace; continue; @@ -462,12 +463,15 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) { } if (pfc.left(5) == s_class || pfc.left(6) == s_struct || pfc.left(5) == s_union) { int dind = pfc.find('{', 0), find = pfc.find(';', 0); + // piCout << pfc.left(6) << dind << find; if (dind < 0 && find < 0) { pfc.cutLeft(6); continue; } if (dind < 0 || find < dind) { - pfc.cutLeft(6); + // piCout << "skip FC" << (find + 1) << pfc.left(find + 1); + pfc.cutLeft(find + 1); + // pfc.cutLeft(6); continue; } ccmn = pfc.left(dind) + s_bo + pfc.mid(dind).takeRange('{', '}') + s_bc; @@ -557,7 +561,7 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc) bool has_name = !cn.isEmpty(); if (cn.isEmpty()) cn = PIStringAscii("'; // piCout << "found " << typename_ << cn; - if (cn.isEmpty()) return 0; + if (cn.isEmpty()) return nullptr; Entity * e = new Entity(); e->meta = meta; e->name = cur_namespace + cn; @@ -587,10 +591,6 @@ void PICodeParser::parseClass(Entity * parent, PIString & fc, bool is_namespace) Visibility prev_vis = cur_def_vis; int dind = fc.find('{'), find = fc.find(';'), end = 0; 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) { @@ -598,7 +598,6 @@ void PICodeParser::parseClass(Entity * parent, PIString & fc, bool is_namespace) fc.trim().cutLeft(1).cutRight(1).trim(); } // piCout << "found class <****\n" << fc << "\n****>"; - /// if (!ce) return PIString(); if (ce) { if (parent) parent->children << ce; ce->parent_scope = parent; @@ -636,6 +635,7 @@ void PICodeParser::parseClass(Entity * parent, PIString & fc, bool is_namespace) continue; } if (cw == s_class || cw == s_struct || cw == s_union) { + // piCout << cw << isDeclaration(fc, 0, &end); if (isDeclaration(fc, 0, &end)) { fc.cutLeft(end); fc.takeSymbol(); diff --git a/main.cpp b/main.cpp index c06b4200..17cc3dd0 100644 --- a/main.cpp +++ b/main.cpp @@ -1,4 +1,5 @@ #include "pibytearray.h" +#include "picodeparser.h" #include "piiostream.h" #include "pijson.h" #include "pimathbase.h" @@ -7,73 +8,9 @@ using namespace PICoutManipulators; -struct SomeType { - int i; - float f; -}; - -PICout operator<<(PICout c, const SomeType & v) { - c << "SomeType(" << v.i << "," << v.f << ")"; - return c; -} - -REGISTER_VARIANT(SomeType); -REGISTER_VARIANT_CAST(SomeType, PIString) { - return PIString::fromNumber(v.i) + ";" + PIString::fromNumber(v.f); -} -REGISTER_VARIANT_CAST(PIString, SomeType) { - PIStringList sl = v.split(';').resize(2); - return SomeType{sl[0].toInt(), sl[1].toFloat()}; -} -#include "piliterals.h" int main(int argc, char * argv[]) { - /*PIValueTree root; - root.addChild({"bool", PIVariant(false)}); - root.addChild({"integer", PIVariant(256)}); - root.addChild({"string", PIVariant("str")}); - for (auto it: root.children()) { - piCout << it.name() << it.value(); - } - piCout << piSerialize(root);*/ - // PIVariant v = PIVariant::fromType(PIVariant::typeID()); - // piCout << v; - // piCout << v.toString(); - // v.setValueFromString("2E-3"); - // piCout << v.value(); - // piCout << v.toString(); - - // piCout << PITime(); - // piCout << PITime::fromString("05:12:56"); - // piCout << PITime::fromString("05: 12:56"); - // piCout << PITime::fromString("05.12:56"); - // piCout << PITime::fromString("05.12:56:333", "h.m.s"); - // piCout << PIDateTime::fromString(PIDateTime::current().toString("__yyyy_MM_d__hh_mm_ss__"), "__yyyy_MM_d__hh_mm_ss__"); - - /*piCout << PIVariantTypes::Color(); - piCout << PIVariantTypes::Color(0xFF00FFff); - PIVariant v = PIVariant::fromType(PIVariant::typeName()); - piCout << PIVariant::typeName(); - piCout << PIVariant::typeFromName(PIVariant::typeName()); - piCout << PIVariant::typeIDFromName(PIVariant::typeName()); - piCout << PIVariant::typeIDFromType(PIVariant::pivColor); - v.setValueFromString("0xFF00FFff"); - piCout << v;*/ - - // PIVariantTypes::Enum e; - // e.enum_name = "MyEnum"; - // e << PIVariantTypes::Enumerator(10105, "Null") << PIVariantTypes::Enumerator(20, "Sec") << PIVariantTypes::Enumerator(100, "Fir"); - // e.selectValue(20); - - // piCout << e.toString(); - // piCout << PIVariantTypes::Enum::fromString(e.toString()).toString(); - // piCout << PIVariantTypes::Enum::fromString("\"MyEnum\"(\"Null\":10105 \"Sec\":20 \"Fir\":100) 20").toString(); - - { - PIScopeExitCall ec([]() { piCout << "exit"; }); - ec.cancel(); - } - piCout << PIVariantTypes::Enum::fromString("(\"DeformationWithTemperature2\":1\n;Sigma1:2\n;Tau:3)").toString(); - + PICodeParser cp; + cp.parseFile("kmm_types.h", false); return 0; }