From cd6e5719b731a300af053bdac325f1745634d3ee Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sat, 4 Jun 2022 14:44:50 +0800 Subject: [PATCH] fix: autolink calculation not stable --- RedPandaIDE/compiler/compiler.cpp | 11 +++++++++-- RedPandaIDE/parser/cppparser.cpp | 16 +++++----------- RedPandaIDE/parser/cppparser.h | 2 +- RedPandaIDE/parser/cpppreprocessor.cpp | 5 ++--- RedPandaIDE/parser/parserutils.h | 3 ++- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/RedPandaIDE/compiler/compiler.cpp b/RedPandaIDE/compiler/compiler.cpp index a609e316..4bf3dec5 100644 --- a/RedPandaIDE/compiler/compiler.cpp +++ b/RedPandaIDE/compiler/compiler.cpp @@ -543,8 +543,15 @@ QString Compiler::parseFileIncludesForAutolink( if (autolink) { result += ' '+autolink->linkOption; } - QSet 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, diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 36516c22..503e17b1 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -639,25 +639,19 @@ QStringList CppParser::getClassesList() return list; } -QSet CppParser::getFileDirectIncludes(const QString &filename) +QStringList CppParser::getFileDirectIncludes(const QString &filename) { QMutexLocker locker(&mMutex); - QSet list; if (mParsing) - return list; + return QStringList(); if (filename.isEmpty()) - return list; + return QStringList(); PFileIncludes fileIncludes = mPreprocessor.includesList().value(filename,PFileIncludes()); if (fileIncludes) { - QMap::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(); } diff --git a/RedPandaIDE/parser/cppparser.h b/RedPandaIDE/parser/cppparser.h index e711fc03..3ff99d0c 100644 --- a/RedPandaIDE/parser/cppparser.h +++ b/RedPandaIDE/parser/cppparser.h @@ -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 getFileDirectIncludes(const QString& filename); + QStringList getFileDirectIncludes(const QString& filename); QSet getFileIncludes(const QString& filename); QSet getFileUsings(const QString& filename); diff --git a/RedPandaIDE/parser/cpppreprocessor.cpp b/RedPandaIDE/parser/cpppreprocessor.cpp index 936b8b77..507a8461 100644 --- a/RedPandaIDE/parser/cpppreprocessor.cpp +++ b/RedPandaIDE/parser/cpppreprocessor.cpp @@ -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 diff --git a/RedPandaIDE/parser/parserutils.h b/RedPandaIDE/parser/parserutils.h index a566a925..266d7b3f 100644 --- a/RedPandaIDE/parser/parserutils.h +++ b/RedPandaIDE/parser/parserutils.h @@ -223,7 +223,8 @@ private: struct FileIncludes { QString baseFile; - QMap includeFiles; // true means the file is directly included, false means included indirectly + QMap includeFiles; // true means the file is directly included, false means included indirectly + QStringList directIncludes; // QSet 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)