fix: #include_next processing

This commit is contained in:
royqh1979@gmail.com 2021-10-04 22:32:34 +08:00
parent 2f76aa42a8
commit 3ed5701621
9 changed files with 75 additions and 45 deletions

View File

@ -18,6 +18,7 @@ Version 0.6.0
- implement: open files pasted by clipboard
- fix: code fold parsing not correct
- enhancement: support #include_next (and clang libc++)
- fix: hide popup windows when the editor is closed
Version 0.5.0
- enhancement: support C++ using type alias;

View File

@ -472,12 +472,6 @@ void Editor::focusOutEvent(QFocusEvent *event)
this,
&SynEdit::invalidate);
}
if (mHeaderCompletionPopup)
mHeaderCompletionPopup->hide();
if (mCompletionPopup)
mCompletionPopup->hide();
if (pMainWindow->functionTip())
pMainWindow->functionTip()->hide();
//pMainWindow->updateClassBrowserForEditor(nullptr);
pMainWindow->updateEditorActions();
pMainWindow->updateStatusbarForLineCol();
@ -1074,6 +1068,16 @@ void Editor::inputMethodEvent(QInputMethodEvent *event)
}
}
void Editor::closeEvent(QCloseEvent *)
{
if (mHeaderCompletionPopup)
mHeaderCompletionPopup->hide();
if (mCompletionPopup)
mCompletionPopup->hide();
if (pMainWindow->functionTip())
pMainWindow->functionTip()->hide();
}
void Editor::copyToClipboard()
{
if (pSettings->editor().copySizeLimit()) {

View File

@ -289,6 +289,10 @@ protected:
// QWidget interface
protected:
void inputMethodEvent(QInputMethodEvent *) override;
// QWidget interface
protected:
void closeEvent(QCloseEvent *event) override;
};
QString getWordAtPosition(SynEdit* editor,

View File

@ -558,8 +558,8 @@ QSet<QString> CppParser::getFileUsings(const QString &filename)
QString CppParser::getHeaderFileName(const QString &relativeTo, const QString &line)
{
QMutexLocker locker(&mMutex);
return ::getHeaderFilename(relativeTo, line, mPreprocessor.includePaths(),
mPreprocessor.projectIncludePaths());
return ::getHeaderFilename(relativeTo, line, mPreprocessor.includePathList(),
mPreprocessor.projectIncludePathList());
}
StatementKind CppParser::getKindOfStatement(const PStatement& statement)

View File

@ -4,6 +4,7 @@
#include <QFile>
#include <QTextCodec>
#include <QDebug>
#include <QMessageBox>
CppPreprocessor::CppPreprocessor()
{
@ -214,14 +215,18 @@ void CppPreprocessor::dumpIncludesListTo(const QString &fileName) const
void CppPreprocessor::addIncludePath(const QString &fileName)
{
mIncludePaths.insert(fileName);
mIncludePathList.append(fileName);
if (!mIncludePaths.contains(fileName)) {
mIncludePaths.insert(fileName);
mIncludePathList.append(fileName);
}
}
void CppPreprocessor::addProjectIncludePath(const QString &fileName)
{
mProjectIncludePaths.insert(fileName);
mProjectIncludeList.append(fileName);
if (!mProjectIncludePaths.contains(fileName)) {
mProjectIncludePaths.insert(fileName);
mProjectIncludePathList.append(fileName);
}
}
void CppPreprocessor::clearIncludePaths()
@ -233,7 +238,7 @@ void CppPreprocessor::clearIncludePaths()
void CppPreprocessor::clearProjectIncludePaths()
{
mProjectIncludePaths.clear();
mProjectIncludeList.clear();
mProjectIncludePathList.clear();
}
QString CppPreprocessor::getNextPreprocessor()
@ -356,28 +361,30 @@ void CppPreprocessor::handleInclude(const QString &line, bool fromNext)
QString fileName;
// Get full header file name
QString currentDir = includeTrailingPathDelimiter(extractFileDir(file->fileName));
QSet<QString> includes;
QSet<QString> projectIncludes;
if (fromNext && mIncludePaths.contains(currentDir)) {
bool found = false;
foreach(const QString& s, mIncludePathList) {
if (found)
includes.insert(s);
if (s == currentDir)
found = true;
QStringList includes;
QStringList projectIncludes;
bool found;
if (fromNext && mIncludePaths.contains(currentDir))
found = false;
else
found = true;
foreach(const QString& s, mIncludePathList) {
if (found) {
includes.append(s);
}
} else
includes = mIncludePaths;
if (fromNext && mProjectIncludePaths.contains(currentDir)) {
bool found = false;
foreach(const QString& s, mProjectIncludeList) {
if (found)
projectIncludes.insert(s);
if (s == currentDir)
found = true;
}
} else
projectIncludes = mProjectIncludePaths;
if (s == currentDir)
found = true;
}
if (fromNext && mProjectIncludePaths.contains(currentDir))
found = false;
else
found = true;
foreach(const QString& s, mProjectIncludePathList) {
if (found)
projectIncludes.append(s);
if (s == currentDir)
found = true;
}
fileName = getHeaderFilename(
file->fileName,
line,
@ -403,10 +410,10 @@ void CppPreprocessor::handlePreprocessor(const QString &value)
|| value.startsWith("else") || value.startsWith("elif")
|| value.startsWith("endif"))
handleBranch(value);
else if (value.startsWith("include"))
handleInclude(value);
else if (value.startsWith("include_next"))
handleInclude(value,true);
else if (value.startsWith("include"))
handleInclude(value);
}
void CppPreprocessor::handleUndefine(const QString &line)
@ -1710,6 +1717,16 @@ int CppPreprocessor::evaluateExpression(QString line)
return result;
}
const QList<QString> &CppPreprocessor::projectIncludePathList() const
{
return mProjectIncludePathList;
}
const QList<QString> &CppPreprocessor::includePathList() const
{
return mIncludePathList;
}
const DefineMap &CppPreprocessor::hardDefines() const
{
return mHardDefines;

View File

@ -76,6 +76,10 @@ public:
const DefineMap &hardDefines() const;
const QList<QString> &includePathList() const;
const QList<QString> &projectIncludePathList() const;
signals:
private:
@ -189,7 +193,7 @@ private:
QSet<QString> mProjectIncludePaths;
//we also need include paths in order (for #include_next)
QList<QString> mIncludePathList;
QList<QString> mProjectIncludeList;
QList<QString> mProjectIncludePathList;
bool mParseSystem;
bool mParseLocal;

View File

@ -294,7 +294,7 @@ void initParser()
}
QString getHeaderFilename(const QString &relativeTo, const QString &line,
const QSet<QString>& includePaths, const QSet<QString>& projectIncludePaths) {
const QStringList& includePaths, const QStringList& projectIncludePaths) {
QString result = "";
// Handle <>
@ -341,7 +341,7 @@ QString getLocalHeaderFilename(const QString &relativeTo, const QString &fileNam
return "";
}
QString getSystemHeaderFilename(const QString &fileName, const QSet<QString>& includePaths)
QString getSystemHeaderFilename(const QString &fileName, const QStringList& includePaths)
{
// Search compiler include directories

View File

@ -196,11 +196,11 @@ extern QSet<QString> STLElementMethods;
void initParser();
QString getHeaderFilename(const QString& relativeTo, const QString& line,
const QSet<QString>& includePaths, const QSet<QString>& projectIncludePaths);
const QStringList& includePaths, const QStringList& projectIncludePaths);
QString getLocalHeaderFilename(const QString& relativeTo, const QString& fileName);
QString getSystemHeaderFilename(const QString& fileName, const QSet<QString>& includePaths);
QString getSystemHeaderFilename(const QString& fileName, const QStringList& includePaths);
bool isSystemHeaderFile(const QString& fileName, const QSet<QString>& includePaths);
bool isHfile(const QString& filename);
bool isCfile(const QString& filename);

View File

@ -557,16 +557,16 @@ void resetCppParser(std::shared_ptr<CppParser> parser)
Settings::PCompilerSet compilerSet = pSettings->compilerSets().defaultSet();
parser->clearIncludePaths();
if (compilerSet) {
for (QString file:compilerSet->CIncludeDirs()) {
foreach (const QString& file,compilerSet->CppIncludeDirs()) {
parser->addIncludePath(file);
}
for (QString file:compilerSet->CppIncludeDirs()) {
foreach (const QString& file,compilerSet->CIncludeDirs()) {
parser->addIncludePath(file);
}
for (QString file:compilerSet->defaultCIncludeDirs()) {
foreach (const QString& file,compilerSet->defaultCppIncludeDirs()) {
parser->addIncludePath(file);
}
for (QString file:compilerSet->defaultCppIncludeDirs()) {
foreach (const QString& file,compilerSet->defaultCIncludeDirs()) {
parser->addIncludePath(file);
}
//TODO: Add default include dirs last, just like gcc does