PIString hard optimization

This commit is contained in:
2020-07-31 14:12:47 +03:00
parent 1d5c979607
commit e728b30e5e
7 changed files with 318 additions and 258 deletions

View File

@@ -24,7 +24,7 @@
PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const {
PIStringList arg_vals;
while (!args_.isEmpty()) {
int ci = args_.find(","), bi = args_.find("(");
int ci = args_.find(','), bi = args_.find('(');
if (ci < 0) {
arg_vals << args_;
break;
@@ -33,7 +33,7 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const {
if (bi >= 0 && bi < ci) {
ca = args_.left(args_.takeLeft(bi).toInt());
ci -= ca.size_s(); bi -= ca.size_s();
ca += "(" + args_.takeRange("(", ")") + ")";
ca += '(' + args_.takeRange('(', ')') + ')';
} else {
ca = args_.takeLeft(ci);
}
@@ -41,7 +41,7 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const {
args_.trim(); args_.takeLeft(1); args_.trim();
}
if (args.size() != arg_vals.size()) {
piCout << ("Error: in expansion of macro \"" + name + "(" + args.join(", ") + ")\": expect")
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();
@@ -57,7 +57,7 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const {
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 + "\"");
ret.replace(ind, an.size_s() + 1, '\"' + av + '\"');
ind -= an.size_s() - av.size_s() - 1;
continue;
}
@@ -66,7 +66,7 @@ PIString PICodeParser::Macro::expand(PIString args_, bool * ok) const {
ind -= an.size_s() - av.size_s();
}
}
ret.replaceAll("##", "");
ret.replaceAll(PIStringAscii("##"), "");
if (ok != 0) *ok = true;
return ret;
}
@@ -99,20 +99,20 @@ void PICodeParser::parseFile(const PIString & file, bool follow_includes) {
}
piCout << "\n\nDefines:";
piForeachC (Define & m, defines)
piCout << "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 << "\n\nClasses:";
piCout << "\n\nEnums:";
piForeachC (Enum & c, enums) {
piCout << "enum" << c.name << c.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 << "typedef" << c;*/
piCout << PIStringAscii("typedef") << c;*/
}
@@ -122,19 +122,19 @@ void PICodeParser::parseFiles(const PIStringList & files, bool follow_includes)
parseFileInternal(f, follow_includes);
/*piCout << "\n\nDefines:";
piForeachC (Define & m, defines)
piCout << "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 << "\n\nClasses:";
piForeachC (Entity * c, entities)
piCout << "class" << c->name << c->parents;
piCout << PIStringAscii("class") << c->name << c->parents;
piCout << "\n\nEnums:";
piForeachC (Enum & c, enums)
piCout << "enum" << c.name << c.members;
piCout << PIStringAscii("enum") << c.name << c.members;
piCout << "\n\nTypedefs:";
piForeachC (Typedef & c, typedefs)
piCout << "typedef" << c;*/
piCout << PIStringAscii("typedef") << c;*/
}
@@ -153,7 +153,7 @@ bool PICodeParser::parseFileInternal(const PIString & file, bool follow_includes
PIFile f(file, PIIODevice::ReadOnly);
int ii = 0;
while (!f.isOpened() && ii < (includes.size_s() - 1)) {
f.setPath(includes[++ii] + "/" + file);
f.setPath(includes[++ii] + '/' + file);
//piCout << "try" << f.path();
f.open(PIIODevice::ReadOnly);
}
@@ -186,7 +186,7 @@ void PICodeParser::clear() {
evaluator.clearCustomVariables();
cur_def_vis = Global;
anon_num = 0;
defines << Define("PICODE", "") << custom_defines;
defines << Define(PIStringAscii("PICODE"), "") << custom_defines;
}
@@ -197,9 +197,9 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
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");
/// Remove comments, join multiline '*' and replace '*' to $n (cchars)
fc.replaceAll("\r\n", '\n');
fc.replaceAll('\r', '\n');
for (int i = 0; i < fc.size_s() - 1; ++i) {
if (fc[i].unicode16Code() >= 255) continue;
if (i > 0) pc = c;
@@ -256,7 +256,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
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);
range = pfc.mid(ind + m.name.size_s()).takeRange("(", ")");
range = pfc.mid(ind + m.name.size_s()).takeRange('(', ')');
ret = m.expand(range, &ok);
if (!ok) return false;
int rlen = pfc.find(range, ind + m.name.size_s()) + range.size_s() + 1 - ind;
@@ -275,20 +275,20 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
if (pl == nl) break;
pl = nl;
if (pfc.left(9) == "namespace") {
pfc.cutLeft(pfc.find("{") + 1);
pfc.cutLeft(pfc.find('{') + 1);
continue;
}
if (pfc.left(8) == "template") {
pfc.cutLeft(8);
pfc.takeRange("<", ">");
pfc.takeRange('<', '>');
bool def = !isDeclaration(pfc, 0, &end);
pfc.cutLeft(end);
if (def) pfc.takeRange("{", "}");
if (def) pfc.takeRange('{', '}');
else pfc.takeSymbol();
continue;
}
if (pfc.left(5) == "class" || pfc.left(6) == "struct" || pfc.left(5) == "union") {
int dind = pfc.find("{", 0), find = pfc.find(";", 0);
if (pfc.left(5) == PIStringAscii("class") || pfc.left(6) == "struct" || pfc.left(5) == "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;}
ccmn = pfc.left(dind) + "{\n" + pfc.mid(dind).takeRange('{', '}') + "\n}\n";
@@ -296,24 +296,24 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
parseClass(0, ccmn);
continue;
}
if (pfc.left(4) == "enum") {
if (pfc.left(4) == PIStringAscii("enum")) {
pfc.cutLeft(4);
tmp = pfc.takeCWord();
pfc.trim();
MetaMap meta = maybeMeta(pfc);
parseEnum(0, cur_namespace + tmp, pfc.takeRange("{", "}"), meta);
parseEnum(0, cur_namespace + tmp, pfc.takeRange('{', '}'), meta);
pfc.takeSymbol();
continue;
}
if (pfc.left(7) == "typedef") {
if (pfc.left(7) == PIStringAscii("typedef")) {
pfc.cutLeft(7);
typedefs << parseTypedef(pfc.takeLeft(pfc.find(";")));
typedefs << parseTypedef(pfc.takeLeft(pfc.find(';')));
if (typedefs.back().first.isEmpty()) typedefs.pop_back();
else root_.typedefs << typedefs.back();
pfc.takeSymbol();
continue;
}
int sci = pfc.find(";", 0), obi = pfc.find("{", 0);
int sci = pfc.find(';', 0), obi = pfc.find('{', 0);
if (sci < 0 && obi < 0) {
pfc.takeLeft(1);
continue;
@@ -323,7 +323,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
str = pfc.takeLeft(sci + 1);
} else {
str = pfc.takeLeft(obi);
pfc.cutLeft(pfc.takeRange("{", "}").toInt());
pfc.cutLeft(pfc.takeRange('{', '}').toInt());
}
parseMember(&root_, str);
}
@@ -333,22 +333,22 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc) {
PIString cd = fc.trimmed().removeAll('\n').replaceAll("\t", " ").replaceAll(" ", " "), pn;
PIString cd = fc.trimmed().removeAll('\n').replaceAll('\t', ' ').replaceAll(PIStringAscii(" "), ' '), pn;
MetaMap meta;
int ind = cd.find("$M");
int ind = cd.find(PIStringAscii("$M"));
if (ind >= 0) {
meta = tmp_meta.value(cd.takeMid(ind, 5));
cd.replaceAll(" ", " ");
cd.replaceAll(PIStringAscii(" "), ' ');
}
//piCout << "found class <****\n" << cd << "\n****>";
ind = cd.find(":");
ind = cd.find(':');
PIVector<Entity * > parents;
if (ind > 0) {
PIStringList pl = cd.takeMid(ind + 1).trim().split(",");
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);
if (p.contains(' ')) pn = p.mid(p.find(' ') + 1);
else pn = p;
pe = findEntityByName(pn);
if (pe == 0) ;//{piCout << "Error: can`t find" << pn;}
@@ -356,11 +356,11 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc)
}
}
PIString typename_ = cd.left(6).trim();
bool is_class = typename_ == "class";
bool is_class = typename_ == PIStringAscii("class");
cur_def_vis = (is_class ? Private : Public);
PIString cn = cd.mid(6).trim();
bool has_name = !cn.isEmpty();
if (cn.isEmpty()) cn = "<unnamed_" + PIString::fromNumber(anon_num++) + ">";
if (cn.isEmpty()) cn = "<unnamed_" + PIString::fromNumber(anon_num++) + '>';
//piCout << "found " << typename_ << cn;
if (cn.isEmpty()) return 0;
Entity * e = new Entity();
@@ -377,7 +377,7 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc)
PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
Visibility prev_vis = cur_def_vis;
int dind = fc.find("{"), find = fc.find(";"), end = 0;
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****>";
@@ -396,37 +396,37 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
while (!fc.isEmpty()) {
PIString cw = fc.takeCWord(), tmp;
//piCout << "\ntaked word" << cw;
if (cw == "public") {cur_def_vis = Public; fc.cutLeft(1); continue;}
if (cw == "protected") {cur_def_vis = Protected; fc.cutLeft(1); continue;}
if (cw == "private") {cur_def_vis = Private; fc.cutLeft(1); continue;}
if (cw == "class" || cw == "struct" || cw == "union") {
if (cw == PIStringAscii("public" )) {cur_def_vis = Public; fc.cutLeft(1); continue;}
if (cw == PIStringAscii("protected")) {cur_def_vis = Protected; fc.cutLeft(1); continue;}
if (cw == PIStringAscii("private" )) {cur_def_vis = Private; fc.cutLeft(1); continue;}
if (cw == PIStringAscii("class") || cw == PIStringAscii("struct") || cw == PIStringAscii("union")) {
if (isDeclaration(fc, 0, &end)) {
fc.cutLeft(end);
fc.takeSymbol();
continue;
}
tmp = fc.takeLeft(fc.find("{"));
stmp = fc.takeRange("{", "}");
tmp = fc.takeLeft(fc.find('{'));
stmp = fc.takeRange('{', '}');
fc.takeSymbol();
stmp = cw + " " + tmp + "{" + stmp + "}";
stmp = cw + ' ' + tmp + '{' + stmp + '}';
parseClass(ce, stmp);
continue;
}
if (cw == "enum") {
if (cw == PIStringAscii("enum")) {
tmp = fc.takeCWord();
fc.trim();
MetaMap meta = maybeMeta(fc);
parseEnum(ce, cur_namespace + tmp, fc.takeRange("{", "}"), meta);
parseEnum(ce, cur_namespace + tmp, fc.takeRange('{', '}'), meta);
fc.takeSymbol();
continue;
}
if (cw == "friend") {fc.cutLeft(fc.find(";") + 1); continue;}
if (cw == "typedef") {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;}
if (cw == PIStringAscii("friend")) {fc.cutLeft(fc.find(';') + 1); continue;}
if (cw == PIStringAscii("typedef")) {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;}
if (cw == "template") {
fc.takeRange("<", ">");
fc.takeRange('<', '>');
def = !isDeclaration(fc, 0, &end);
fc.cutLeft(end);
if (def) fc.takeRange("{", "}");
if (def) fc.takeRange('{', '}');
else fc.takeSymbol();
continue;
}
@@ -434,7 +434,7 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
tmp = (cw + fc.takeLeft(end)).trim();
if (!tmp.isEmpty())
parseMember(ce, tmp);
if (def) fc.takeRange("{", "}");
if (def) fc.takeRange('{', '}');
else fc.takeSymbol();
if (ps == fc.size_s()) {fc.cutLeft(1);}
ps = fc.size_s();
@@ -448,13 +448,13 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
PICodeParser::MetaMap PICodeParser::parseMeta(PIString & fc) {
PICodeParser::MetaMap ret;
if (fc.isEmpty()) return ret;
PIStringList ml = fc.split(",");
PIStringList ml = fc.split(',');
piForeachC (PIString & m, ml) {
int i = m.find("=");
if (i < 0) continue;
PIString mv = m.mid(i + 1).trim();
if (mv.startsWith("\"")) mv.cutLeft(1);
if (mv.endsWith("\"")) mv.cutRight(1);
if (mv.startsWith('\"')) mv.cutLeft(1);
if (mv.endsWith('\"')) mv.cutRight(1);
ret[m.left(i).trim()] = mv;
}
//piCout << ms << ret;
@@ -463,18 +463,18 @@ PICodeParser::MetaMap PICodeParser::parseMeta(PIString & fc) {
bool PICodeParser::parseEnum(Entity * parent, const PIString & name, PIString fc, const MetaMap & meta) {
//piCout << "enum" << name << fc;
//piCout << PIStringAscii("enum") << name << fc;
Enum e(name);
e.meta = meta;
PIStringList vl(fc.split(","));
PIStringList vl(fc.split(','));
PIString vn;
int cv = -1, ind = 0;
piForeach (PIString & v, vl) {
MetaMap meta;
int mi = v.find("$M");
int mi = v.find(PIStringAscii("$M"));
if (mi >= 0) {
meta = tmp_meta.value(v.takeMid(mi, 5));
v.replaceAll(" ", " ");
v.replaceAll(" ", ' ');
}
vn = v; ind = v.find("=");
if (ind > 0) {cv = v.right(v.size_s() - ind - 1).toInt(); vn = v.left(ind);}
@@ -492,15 +492,15 @@ bool PICodeParser::parseEnum(Entity * parent, const PIString & name, PIString fc
PICodeParser::Typedef PICodeParser::parseTypedef(PIString fc) {
//piCout << "parse typedef" << fc;
Typedef td;
fc.replaceAll("\t", " ");
fc.replaceAll('\t', ' ');
if (fc.contains("(")) {
int start = fc.find("("), end = fc.find(")");
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) == "*") {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;
@@ -513,30 +513,30 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
if (fc.find("operator") >= 0) return true;
tmp_temp.clear();
//piCout << "parse member" << fc;
int ts = fc.find("<"), te = 0;
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;}
crepl = "$T" + PIString::fromNumber(tmp_temp.size_s()).expandLeftTo(3, "0");
ctemp = fc.mid(ts).takeRange('<', '>');
if (ctemp.isEmpty()) {te = ts + 1; ts = fc.find('<', te); continue;}
crepl = PIStringAscii("$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);
tmp_temp[crepl] = '<' + ctemp + '>';
ts = fc.find('<', te);
}
fc.replaceAll("\n", " ").replaceAll("\t", " ").replaceAll(" ", " ").replaceAll(", ", ",").replaceAll(" (", "(").replaceAll(" $M", "$M");
fc.replaceAll('\n', ' ').replaceAll('\t', ' ').replaceAll(" ", ' ').replaceAll(", ", ',').replaceAll(PIStringAscii(" ("), '(').replaceAll(PIStringAscii(" $M"), PIStringAscii("$M"));
//piCout << "parse member" << fc;
PIStringList tl, al;
Member me;
//piCout << fc;
if (fc.contains("(")) {
if (fc.contains('(')) {
MetaMap meta;
int ind = fc.find("$M");
int ind = fc.find(PIStringAscii("$M"));
if (ind >= 0) {
meta = tmp_meta.value(fc.takeMid(ind, 5));
fc.replaceAll(" ", " ").replaceAll(" (", "(");
fc.replaceAll(PIStringAscii(" "), ' ').replaceAll(PIStringAscii(" ("), '(');
}
fc.cutRight(fc.size_s() - fc.findLast(")") - 1);
te = fc.find("(");
fc.cutRight(fc.size_s() - fc.findLast(')') - 1);
te = fc.find('(');
//piCout << fc;
for (ts = te - 1; ts >= 0; --ts)
if (!_isCChar(fc[ts]) && !(fc[ts].isDigit())) break;
@@ -544,20 +544,20 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
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.arguments_full = fc.takeMid(ts + 2).cutRight(1).split(',');
me.type = fc.cutRight(1).trim();
me.visibility = cur_def_vis;
if (me.type.find("inline ") >= 0) {
if (me.type.find(PIStringAscii("inline ")) >= 0) {
me.attributes |= Inline;
me.type.removeAll("inline ");
me.type.removeAll(PIStringAscii("inline "));
}
if (me.type.find("static ") >= 0) {
if (me.type.find(PIStringAscii("static ")) >= 0) {
me.attributes |= Static;
me.type.removeAll("static ");
me.type.removeAll(PIStringAscii("static "));
}
if (me.type.find("virtual ") >= 0) {
if (me.type.find(PIStringAscii("virtual ")) >= 0) {
me.attributes |= Virtual;
me.type.removeAll("virtual ");
me.type.removeAll(PIStringAscii("virtual "));
}
normalizeEntityNamespace(me.type);
int i = 0;
@@ -566,15 +566,15 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
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] == "void") {
if (me.arguments_full[j] == PIStringAscii("void")) {
me.arguments_full.remove(j);
--j;
}
me.arguments_type = me.arguments_full;
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);
@@ -586,18 +586,18 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
//piCout << "func" << me.type << me.name << me.arguments_full << me.arguments_type;
parent->functions << me;
} else {
if (fc.endsWith(";")) fc.cutRight(1);
if (fc.startsWith("using") || !(fc.contains(' ') || fc.contains('\t') || fc.contains('\n'))) return true;
if (fc.endsWith(';')) fc.cutRight(1);
if (fc.startsWith(PIStringAscii("using")) || !(fc.contains(' ') || fc.contains('\t') || fc.contains('\n'))) return true;
int bits = extractMemberBits(fc);
tl = fc.split(",");
tl = fc.split(',');
//piCout << "member" << fc << tl;
//piCout << "member after eb" << fc << ", bits =" << bits;
if (tl.isEmpty()) return true;
bool vn = true;
ctemp = tl.front().trim();
PIString meta_t;
if (ctemp.contains("$M"))
meta_t = ctemp.takeMid(ctemp.find("$M"));
if (ctemp.contains(PIStringAscii("$M")))
meta_t = ctemp.takeMid(ctemp.find(PIStringAscii("$M")));
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;}
@@ -606,26 +606,26 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
me.visibility = cur_def_vis;
ctemp += meta_t;
restoreTmpTemp(&me);
PIString type = " " + me.type;
if (type.find(" const ") >= 0) {
PIString type = PIStringAscii(" ") + me.type;
if (type.find(PIStringAscii(" const ")) >= 0) {
me.attributes |= Const;
type.replaceAll(" const ", " ");
type.replaceAll(PIStringAscii(" const "), ' ');
}
if (type.find(" static ") >= 0) {
if (type.find(PIStringAscii(" static ")) >= 0) {
me.attributes |= Static;
type.replaceAll(" static ", " ");
type.replaceAll(PIStringAscii(" static "), ' ');
}
if (type.find(" mutable ") >= 0) {
if (type.find(PIStringAscii(" mutable ")) >= 0) {
me.attributes |= Mutable;
type.replaceAll(" mutable ", " ");
type.replaceAll(PIStringAscii(" mutable "), ' ');
}
if (type.find(" volatile ") >= 0) {
if (type.find(PIStringAscii(" volatile ")) >= 0) {
me.attributes |= Volatile;
type.replaceAll(" volatile ", " ");
type.replaceAll(PIStringAscii(" volatile "), ' ');
}
if (type.find(" extern ") >= 0) {
if (type.find(PIStringAscii(" extern ")) >= 0) {
me.attributes |= Extern;
type.replaceAll(" extern ", " ");
type.replaceAll(PIStringAscii(" extern "), ' ');
}
type.trim();
normalizeEntityNamespace(type);
@@ -637,15 +637,15 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
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() == "*" || me.name.front() == "&") {
if (me.name.front() == PIChar('*') || me.name.front() == PIChar('&')) {
me.type += me.name.takeLeft(1);
me.name.trim();
} else break;
}
me.is_type_ptr = (me.type.right(1) == "]" || me.type.right(1) == "*");
me.is_type_ptr = (me.type.right(1) == PIChar(']') || me.type.right(1) == PIChar('*'));
me.type += crepl;
me.bits = bits;
while (!crepl.isEmpty()) {
@@ -664,7 +664,7 @@ bool PICodeParser::parseMember(Entity * parent, PIString & fc) {
int PICodeParser::extractMemberBits(PIString & fc) {
int i = fc.findLast(":");
int i = fc.findLast(':');
if (i <= 0) return -1;
if (fc[i - 1].toAscii() == ':') return -1;
PIString bs = fc.takeMid(i).mid(1).trim();
@@ -681,11 +681,11 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) {
n.cutRight(suff.size_s());
break;
}
n.push_front(" ");
if (n.find(" static ") >= 0) {n.replaceAll(" static ", ""); pref += "static ";}
if (n.find(" const ") >= 0) {n.replaceAll(" const ", ""); pref += "const ";}
if (n.find(" mutable ") >= 0) {n.replaceAll(" mutable ", ""); pref += "mutable ";}
if (n.find(" volatile ") >= 0) {n.replaceAll(" volatile ", ""); pref += "volatile ";}
n.push_front(' ');
if (n.find(PIStringAscii(" static ")) >= 0) {n.replaceAll(PIStringAscii(" static "), ""); pref += PIStringAscii("static ");}
if (n.find(PIStringAscii(" const ")) >= 0) {n.replaceAll(PIStringAscii(" const "), ""); pref += PIStringAscii("const ");}
if (n.find(PIStringAscii(" mutable ")) >= 0) {n.replaceAll(PIStringAscii(" mutable "), ""); pref += PIStringAscii("mutable ");}
if (n.find(PIStringAscii(" volatile ")) >= 0) {n.replaceAll(PIStringAscii(" volatile "), ""); pref += PIStringAscii("volatile ");}
n.trim();
int f = 0;
piForeachC (Entity * e, entities) {
@@ -694,7 +694,7 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) {
return;
}
if ((f = e->name.find(n)) >= 0)
if (e->name.mid(f - 1, 1) == ":")
if (e->name.mid(f - 1, 1) == PIChar(':'))
if (e->name.find(cur_namespace) >= 0) {
n = pref + e->name + suff;
return;
@@ -702,7 +702,7 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) {
}
piForeachC (Enum & e, enums)
if ((f = e.name.find(n)) >= 0)
if (e.name.mid(f - 1, 1) == ":")
if (e.name.mid(f - 1, 1) == PIChar(':'))
if (e.name.find(cur_namespace) >= 0) {
//piCout << "change" << n << "to" << e.name + suff;
n = pref + e.name + suff;
@@ -710,7 +710,7 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) {
}
piForeachC (Typedef & e, typedefs)
if ((f = e.first.find(n)) >= 0)
if (e.first.mid(f - 1, 1) == ":")
if (e.first.mid(f - 1, 1) == PIChar(':'))
if (e.first.find(cur_namespace) >= 0) {
//piCout << "change" << n << "to" << e.name + suff;
n = pref + e.first + suff;
@@ -723,20 +723,20 @@ void PICodeParser::normalizeEntityNamespace(PIString & n) {
void PICodeParser::restoreTmpTemp(Member * e) {
int i = 0;
piForeach (PIString & a, e->arguments_full) {
while ((i = a.find("$T")) >= 0)
while ((i = a.find(PIStringAscii("$T"))) >= 0)
a.replace(i, 5, tmp_temp[a.mid(i, 5)]);
}
piForeach (PIString & a, e->arguments_type) {
while ((i = a.find("$T")) >= 0)
while ((i = a.find(PIStringAscii("$T"))) >= 0)
a.replace(i, 5, tmp_temp[a.mid(i, 5)]);
}
while ((i = e->type.find("$T")) >= 0)
while ((i = e->type.find(PIStringAscii("$T"))) >= 0)
e->type.replace(i, 5, tmp_temp[e->type.mid(i, 5)]);
}
void PICodeParser::restoreTmpMeta(PICodeParser::Member * e) {
int i = e->name.find("$M");
int i = e->name.find(PIStringAscii("$M"));
if (i < 0) return;
e->meta = tmp_meta[e->name.takeMid(i, 5)];
}
@@ -744,7 +744,7 @@ void PICodeParser::restoreTmpMeta(PICodeParser::Member * e) {
PICodeParser::MetaMap PICodeParser::maybeMeta(PIString & fc) {
PICodeParser::MetaMap ret;
if (fc.left(2) == "$M") {
if (fc.left(2) == PIStringAscii("$M")) {
ret = tmp_meta.value(fc.takeLeft(5));
fc.trim();
}
@@ -754,10 +754,10 @@ PICodeParser::MetaMap PICodeParser::maybeMeta(PIString & fc) {
bool PICodeParser::macroCondition(const PIString & mif, PIString mifcond) {
//piCout << "macroCondition" << mif << mifcond;
if (mif == "ifdef") return isDefineExists(mifcond);
if (mif == "ifndef") return !isDefineExists(mifcond);
if (mif == "if" || mif == "elif") {
mifcond.removeAll(" ").removeAll("\t");
if (mif == PIStringAscii("ifdef")) return isDefineExists(mifcond);
if (mif == PIStringAscii("ifndef")) return !isDefineExists(mifcond);
if (mif == PIStringAscii("if") || mif == PIStringAscii("elif")) {
mifcond.removeAll(' ').removeAll('\t');
return procMacrosCond(mifcond) > 0.;
}
return false;
@@ -770,7 +770,7 @@ double PICodeParser::procMacrosCond(PIString fc) {
int oper = 0, ps = -1;
char cc, nc;
PIString ce;
fc.removeAll("defined");
fc.removeAll(PIStringAscii("defined"));
//piCout << "procMacrosCond" << fc;
while (!fc.isEmpty()) {
cc = fc[0].toAscii();
@@ -825,17 +825,17 @@ double PICodeParser::defineValue(const PIString & dn) {
void PICodeParser::replaceMeta(PIString & dn) {
tmp_meta.clear();
if (dn.isEmpty()) return;
int s = dn.find("PIMETA");
int s = dn.find(PIStringAscii("PIMETA"));
while (s >= 0) {
int ms = 0, ml = 0;
ms = dn.findRange('(', ')', '\\', s + 6, &ml);
if (ms < 0) return;
PIString meta = dn.mid(ms, ml).trim();
PIString rm = "$M" + PIString::fromNumber(tmp_meta.size_s()).expandLeftTo(3, "0");
PIString rm = PIStringAscii("$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("PIMETA");
s = dn.find(PIStringAscii("PIMETA"));
}
}
@@ -849,7 +849,7 @@ PICodeParser::Entity * PICodeParser::findEntityByName(const PIString & en) {
bool PICodeParser::isDeclaration(const PIString & fc, int start, int * end) {
int dind = fc.find("{", start), find = fc.find(";", start);
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;}
@@ -866,11 +866,11 @@ bool PICodeParser::isMainFile(const PIString & fc) {
if (csi < 0) csi = fc.find("\nmain", si);
if (csi < 0) return false;
si = csi;
int fi = fc.find("(", si + 5);
int fi = fc.find('(', si + 5);
if (fi < 0) return false;
if (fi - si < 10) {
PIString ms(fc.mid(si, fi - si + 1));
ms.removeAll(" ").removeAll("\t").removeAll("\n");
ms.removeAll(' ').removeAll('\t').removeAll('\n');
if (ms == "main(") return true;
}
si += 5;
@@ -885,17 +885,17 @@ PIString PICodeParser::procMacros(PIString fc) {
bool grab = false, skip = false, cond_ok = false;
PIString pfc, nfc, line, mif, mifcond;
//piCout << "procMacros\n<******" << fc << "\n******>";
fc += "\n";
fc += '\n';
while (!fc.isEmpty()) {
line = fc.takeLine().trimmed();
if (line.left(1) == "#") {
if (line.left(1) == PIChar('#')) {
mifcond = line.mid(1);
mif = mifcond.takeCWord();
//piCout << mif;
//piCout << "mif mifcond" << mif << mifcond << ifcnt;
if (skip || grab) {
if (mif.left(2) == "if") ifcnt++;
if (mif.left(5) == "endif") {
if (mif.left(2) == PIStringAscii("if")) ifcnt++;
if (mif.left(5) == PIStringAscii("endif")) {
if (ifcnt > 0) ifcnt--;
else {
//piCout << "main endif" << skip << grab;
@@ -904,7 +904,7 @@ PIString PICodeParser::procMacros(PIString fc) {
continue;
}
}
if (mif.left(4) == "elif" && ifcnt == 0) {
if (mif.left(4) == PIStringAscii("elif") && ifcnt == 0) {
//piCout << "main elif" << skip << grab << cond_ok;
if (cond_ok) {
if (grab) {
@@ -929,10 +929,10 @@ PIString PICodeParser::procMacros(PIString fc) {
else {skip = true; grab = false;}
continue;
}
if (grab) nfc << line << "\n";
if (grab) nfc << line << '\n';
continue;
}
if (mif.left(2) == "if") {
if (mif.left(2) == PIStringAscii("if")) {
//piCout << "main if";
skip = grab = cond_ok = false;
if (macroCondition(mif, mifcond.trimmed())) grab = cond_ok = true;
@@ -944,8 +944,8 @@ PIString PICodeParser::procMacros(PIString fc) {
//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;
@@ -957,20 +957,20 @@ bool PICodeParser::parseDirective(PIString d) {
PIString dname = d.takeCWord();
//piCout << "parseDirective" << d;
if (dname == "include") {
d.replaceAll("<", "\"").replaceAll(">", "\"");
PIString cf = cur_file, ifc = d.takeRange("\"", "\"");
d.replaceAll('<', '\"').replaceAll('>', '\"');
PIString cf = cur_file, ifc = d.takeRange('\"', '\"');
if (with_includes) {
bool ret = parseFileInternal(ifc, with_includes);
cur_file = cf;
return ret;
}
}
if (dname == "define") {
if (dname == PIStringAscii("define")) {
PIString mname = d.takeCWord();
//piCout << mname;
if (mname == "PIMETA") return true;
if (d.left(1) == "(") { // macro
PIStringList args = d.takeRange("(", ")").split(",").trim();
if (mname == PIStringAscii("PIMETA")) return true;
if (d.left(1) == PIChar('(')) { // macro
PIStringList args = d.takeRange('(', ')').split(',').trim();
macros << Macro(mname, d.trim(), args);
} else { // define
d.trim();