From dd5640d334c1359778957a819e2ea32883b97bd6 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 17 Aug 2023 13:24:08 +0800 Subject: [PATCH] - enhancement: False branches are displayed as comments. --- NEWS.md | 1 + RedPandaIDE/editor.cpp | 7 +++++++ RedPandaIDE/parser/cppparser.cpp | 11 ++++++++++- RedPandaIDE/parser/cppparser.h | 1 + RedPandaIDE/parser/cpppreprocessor.h | 10 +++++++++- RedPandaIDE/parser/parserutils.cpp | 12 ++++++++++++ RedPandaIDE/parser/parserutils.h | 2 ++ 7 files changed, 42 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 8f161887..bed26140 100644 --- a/NEWS.md +++ b/NEWS.md @@ -32,6 +32,7 @@ Red Panda C++ Version 2.24 - fix: Press up/down arrow key in the option dialog's left panel won't switch page. - fix: Can't suggest header filename starting with numbers. - enhancement: Better layout for compiler options page. + - enhancement: False branches are displayed as comments. Red Panda C++ Version 2.23 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 563c8226..7147012f 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1136,6 +1136,13 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to return; if (mParser && syntaxer()) { + if (!mParser->isLineVisible(mFilename, line)) { + if (syntaxer()->commentAttribute()->foreground().isValid()) + foreground = syntaxer()->commentAttribute()->foreground(); + if (syntaxer()->commentAttribute()->background().isValid()) + background = syntaxer()->commentAttribute()->background(); + return; + } QString lineText = document()->getLine(line-1); if (mParser->isIncludeLine(lineText)) { if (cursor() == Qt::PointingHandCursor) { diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index a13e7575..fe0203c6 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -849,7 +849,16 @@ QString CppParser::getHeaderFileName(const QString &relativeTo, const QString &h projectIncludes = mPreprocessor.projectIncludePathList(); } return ::getHeaderFilename(relativeTo, headerName, includes, - projectIncludes); + projectIncludes); +} + +bool CppParser::isLineVisible(const QString &fileName, int line) +{ + QMutexLocker locker(&mMutex); + PFileIncludes fileIncludes = mPreprocessor.includesList().value(fileName); + if (!fileIncludes) + return true; + return fileIncludes->isLineVisible(line); } void CppParser::invalidateFile(const QString &fileName) diff --git a/RedPandaIDE/parser/cppparser.h b/RedPandaIDE/parser/cppparser.h index 7c3d293b..9cff2f01 100644 --- a/RedPandaIDE/parser/cppparser.h +++ b/RedPandaIDE/parser/cppparser.h @@ -104,6 +104,7 @@ public: QString getHeaderFileName(const QString& relativeTo, const QString& headerName, bool fromNext=false);// both void invalidateFile(const QString& fileName); + bool isLineVisible(const QString& fileName, int line); bool isIncludeLine(const QString &line); bool isIncludeNextLine(const QString &line); bool isProjectHeaderFile(const QString& fileName); diff --git a/RedPandaIDE/parser/cpppreprocessor.h b/RedPandaIDE/parser/cpppreprocessor.h index ca94a367..cae71c39 100644 --- a/RedPandaIDE/parser/cpppreprocessor.h +++ b/RedPandaIDE/parser/cpppreprocessor.h @@ -137,11 +137,19 @@ private: return true; } void setCurrentBranch(bool value){ + if (value!=getCurrentBranch()) { + mCurrentIncludes->branches.insert(mIndex+1,value); + } mBranchResults.append(value); } void removeCurrentBranch(){ - if (mBranchResults.size()>0) + bool result = getCurrentBranch(); + if (mBranchResults.size()>0) { mBranchResults.pop_back(); + } + if (getCurrentBranch()!=result) { + mCurrentIncludes->branches.insert(mIndex,getCurrentBranch()); + } }; // include stuff PFileIncludes getFileIncludesEntry(const QString& fileName){ diff --git a/RedPandaIDE/parser/parserutils.cpp b/RedPandaIDE/parser/parserutils.cpp index e81eefbb..2dbd7e61 100644 --- a/RedPandaIDE/parser/parserutils.cpp +++ b/RedPandaIDE/parser/parserutils.cpp @@ -765,3 +765,15 @@ bool isTypeKind(StatementKind kind) return false; } } + +bool FileIncludes::isLineVisible(int line) +{ + int lastI=-1; + foreach(int i,branches.keys()) { + if (line branches; + bool isLineVisible(int line); }; using PFileIncludes = std::shared_ptr;