fix: autolink calculation not stable

This commit is contained in:
Roy Qu 2022-06-04 14:44:50 +08:00
parent f687519fd9
commit cd6e5719b7
5 changed files with 19 additions and 18 deletions

View File

@ -543,8 +543,15 @@ QString Compiler::parseFileIncludesForAutolink(
if (autolink) {
result += ' '+autolink->linkOption;
}
QSet<QString> includedFiles = parser->getFileDirectIncludes(filename);
foreach (const QString& includeFilename, includedFiles) {
QStringList includedFiles = parser->getFileDirectIncludes(filename);
// log(QString("File %1 included:").arg(filename));
// for (int i=includedFiles.size()-1;i>=0;i--) {
// QString includeFilename = includedFiles[i];
// log(includeFilename);
// }
for (int i=includedFiles.size()-1;i>=0;i--) {
QString includeFilename = includedFiles[i];
result += parseFileIncludesForAutolink(
includeFilename,
parsedFiles,

View File

@ -639,25 +639,19 @@ QStringList CppParser::getClassesList()
return list;
}
QSet<QString> CppParser::getFileDirectIncludes(const QString &filename)
QStringList CppParser::getFileDirectIncludes(const QString &filename)
{
QMutexLocker locker(&mMutex);
QSet<QString> list;
if (mParsing)
return list;
return QStringList();
if (filename.isEmpty())
return list;
return QStringList();
PFileIncludes fileIncludes = mPreprocessor.includesList().value(filename,PFileIncludes());
if (fileIncludes) {
QMap<QString, bool>::const_iterator iter = fileIncludes->includeFiles.cbegin();
while (iter != fileIncludes->includeFiles.cend()) {
if (iter.value())
list.insert(iter.key());
iter++;
}
return fileIncludes->directIncludes;
}
return list;
return QStringList();
}

View File

@ -93,7 +93,7 @@ public:
bool freeze(); // Freeze/Lock (stop reparse while searching)
bool freeze(const QString& serialId); // Freeze/Lock (stop reparse while searching)
QStringList getClassesList();
QSet<QString> getFileDirectIncludes(const QString& filename);
QStringList getFileDirectIncludes(const QString& filename);
QSet<QString> getFileIncludes(const QString& filename);
QSet<QString> getFileUsings(const QString& filename);

View File

@ -430,7 +430,7 @@ void CppPreprocessor::handleInclude(const QString &line, bool fromNext)
PFileIncludes oldCurrentIncludes = mCurrentIncludes;
openInclude(fileName);
oldCurrentIncludes->includeFiles.insert(fileName,true);
//oldCurrentIncludes->includeFiles.insert(fileName,true);
}
void CppPreprocessor::handlePreprocessor(const QString &value)
@ -635,14 +635,13 @@ void CppPreprocessor::openInclude(const QString &fileName, QStringList bufferedT
for (PParsedFile& parsedFile:mIncludes) {
parsedFile->fileIncludes->includeFiles.insert(fileName,false);
}
}
if (mIncludes.size()>0) {
// Backup old position if we're entering a new file
PParsedFile innerMostFile = mIncludes.back();
innerMostFile->index = mIndex;
innerMostFile->branches = mBranchResults.count();
innerMostFile->fileIncludes->includeFiles.insert(fileName,true);
innerMostFile->fileIncludes->directIncludes.append(fileName);
}
// // Add the new file to the includes of the current file

View File

@ -223,7 +223,8 @@ private:
struct FileIncludes {
QString baseFile;
QMap<QString,bool> includeFiles; // true means the file is directly included, false means included indirectly
QMap<QString, bool> includeFiles; // true means the file is directly included, false means included indirectly
QStringList directIncludes; //
QSet<QString> usings; // namespaces it usings
StatementMap statements; // but we don't save temporary statements (full name as key)
StatementMap declaredStatements; // statements declared in this file (full name as key)