pip_cmg namespaces fix

This commit is contained in:
2022-05-20 15:23:01 +03:00
parent ffa25c18f0
commit 12c032392c
2 changed files with 39 additions and 21 deletions

View File

@@ -321,7 +321,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
PIString prev_namespace = cur_namespace, ccmn; PIString prev_namespace = cur_namespace, ccmn;
cur_namespace += pfc.takeCWord() + s_ns; cur_namespace += pfc.takeCWord() + s_ns;
ccmn = pfc.takeRange('{', '}'); ccmn = pfc.takeRange('{', '}');
parseClass(0, ccmn); parseClass(0, ccmn, true);
cur_namespace = prev_namespace; cur_namespace = prev_namespace;
continue; continue;
} }
@@ -340,7 +340,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
if (dind < 0 || find < dind) {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; ccmn = pfc.left(dind) + s_bo + pfc.mid(dind).takeRange('{', '}') + s_bc;
pfc.remove(0, ccmn.size()); pfc.remove(0, ccmn.size());
parseClass(0, ccmn); parseClass(0, ccmn, false);
continue; continue;
} }
if (pfc.left(4) == s_enum) { if (pfc.left(4) == s_enum) {
@@ -425,7 +425,7 @@ PICodeParser::Entity * PICodeParser::parseClassDeclaration(const PIString & fc)
} }
PIString PICodeParser::parseClass(Entity * parent, PIString & fc) { void PICodeParser::parseClass(Entity * parent, PIString & fc, bool is_namespace) {
static const PIString s_ns = PIStringAscii("::"); static const PIString s_ns = PIStringAscii("::");
static const PIString s_public = PIStringAscii("public"); static const PIString s_public = PIStringAscii("public");
static const PIString s_protected = PIStringAscii("protected"); static const PIString s_protected = PIStringAscii("protected");
@@ -436,22 +436,31 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
static const PIString s_enum = PIStringAscii("enum"); static const PIString s_enum = PIStringAscii("enum");
static const PIString s_friend = PIStringAscii("friend"); static const PIString s_friend = PIStringAscii("friend");
static const PIString s_typedef = PIStringAscii("typedef"); static const PIString s_typedef = PIStringAscii("typedef");
static const PIString s_namespace = PIStringAscii("namespace");
static const PIString s_template = PIStringAscii("template"); 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; int dind = fc.find('{'), find = fc.find(';'), end = 0;
if (dind < 0 && find < 0) return PIString(); if (dind < 0 && find < 0) return;
if (dind < 0 || find < dind) return fc.left(find); if (dind < 0 || find < dind) {
//piCout << "parse class <****\n" << fc.left(20) << "\n****>"; fc.left(find);
Entity * ce = parseClassDeclaration(fc.takeLeft(dind)); return;
fc.trim().cutLeft(1).cutRight(1).trim(); }
//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****>"; //piCout << "found class <****\n" << fc << "\n****>";
if (!ce) return PIString(); ///if (!ce) return PIString();
if (parent) parent->children << ce; if (ce) {
ce->parent_scope = parent; if (parent) parent->children << ce;
ce->parent_scope = parent;
}
int ps = -1; int ps = -1;
bool def = false; bool def = false;
PIString prev_namespace = cur_namespace, stmp; PIString prev_namespace = cur_namespace, stmp;
cur_namespace += ce->name + s_ns; if (ce) cur_namespace += ce->name + s_ns;
//piCout << "parse class" << ce->name << "namespace" << cur_namespace; //piCout << "parse class" << ce->name << "namespace" << cur_namespace;
//piCout << "\nparse class" << ce->name << "namespace" << cur_namespace; //piCout << "\nparse class" << ce->name << "namespace" << cur_namespace;
while (!fc.isEmpty()) { while (!fc.isEmpty()) {
@@ -460,6 +469,14 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
if (cw == s_public ) {cur_def_vis = Public; fc.cutLeft(1); continue;} 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_protected) {cur_def_vis = Protected; fc.cutLeft(1); continue;}
if (cw == s_private ) {cur_def_vis = Private; 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;
ccmn = fc.takeRange('{', '}');
parseClass(ce, ccmn, true);
cur_namespace = prev_namespace;
continue;
}
if (cw == s_class || cw == s_struct || cw == s_union) { if (cw == s_class || cw == s_struct || cw == s_union) {
if (isDeclaration(fc, 0, &end)) { if (isDeclaration(fc, 0, &end)) {
fc.cutLeft(end); fc.cutLeft(end);
@@ -470,7 +487,7 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
stmp = fc.takeRange('{', '}'); stmp = fc.takeRange('{', '}');
fc.takeSymbol(); fc.takeSymbol();
stmp = cw + ' ' + tmp + '{' + stmp + '}'; stmp = cw + ' ' + tmp + '{' + stmp + '}';
parseClass(ce, stmp); parseClass(ce, stmp, false);
continue; continue;
} }
if (cw == s_enum) { if (cw == s_enum) {
@@ -483,11 +500,13 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
} }
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 (cw == s_typedef) {
ce->typedefs << parseTypedef(fc.takeLeft(fc.find(';'))); if (ce) {
typedefs << ce->typedefs.back(); ce->typedefs << parseTypedef(fc.takeLeft(fc.find(';')));
typedefs.back().first.insert(0, cur_namespace); typedefs << ce->typedefs.back();
if (ce->typedefs.back().first.isEmpty()) typedefs.back().first.insert(0, cur_namespace);
ce->typedefs.pop_back(); if (ce->typedefs.back().first.isEmpty())
ce->typedefs.pop_back();
}
fc.takeSymbol(); fc.takeSymbol();
continue; continue;
} }
@@ -501,7 +520,7 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
} }
def = !isDeclaration(fc, 0, &end); def = !isDeclaration(fc, 0, &end);
tmp = (cw + fc.takeLeft(end)).trim(); tmp = (cw + fc.takeLeft(end)).trim();
if (!tmp.isEmpty()) if (!tmp.isEmpty() && ce)
parseMember(ce, tmp); parseMember(ce, tmp);
if (def) fc.takeRange('{', '}'); if (def) fc.takeRange('{', '}');
else fc.takeSymbol(); else fc.takeSymbol();
@@ -510,7 +529,6 @@ PIString PICodeParser::parseClass(Entity * parent, PIString & fc) {
} }
cur_def_vis = prev_vis; cur_def_vis = prev_vis;
cur_namespace = prev_namespace; cur_namespace = prev_namespace;
return ce->name;
} }

View File

@@ -151,7 +151,7 @@ private:
bool parseFileContent(PIString & fc, bool main); bool parseFileContent(PIString & fc, bool main);
bool parseDirective(PIString d); bool parseDirective(PIString d);
Entity * parseClassDeclaration(const PIString & fc); Entity * parseClassDeclaration(const PIString & fc);
PIString parseClass(Entity * parent, PIString & fc); void parseClass(Entity * parent, PIString & fc, bool is_namespace);
MetaMap parseMeta(PIString & fc); MetaMap parseMeta(PIString & fc);
bool parseEnum(Entity * parent, const PIString & name, PIString fc, const MetaMap & meta); bool parseEnum(Entity * parent, const PIString & name, PIString fc, const MetaMap & meta);
Typedef parseTypedef(PIString fc); Typedef parseTypedef(PIString fc);