- 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: Correct tab orders for all setting pages/dialogs.
- enhancement: Shortcut key for buttons in find/replace and "find in files" 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: 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. - 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: 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 Red Panda C++ Version 2.26
- enhancement: Code suggestion for embedded std::vectors. - enhancement: Code suggestion for embedded std::vectors.

View File

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

View File

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

View File

@ -225,12 +225,7 @@ void ProjectCompiler::writeMakeDefines(QFile &file)
// Get list of applicable flags // Get list of applicable flags
QStringList cCompileArguments = getCCompileArguments(false); QStringList cCompileArguments = getCCompileArguments(false);
QStringList cxxCompileArguments = getCppCompileArguments(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 libraryArguments = getLibraryArguments(FileType::Project);
QStringList cIncludeArguments = getCIncludeArguments(); QStringList cIncludeArguments = getCIncludeArguments();
QStringList cxxIncludeArguments = getCppIncludeArguments(); 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 //last word is a type keyword, this is a var or param define, and dont show suggestion
return; return;
} else if (lastWord == "#ifdef" || lastWord == "#ifndef") { } else if (lastWord == "#ifdef" || lastWord == "#ifndef" || lastWord == "#undef") {
processCommand(QSynedit::EditCommand::Char,ch,nullptr); processCommand(QSynedit::EditCommand::Char,ch,nullptr);
showCompletion(lastWord,false, CodeCompletionType::Macros); showCompletion(lastWord,false, CodeCompletionType::Macros);
handled=true; handled=true;

View File

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