add infrastructure for number compiler options

This commit is contained in:
Roy Qu 2024-05-04 21:03:40 +08:00
parent ce97272fc0
commit c19ca5e362
5 changed files with 101 additions and 7 deletions

View File

@ -159,7 +159,7 @@ Red Panda C++ Version 2.27
- fix: In options -> code format -> Program, Choose astyle path button doesn't work. - fix: In options -> code format -> Program, Choose astyle path button doesn't work.
- fix: project not correctly reparsed after rename unit. - fix: project not correctly reparsed after rename unit.
- enhancement: support C++ 17 structured binding in stl map containers foreach loop. - enhancement: support C++ 17 structured binding in stl map containers foreach loop.
- fix: Crash when has source line like "std::cout << (3+4*4>5*(4+3)-1 && (4-3>5)) <<std::endl;"; - fix: Crash when has source line like "std::cout << (3+4*4>5*(4+3)-1 && (4-3>5)) <<std::endl;".
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

@ -433,7 +433,14 @@ QStringList Compiler::getCCompileArguments(bool checkSyntax)
result << pOption->setting; result << pOption->setting;
else if (pOption->type == CompilerOptionType::Input) else if (pOption->type == CompilerOptionType::Input)
result += {pOption->setting, compileOptions[key]}; result += {pOption->setting, compileOptions[key]};
else { else if (pOption->type == CompilerOptionType::Number) {
bool ok;
int val = compileOptions[key].toInt(&ok);
if (ok) {
val = pOption->scale * val;
result += QString("%1%2").arg(pOption->setting).arg(val);
}
} else {
result << pOption->setting + compileOptions[key]; result << pOption->setting + compileOptions[key];
} }
} }
@ -480,7 +487,14 @@ QStringList Compiler::getCppCompileArguments(bool checkSyntax)
result << pOption->setting; result << pOption->setting;
else if (pOption->type == CompilerOptionType::Input) else if (pOption->type == CompilerOptionType::Input)
result += {pOption->setting, compileOptions[key]}; result += {pOption->setting, compileOptions[key]};
else { else if (pOption->type == CompilerOptionType::Number) {
bool ok;
int val = compileOptions[key].toInt(&ok);
if (ok) {
val = pOption->scale * val;
result += QString("%1%2").arg(pOption->setting).arg(val);
}
} else {
result << pOption->setting + compileOptions[key]; result << pOption->setting + compileOptions[key];
} }
} }
@ -590,7 +604,14 @@ QStringList Compiler::getLibraryArguments(FileType fileType)
result << pOption->setting; result << pOption->setting;
else if (pOption->type == CompilerOptionType::Input) else if (pOption->type == CompilerOptionType::Input)
result += {pOption->setting, compileOptions[key]}; result += {pOption->setting, compileOptions[key]};
else { else if (pOption->type == CompilerOptionType::Number) {
bool ok;
int val = compileOptions[key].toInt(&ok);
if (ok) {
val = pOption->scale * val;
result += QString("%1%2").arg(pOption->setting).arg(val);
}
} else {
result << pOption->setting + compileOptions[key]; result << pOption->setting + compileOptions[key];
} }
} }

View File

