- fix: Remove duplicated macro defines make it's lost in the parse result.

- fix: An undefined macro is still missing the the parse result after #undef is removed.
This commit is contained in:
Roy Qu 2024-03-26 16:33:22 +08:00
parent 8ca693f8dc
commit df992c5cbc
7 changed files with 38 additions and 12 deletions

View File

@ -89,9 +89,11 @@ Red Panda C++ Version 2.27
- enhancement: Correct tab orders for all setting pages/dialogs.
- enhancement: Shortcut key for buttons in find/replace and "find in files" dialogs.
- enhancement: Auto define macro "_DEBUG" for "Debug" compiler set(like visual studio).
- enhancement: Suggest macro names after "#ifdef"/"#ifndef".
- enhancement: Suggest macro names after "#ifdef"/"#ifndef"/"#undef".
- enhancement: If contents from stderr are logged into "Tools Output" panel, add problem case name info to the log.
- fix: In split screen mode, editor on the right can't be correctly found by commands.
- fix: Remove duplicated macro defines make it's lost in the parse result.
- fix: An undefined macro is still missing the the parse result after #undef is removed.
Red Panda C++ Version 2.26
- enhancement: Code suggestion for embedded std::vectors.

View File

@ -452,6 +452,10 @@ QStringList Compiler::getCCompileArguments(bool checkSyntax)
result << parseArguments(s, macros, true);
}
}
if (result.contains("-g3")) {
result << "-D_DEBUG";
}
return result;
}
@ -493,6 +497,10 @@ QStringList Compiler::getCppCompileArguments(bool checkSyntax)
result << parseArguments(s, macros, true);
}
}
if (result.contains("-g3")) {
result << "-D_DEBUG";
}
return result;
}

View File

@ -138,9 +138,6 @@ bool FileCompiler::prepareForCompile()
default:
throw CompileError(tr("Can't find the compiler for file %1").arg(mFilename));
}
if (mArguments.contains("-g3")) {
mArguments << "-D_DEBUG";
}
if (!mOnlyCheckSyntax)
mArguments += getLibraryArguments(fileType);

View File

@ -225,12 +225,7 @@ void ProjectCompiler::writeMakeDefines(QFile &file)
// Get list of applicable flags
QStringList cCompileArguments = getCCompileArguments(false);
QStringList cxxCompileArguments = getCppCompileArguments(false);
if (cCompileArguments.contains("-g3")) {
cCompileArguments << "-D_DEBUG";
}
if (cxxCompileArguments.contains("-g3")) {
cxxCompileArguments << "-D_DEBUG";
}
QStringList libraryArguments = getLibraryArguments(FileType::Project);
QStringList cIncludeArguments = getCIncludeArguments();
QStringList cxxIncludeArguments = getCppIncludeArguments();

View File

@ -928,7 +928,7 @@ void Editor::keyPressEvent(QKeyEvent *event)
//last word is a type keyword, this is a var or param define, and dont show suggestion
return;
} else if (lastWord == "#ifdef" || lastWord == "#ifndef") {
} else if (lastWord == "#ifdef" || lastWord == "#ifndef" || lastWord == "#undef") {
processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion(lastWord,false, CodeCompletionType::Macros);
handled=true;

View File

@ -35,6 +35,7 @@ void CppPreprocessor::clear()
//used by parser even preprocess finished
mIncludesList.clear();
mFileDefines.clear(); //dictionary to save defines for each headerfile;
mFileUndefines.clear(); //dictionary to save undefines for each headerfile;
mScannedFiles.clear();
//option data for the parser
@ -175,16 +176,28 @@ void CppPreprocessor::preprocess(const QString &fileName)
void CppPreprocessor::invalidDefinesInFile(const QString &fileName)
{
//remove all defines defined in this file
PDefineMap defineMap = mFileDefines.value(fileName,PDefineMap());
if (defineMap) {
foreach (const PDefine& define, *defineMap) {
const PDefine& p = mDefines.value(define->name);
if (p == define) {
mDefines.remove(define->name);
PDefine p2 = mHardDefines.value(define->name);
if (p2)
mDefines.insert(define->name, p2);
}
}
mFileDefines.remove(fileName);
}
//restore all defines undefined in this file
PDefineMap undefineMap = mFileUndefines.value(fileName,PDefineMap());
if (undefineMap) {
foreach (const PDefine& define, *undefineMap) {
mDefines.insert(define->name, define);
}
mFileUndefines.remove(fileName);
}
}
void CppPreprocessor::dumpDefinesTo(const QString &fileName) const
@ -312,6 +325,7 @@ void CppPreprocessor::removeScannedFile(const QString &filename)
mScannedFiles.remove(filename);
mIncludesList.remove(filename);
mFileDefines.remove(filename);
mFileUndefines.remove(filename);
}
QString CppPreprocessor::getNextPreprocessor()
@ -505,12 +519,21 @@ void CppPreprocessor::handleUndefine(const QString &line)
if (define) {
//remove the define from defines set
mDefines.remove(name);
//remove the define form the file where it defines
if (define->filename == mFileName) {
//remove the define form the file where it defines
PDefineMap defineMap = mFileDefines.value(mFileName);
if (defineMap) {
defineMap->remove(name);
}
} else {
// add it to undefine map
PDefineMap undefineMap = mFileUndefines.value(mFileName);
if (!undefineMap) {
undefineMap = std::make_shared<DefineMap>();
mFileUndefines.insert(mFileName,undefineMap);
}
if (!undefineMap->contains(name))
undefineMap->insert(name, define);
}
}
}

View File

@ -274,6 +274,7 @@ private:
//used by parser even preprocess finished
QHash<QString,PFileIncludes> mIncludesList;
QHash<QString, PDefineMap> mFileDefines; //dictionary to save defines for each headerfile;
QHash<QString, PDefineMap> mFileUndefines; //dictionary to save defines for each headerfile;
QSet<QString> mScannedFiles;
//option data for the parser