Skip to content

Commit

Permalink
- change: Don't turn on "Show some more warnings (-Wextra)" option by…
Browse files Browse the repository at this point in the history
… default for DEBUG compiler set

  - fix: Changes mainwindows's compiler set combobox not correctly handled for project
  - change: Don't localize autogenerated name for new files and new project (new msys2 gcc compiler can't correctly handle non-ascii chars in filenames)
  • Loading branch information
royqh1979 committed Oct 30, 2022
1 parent 819d217 commit 01c1e96
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 76 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Red Panda C++ Version 2.1
- change: escape spaces in the executabe path under linux.
- fix: Before run a project's executable, we should check timestamp for project files AND modification states of files openned in editor.
- change: Don't turn on "Show some more warnings (-Wextra)" option by default for DEBUG compiler set
- fix: Changes mainwindows's compiler set combobox not correctly handled for project
- change: Don't localize autogenerated name for new files and new project (new msys2 gcc compiler can't correctly handle non-ascii chars in filenames)

Red Panda C++ Version 2.0

Expand Down
6 changes: 3 additions & 3 deletions RedPandaIDE/compiler/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ QString Compiler::getCharsetArgument(const QByteArray& encoding,FileType fileTyp

}
if ((forceExecUTF8 || compilerSet()->autoAddCharsetParams()) && encoding != ENCODING_ASCII
&& compilerSet()->compilerType()!=COMPILER_CLANG) {
&& compilerSet()->compilerType()!=CompilerType::Clang) {
QString encodingName;
QString execEncodingName;
QString compilerSetExecCharset = compilerSet()->execCharset();
Expand Down Expand Up @@ -674,13 +674,13 @@ void Compiler::runCommand(const QString &cmd, const QString &arguments, const Q
errorOccurred= true;
});
process.connect(&process, &QProcess::readyReadStandardError,[&process,this](){
if (compilerSet()->compilerType() == COMPILER_CLANG)
if (compilerSet()->compilerType() == CompilerType::Clang)
this->error(QString::fromUtf8(process.readAllStandardError()));
else
this->error(QString::fromLocal8Bit( process.readAllStandardError()));
});
process.connect(&process, &QProcess::readyReadStandardOutput,[&process,this](){
if (compilerSet()->compilerType() == COMPILER_CLANG)
if (compilerSet()->compilerType() == CompilerType::Clang)
this->log(QString::fromUtf8(process.readAllStandardOutput()));
else
this->log(QString::fromLocal8Bit( process.readAllStandardOutput()));
Expand Down
36 changes: 26 additions & 10 deletions RedPandaIDE/compiler/compilerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,48 +180,49 @@ void CompilerInfo::prepareCompilerOptions()

CompilerInfoManager::CompilerInfoManager()
{
mInfos.insert(COMPILER_CLANG, std::make_shared<ClangCompilerInfo>());
mInfos.insert(COMPILER_GCC, std::make_shared<GCCCompilerInfo>());
mInfos.insert(CompilerType::Clang, std::make_shared<ClangCompilerInfo>());
mInfos.insert(CompilerType::GCC, std::make_shared<GCCCompilerInfo>());
mInfos.insert(CompilerType::GCC_UTF8, std::make_shared<GCCUTF8CompilerInfo>());
}

PCompilerInfo CompilerInfoManager::getInfo(const QString &compilerType)
PCompilerInfo CompilerInfoManager::getInfo(CompilerType compilerType)
{
return getInstance()->mInfos.value(compilerType,PCompilerInfo());
}

bool CompilerInfoManager::hasCompilerOption(const QString &compilerType, const QString &optKey)
bool CompilerInfoManager::hasCompilerOption(CompilerType compilerType, const QString &optKey)
{
PCompilerInfo pInfo = getInfo(compilerType);
if (!pInfo)
return false;
return pInfo->hasCompilerOption(optKey);
}

PCompilerOption CompilerInfoManager::getCompilerOption(const QString &compilerType, const QString &optKey)
PCompilerOption CompilerInfoManager::getCompilerOption(CompilerType compilerType, const QString &optKey)
{
PCompilerInfo pInfo = getInfo(compilerType);
if (!pInfo)
return PCompilerOption();
return pInfo->getCompilerOption(optKey);
}

QList<PCompilerOption> CompilerInfoManager::getCompilerOptions(const QString &compilerType)
QList<PCompilerOption> CompilerInfoManager::getCompilerOptions(CompilerType compilerType)
{
PCompilerInfo pInfo = getInfo(compilerType);
if (!pInfo)
return QList<PCompilerOption>();
return pInfo->compilerOptions();
}

bool CompilerInfoManager::supportCovertingCharset(const QString &compilerType)
bool CompilerInfoManager::supportCovertingCharset(CompilerType compilerType)
{
PCompilerInfo pInfo = getInfo(compilerType);
if (!pInfo)
return false;
return pInfo->supportConvertingCharset();
}

bool CompilerInfoManager::forceUTF8InDebugger(const QString &compilerType)
bool CompilerInfoManager::forceUTF8InDebugger(CompilerType compilerType)
{
PCompilerInfo pInfo = getInfo(compilerType);
if (!pInfo)
Expand All @@ -239,9 +240,9 @@ PCompilerInfoManager CompilerInfoManager::getInstance()
return instance;
}

void CompilerInfoManager::addInfo(const QString &name, PCompilerInfo info)
void CompilerInfoManager::addInfo(CompilerType compilerType, PCompilerInfo info)
{
getInstance()->mInfos.insert(name,info);
getInstance()->mInfos.insert(compilerType,info);
}

ClangCompilerInfo::ClangCompilerInfo():CompilerInfo(COMPILER_CLANG)
Expand All @@ -258,6 +259,11 @@ bool ClangCompilerInfo::forceUTF8InDebugger()
return true;
}

bool ClangCompilerInfo::forceUTF8InMakefile()
{
return false;
}

GCCCompilerInfo::GCCCompilerInfo():CompilerInfo(COMPILER_GCC)
{
}
Expand All @@ -272,6 +278,11 @@ bool GCCCompilerInfo::forceUTF8InDebugger()
return false;
}

