diff --git a/NEWS.md b/NEWS.md index f2478a5d..b03786d8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/RedPandaIDE/compiler/compiler.cpp b/RedPandaIDE/compiler/compiler.cpp index d3566b07..d9dd4d9a 100644 --- a/RedPandaIDE/compiler/compiler.cpp +++ b/RedPandaIDE/compiler/compiler.cpp @@ -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; } diff --git a/RedPandaIDE/compiler/filecompiler.cpp b/RedPandaIDE/compiler/filecompiler.cpp index bf9afd65..e50e58e3 100644 --- a/RedPandaIDE/compiler/filecompiler.cpp +++ b/RedPandaIDE/compiler/filecompiler.cpp @@ -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); diff --git a/RedPandaIDE/compiler/projectcompiler.cpp b/RedPandaIDE/compiler/projectcompiler.cpp index f4891244..b003ff84 100644 --- a/RedPandaIDE/compiler/projectcompiler.cpp +++ b/RedPandaIDE/compiler/projectcompiler.cpp @@ -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(); diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 69305ce5..e807501e 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -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; diff --git a/RedPandaIDE/parser/cpppreprocessor.cpp b/RedPandaIDE/parser/cpppreprocessor.cpp index 09aadb6c..254273bd 100644 --- a/RedPandaIDE/parser/cpppreprocessor.cpp +++ b/RedPandaIDE/parser/cpppreprocessor.cpp @@ -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(); + mFileUndefines.insert(mFileName,undefineMap); + } + if (!undefineMap->contains(name)) + undefineMap->insert(name, define); } } } diff --git a/RedPandaIDE/parser/cpppreprocessor.h b/RedPandaIDE/parser/cpppreprocessor.h index e90af39d..aee839a8 100644 --- a/RedPandaIDE/parser/cpppreprocessor.h +++ b/RedPandaIDE/parser/cpppreprocessor.h @@ -274,6 +274,7 @@ private: //used by parser even preprocess finished QHash mIncludesList; QHash mFileDefines; //dictionary to save defines for each headerfile; + QHash mFileUndefines; //dictionary to save defines for each headerfile; QSet mScannedFiles; //option data for the parser