code format
This commit is contained in:
@@ -1,26 +1,25 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
C++ code parser
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
PIP - Platform Independent Primitives
|
||||
C++ code parser
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "picodeparser.h"
|
||||
|
||||
|
||||
|
||||
PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const {
|
||||
PIStringList arg_vals;
|
||||
while (!args_.isEmpty()) {
|
||||
@@ -32,29 +31,32 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const {
|
||||
PIString ca;
|
||||
if (bi >= 0 && bi < ci) {
|
||||
ca = args_.left(args_.takeLeft(bi).toInt());
|
||||
ci -= ca.size_s(); bi -= ca.size_s();
|
||||
ci -= ca.size_s();
|
||||
bi -= ca.size_s();
|
||||
ca += '(' + args_.takeRange('(', ')') + ')';
|
||||
} else {
|
||||
ca = args_.takeLeft(ci);
|
||||
}
|
||||
arg_vals << ca;
|
||||
args_.trim(); args_.takeLeft(1); args_.trim();
|
||||
args_.trim();
|
||||
args_.takeLeft(1);
|
||||
args_.trim();
|
||||
}
|
||||
if (args.size() != arg_vals.size()) {
|
||||
piCout << ("Error: in expansion of macro \"" + name + '(' + args.join(", ") + ")\": expect")
|
||||
<< args.size() << "arguments but takes" << arg_vals.size() << "!";
|
||||
piCout << ("Error: in expansion of macro \"" + name + '(' + args.join(", ") + ")\": expect") << args.size() << "arguments but takes"
|
||||
<< arg_vals.size() << "!";
|
||||
if (ok != 0) *ok = false;
|
||||
return PIString();
|
||||
}
|
||||
PIString ret = value;
|
||||
for (int i = 0; i < args.size_s(); ++i) {
|
||||
const PIString & an(args[i]), av(arg_vals[i]);
|
||||
const PIString &an(args[i]), av(arg_vals[i]);
|
||||
int ind(-1);
|
||||
while ((ind = ret.find(an, ind + 1)) >= 0) {
|
||||
PIChar ppc, pc, nc;
|
||||
if (ind > 1) ppc = ret[ind - 2];
|
||||
if (ind > 0) pc = ret[ind - 1];
|
||||
if (ind + an.size_s() < ret.size_s()) nc = ret.mid(ind + an.size_s(),1)[0];
|
||||
if (ind + an.size_s() < ret.size_s()) nc = ret.mid(ind + an.size_s(), 1)[0];
|
||||
if (ppc != '#' && pc == '#' && !_isCChar(nc)) { // to chars
|
||||
ind--;
|
||||
ret.replace(ind, an.size_s() + 1, '\"' + av + '\"');
|
||||
@@ -72,9 +74,8 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const {
|
||||
}
|
||||
|
||||
|
||||
|
||||
PICodeParser::PICodeParser() {
|
||||
macros_iter = 32;
|
||||
macros_iter = 32;
|
||||
with_includes = true;
|
||||
clear();
|
||||
includes << "";
|
||||
@@ -86,62 +87,61 @@ void PICodeParser::parseFile(const PIString & file, bool follow_includes) {
|
||||
parseFileInternal(file, follow_includes);
|
||||
/*piCout << "\n\n";
|
||||
piForeachC (Entity * c, entities) {
|
||||
piCout << "";
|
||||
piCout << c->type << c->name << c->parent_scope << c->parents << c->children << c->meta;
|
||||
if (c->parent_scope)
|
||||
piCout << "parent" << c->parent_scope->name;
|
||||
piCout << "Functions:";
|
||||
piForeachC (Member & m, c->functions)
|
||||
piCout << m.type << m.name << m.meta;
|
||||
piCout << "Members:";
|
||||
piForeachC (Member & m, c->members)
|
||||
piCout << m.type << m.name << m.meta;
|
||||
piCout << "";
|
||||
piCout << c->type << c->name << c->parent_scope << c->parents << c->children << c->meta;
|
||||
if (c->parent_scope)
|
||||
piCout << "parent" << c->parent_scope->name;
|
||||
piCout << "Functions:";
|
||||
piForeachC (Member & m, c->functions)
|
||||
piCout << m.type << m.name << m.meta;
|
||||
piCout << "Members:";
|
||||
piForeachC (Member & m, c->members)
|
||||
piCout << m.type << m.name << m.meta;
|
||||
}
|
||||
piCout << "\n\nDefines:";
|
||||
piForeachC (Define & m, defines)
|
||||
piCout << PIStringAscii("define") << m.first << m.second;
|
||||
piCout << PIStringAscii("define") << m.first << m.second;
|
||||
piCout << "\n\nMacros:";
|
||||
piForeachC (Macro & m, macros)
|
||||
piCout << "Macro:" << m.name << m.args << m.value;
|
||||
piCout << "Macro:" << m.name << m.args << m.value;
|
||||
piCout << "\n\nClasses:";
|
||||
piCout << "\n\nEnums:";
|
||||
piForeachC (Enum & c, enums) {
|
||||
piCout << PIStringAscii("enum") << c.name << c.meta;
|
||||
piForeachC (EnumeratorInfo & e, c.members)
|
||||
piCout << " " << e.name << '=' << e.value << e.meta;
|
||||
piCout << PIStringAscii("enum") << c.name << c.meta;
|
||||
piForeachC (EnumeratorInfo & e, c.members)
|
||||
piCout << " " << e.name << '=' << e.value << e.meta;
|
||||
}
|
||||
piCout << "\n\nTypedefs:";
|
||||
piForeachC (Typedef & c, typedefs)
|
||||
piCout << PIStringAscii("typedef") << c;*/
|
||||
piCout << PIStringAscii("typedef") << c;*/
|
||||
}
|
||||
|
||||
|
||||
void PICodeParser::parseFiles(const PIStringList & files, bool follow_includes) {
|
||||
clear();
|
||||
piForeachC (PIString & f, files)
|
||||
piForeachC(PIString & f, files)
|
||||
parseFileInternal(f, follow_includes);
|
||||
/*piCout << "\n\nDefines:";
|
||||
piForeachC (Define & m, defines)
|
||||
piCout << PIStringAscii("define") << m.first << m.second;
|
||||
piCout << PIStringAscii("define") << m.first << m.second;
|
||||
piCout << "\n\nMacros:";
|
||||
piForeachC (Macro & m, macros)
|
||||
piCout << "Macro:" << m.name << m.args << m.value;
|
||||
piCout << "Macro:" << m.name << m.args << m.value;
|
||||
piCout << "\n\nClasses:";
|
||||
piForeachC (Entity * c, entities)
|
||||
piCout << PIStringAscii("class") << c->name << c->parents;
|
||||
piCout << PIStringAscii("class") << c->name << c->parents;
|
||||
piCout << "\n\nEnums:";
|
||||
piForeachC (Enum & c, enums)
|
||||
piCout << PIStringAscii("enum") << c.name << c.members;
|
||||
piCout << PIStringAscii("enum") << c.name << c.members;
|
||||
piCout << "\n\nTypedefs:";
|
||||
piForeachC (Typedef & c, typedefs)
|
||||
piCout << PIStringAscii("typedef") << c;*/
|
||||
piCout << PIStringAscii("typedef") << c;*/
|
||||
}
|
||||
|
||||
|
||||
bool PICodeParser::isEnum(const PIString & name) {
|
||||
piForeachC (Enum & e, enums)
|
||||
if (e.name == name)
|
||||
return true;
|
||||
piForeachC(Enum & e, enums)
|
||||
if (e.name == name) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -149,19 +149,19 @@ bool PICodeParser::isEnum(const PIString & name) {
|
||||
bool PICodeParser::parseFileInternal(const PIString & file, bool follow_includes) {
|
||||
if (proc_files[file]) return true;
|
||||
with_includes = follow_includes;
|
||||
cur_file = file;
|
||||
cur_file = file;
|
||||
PIFile f(file, PIIODevice::ReadOnly);
|
||||
int ii = 0;
|
||||
while (!f.isOpened() && ii < (includes.size_s() - 1)) {
|
||||
f.setPath(includes[++ii] + '/' + file);
|
||||
//piCout << "try" << f.path();
|
||||
// piCout << "try" << f.path();
|
||||
f.open(PIIODevice::ReadOnly);
|
||||
}
|
||||
if (!f.isOpened()) {
|
||||
piCout << ("Error: can`t open file \"" + file + "\"!");
|
||||
return false;
|
||||
}
|
||||
//piCout << "add" << file;
|
||||
// piCout << "add" << file;
|
||||
proc_files << f.path();
|
||||
PIString fc = PIString::fromUTF8(f.readAll());
|
||||
piCout << "parsing" << f.path() << "...";
|
||||
@@ -174,7 +174,8 @@ bool PICodeParser::parseFileInternal(const PIString & file, bool follow_includes
|
||||
|
||||
|
||||
void PICodeParser::clear() {
|
||||
piForeach (Entity * i, entities) delete i;
|
||||
piForeach(Entity * i, entities)
|
||||
delete i;
|
||||
defines.clear();
|
||||
macros.clear();
|
||||
enums.clear();
|
||||
@@ -184,40 +185,145 @@ void PICodeParser::clear() {
|
||||
cur_namespace.clear();
|
||||
main_file.clear();
|
||||
evaluator.clearCustomVariables();
|
||||
cur_def_vis = Global;
|
||||
anon_num = 0;
|
||||
cur_def_vis = Global;
|
||||
anon_num = 0;
|
||||
PIStringList defs = PIStringAscii(PICODE_DEFINES).split(",");
|
||||
piForeachC (PIString & d, defs)
|
||||
piForeachC(PIString & d, defs)
|
||||
defines << Define(d, "");
|
||||
defines << Define(PIStringAscii("PICODE"), "") << custom_defines;
|
||||
macros << Macro(PIStringAscii("PIOBJECT"), "", PIStringList() << "name")
|
||||
<< Macro(PIStringAscii("PIOBJECT_PARENT"), "", PIStringList() << "parent")
|
||||
<< Macro(PIStringAscii("PIOBJECT_SUBCLASS"), "", PIStringList() << "name" << "parent")
|
||||
<< Macro(PIStringAscii("PIOBJECT_SUBCLASS"),
|
||||
"",
|
||||
PIStringList() << "name"
|
||||
<< "parent")
|
||||
<< Macro(PIStringAscii("PIIODEVICE"), "", PIStringList() << "name")
|
||||
<< Macro(PIStringAscii("NO_COPY_CLASS"), "", PIStringList() << "name")
|
||||
<< Macro(PIStringAscii("PRIVATE_DECLARATION"))
|
||||
<< Macro(PIStringAscii("NO_COPY_CLASS"), "", PIStringList() << "name") << Macro(PIStringAscii("PRIVATE_DECLARATION"))
|
||||
|
||||
<< Macro(PIStringAscii("EVENT" ), "void name();", PIStringList() << "name")
|
||||
<< Macro(PIStringAscii("EVENT"), "void name();", PIStringList() << "name")
|
||||
<< Macro(PIStringAscii("EVENT0"), "void name();", PIStringList() << "name")
|
||||
<< Macro(PIStringAscii("EVENT1"), "void name(a0 n0);", PIStringList() << "name" << "a0" << "n0")
|
||||
<< Macro(PIStringAscii("EVENT2"), "void name(a0 n0, a1 n1);", PIStringList() << "name" << "a0" << "n0" << "a1" << "n1")
|
||||
<< Macro(PIStringAscii("EVENT3"), "void name(a0 n0, a1 n1, a2 n2);", PIStringList() << "name" << "a0" << "n0" << "a1" << "n1" << "a2" << "n2")
|
||||
<< Macro(PIStringAscii("EVENT4"), "void name(a0 n0, a1 n1, a2 n2, a3 n3);", PIStringList() << "name" << "a0" << "n0" << "a1" << "n1" << "a2" << "n2" << "a3" << "n3")
|
||||
<< Macro(PIStringAscii("EVENT1"),
|
||||
"void name(a0 n0);",
|
||||
PIStringList() << "name"
|
||||
<< "a0"
|
||||
<< "n0")
|
||||
<< Macro(PIStringAscii("EVENT2"),
|
||||
"void name(a0 n0, a1 n1);",
|
||||
PIStringList() << "name"
|
||||
<< "a0"
|
||||
<< "n0"
|
||||
<< "a1"
|
||||
<< "n1")
|
||||
<< Macro(PIStringAscii("EVENT3"),
|
||||
"void name(a0 n0, a1 n1, a2 n2);",
|
||||
PIStringList() << "name"
|
||||
<< "a0"
|
||||
<< "n0"
|
||||
<< "a1"
|
||||
<< "n1"
|
||||
<< "a2"
|
||||
<< "n2")
|
||||
<< Macro(PIStringAscii("EVENT4"),
|
||||
"void name(a0 n0, a1 n1, a2 n2, a3 n3);",
|
||||
PIStringList() << "name"
|
||||
<< "a0"
|
||||
<< "n0"
|
||||
<< "a1"
|
||||
<< "n1"
|
||||
<< "a2"
|
||||
<< "n2"
|
||||
<< "a3"
|
||||
<< "n3")
|
||||
|
||||
<< Macro(PIStringAscii("EVENT_HANDLER" ), "ret name()", PIStringList() << "ret" << "name")
|
||||
<< Macro(PIStringAscii("EVENT_HANDLER0"), "ret name()", PIStringList() << "ret" << "name")
|
||||
<< Macro(PIStringAscii("EVENT_HANDLER1"), "ret name(a0 n0)", PIStringList() << "ret" << "name" << "a0" << "n0")
|
||||
<< Macro(PIStringAscii("EVENT_HANDLER2"), "ret name(a0 n0, a1 n1)", PIStringList() << "ret" << "name" << "a0" << "n0" << "a1" << "n1")
|
||||
<< Macro(PIStringAscii("EVENT_HANDLER3"), "ret name(a0 n0, a1 n1, a2 n2)", PIStringList() << "ret" << "name" << "a0" << "n0" << "a1" << "n1" << "a2" << "n2")
|
||||
<< Macro(PIStringAscii("EVENT_HANDLER4"), "ret name(a0 n0, a1 n1, a2 n2, a3 n3)", PIStringList() << "ret" << "name" << "a0" << "n0" << "a1" << "n1" << "a2" << "n2" << "a3" << "n3")
|
||||
<< Macro(PIStringAscii("EVENT_HANDLER"),
|
||||
"ret name()",
|
||||
PIStringList() << "ret"
|
||||
<< "name")
|
||||
<< Macro(PIStringAscii("EVENT_HANDLER0"),
|
||||
"ret name()",
|
||||
PIStringList() << "ret"
|
||||
<< "name")
|
||||
<< Macro(PIStringAscii("EVENT_HANDLER1"),
|
||||
"ret name(a0 n0)",
|
||||
PIStringList() << "ret"
|
||||
<< "name"
|
||||
<< "a0"
|
||||
<< "n0")
|
||||
<< Macro(PIStringAscii("EVENT_HANDLER2"),
|
||||
"ret name(a0 n0, a1 n1)",
|
||||
PIStringList() << "ret"
|
||||
<< "name"
|
||||
<< "a0"
|
||||
<< "n0"
|
||||
<< "a1"
|
||||
<< "n1")
|
||||
<< Macro(PIStringAscii("EVENT_HANDLER3"),
|
||||
"ret name(a0 n0, a1 n1, a2 n2)",
|
||||
PIStringList() << "ret"
|
||||
<< "name"
|
||||
<< "a0"
|
||||
<< "n0"
|
||||
<< "a1"
|
||||
<< "n1"
|
||||
<< "a2"
|
||||
<< "n2")
|
||||
<< Macro(PIStringAscii("EVENT_HANDLER4"),
|
||||
"ret name(a0 n0, a1 n1, a2 n2, a3 n3)",
|
||||
PIStringList() << "ret"
|
||||
<< "name"
|
||||
<< "a0"
|
||||
<< "n0"
|
||||
<< "a1"
|
||||
<< "n1"
|
||||
<< "a2"
|
||||
<< "n2"
|
||||
<< "a3"
|
||||
<< "n3")
|
||||
|
||||
<< Macro(PIStringAscii("EVENT_VHANDLER" ), "virtual ret name()", PIStringList() << "ret" << "name")
|
||||
<< Macro(PIStringAscii("EVENT_VHANDLER0"), "virtual ret name()", PIStringList() << "ret" << "name")
|
||||
<< Macro(PIStringAscii("EVENT_VHANDLER1"), "virtual ret name(a0 n0)", PIStringList() << "ret" << "name" << "a0" << "n0")
|
||||
<< Macro(PIStringAscii("EVENT_VHANDLER2"), "virtual ret name(a0 n0, a1 n1)", PIStringList() << "ret" << "name" << "a0" << "n0" << "a1" << "n1")
|
||||
<< Macro(PIStringAscii("EVENT_VHANDLER3"), "virtual ret name(a0 n0, a1 n1, a2 n2)", PIStringList() << "ret" << "name" << "a0" << "n0" << "a1" << "n1" << "a2" << "n2")
|
||||
<< Macro(PIStringAscii("EVENT_VHANDLER4"), "virtual ret name(a0 n0, a1 n1, a2 n2, a3 n3)", PIStringList() << "ret" << "name" << "a0" << "n0" << "a1" << "n1" << "a2" << "n2" << "a3" << "n3")
|
||||
;
|
||||
<< Macro(PIStringAscii("EVENT_VHANDLER"),
|
||||
"virtual ret name()",
|
||||
PIStringList() << "ret"
|
||||
<< "name")
|
||||
<< Macro(PIStringAscii("EVENT_VHANDLER0"),
|
||||
"virtual ret name()",
|
||||
PIStringList() << "ret"
|
||||
<< "name")
|
||||
<< Macro(PIStringAscii("EVENT_VHANDLER1"),
|
||||
"virtual ret name(a0 n0)",
|
||||
PIStringList() << "ret"
|
||||
<< "name"
|
||||
<< "a0"
|
||||
<< "n0")
|
||||
<< Macro(PIStringAscii("EVENT_VHANDLER2"),
|
||||
"virtual ret name(a0 n0, a1 n1)",
|
||||
PIStringList() << "ret"
|
||||
<< "name"
|
||||
<< "a0"
|
||||
<< "n0"
|
||||
<< "a1"
|
||||
<< "n1")
|
||||
<< Macro(PIStringAscii("EVENT_VHANDLER3"),
|
||||
"virtual ret name(a0 n0, a1 n1, a2 n2)",
|
||||
PIStringList() << "ret"
|
||||
<< "name"
|
||||
<< "a0"
|
||||
<< "n0"
|
||||
<< "a1"
|
||||
<< "n1"
|
||||
<< "a2"
|
||||
<< "n2")
|
||||
<< Macro(PIStringAscii("EVENT_VHANDLER4"),
|
||||
"virtual ret name(a0 n0, a1 n1, a2 n2, a3 n3)",
|
||||
PIStringList() << "ret"
|
||||
<< "name"
|
||||
<< "a0"
|
||||
<< "n0"
|
||||
<< "a1"
|
||||
<< "n1"
|
||||
<< "a2"
|
||||
<< "n2"
|
||||
<< "a3"
|
||||
<< "n3");
|
||||
}
|
||||
|
||||
|
||||
@@ -238,7 +344,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
char c = 0, pc = 0;
|
||||
PIString pfc, line, ccmn, tmp;
|
||||
PIMap<PIString, PIString> cchars;
|
||||
|
||||
|
||||
/// Remove comments, join multiline '*' and replace '*' to $n (cchars)
|
||||
fc.replaceAll("\r\n", '\n');
|
||||
fc.replaceAll('\r', '\n');
|
||||
@@ -247,7 +353,8 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
if (i > 0) pc = c;
|
||||
c = fc[i].toAscii();
|
||||
if (c == '"' && !mlc && pc != '\'') {
|
||||
if (i > 0) if (fc[i - 1] == '\\') continue;
|
||||
if (i > 0)
|
||||
if (fc[i - 1] == '\\') continue;
|
||||
cc = !cc;
|
||||
continue;
|
||||
}
|
||||
@@ -258,46 +365,62 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
continue;
|
||||
}
|
||||
if (cc) continue;
|
||||
if (fc.mid(i, 2) == "/*") {mlc = true; mls = i; ++i; continue;}
|
||||
if (fc.mid(i, 2) == "*/" && mlc) {mlc = false; fc.cutMid(mls, i - mls + 2); i = mls - 1; continue;}
|
||||
if (fc.mid(i, 2) == "//" && !mlc) {ole = fc.find('\n', i); fc.cutMid(i, ole < 0 ? -1 : ole - i); --i; continue;}
|
||||
if (fc.mid(i, 2) == "/*") {
|
||||
mlc = true;
|
||||
mls = i;
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
if (fc.mid(i, 2) == "*/" && mlc) {
|
||||
mlc = false;
|
||||
fc.cutMid(mls, i - mls + 2);
|
||||
i = mls - 1;
|
||||
continue;
|
||||
}
|
||||
if (fc.mid(i, 2) == "//" && !mlc) {
|
||||
ole = fc.find('\n', i);
|
||||
fc.cutMid(i, ole < 0 ? -1 : ole - i);
|
||||
--i;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
pfc = procMacros(fc);
|
||||
|
||||
|
||||
if (main) return true;
|
||||
|
||||
bool replaced = true;
|
||||
|
||||
bool replaced = true;
|
||||
int replaced_cnt = 0;
|
||||
while (replaced) {
|
||||
//piCout << "MACRO iter" << replaced_cnt;
|
||||
// piCout << "MACRO iter" << replaced_cnt;
|
||||
if (replaced_cnt >= macros_iter) {
|
||||
piCout << "Error: recursive macros detected!";
|
||||
break;//return false;
|
||||
break; // return false;
|
||||
}
|
||||
replaced_cnt++;
|
||||
replaced = false;
|
||||
piForeachC (Define & d, defines) {
|
||||
piForeachC(Define & d, defines) {
|
||||
int ind(-1);
|
||||
while ((ind = pfc.find(d.first, ind + 1)) >= 0) {
|
||||
PIChar pc, nc;
|
||||
if (ind > 0) pc = pfc[ind - 1];
|
||||
if (ind + d.first.size_s() < pfc.size_s()) nc = pfc.mid(ind + d.first.size_s(),1)[0];
|
||||
if (ind + d.first.size_s() < pfc.size_s()) nc = pfc.mid(ind + d.first.size_s(), 1)[0];
|
||||
if (_isCChar(pc) || _isCChar(nc) || nc.isDigit()) continue;
|
||||
pfc.replace(ind, d.first.size_s(), d.second);
|
||||
ind -= d.first.size_s() - d.second.size_s();
|
||||
replaced = true;
|
||||
}
|
||||
}
|
||||
piForeachC (Macro & m, macros) {
|
||||
piForeachC(Macro & m, macros) {
|
||||
int ind(-1);
|
||||
while ((ind = pfc.find(m.name, ind + 1)) >= 0) {
|
||||
PIChar pc, nc;
|
||||
if (ind > 0) pc = pfc[ind - 1];
|
||||
if (ind + m.name.size_s() < pfc.size_s()) nc = pfc.mid(ind + m.name.size_s(),1)[0];
|
||||
if (ind + m.name.size_s() < pfc.size_s()) nc = pfc.mid(ind + m.name.size_s(), 1)[0];
|
||||
if (_isCChar(pc) || _isCChar(nc) || nc.isDigit()) continue;
|
||||
PIString ret, range; bool ok(false);
|
||||
PIString ret, range;
|
||||
bool ok(false);
|
||||
range = pfc.mid(ind + m.name.size_s()).takeRange('(', ')');
|
||||
ret = m.expand(range, &ok);
|
||||
ret = m.expand(range, &ok);
|
||||
if (!ok) return false;
|
||||
int rlen = pfc.find(range, ind + m.name.size_s()) + range.size_s() + 1 - ind;
|
||||
pfc.replace(ind, rlen, ret);
|
||||
@@ -308,9 +431,9 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
}
|
||||
|
||||
replaceMeta(pfc);
|
||||
|
||||
//piCout << PICoutManipulators::NewLine << "file" << cur_file << pfc;
|
||||
int pl = -1;
|
||||
|
||||
// piCout << PICoutManipulators::NewLine << "file" << cur_file << pfc;
|
||||
int pl = -1;
|
||||
cur_def_vis = Global;
|
||||
while (!pfc.isEmpty()) {
|
||||
pfc.trim();
|
||||
@@ -331,14 +454,22 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
pfc.takeRange('<', '>');
|
||||
bool def = !isDeclaration(pfc, 0, &end);
|
||||
pfc.cutLeft(end);
|
||||
if (def) pfc.takeRange('{', '}');
|
||||
else pfc.takeSymbol();
|
||||
if (def)
|
||||
pfc.takeRange('{', '}');
|
||||
else
|
||||
pfc.takeSymbol();
|
||||
continue;
|
||||
}
|
||||
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);
|
||||
if (dind < 0 && find < 0) {pfc.cutLeft(6); continue;}
|
||||
if (dind < 0 || find < dind) {pfc.cutLeft(6); continue;}
|
||||
if (dind < 0 && find < 0) {
|
||||
pfc.cutLeft(6);
|
||||
continue;
|
||||
}
|
||||
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, false);
|
||||
@@ -356,8 +487,10 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
if (pfc.left(7) == s_typedef) {
|
||||
pfc.cutLeft(7);
|
||||
typedefs << parseTypedef(pfc.takeLeft(pfc.find(';')));
|
||||
if (typedefs.back().first.isEmpty()) typedefs.pop_back();
|
||||
else root_.typedefs << typedefs.back();
|
||||
if (typedefs.back().first.isEmpty())
|
||||
typedefs.pop_back();
|
||||
else
|
||||
root_.typedefs << typedefs.back();
|
||||
pfc.takeSymbol();
|
||||
continue;
|
||||
}
|
||||
@@ -375,7 +508,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
||||
}
|
||||
parseMember(&root_, str);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -384,45 +517,49 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc)
|
||||
static const PIString s_ss = PIStringAscii(" ");
|
||||
static const PIString s_M = PIStringAscii("$M");
|
||||
static const PIString s_class = PIStringAscii("class");
|
||||
PIString cd = fc.trimmed().removeAll('\n').replaceAll('\t', ' ').replaceAll(s_ss, ' '), pn;
|
||||
PIString cd = fc.trimmed().removeAll('\n').replaceAll('\t', ' ').replaceAll(s_ss, ' '), pn;
|
||||
MetaMap meta;
|
||||
int ind = cd.find(s_M);
|
||||
if (ind >= 0) {
|
||||
meta = tmp_meta.value(cd.takeMid(ind, 5));
|
||||
cd.replaceAll(s_ss, ' ');
|
||||
}
|
||||
//piCout << "found class <****\n" << cd << "\n****>";
|
||||
// piCout << "found class <****\n" << cd << "\n****>";
|
||||
ind = cd.find(':');
|
||||
PIVector<Entity * > parents;
|
||||
PIVector<Entity *> parents;
|
||||
if (ind > 0) {
|
||||
PIStringList pl = cd.takeMid(ind + 1).trim().split(',');
|
||||
cd.cutRight(1);
|
||||
Entity * pe = 0;
|
||||
piForeachC (PIString & p, pl) {
|
||||
if (p.contains(' ')) pn = p.mid(p.find(' ') + 1);
|
||||
else pn = p;
|
||||
piForeachC(PIString & p, pl) {
|
||||
if (p.contains(' '))
|
||||
pn = p.mid(p.find(' ') + 1);
|
||||
else
|
||||
pn = p;
|
||||
pe = findEntityByName(pn);
|
||||
if (pe == 0) ;//{piCout << "Error: can`t find" << pn;}
|
||||
else parents << pe;
|
||||
if (pe == 0)
|
||||
; //{piCout << "Error: can`t find" << pn;}
|
||||
else
|
||||
parents << pe;
|
||||
}
|
||||
}
|
||||
PIString typename_ = cd.left(6).trim();
|
||||
bool is_class = typename_ == s_class;
|
||||
Visibility vis = cur_def_vis;
|
||||
cur_def_vis = (is_class ? Private : Public);
|
||||
PIString cn = cd.mid(6).trim();
|
||||
bool has_name = !cn.isEmpty();
|
||||
bool is_class = typename_ == s_class;
|
||||
Visibility vis = cur_def_vis;
|
||||
cur_def_vis = (is_class ? Private : Public);
|
||||
PIString cn = cd.mid(6).trim();
|
||||
bool has_name = !cn.isEmpty();
|
||||
if (cn.isEmpty()) cn = PIStringAscii("<unnamed_") + PIString::fromNumber(anon_num++) + '>';
|
||||
//piCout << "found " << typename_ << cn;
|
||||
// piCout << "found " << typename_ << cn;
|
||||
if (cn.isEmpty()) return 0;
|
||||
Entity * e = new Entity();
|
||||
e->meta = meta;
|
||||
e->name = cur_namespace + cn;
|
||||
e->type = typename_;
|
||||
e->has_name = has_name;
|
||||
e->parents = parents;
|
||||
Entity * e = new Entity();
|
||||
e->meta = meta;
|
||||
e->name = cur_namespace + cn;
|
||||
e->type = typename_;
|
||||
e->has_name = has_name;
|
||||
e->parents = parents;
|
||||
e->visibility = vis;
|
||||
e->file = cur_file;
|
||||
e->file = cur_file;
|
||||
entities << e;
|
||||
return e;
|
||||
}
|
||||
@@ -441,37 +578,49 @@ void PICodeParser::parseClass(Entity * parent, PIString & fc, bool is_namespace)
|
||||
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;
|
||||
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****>";
|
||||
// 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();
|
||||
// piCout << "found class <****\n" << fc << "\n****>";
|
||||
/// if (!ce) return PIString();
|
||||
if (ce) {
|
||||
if (parent) parent->children << ce;
|
||||
ce->parent_scope = parent;
|
||||
}
|
||||
int ps = -1;
|
||||
bool def = false;
|
||||
int ps = -1;
|
||||
bool def = false;
|
||||
PIString prev_namespace = cur_namespace, stmp;
|
||||
if (ce) cur_namespace += ce->name + s_ns;
|
||||
//piCout << "parse class" << ce->name << "namespace" << cur_namespace;
|
||||
//piCout << "\nparse class" << ce->name << "namespace" << cur_namespace;
|
||||
// piCout << "parse class" << ce->name << "namespace" << cur_namespace;
|
||||
// piCout << "\nparse class" << ce->name << "namespace" << cur_namespace;
|
||||
while (!fc.isEmpty()) {
|
||||
PIString cw = fc.takeCWord(), tmp;
|
||||
//piCout << "\ntaked word" << cw;
|
||||
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;}
|
||||
// piCout << "\ntaked word" << cw;
|
||||
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;
|
||||
@@ -486,10 +635,10 @@ void PICodeParser::parseClass(Entity * parent, PIString & fc, bool is_namespace)
|
||||
fc.takeSymbol();
|
||||
continue;
|
||||
}
|
||||
tmp = fc.takeLeft(fc.find('{'));
|
||||
tmp = fc.takeLeft(fc.find('{'));
|
||||
stmp = fc.takeRange('{', '}');
|
||||
fc.takeSymbol();
|
||||
stmp = cw + ' ' + tmp + '{' + stmp + '}';
|
||||
stmp = cw + ' ' + tmp + '{' + stmp + '}';
|
||||
parseClass(ce, stmp, false);
|
||||
continue;
|
||||
}
|
||||
@@ -501,14 +650,16 @@ void PICodeParser::parseClass(Entity * parent, PIString & fc, bool is_namespace)
|
||||
fc.takeSymbol();
|
||||
continue;
|
||||
}
|
||||
if (cw == s_friend) {fc.cutLeft(fc.find(';') + 1); continue;}
|
||||
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();
|
||||
if (ce->typedefs.back().first.isEmpty()) ce->typedefs.pop_back();
|
||||
}
|
||||
fc.takeSymbol();
|
||||
continue;
|
||||
@@ -517,20 +668,25 @@ void PICodeParser::parseClass(Entity * parent, PIString & fc, bool is_namespace)
|
||||
fc.takeRange('<', '>');
|
||||
def = !isDeclaration(fc, 0, &end);
|
||||
fc.cutLeft(end);
|
||||
if (def) fc.takeRange('{', '}');
|
||||
else fc.takeSymbol();
|
||||
if (def)
|
||||
fc.takeRange('{', '}');
|
||||
else
|
||||
fc.takeSymbol();
|
||||
continue;
|
||||
}
|
||||
def = !isDeclaration(fc, 0, &end);
|
||||
tmp = (cw + fc.takeLeft(end)).trim();
|
||||
if (!tmp.isEmpty() && ce)
|
||||
parseMember(ce, tmp);
|
||||
if (def) fc.takeRange('{', '}');
|
||||
else fc.takeSymbol();
|
||||
if (ps == fc.size_s()) {fc.cutLeft(1);}
|
||||
if (!tmp.isEmpty() && ce) parseMember(ce, tmp);
|
||||
if (def)
|
||||
fc.takeRange('{', '}');
|
||||
else
|
||||
fc.takeSymbol();
|
||||
if (ps == fc.size_s()) {
|
||||
fc.cutLeft(1);
|
||||
}
|
||||
ps = fc.size_s();
|
||||
}
|
||||
cur_def_vis = prev_vis;
|
||||
cur_def_vis = prev_vis;
|
||||
cur_namespace = prev_namespace;
|
||||
}
|
||||
|
||||
@@ -539,7 +695,7 @@ PICodeParser::MetaMap PICodeParser::parseMeta(PIString & fc) {
|
||||
PICodeParser::MetaMap ret;
|
||||
if (fc.isEmpty()) return ret;
|
||||
PIStringList ml = fc.split(',');
|
||||
piForeachC (PIString & m, ml) {
|
||||
piForeachC(PIString & m, ml) {
|
||||
int i = m.find('=');
|
||||
if (i < 0) {
|
||||
ret[m.trimmed()] = PIString();
|
||||
@@ -550,55 +706,61 @@ PICodeParser::MetaMap PICodeParser::parseMeta(PIString & fc) {
|
||||
ret[m.left(i).trim()] = mv;
|
||||
}
|
||||
}
|
||||
//piCout << ms << ret;
|
||||
// piCout << ms << ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool PICodeParser::parseEnum(Entity * parent, const PIString & name, PIString fc, const MetaMap & meta) {
|
||||
static const PIString s_ss = PIStringAscii(" ");
|
||||
static const PIString s_M = PIStringAscii("$M");
|
||||
//piCout << PIStringAscii("enum") << name << fc;
|
||||
static const PIString s_M = PIStringAscii("$M");
|
||||
// piCout << PIStringAscii("enum") << name << fc;
|
||||
Enum e(name);
|
||||
e.meta = meta;
|
||||
PIStringList vl(fc.split(','));
|
||||
PIString vn;
|
||||
int cv = -1, ind = 0;
|
||||
piForeach (PIString & v, vl) {
|
||||
piForeach(PIString & v, vl) {
|
||||
MetaMap meta;
|
||||
int mi = v.find(s_M);
|
||||
if (mi >= 0) {
|
||||
meta = tmp_meta.value(v.takeMid(mi, 5));
|
||||
v.replaceAll(s_ss, ' ');
|
||||
}
|
||||
vn = v; ind = v.find('=');
|
||||
if (ind > 0) {cv = v.right(v.size_s() - ind - 1).toInt(); vn = v.left(ind);}
|
||||
vn = v;
|
||||
ind = v.find('=');
|
||||
if (ind > 0) {
|
||||
cv = v.right(v.size_s() - ind - 1).toInt();
|
||||
vn = v.left(ind);
|
||||
}
|
||||
if (ind < 0) ++cv;
|
||||
e.members << EnumeratorInfo(vn.trim(), cv, meta);
|
||||
}
|
||||
if (!e.members.isEmpty())
|
||||
if (e.members.back().name.isEmpty())
|
||||
e.members.pop_back();
|
||||
if (e.members.back().name.isEmpty()) e.members.pop_back();
|
||||
enums << e;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
PICodeParser::Typedef PICodeParser::parseTypedef(PIString fc) {
|
||||
//piCout << "parse typedef" << fc;
|
||||
// piCout << "parse typedef" << fc;
|
||||
Typedef td;
|
||||
fc.replaceAll('\t', ' ');
|
||||
|
||||
|
||||
if (fc.contains('(')) {
|
||||
int start = fc.find('('), end = fc.find(')');
|
||||
td.first = fc.takeMid(start + 1, end - start - 1).trim();
|
||||
if (td.first.left(1) == PIChar('*')) {td.first.cutLeft(1).trim(); fc.insert(start + 1, '*');}
|
||||
if (td.first.left(1) == PIChar('*')) {
|
||||
td.first.cutLeft(1).trim();
|
||||
fc.insert(start + 1, '*');
|
||||
}
|
||||
td.second = fc.trim();
|
||||
} else {
|
||||
td.first = fc.takeMid(fc.findLast(' ')).trim();
|
||||
td.first = fc.takeMid(fc.findLast(' ')).trim();
|
||||
td.second = fc.trim();
|
||||
}
|
||||
//piCout << "found typedef" << td;
|
||||
// piCout << "found typedef" << td;
|
||||
return td;
|
||||
}
|
||||
|
||||
@@ -634,22 +796,26 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
if (fc.trim().isEmpty()) return true;
|
||||
if (fc.find(s_operator) >= 0) return true;
|
||||
tmp_temp.clear();
|
||||
//piCout << "parse member" << fc;
|
||||
// piCout << "parse member" << fc;
|
||||
int ts = fc.find('<'), te = 0;
|
||||
PIString ctemp, crepl;
|
||||
while (ts >= 0) {
|
||||
ctemp = fc.mid(ts).takeRange('<', '>');
|
||||
if (ctemp.isEmpty()) {te = ts + 1; ts = fc.find('<', te); continue;}
|
||||
if (ctemp.isEmpty()) {
|
||||
te = ts + 1;
|
||||
ts = fc.find('<', te);
|
||||
continue;
|
||||
}
|
||||
crepl = s_T + PIString::fromNumber(tmp_temp.size_s()).expandLeftTo(3, '0');
|
||||
fc.replace(ts, ctemp.size_s() + 2, crepl);
|
||||
tmp_temp[crepl] = '<' + ctemp + '>';
|
||||
ts = fc.find('<', te);
|
||||
ts = fc.find('<', te);
|
||||
}
|
||||
fc.replaceAll('\n', ' ').replaceAll('\t', ' ').replaceAll(s_ss, ' ').replaceAll(s_cs, ',').replaceAll(s_sb, '(').replaceAll(s_sM, s_M);
|
||||
//piCout << "parse member" << fc;
|
||||
// piCout << "parse member" << fc;
|
||||
PIStringList tl, al;
|
||||
Member me;
|
||||
//piCout << fc;
|
||||
// piCout << fc;
|
||||
if (fc.contains('(')) {
|
||||
MetaMap meta;
|
||||
int ind = fc.find(s_M);
|
||||
@@ -659,16 +825,16 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
}
|
||||
fc.cutRight(fc.size_s() - fc.findLast(')') - 1);
|
||||
te = fc.find('(');
|
||||
//piCout << fc;
|
||||
// piCout << fc;
|
||||
for (ts = te - 1; ts >= 0; --ts)
|
||||
if (!_isCChar(fc[ts]) && !(fc[ts].isDigit())) break;
|
||||
//piCout << "takeMid" << ts + 1 << te - ts - 1;
|
||||
// piCout << "takeMid" << ts + 1 << te - ts - 1;
|
||||
me.meta = meta;
|
||||
me.name = fc.takeMid(ts + 1, te - ts - 1);
|
||||
if (me.name == parent->name) return true;
|
||||
me.arguments_full = fc.takeMid(ts + 2).cutRight(1).split(',');
|
||||
me.type = fc.cutRight(1).trim();
|
||||
me.visibility = cur_def_vis;
|
||||
me.type = fc.cutRight(1).trim();
|
||||
me.visibility = cur_def_vis;
|
||||
if (me.type.find(s_inline_s) >= 0) {
|
||||
me.attributes |= Inline;
|
||||
me.type.removeAll(s_inline_s);
|
||||
@@ -683,20 +849,18 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
}
|
||||
normalizeEntityNamespace(me.type);
|
||||
int i = 0;
|
||||
//piCout << me.arguments_full;
|
||||
piForeach (PIString & a, me.arguments_full)
|
||||
if ((i = a.find('=')) > 0)
|
||||
a.cutRight(a.size_s() - i).trim();
|
||||
// piCout << me.arguments_full;
|
||||
piForeach(PIString & a, me.arguments_full)
|
||||
if ((i = a.find('=')) > 0) a.cutRight(a.size_s() - i).trim();
|
||||
for (int j = 0; j < me.arguments_full.size_s(); ++j)
|
||||
if (me.arguments_full[j] == s_void) {
|
||||
me.arguments_full.remove(j);
|
||||
--j;
|
||||
}
|
||||
me.arguments_type = me.arguments_full;
|
||||
piForeach (PIString & a, me.arguments_type) {
|
||||
piForeach(PIString & a, me.arguments_type) {
|
||||
crepl.clear();
|
||||
if (a.contains('['))
|
||||
crepl = a.takeMid(a.find('['), a.findLast(']') - a.find('[') + 1);
|
||||
if (a.contains('[')) crepl = a.takeMid(a.find('['), a.findLast(']') - a.find('[') + 1);
|
||||
for (ts = a.size_s() - 1; ts >= 0; --ts)
|
||||
if (!_isCChar(a[ts]) && !(a[ts].isDigit())) break;
|
||||
a.cutRight(a.size_s() - ts - 1);
|
||||
@@ -705,31 +869,34 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
a.trim();
|
||||
}
|
||||
restoreTmpTemp(&me);
|
||||
//piCout << "func" << me.type << me.name << me.arguments_full << me.arguments_type;
|
||||
// piCout << "func" << me.type << me.name << me.arguments_full << me.arguments_type;
|
||||
parent->functions << me;
|
||||
} else {
|
||||
if (fc.endsWith(';')) fc.cutRight(1);
|
||||
//piCout << "member" << fc;
|
||||
// piCout << "member" << fc;
|
||||
if (fc.startsWith(s_using) || !(fc.contains(' ') || fc.contains('\t') || fc.contains('\n'))) return true;
|
||||
int bits = extractMemberBits(fc);
|
||||
tl = fc.split(',');
|
||||
//piCout << "member" << fc << tl;
|
||||
//piCout << "member after eb" << fc << ", bits =" << bits;
|
||||
tl = fc.split(',');
|
||||
// piCout << "member" << fc << tl;
|
||||
// piCout << "member after eb" << fc << ", bits =" << bits;
|
||||
if (tl.isEmpty()) return true;
|
||||
piForeach (PIString & v, tl)
|
||||
piForeach(PIString & v, tl)
|
||||
removeAssignment(v);
|
||||
bool vn = true;
|
||||
ctemp = tl.front().trim();
|
||||
ctemp = tl.front().trim();
|
||||
PIString meta_t;
|
||||
if (ctemp.contains(s_M)) {
|
||||
meta_t = ctemp.takeMid(ctemp.find(s_M), 5);
|
||||
ctemp.trim();
|
||||
}
|
||||
for (ts = ctemp.size_s() - 1; ts > 0; --ts) {
|
||||
if (vn) {if (!_isCChar(ctemp[ts]) && !ctemp[ts].isDigit() && ctemp[ts] != '[' && ctemp[ts] != ']') vn = false;}
|
||||
else {if (_isCChar(ctemp[ts]) || ctemp[ts].isDigit()) break;}
|
||||
if (vn) {
|
||||
if (!_isCChar(ctemp[ts]) && !ctemp[ts].isDigit() && ctemp[ts] != '[' && ctemp[ts] != ']') vn = false;
|
||||
} else {
|
||||
if (_isCChar(ctemp[ts]) || ctemp[ts].isDigit()) break;
|
||||
}
|
||||
}
|
||||
me.type = ctemp.takeLeft(ts + 1);
|
||||
me.type = ctemp.takeLeft(ts + 1);
|
||||
me.visibility = cur_def_vis;
|
||||
ctemp += meta_t;
|
||||
restoreTmpTemp(&me);
|
||||
@@ -757,21 +924,21 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
type.trim();
|
||||
normalizeEntityNamespace(type);
|
||||
tl[0] = ctemp.trim();
|
||||
//piCout << "vars" << tl;
|
||||
piForeachC (PIString & v, tl) {
|
||||
// piCout << "vars" << tl;
|
||||
piForeachC(PIString & v, tl) {
|
||||
crepl.clear();
|
||||
|
||||
me.name = v.trimmed();
|
||||
me.type = type;
|
||||
restoreTmpMeta(&me);
|
||||
if (me.name.isEmpty()) continue;
|
||||
if (me.name.contains('['))
|
||||
crepl = me.name.takeMid(me.name.find('['), me.name.findLast(']') - me.name.find('[') + 1);
|
||||
if (me.name.contains('[')) crepl = me.name.takeMid(me.name.find('['), me.name.findLast(']') - me.name.find('[') + 1);
|
||||
while (!me.name.isEmpty()) {
|
||||
if (me.name.front() == PIChar('*') || me.name.front() == PIChar('&')) {
|
||||
me.type += me.name.takeLeft(1);
|
||||
me.name.trim();
|
||||
} else break;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
me.is_type_ptr = (me.type.right(1) == PIChar(']') || me.type.right(1) == PIChar('*'));
|
||||
me.type += crepl;
|
||||
@@ -781,12 +948,12 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
|
||||
if (cdim.isEmpty()) break;
|
||||
me.dims << cdim;
|
||||
}
|
||||
//PICout(PICoutManipulators::AddAll) << "var" << me.type << me.name << me.bits;
|
||||
//piCout << "var" << v << me.type << me.name << me.bits;
|
||||
// PICout(PICoutManipulators::AddAll) << "var" << me.type << me.name << me.bits;
|
||||
// piCout << "var" << v << me.type << me.name << me.bits;
|
||||
parent->members << me;
|
||||
}
|
||||
}
|
||||
//piCout << "parse member" << fc;
|
||||
// piCout << "parse member" << fc;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -818,13 +985,25 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) {
|
||||
break;
|
||||
}
|
||||
n.push_front(' ');
|
||||
if (n.find(s_s_const_s) >= 0) {n.replaceAll(s_s_const_s, ""); pref += s_const_s;}
|
||||
if (n.find(s_s_static_s) >= 0) {n.replaceAll(s_s_static_s, ""); pref += s_static_s;}
|
||||
if (n.find(s_s_mutable_s) >= 0) {n.replaceAll(s_s_mutable_s, ""); pref += s_mutable_s;}
|
||||
if (n.find(s_s_volatile_s) >= 0) {n.replaceAll(s_s_volatile_s, ""); pref += s_volatile_s;}
|
||||
if (n.find(s_s_const_s) >= 0) {
|
||||
n.replaceAll(s_s_const_s, "");
|
||||
pref += s_const_s;
|
||||
}
|
||||
if (n.find(s_s_static_s) >= 0) {
|
||||
n.replaceAll(s_s_static_s, "");
|
||||
pref += s_static_s;
|
||||
}
|
||||
if (n.find(s_s_mutable_s) >= 0) {
|
||||
n.replaceAll(s_s_mutable_s, "");
|
||||
pref += s_mutable_s;
|
||||
}
|
||||
if (n.find(s_s_volatile_s) >= 0) {
|
||||
n.replaceAll(s_s_volatile_s, "");
|
||||
pref += s_volatile_s;
|
||||
}
|
||||
n.trim();
|
||||
int f = 0;
|
||||
piForeachC (Entity * e, entities) {
|
||||
piForeachC(Entity * e, entities) {
|
||||
if (e->name == n) {
|
||||
n = (pref + n + suff).trim();
|
||||
return;
|
||||
@@ -836,20 +1015,20 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
piForeachC (Enum & e, enums) {
|
||||
piForeachC(Enum & e, enums) {
|
||||
if ((f = e.name.find(n)) >= 0)
|
||||
if (e.name.at(f - 1) == PIChar(':'))
|
||||
if (e.name.find(cur_namespace) >= 0) {
|
||||
//piCout << "change" << n << "to" << e.name + suff;
|
||||
// piCout << "change" << n << "to" << e.name + suff;
|
||||
n = pref + e.name + suff;
|
||||
return;
|
||||
}
|
||||
}
|
||||
piForeachC (Typedef & e, typedefs) {
|
||||
piForeachC(Typedef & e, typedefs) {
|
||||
if ((f = e.first.find(n)) >= 0)
|
||||
if (e.first.at(f - 1) == PIChar(':'))
|
||||
if (e.first.find(cur_namespace) >= 0) {
|
||||
//piCout << "change" << n << "to" << e.name + suff;
|
||||
// piCout << "change" << n << "to" << e.name + suff;
|
||||
n = pref + e.first + suff;
|
||||
return;
|
||||
}
|
||||
@@ -860,12 +1039,12 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) {
|
||||
|
||||
void PICodeParser::restoreTmpTemp(Member * e) {
|
||||
static const PIString s_T = PIStringAscii("$T");
|
||||
int i = 0;
|
||||
piForeach (PIString & a, e->arguments_full) {
|
||||
int i = 0;
|
||||
piForeach(PIString & a, e->arguments_full) {
|
||||
while ((i = a.find(s_T)) >= 0)
|
||||
a.replace(i, 5, tmp_temp[a.mid(i, 5)]);
|
||||
}
|
||||
piForeach (PIString & a, e->arguments_type) {
|
||||
piForeach(PIString & a, e->arguments_type) {
|
||||
while ((i = a.find(s_T)) >= 0)
|
||||
a.replace(i, 5, tmp_temp[a.mid(i, 5)]);
|
||||
}
|
||||
@@ -876,7 +1055,7 @@ void PICodeParser::restoreTmpTemp(Member * e) {
|
||||
|
||||
void PICodeParser::restoreTmpMeta(PICodeParser::Member * e) {
|
||||
static const PIString s_M = PIStringAscii("$M");
|
||||
int i = e->name.find(s_M);
|
||||
int i = e->name.find(s_M);
|
||||
if (i < 0) return;
|
||||
e->meta = tmp_meta[e->name.takeMid(i, 5)];
|
||||
}
|
||||
@@ -898,7 +1077,7 @@ bool PICodeParser::macroCondition(const PIString & mif, PIString mifcond) {
|
||||
static const PIString s_ifndef = PIStringAscii("ifndef");
|
||||
static const PIString s_if = PIStringAscii("if");
|
||||
static const PIString s_elif = PIStringAscii("elif");
|
||||
//piCout << "macroCondition" << mif << mifcond;
|
||||
// piCout << "macroCondition" << mif << mifcond;
|
||||
if (mif == s_ifdef) return isDefineExists(mifcond);
|
||||
if (mif == s_ifndef) return !isDefineExists(mifcond);
|
||||
if (mif == s_if || mif == s_elif) {
|
||||
@@ -917,52 +1096,65 @@ double PICodeParser::procMacrosCond(PIString fc) {
|
||||
char cc, nc;
|
||||
PIString ce;
|
||||
fc.removeAll(s_defined);
|
||||
//piCout << "procMacrosCond" << fc;
|
||||
// piCout << "procMacrosCond" << fc;
|
||||
while (!fc.isEmpty()) {
|
||||
cc = fc[0].toAscii();
|
||||
nc = (fc.size() > 1 ? fc[1].toAscii() : 0);
|
||||
if (cc == '!') {neg = true; fc.pop_front(); continue;}
|
||||
if (cc == '(') {br = true; brv = procMacrosCond(fc.takeRange('(', ')'));}
|
||||
if (cc == '&' && nc == '&') {fc.remove(0, 2); oper = 1; continue;}
|
||||
if (cc == '|' && nc == '|') {fc.remove(0, 2); oper = 2; continue;}
|
||||
if (cc == '!') {
|
||||
neg = true;
|
||||
fc.pop_front();
|
||||
continue;
|
||||
}
|
||||
if (cc == '(') {
|
||||
br = true;
|
||||
brv = procMacrosCond(fc.takeRange('(', ')'));
|
||||
}
|
||||
if (cc == '&' && nc == '&') {
|
||||
fc.remove(0, 2);
|
||||
oper = 1;
|
||||
continue;
|
||||
}
|
||||
if (cc == '|' && nc == '|') {
|
||||
fc.remove(0, 2);
|
||||
oper = 2;
|
||||
continue;
|
||||
}
|
||||
if (!br) {
|
||||
ce = fc.takeCWord();
|
||||
if (ce.isEmpty()) ce = fc.takeNumber();
|
||||
}
|
||||
if (first) {
|
||||
first = false;
|
||||
ret = br ? brv : defineValue(ce);
|
||||
ret = br ? brv : defineValue(ce);
|
||||
if (neg) ret = -ret;
|
||||
} else {
|
||||
//piCout << "oper" << oper << "with" << ce;
|
||||
// piCout << "oper" << oper << "with" << ce;
|
||||
if (!br) brv = defineValue(ce);
|
||||
switch (oper) {
|
||||
case 1: ret = ret && (neg ? -brv : brv); break;
|
||||
case 2: ret = ret || (neg ? -brv : brv); break;
|
||||
case 1: ret = ret && (neg ? -brv : brv); break;
|
||||
case 2: ret = ret || (neg ? -brv : brv); break;
|
||||
}
|
||||
}
|
||||
if (ps == fc.size_s()) fc.cutLeft(1);
|
||||
ps = fc.size_s();
|
||||
br = neg = false;
|
||||
}
|
||||
//piCout << "return" << ret;
|
||||
// piCout << "return" << ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool PICodeParser::isDefineExists(const PIString & dn) {
|
||||
piForeachC (Define & d, defines) {
|
||||
if (d.first == dn)
|
||||
return true;
|
||||
piForeachC(Define & d, defines) {
|
||||
if (d.first == dn) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
double PICodeParser::defineValue(const PIString & dn) {
|
||||
piForeachC (Define & d, defines) {
|
||||
if (d.first == dn)
|
||||
return d.second.isEmpty() ? 1. : d.second.toDouble();
|
||||
piForeachC(Define & d, defines) {
|
||||
if (d.first == dn) return d.second.isEmpty() ? 1. : d.second.toDouble();
|
||||
}
|
||||
return dn.toDouble();
|
||||
}
|
||||
@@ -979,28 +1171,33 @@ void PICodeParser::replaceMeta(PIString & dn) {
|
||||
ms = dn.findRange('(', ')', '\\', s + 6, &ml);
|
||||
if (ms < 0) return;
|
||||
PIString meta = dn.mid(ms, ml).trim();
|
||||
PIString rm = s_M + PIString::fromNumber(tmp_meta.size_s()).expandLeftTo(3, '0');
|
||||
PIString rm = s_M + PIString::fromNumber(tmp_meta.size_s()).expandLeftTo(3, '0');
|
||||
dn.replace(s, ms + ml + 1 - s, rm);
|
||||
//piCout << "FOUND META \"" << meta << '\"';
|
||||
// piCout << "FOUND META \"" << meta << '\"';
|
||||
tmp_meta[rm] = parseMeta(meta);
|
||||
s = dn.find(s_PIMETA);
|
||||
s = dn.find(s_PIMETA);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PICodeParser::Entity * PICodeParser::findEntityByName(const PIString & en) {
|
||||
piForeach (Entity * e, entities)
|
||||
if (e->name == en)
|
||||
return e;
|
||||
piForeach(Entity * e, entities)
|
||||
if (e->name == en) return e;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool PICodeParser::isDeclaration(const PIString & fc, int start, int * end) {
|
||||
int dind = fc.find('{', start), find = fc.find(';', start);
|
||||
//piCout << "isDeclaration" << dind << find << fc.left(10);
|
||||
if (dind < 0 && find < 0) {if (end) *end = -1; return true;}
|
||||
if (dind < 0 || find < dind) {if (end) *end = find; return true;}
|
||||
// piCout << "isDeclaration" << dind << find << fc.left(10);
|
||||
if (dind < 0 && find < 0) {
|
||||
if (end) *end = -1;
|
||||
return true;
|
||||
}
|
||||
if (dind < 0 || find < dind) {
|
||||
if (end) *end = find;
|
||||
return true;
|
||||
}
|
||||
if (end) *end = dind;
|
||||
return false;
|
||||
}
|
||||
@@ -1013,7 +1210,7 @@ bool PICodeParser::isMainFile(const PIString & fc) {
|
||||
if (csi < 0) csi = fc.find(PIStringAscii("\tmain"), si);
|
||||
if (csi < 0) csi = fc.find(PIStringAscii("\nmain"), si);
|
||||
if (csi < 0) return false;
|
||||
si = csi;
|
||||
si = csi;
|
||||
int fi = fc.find('(', si + 5);
|
||||
if (fi < 0) return false;
|
||||
if (fi - si < 10) {
|
||||
@@ -1038,68 +1235,80 @@ PIString PICodeParser::procMacros(PIString fc) {
|
||||
int ifcnt = 0;
|
||||
bool grab = false, skip = false, cond_ok = false;
|
||||
PIString pfc, nfc, line, mif, mifcond;
|
||||
//piCout << "procMacros\n<******" << fc << "\n******>";
|
||||
// piCout << "procMacros\n<******" << fc << "\n******>";
|
||||
fc += '\n';
|
||||
while (!fc.isEmpty()) {
|
||||
line = fc.takeLine().trimmed();
|
||||
if (line.left(1) == PIChar('#')) {
|
||||
mifcond = line.mid(1);
|
||||
mif = mifcond.takeCWord();
|
||||
//piCout << mif;
|
||||
//piCout << "mif mifcond" << mif << mifcond << ifcnt;
|
||||
mif = mifcond.takeCWord();
|
||||
// piCout << mif;
|
||||
// piCout << "mif mifcond" << mif << mifcond << ifcnt;
|
||||
if (skip || grab) {
|
||||
if (mif.left(2) == s_if) ifcnt++;
|
||||
if (mif.left(5) == s_endif) {
|
||||
if (ifcnt > 0) ifcnt--;
|
||||
if (ifcnt > 0)
|
||||
ifcnt--;
|
||||
else {
|
||||
//piCout << "main endif" << skip << grab;
|
||||
// piCout << "main endif" << skip << grab;
|
||||
if (grab) pfc += procMacros(nfc);
|
||||
skip = grab = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (mif.left(4) == s_elif && ifcnt == 0) {
|
||||
//piCout << "main elif" << skip << grab << cond_ok;
|
||||
// piCout << "main elif" << skip << grab << cond_ok;
|
||||
if (cond_ok) {
|
||||
if (grab) {
|
||||
pfc += procMacros(nfc);
|
||||
skip = true; grab = false;
|
||||
skip = true;
|
||||
grab = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (skip) {
|
||||
//piCout << "check elif" << skip << grab << cond_ok;
|
||||
// piCout << "check elif" << skip << grab << cond_ok;
|
||||
if (!macroCondition(mif, mifcond.trimmed())) continue;
|
||||
//piCout << "check elif ok";
|
||||
skip = false; grab = cond_ok = true;
|
||||
// piCout << "check elif ok";
|
||||
skip = false;
|
||||
grab = cond_ok = true;
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (mif.left(4) == s_else && ifcnt == 0) {
|
||||
//piCout << "main else" << skip << grab;
|
||||
// piCout << "main else" << skip << grab;
|
||||
if (grab) pfc += procMacros(nfc);
|
||||
if (skip && !cond_ok) {skip = false; grab = true;}
|
||||
else {skip = true; grab = false;}
|
||||
if (skip && !cond_ok) {
|
||||
skip = false;
|
||||
grab = true;
|
||||
} else {
|
||||
skip = true;
|
||||
grab = false;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (grab) nfc += line + '\n';
|
||||
continue;
|
||||
}
|
||||
if (mif.left(2) == s_if) {
|
||||
//piCout << "main if";
|
||||
// piCout << "main if";
|
||||
skip = grab = cond_ok = false;
|
||||
if (macroCondition(mif, mifcond.trimmed())) grab = cond_ok = true;
|
||||
else skip = true;
|
||||
if (macroCondition(mif, mifcond.trimmed()))
|
||||
grab = cond_ok = true;
|
||||
else
|
||||
skip = true;
|
||||
ifcnt = 0;
|
||||
nfc.clear();
|
||||
} else {
|
||||
parseDirective(line.cutLeft(1).trim());
|
||||
//return false; /// WARNING: now skip errors
|
||||
// return false; /// WARNING: now skip errors
|
||||
}
|
||||
} else {
|
||||
if (grab) nfc += line + '\n';
|
||||
else if (!skip) pfc += line + '\n';
|
||||
if (grab)
|
||||
nfc += line + '\n';
|
||||
else if (!skip)
|
||||
pfc += line + '\n';
|
||||
}
|
||||
}
|
||||
return pfc;
|
||||
@@ -1107,13 +1316,13 @@ PIString PICodeParser::procMacros(PIString fc) {
|
||||
|
||||
|
||||
bool PICodeParser::parseDirective(PIString d) {
|
||||
static const PIString s_include = PIStringAscii("include");
|
||||
static const PIString s_define = PIStringAscii("define");
|
||||
static const PIString s_undef = PIStringAscii("undef");
|
||||
static const PIString s_PIMETA = PIStringAscii("PIMETA");
|
||||
static const PIString s_include = PIStringAscii("include");
|
||||
static const PIString s_define = PIStringAscii("define");
|
||||
static const PIString s_undef = PIStringAscii("undef");
|
||||
static const PIString s_PIMETA = PIStringAscii("PIMETA");
|
||||
if (d.isEmpty()) return true;
|
||||
PIString dname = d.takeCWord();
|
||||
//piCout << "parseDirective" << d;
|
||||
// piCout << "parseDirective" << d;
|
||||
if (dname == s_include) {
|
||||
d.replaceAll('<', '\"').replaceAll('>', '\"');
|
||||
PIString cf = cur_file, ifc = d.takeRange('\"', '\"');
|
||||
@@ -1125,7 +1334,7 @@ bool PICodeParser::parseDirective(PIString d) {
|
||||
}
|
||||
if (dname == s_define) {
|
||||
PIString mname = d.takeCWord();
|
||||
//piCout << mname;
|
||||
// piCout << mname;
|
||||
if (mname == s_PIMETA) return true;
|
||||
if (d.left(1) == PIChar('(')) { // macro
|
||||
PIStringList args = d.takeRange('(', ')').split(',').trim();
|
||||
@@ -1150,7 +1359,10 @@ bool PICodeParser::parseDirective(PIString d) {
|
||||
if (dname == s_undef) {
|
||||
PIString mname = d.takeCWord();
|
||||
for (int i = 0; i < defines.size_s(); ++i)
|
||||
if (defines[i].first == mname) {defines.remove(i); --i;}
|
||||
if (defines[i].first == mname) {
|
||||
defines.remove(i);
|
||||
--i;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user