bool GCCCompilerInfo::forceUTF8InMakefile()
{
return false;
}

GCCUTF8CompilerInfo::GCCUTF8CompilerInfo():CompilerInfo(COMPILER_GCC_UTF8)
{
}
Expand All @@ -285,3 +296,8 @@ bool GCCUTF8CompilerInfo::forceUTF8InDebugger()
{
return true;
}

bool GCCUTF8CompilerInfo::forceUTF8InMakefile()
{
return true;
}
32 changes: 24 additions & 8 deletions RedPandaIDE/compiler/compilerinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@

#define COMPILER_OPTION_ON "on"

enum class CompilerSetType {
RELEASE,
DEBUG,
PROFILING
};

enum class CompilerType {
GCC,
GCC_UTF8,
Clang
};

using CompileOptionChoiceList = QList<QPair<QString,QString>>;

typedef struct {
Expand Down Expand Up @@ -73,6 +85,7 @@ class CompilerInfo

virtual bool supportConvertingCharset()=0;
virtual bool forceUTF8InDebugger()=0;
virtual bool forceUTF8InMakefile()=0;
protected:
void addOption(const QString& key,
const QString& name,
Expand All @@ -98,38 +111,41 @@ using PCompilerInfoManager = std::shared_ptr<CompilerInfoManager>;
class CompilerInfoManager {
public:
CompilerInfoManager();
static PCompilerInfo getInfo(const QString& compilerType);
static bool hasCompilerOption(const QString& compilerType, const QString& optKey);
static PCompilerOption getCompilerOption(const QString& compilerType, const QString& optKey);
static QList<PCompilerOption> getCompilerOptions(const QString& compilerType);
static bool supportCovertingCharset(const QString& compilerType);
static bool forceUTF8InDebugger(const QString& compilerType);
static PCompilerInfo getInfo(CompilerType compilerType);
static bool hasCompilerOption(CompilerType compilerType, const QString& optKey);
static PCompilerOption getCompilerOption(CompilerType compilerType, const QString& optKey);
static QList<PCompilerOption> getCompilerOptions(CompilerType compilerType);
static bool supportCovertingCharset(CompilerType compilerType);
static bool forceUTF8InDebugger(CompilerType compilerType);
static PCompilerInfoManager getInstance();
static void addInfo(const QString& name, PCompilerInfo info);
static void addInfo(CompilerType compilerType, PCompilerInfo info);
private:
static PCompilerInfoManager instance;
QMap<QString,PCompilerInfo> mInfos;
QMap<CompilerType,PCompilerInfo> mInfos;
};

class ClangCompilerInfo: public CompilerInfo{
public:
ClangCompilerInfo();
bool supportConvertingCharset() override;
bool forceUTF8InDebugger() override;
bool forceUTF8InMakefile() override;
};

class GCCCompilerInfo: public CompilerInfo{
public:
GCCCompilerInfo();
bool supportConvertingCharset() override;
bool forceUTF8InDebugger() override;
bool forceUTF8InMakefile() override;
};

class GCCUTF8CompilerInfo: public CompilerInfo{
public:
GCCUTF8CompilerInfo();
bool supportConvertingCharset() override;
bool forceUTF8InDebugger() override;
bool forceUTF8InMakefile() override;
};


Expand Down
2 changes: 1 addition & 1 deletion RedPandaIDE/compiler/projectcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
// Or roll our own
} else {
QString encodingStr;
if (compilerSet()->compilerType() != COMPILER_CLANG && mProject->options().addCharset) {
if (compilerSet()->compilerType() != CompilerType::Clang && mProject->options().addCharset) {
QByteArray defaultSystemEncoding=pCharsetInfoManager->getDefaultSystemEncoding();
QByteArray encoding = mProject->options().execEncoding;
QByteArray targetEncoding;
Expand Down
4 changes: 2 additions & 2 deletions RedPandaIDE/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const char* SaveException::what() const noexcept {
QHash<ParserLanguage,std::weak_ptr<CppParser>> Editor::mSharedParsers;

Editor::Editor(QWidget *parent):
Editor(parent,QObject::tr("untitled"),ENCODING_AUTO_DETECT,nullptr,true,nullptr)
Editor(parent,"untitled",ENCODING_AUTO_DETECT,nullptr,true,nullptr)
{
}

Expand Down Expand Up @@ -104,7 +104,7 @@ Editor::Editor(QWidget *parent, const QString& filename,
mCurrentLineModified = false;
mUseCppSyntax = pSettings->editor().defaultFileCpp();
if (mFilename.isEmpty()) {
mFilename = tr("untitled")+QString("%1").arg(getNewFileNumber());
mFilename = QString("untitled%1").arg(getNewFileNumber());
}
QFileInfo fileInfo(mFilename);
QSynedit::PHighlighter highlighter;
Expand Down
8 changes: 4 additions & 4 deletions RedPandaIDE/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3916,11 +3916,11 @@ void MainWindow::onFilesViewCreateFile()
suffix=".cpp";
else
suffix=".c";
QString fileName = tr("untitled")+suffix;
QString fileName = QString("untitled")+suffix;
int count = 0;
while (dir.exists(fileName)) {
count++;
fileName = tr("untitled%1").arg(count)+suffix;
fileName = QString("untitled%1").arg(count)+suffix;
}
QFile file(dir.filePath(fileName));
file.open(QFile::NewOnly);
Expand Down Expand Up @@ -5044,7 +5044,7 @@ void MainWindow::onCompilerSetChanged(int index)
mCompilerSet->setCurrentIndex(mProject->options().compilerSet);
return;
}
mProject->setCompilerSet(mProject->options().compilerSet);
mProject->setCompilerSet(index);
mProject->saveOptions();
scanActiveProject(true);
return;
Expand Down Expand Up @@ -6669,7 +6669,7 @@ void MainWindow::newProjectUnitFile()
return;
} else {
do {
newFileName = tr("untitled")+QString("%1").arg(getNewFileNumber());
newFileName = QString("untitled")+QString("%1").arg(getNewFileNumber());
if (mProject->options().isCpp)
newFileName += ".cpp";
else
Expand Down
11 changes: 7 additions & 4 deletions RedPandaIDE/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ PProjectUnit Project::newUnit(PProjectModelNode parentNode, const QString& custo
// Find unused 'new' filename
if (customFileName.isEmpty()) {
do {
s = cleanPath(dir.absoluteFilePath(tr("untitled")+QString("%1").arg(getNewFileNumber())));
s = cleanPath(dir.absoluteFilePath(QString("untitled%1").arg(getNewFileNumber())));
} while (fileExists(s));
} else {
s = cleanPath(dir.absoluteFilePath(customFileName));
Expand Down Expand Up @@ -1123,7 +1123,7 @@ void Project::saveOptions()
ini.SetLongValue("Project","IncludeVersionInfo", mOptions.includeVersionInfo);
ini.SetLongValue("Project","SupportXPThemes", mOptions.supportXPThemes);
ini.SetLongValue("Project","CompilerSet", mOptions.compilerSet);
ini.SetLongValue("Project","CompilerSetType", mOptions.compilerSetType);
ini.SetLongValue("Project","CompilerSetType", (int)mOptions.compilerSetType);
ini.Delete("Project","CompilerSettings"); // remove old compiler settings
ini.Delete("CompilerSettings",nullptr); // remove old compiler settings
foreach (const QString& key, mOptions.compilerOptions.keys()) {
Expand Down Expand Up @@ -2043,8 +2043,11 @@ void Project::loadOptions(SimpleIni& ini)
mOptions.execEncoding = ini.GetValue("Project","ExecEncoding", ENCODING_SYSTEM_DEFAULT);
mOptions.addCharset = ini.GetBoolValue("Project", "AddCharset", true);

if (mOptions.compilerSetType<0) {
int val=ini.GetLongValue("Project","CompilerSetType",-1);
if (val<0) {
updateCompilerSetType();
} else {
mOptions.compilerSetType=(CompilerSetType)val;
}
bool useUTF8 = ini.GetBoolValue("Project", "UseUTF8", false);
if (useUTF8) {
Expand Down Expand Up @@ -2179,7 +2182,7 @@ void Project::updateCompilerSetType()
mOptions.staticLink = defaultSet->staticLink();
mOptions.compilerOptions = defaultSet->compileOptions();
} else {
mOptions.compilerSetType=CST_DEBUG;
mOptions.compilerSetType=CompilerSetType::DEBUG;
mOptions.staticLink = false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion RedPandaIDE/projectoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ProjectOptions::ProjectOptions()
includeVersionInfo = false;
supportXPThemes = false;
compilerSet = 0;
compilerSetType = 0;
compilerSetType = CompilerSetType::DEBUG;
staticLink = true;
addCharset = true;
modelType = ProjectModelType::FileSystem;
Expand Down
3 changes: 2 additions & 1 deletion RedPandaIDE/projectoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <QMap>
#include <QWidget>
#include "compiler/compilerinfo.h"

enum class ProjectModelType {
FileSystem,
Expand Down Expand Up @@ -88,7 +89,7 @@ struct ProjectOptions{
bool includeVersionInfo;
bool supportXPThemes;
int compilerSet;
int compilerSetType;
CompilerSetType compilerSetType;
QMap<QString,QString> compilerOptions;
ProjectVersionInfo versionInfo;
QString cmdLineArgs;
Expand Down
Loading

0 comments on commit 01c1e96

Please sign in to comment.