- enhancement: False branches are displayed as comments.

This commit is contained in:
Roy Qu 2023-08-17 13:24:08 +08:00
parent d720421830
commit dd5640d334
7 changed files with 42 additions and 2 deletions

View File

@ -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

View File

@ -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) {

View File

@ -852,6 +852,15 @@ QString CppParser::getHeaderFileName(const QString &relativeTo, const QString &h
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)
{
if (!mEnabled)

View File

@ -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);

View File

@ -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){

View File

@ -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<i)
break;
else
lastI = i;
}
return lastI<0?true:branches[lastI];
}

View File

@ -300,6 +300,8 @@ struct FileIncludes {
StatementMap statements; // but we don't save temporary statements (full name as key)
StatementMap declaredStatements; // statements declared in this file (full name as key)
CppScopes scopes; // int is start line of the statement scope
QMap<int,bool> branches;
bool isLineVisible(int line);
};
using PFileIncludes = std::shared_ptr<FileIncludes>;