Skip to content

Commit

Permalink
Add initial support for GCC 15 import std; (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanoHao authored Dec 13, 2024
1 parent d118641 commit 9056a10
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 1 deletion.
15 changes: 15 additions & 0 deletions RedPandaIDE/compiler/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "compiler.h"
#include "compiler/compilerinfo.h"
#include "utils.h"
#include "utils/escape.h"
#include "utils/parsearg.h"
Expand Down Expand Up @@ -412,6 +413,20 @@ QStringList Compiler::getCharsetArgument(const QByteArray& encoding,FileType fil
return result;
}

QStringList Compiler::getCppGccImportStdSources(bool checkSyntax)
{
QStringList result;
if (!checkSyntax && compilerSet()->getCompileOptionValue(CC_CMD_OPT_ENABLE_GCC_IMPORT_STD) == COMPILER_OPTION_ON) {
// libstdc++ extends `import std` to C++20
// FIXME: use robust method to check C++ standard version
const QString &std = compilerSet()->getCompileOptionValue(CC_CMD_OPT_STD);
if (std.startsWith("c++2") || std.startsWith("gnu++2")) {
result += {"-fsearch-include-path", "bits/std.cc", "bits/std.compat.cc"};
}
}
return result;
}

QStringList Compiler::getCCompileArguments(bool checkSyntax)
{
QStringList result;
Expand Down
1 change: 1 addition & 0 deletions RedPandaIDE/compiler/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public slots:
virtual bool prepareForRebuild() = 0;
virtual bool beforeRunExtraCommand(int idx);
virtual QStringList getCharsetArgument(const QByteArray& encoding, FileType fileType, bool onlyCheckSyntax);
virtual QStringList getCppGccImportStdSources(bool checkSyntax);
virtual QStringList getCCompileArguments(bool checkSyntax);
virtual QStringList getCppCompileArguments(bool checkSyntax);
virtual QStringList getCIncludeArguments();
Expand Down
7 changes: 7 additions & 0 deletions RedPandaIDE/compiler/compilerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,29 @@ void CompilerInfo::prepareCompilerOptions()
sl.append(QPair<QString,QString>("ISO C++17","c++17"));
sl.append(QPair<QString,QString>("ISO C++20","c++2a"));
sl.append(QPair<QString,QString>("ISO C++23","c++2b"));
sl.append(QPair<QString,QString>("ISO C++26","c++2c"));
sl.append(QPair<QString,QString>("GNU C++","gnu++98"));
sl.append(QPair<QString,QString>("GNU C++11","gnu++11"));
sl.append(QPair<QString,QString>("GNU C++14","gnu++14"));
sl.append(QPair<QString,QString>("GNU C++17","gnu++17"));
sl.append(QPair<QString,QString>("GNU C++20","gnu++2a"));
sl.append(QPair<QString,QString>("GNU C++23","gnu++2b"));
sl.append(QPair<QString,QString>("GNU C++26","gnu++2c"));
addOption(CC_CMD_OPT_STD, QObject::tr("C++ Language standard (-std)"), groupName, false, true, false, "-std=",CompilerOptionType::Choice, sl);

sl.clear();
sl.append(QPair<QString,QString>("ISO C90","c90"));
sl.append(QPair<QString,QString>("ISO C99","c99"));
sl.append(QPair<QString,QString>("ISO C11","c11"));
sl.append(QPair<QString,QString>("ISO C17","c17"));
sl.append(QPair<QString,QString>("ISO C23","c2x"));
sl.append(QPair<QString,QString>("ISO C2Y","c2y"));
sl.append(QPair<QString,QString>("GNU C90","gnu90"));
sl.append(QPair<QString,QString>("GNU C99","gnu99"));
sl.append(QPair<QString,QString>("GNU C11","gnu11"));
sl.append(QPair<QString,QString>("GNU C17","gnu17"));
sl.append(QPair<QString,QString>("GNU C23","gnu2x"));
sl.append(QPair<QString,QString>("GNU C2Y","gnu2y"));
addOption(C_CMD_OPT_STD, QObject::tr("C Language standard (-std)"), groupName, true, false, false, "-std=", CompilerOptionType::Choice, sl);

// Optimization for cpu type
Expand Down Expand Up @@ -187,6 +193,7 @@ void CompilerInfo::prepareCompilerOptions()
addOption(CC_CMD_OPT_DEBUG_INFO, QObject::tr("Generate debugging information (-g3)"), groupName, true, true, false, "-g3");
addOption(CC_CMD_OPT_PROFILE_INFO, QObject::tr("Generate profiling info for analysis (-pg)"), groupName, true, true, true, "-pg");
addOption(CC_CMD_OPT_SYNTAX_ONLY, QObject::tr("Only check the code for syntax errors (-fsyntax-only)"), groupName, true, true, false, "-fsyntax-only");
addOption(CC_CMD_OPT_ENABLE_GCC_IMPORT_STD, QObject::tr("Enable experimental support for GCC standard library modules (-fmodules)"), groupName, false, true, false, "-fmodules");

// Warnings
groupName = QObject::tr("Warnings");
Expand Down
1 change: 1 addition & 0 deletions RedPandaIDE/compiler/compilerinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define CC_CMD_OPT_SYNTAX_ONLY "cc_cmd_opt_syntax_only"
#define CC_CMD_OPT_WARNING_AS_ERROR "cc_cmd_opt_warning_as_error"
#define CC_CMD_OPT_ABORT_ON_ERROR "cc_cmd_opt_abort_on_error"
#define CC_CMD_OPT_ENABLE_GCC_IMPORT_STD "cc_opt_enable_gcc_import_std"

#define CC_CMD_OPT_PROFILE_INFO "cc_cmd_opt_profile_info"

Expand Down
11 changes: 10 additions & 1 deletion RedPandaIDE/compiler/filecompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,17 @@ bool FileCompiler::prepareForCompile()
log(tr("- Filename: %1").arg(mFilename));
log(tr("- Compiler Set Name: %1").arg(compilerSet()->name()));
log("");

FileType fileType = getFileType(mFilename);
mArguments = QStringList{localizePath(mFilename)};
CompilerType compilerType = compilerSet()->compilerType();

// GCC `import std;` sources should be added before the main file to generate GCM cache
if (fileType == FileType::CppSource &&
(compilerType == CompilerType::GCC || compilerType == CompilerType::GCC_UTF8)) {
mArguments += getCppGccImportStdSources(mOnlyCheckSyntax);
}

mArguments += QStringList{localizePath(mFilename)};
if (!mOnlyCheckSyntax) {
switch(compilerSet()->compilationStage()) {
case Settings::CompilerSet::CompilationStage::PreprocessingOnly:
Expand Down
7 changes: 7 additions & 0 deletions RedPandaIDE/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "settings.h"
#include <QApplication>
#include <algorithm>
#include "compiler/compilerinfo.h"
#include "utils.h"
#include "utils/escape.h"
#include "utils/font.h"
Expand Down Expand Up @@ -1859,6 +1860,7 @@ Settings::CompilerSet::CompilerSet(const QJsonObject &set) :
{CC_CMD_OPT_DEBUG_INFO, "ccCmdOptDebugInfo"},
{CC_CMD_OPT_PROFILE_INFO, "ccCmdOptProfileInfo"},
{CC_CMD_OPT_SYNTAX_ONLY, "ccCmdOptSyntaxOnly"},
{CC_CMD_OPT_ENABLE_GCC_IMPORT_STD, "ccCmdOptEnableGccImportStd"},

{CC_CMD_OPT_INHIBIT_ALL_WARNING, "ccCmdOptInhibitAllWarning"},
{CC_CMD_OPT_WARNING_ALL, "ccCmdOptWarningAll"},
Expand Down Expand Up @@ -2486,6 +2488,10 @@ QStringList Settings::CompilerSet::defines(bool isCpp) {
if (!mCompileOptions[key].isEmpty())
arguments.append(pOption->setting + mCompileOptions[key]);
}
pOption = CompilerInfoManager::getCompilerOption(compilerType(), CC_CMD_OPT_ENABLE_GCC_IMPORT_STD);
if (pOption && mCompileOptions.contains(CC_CMD_OPT_ENABLE_GCC_IMPORT_STD)) {
arguments.append(pOption->setting);
}
pOption = CompilerInfoManager::getCompilerOption(compilerType(), CC_CMD_OPT_DEBUG_INFO);
if (pOption && mCompileOptions.contains(CC_CMD_OPT_DEBUG_INFO)) {
arguments.append(pOption->setting);
Expand Down Expand Up @@ -3711,6 +3717,7 @@ void Settings::CompilerSets::prepareCompatibleIndex()
mCompilerCompatibleIndex.append(CC_CMD_OPT_SYNTAX_ONLY);
mCompilerCompatibleIndex.append(CC_CMD_OPT_WARNING_AS_ERROR);
mCompilerCompatibleIndex.append(CC_CMD_OPT_ABORT_ON_ERROR);
mCompilerCompatibleIndex.append(CC_CMD_OPT_ENABLE_GCC_IMPORT_STD);

mCompilerCompatibleIndex.append(CC_CMD_OPT_PROFILE_INFO);

Expand Down

0 comments on commit 9056a10

Please sign in to comment.