@ -32,7 +32,7 @@ bool CompilerInfo::supportSyntaxCheck()
return true; return true;
} }
void CompilerInfo::addOption(const QString &key, const QString &name, PCompilerOption CompilerInfo::addOption(const QString &key, const QString &name,
const QString section, bool isC, bool isCpp, bool isLinker, const QString &setting, const QString section, bool isC, bool isCpp, bool isLinker, const QString &setting,
CompilerOptionType type, const CompileOptionChoiceList &choices) CompilerOptionType type, const CompileOptionChoiceList &choices)
{ {
@ -47,8 +47,30 @@ void CompilerInfo::addOption(const QString &key, const QString &name,
pOption->setting= setting; pOption->setting= setting;
pOption->type = type; pOption->type = type;
pOption->choices = choices; pOption->choices = choices;
pOption->scale = 1;
mCompilerOptions.insert(key,pOption); mCompilerOptions.insert(key,pOption);
mCompilerOptionList.append(pOption); mCompilerOptionList.append(pOption);
return pOption;
}
PCompilerOption CompilerInfo::addNumberOption(const QString &key, const QString &name, const QString section, bool isC, bool isCpp, bool isLinker, const QString &setting, const QString &suffix, int scale, int minValue, int maxValue)
{
PCompilerOption pOption = std::make_shared<CompilerOption>();
pOption->key = key;
pOption->name = name;
pOption->section = section;
pOption->isC = isC;
pOption->isCpp = isCpp;
pOption->isLinker = isLinker;
pOption->setting= setting;
pOption->type = CompilerOptionType::Number;
pOption->unit = suffix;
pOption->scale = scale;
pOption->minValue = minValue;
pOption->maxValue = maxValue;
mCompilerOptions.insert(key,pOption);
mCompilerOptionList.append(pOption);
return pOption;
} }
void CompilerInfo::init() void CompilerInfo::init()
@ -194,6 +216,8 @@ void CompilerInfo::prepareCompilerOptions()
// Linker // Linker
groupName = QObject::tr("Linker"); groupName = QObject::tr("Linker");
//addNumberOption(LINK_CMD_OPT_STACK_SIZE, QObject::tr("Stack Size"), groupName, false, false, true, "-Wl,--stack,","MB",1024*1024,0,99999);
addOption(CC_CMD_OPT_USE_PIPE, QObject::tr("Use pipes instead of temporary files during compilation (-pipe)"), groupName, true, true, false, "-pipe"); addOption(CC_CMD_OPT_USE_PIPE, QObject::tr("Use pipes instead of temporary files during compilation (-pipe)"), groupName, true, true, false, "-pipe");
//addOption(LINK_CMD_OPT_LINK_OBJC, QObject::tr("Link an Objective C program (-lobjc)"), groupName, false, false, true, "-lobjc"); //addOption(LINK_CMD_OPT_LINK_OBJC, QObject::tr("Link an Objective C program (-lobjc)"), groupName, false, false, true, "-lobjc");
addOption(LINK_CMD_OPT_NO_LINK_STDLIB,QObject::tr("Do not use standard system libraries (-nostdlib)"), groupName, false, false, true, "-nostdlib"); addOption(LINK_CMD_OPT_NO_LINK_STDLIB,QObject::tr("Do not use standard system libraries (-nostdlib)"), groupName, false, false, true, "-nostdlib");

View File

@ -39,6 +39,7 @@
#define LINK_CMD_OPT_NO_LINK_STDLIB "link_cmd_opt_no_link_stdlib" #define LINK_CMD_OPT_NO_LINK_STDLIB "link_cmd_opt_no_link_stdlib"
#define LINK_CMD_OPT_NO_CONSOLE "link_cmd_opt_no_console" #define LINK_CMD_OPT_NO_CONSOLE "link_cmd_opt_no_console"
#define LINK_CMD_OPT_STRIP_EXE "link_cmd_opt_strip_exe" #define LINK_CMD_OPT_STRIP_EXE "link_cmd_opt_strip_exe"
#define LINK_CMD_OPT_STACK_SIZE "link_cmd_opt_stack_size"
#define CC_CMD_OPT_DEBUG_INFO "cc_cmd_opt_debug_info" #define CC_CMD_OPT_DEBUG_INFO "cc_cmd_opt_debug_info"
#define CC_CMD_OPT_ADDRESS_SANITIZER "cc_cmd_opt_address_sanitizer" #define CC_CMD_OPT_ADDRESS_SANITIZER "cc_cmd_opt_address_sanitizer"
#define CC_CMD_OPT_STACK_PROTECTOR "cc_cmd_opt_stack_protector" #define CC_CMD_OPT_STACK_PROTECTOR "cc_cmd_opt_stack_protector"
@ -85,7 +86,8 @@ enum class CompilerType {
enum class CompilerOptionType { enum class CompilerOptionType {
Checkbox, Checkbox,
Choice, Choice,
Input Input,
Number
}; };
using CompileOptionChoiceList = QList<QPair<QString,QString>>; using CompileOptionChoiceList = QList<QPair<QString,QString>>;
@ -100,6 +102,11 @@ typedef struct {
QString setting; // "-g3" QString setting; // "-g3"
CompilerOptionType type; CompilerOptionType type;
CompileOptionChoiceList choices; // replaces "Yes/No" standard choices (max 30 different choices) CompileOptionChoiceList choices; // replaces "Yes/No" standard choices (max 30 different choices)
/* for spin control */
QString unit; //suffix
int scale; //Scale
int minValue;
int maxValue;
} CompilerOption; } CompilerOption;
using PCompilerOption = std::shared_ptr<CompilerOption>; using PCompilerOption = std::shared_ptr<CompilerOption>;
@ -125,7 +132,7 @@ public:
virtual bool supportStaticLink()=0; virtual bool supportStaticLink()=0;
virtual bool supportSyntaxCheck(); virtual bool supportSyntaxCheck();
protected: protected:
void addOption(const QString& key, PCompilerOption addOption(const QString& key,
const QString& name, const QString& name,
const QString section, const QString section,
bool isC, bool isC,
@ -134,6 +141,18 @@ protected:
const QString& setting, const QString& setting,
CompilerOptionType type = CompilerOptionType::Checkbox, CompilerOptionType type = CompilerOptionType::Checkbox,
const CompileOptionChoiceList& choices = CompileOptionChoiceList()); const CompileOptionChoiceList& choices = CompileOptionChoiceList());
PCompilerOption addNumberOption(const QString& key,
const QString& name,
const QString section,
bool isC,
bool isCpp,
bool isLinker,
const QString& setting,
const QString& suffix,
int scale,
int minValue,
int maxValue
);
virtual void prepareCompilerOptions(); virtual void prepareCompilerOptions();
protected: protected:
CompilerOptionMap mCompilerOptions; CompilerOptionMap mCompilerOptions;

View File

@ -21,6 +21,7 @@
#include <QGridLayout> #include <QGridLayout>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QSpinBox>
CompileArgumentsWidget::CompileArgumentsWidget(QWidget *parent) : CompileArgumentsWidget::CompileArgumentsWidget(QWidget *parent) :
QTabWidget(parent) QTabWidget(parent)
@ -87,6 +88,20 @@ QMap<QString, QString> CompileArgumentsWidget::arguments( bool includeUnset) con
} }
} }
break; break;
case CompilerOptionType::Number:
{
QSpinBox* pInput = static_cast<QSpinBox *>(pLayout->itemAtPosition(j,2)->widget());
int val=pInput->value();
if (val>0)
args.insert(key,QString("%1").arg(val));
else {
if (includeUnset)
args.insert(key,"");
else
args.remove(key);
}
}
break;
} }
} }
} }
@ -158,6 +173,21 @@ void CompileArgumentsWidget::resetUI(Settings::PCompilerSet pSet, const QMap<QSt
pLayout->addWidget(pInput,row,2); pLayout->addWidget(pInput,row,2);
} }
break; break;
case CompilerOptionType::Number:
{
pLayout->addWidget(new QLabel(pOption->name,pWidget),row,1);
QSpinBox* pInput = new QSpinBox(pWidget);
bool ok;
int val = options.value(pOption->key,"").toInt(&ok);
if (!ok)
val = 0;
pInput->setSuffix(pOption->unit);
pInput->setMinimum(pOption->minValue);
pInput->setMaximum(pOption->maxValue);
pInput->setValue(val);
pLayout->addWidget(pInput,row,2);
}
break;
} }
} }
for (int i=0;i<pTab->count();i++) { for (int i=0;i<pTab->count();i++) {