From df4c14caa46c1853d8027e500de5579e5ccbb0c9 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 8 Mar 2024 08:06:23 +0800 Subject: [PATCH] - fix Issue #211: Using alias for global symbols are not correctly handled. --- RedPandaIDE/parser/cppparser.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 8d53e406..98173aea 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -164,6 +164,10 @@ QList CppParser::getListOfFunctions(const QString &fileName, const Q return result; } } + while(statement && statement->kind == StatementKind::skAlias) + statement = doFindAliasedStatement(statement); + if (!statement) + return result; PStatement parentScope; if (statement->kind == StatementKind::skClass) { parentScope = statement; @@ -393,7 +397,7 @@ PStatement CppParser::doFindStatementOf(const QString &fileName, } //using alias like 'using std::vector;' - if (statement->kind == StatementKind::skAlias) { + while (statement->kind == StatementKind::skAlias) { statement = doFindAliasedStatement(statement); if (!statement) return PStatement(); @@ -637,15 +641,23 @@ PStatement CppParser::doFindAliasedStatement(const PStatement &statement) const return PStatement(); QString nsName=statement->type.mid(0,pos); QString name = statement->type.mid(pos+2); - PStatementList namespaceStatements = doFindNamespace(nsName); - if (!namespaceStatements) - return PStatement(); - foreach (const PStatement& namespaceStatement, *namespaceStatements) { - QList resultList = findMembersOfStatement(name,namespaceStatement); + if (nsName.isEmpty()) { + QList resultList = findMembersOfStatement(name,PStatement()); foreach(const PStatement& resultStatement,resultList) { if (resultStatement->kind != StatementKind::skAlias) return resultStatement; } + } else { + PStatementList namespaceStatements = doFindNamespace(nsName); + if (!namespaceStatements) + return PStatement(); + foreach (const PStatement& namespaceStatement, *namespaceStatements) { + QList resultList = findMembersOfStatement(name,namespaceStatement); + foreach(const PStatement& resultStatement,resultList) { + if (resultStatement->kind != StatementKind::skAlias) + return resultStatement; + } + } } return PStatement(); } @@ -4523,8 +4535,8 @@ void CppParser::internalParse(const QString &fileName) handleInheritances(); // qDebug()<<"parse"<