From c19ca5e362022cb5906506f55a39d5b01a10cd55 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sat, 4 May 2024 21:03:40 +0800 Subject: [PATCH] add infrastructure for number compiler options --- NEWS.md | 2 +- RedPandaIDE/compiler/compiler.cpp | 27 +++++++++++++++-- RedPandaIDE/compiler/compilerinfo.cpp | 26 +++++++++++++++- RedPandaIDE/compiler/compilerinfo.h | 23 ++++++++++++-- .../widgets/compileargumentswidget.cpp | 30 +++++++++++++++++++ 5 files changed, 101 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index f487ebb9..d5959f5a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -159,7 +159,7 @@ Red Panda C++ Version 2.27 - fix: In options -> code format -> Program, Choose astyle path button doesn't work. - fix: project not correctly reparsed after rename unit. - 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)) <5*(4+3)-1 && (4-3>5)) <setting; else if (pOption->type == CompilerOptionType::Input) 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]; } } @@ -480,7 +487,14 @@ QStringList Compiler::getCppCompileArguments(bool checkSyntax) result << pOption->setting; else if (pOption->type == CompilerOptionType::Input) 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]; } } @@ -590,7 +604,14 @@ QStringList Compiler::getLibraryArguments(FileType fileType) result << pOption->setting; else if (pOption->type == CompilerOptionType::Input) 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]; } } diff --git a/RedPandaIDE/compiler/compilerinfo.cpp b/RedPandaIDE/compiler/compilerinfo.cpp index 4de787f0..c56d282a 100644 --- a/RedPandaIDE/compiler/compilerinfo.cpp +++ b/RedPandaIDE/compiler/compilerinfo.cpp @@ -32,7 +32,7 @@ bool CompilerInfo::supportSyntaxCheck() 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, CompilerOptionType type, const CompileOptionChoiceList &choices) { @@ -47,8 +47,30 @@ void CompilerInfo::addOption(const QString &key, const QString &name, pOption->setting= setting; pOption->type = type; pOption->choices = choices; + pOption->scale = 1; mCompilerOptions.insert(key,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(); + 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() @@ -194,6 +216,8 @@ void CompilerInfo::prepareCompilerOptions() // 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(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"); diff --git a/RedPandaIDE/compiler/compilerinfo.h b/RedPandaIDE/compiler/compilerinfo.h index 863039e3..74d71e3a 100644 --- a/RedPandaIDE/compiler/compilerinfo.h +++ b/RedPandaIDE/compiler/compilerinfo.h @@ -39,6 +39,7 @@ #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_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_ADDRESS_SANITIZER "cc_cmd_opt_address_sanitizer" #define CC_CMD_OPT_STACK_PROTECTOR "cc_cmd_opt_stack_protector" @@ -85,7 +86,8 @@ enum class CompilerType { enum class CompilerOptionType { Checkbox, Choice, - Input + Input, + Number }; using CompileOptionChoiceList = QList>; @@ -100,6 +102,11 @@ typedef struct { QString setting; // "-g3" CompilerOptionType type; 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; using PCompilerOption = std::shared_ptr; @@ -125,7 +132,7 @@ public: virtual bool supportStaticLink()=0; virtual bool supportSyntaxCheck(); protected: - void addOption(const QString& key, + PCompilerOption addOption(const QString& key, const QString& name, const QString section, bool isC, @@ -134,6 +141,18 @@ protected: const QString& setting, CompilerOptionType type = CompilerOptionType::Checkbox, 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(); protected: CompilerOptionMap mCompilerOptions; diff --git a/RedPandaIDE/widgets/compileargumentswidget.cpp b/RedPandaIDE/widgets/compileargumentswidget.cpp index 5fe4ca9d..d61c1c3d 100644 --- a/RedPandaIDE/widgets/compileargumentswidget.cpp +++ b/RedPandaIDE/widgets/compileargumentswidget.cpp @@ -21,6 +21,7 @@ #include #include #include +#include CompileArgumentsWidget::CompileArgumentsWidget(QWidget *parent) : QTabWidget(parent) @@ -87,6 +88,20 @@ QMap CompileArgumentsWidget::arguments( bool includeUnset) con } } break; + case CompilerOptionType::Number: + { + QSpinBox* pInput = static_cast(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 QMapaddWidget(pInput,row,2); } 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;icount();i++) {