fix #280 : Using aliased functions are not correctly processed.

This commit is contained in:
Roy Qu 2024-03-19 21:22:46 +08:00
parent 4e2053fb56
commit 7593f99c58
2 changed files with 30 additions and 6 deletions

View File

@ -631,7 +631,12 @@ QList<PStatement> CppParser::listTypeStatements(const QString &fileName, int lin
return doListTypeStatements(fileName,line); return doListTypeStatements(fileName,line);
} }
PStatement CppParser::doFindAliasedStatement(const PStatement &statement) const PStatement CppParser::doFindAliasedStatement(const PStatement &statement) const {
QSet<Statement *> foundSet;
return doFindAliasedStatement(statement,foundSet);
}
PStatement CppParser::doFindAliasedStatement(const PStatement &statement, QSet<Statement *> foundSet) const
{ {
if (!statement) if (!statement)
return PStatement(); return PStatement();
@ -641,11 +646,18 @@ PStatement CppParser::doFindAliasedStatement(const PStatement &statement) const
return PStatement(); return PStatement();
QString nsName=statement->type.mid(0,pos); QString nsName=statement->type.mid(0,pos);
QString name = statement->type.mid(pos+2); QString name = statement->type.mid(pos+2);
PFileIncludes fileIncludes = mPreprocessor.findFileIncludes(statement->fileName);
if (!fileIncludes)
return PStatement();
foundSet.insert(statement.get());
PStatement result;
if (nsName.isEmpty()) { if (nsName.isEmpty()) {
QList<PStatement> resultList = findMembersOfStatement(name,PStatement()); QList<PStatement> resultList = findMembersOfStatement(name,PStatement());
foreach(const PStatement& resultStatement,resultList) { foreach(const PStatement& resultStatement,resultList) {
if (resultStatement->kind != StatementKind::skAlias) if (fileIncludes->includeFiles.contains(resultStatement->fileName)) {
return resultStatement; result = resultStatement;
break;
}
} }
} else { } else {
PStatementList namespaceStatements = doFindNamespace(nsName); PStatementList namespaceStatements = doFindNamespace(nsName);
@ -653,13 +665,22 @@ PStatement CppParser::doFindAliasedStatement(const PStatement &statement) const
return PStatement(); return PStatement();
foreach (const PStatement& namespaceStatement, *namespaceStatements) { foreach (const PStatement& namespaceStatement, *namespaceStatements) {
QList<PStatement> resultList = findMembersOfStatement(name,namespaceStatement); QList<PStatement> resultList = findMembersOfStatement(name,namespaceStatement);
foreach(const PStatement& resultStatement,resultList) { foreach(const PStatement& resultStatement,resultList) {
if (resultStatement->kind != StatementKind::skAlias) if (fileIncludes->includeFiles.contains(resultStatement->fileName)) {
return resultStatement; result = resultStatement;
break;
} }
} }
if (result)
break;
} }
}
if (foundSet.contains(result.get()))
return PStatement(); return PStatement();
if (result->kind == StatementKind::skAlias)
result = doFindAliasedStatement(result, foundSet);
return result;
} }
QList<PStatement> CppParser::doListTypeStatements(const QString &fileName, int line) const QList<PStatement> CppParser::doListTypeStatements(const QString &fileName, int line) const
@ -4602,6 +4623,8 @@ QList<PStatement> CppParser::getListOfFunctions(const QString &fileName, int lin
QSet<QString> includedFiles = internalGetIncludedFiles(fileName); QSet<QString> includedFiles = internalGetIncludedFiles(fileName);
for (const PStatement& child:children) { for (const PStatement& child:children) {
if (statement->command == child->command) { if (statement->command == child->command) {
if (child->kind == StatementKind::skAlias)
continue;
if (!includedFiles.contains(fileName)) if (!includedFiles.contains(fileName))
continue; continue;
if (line < child->line && (child->fileName == fileName)) if (line < child->line && (child->fileName == fileName))

View File

@ -260,6 +260,7 @@ private:
PStatement doFindStatementOf(const QString& fileName, PStatement doFindStatementOf(const QString& fileName,
const QStringList& expression, const QStringList& expression,
int line) const; int line) const;
PStatement doFindAliasedStatement(const PStatement& statement, QSet<Statement *> foundSet) const;
PStatement doFindAliasedStatement(const PStatement& statement) const; PStatement doFindAliasedStatement(const PStatement& statement) const;
QList<PStatement> doListTypeStatements(const QString& fileName,int line) const; QList<PStatement> doListTypeStatements(const QString& fileName,int line) const;