Skip to content

Commit b682aed

Browse files
committed
Use Cpp::GetLanguageStandard to get language standard
1 parent 506b645 commit b682aed

5 files changed

Lines changed: 52 additions & 29 deletions

File tree

notebooks/tinyraytracer.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"file_extension": ".cpp",
1111
"mimetype": "text/x-c++src",
1212
"name": "C++",
13-
"version": "23"
13+
"version": "cxx23"
1414
}
1515
},
1616
"nbformat_minor": 5,

notebooks/xeus-cpp-lite-demo.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"file_extension": ".cpp",
1111
"mimetype": "text/x-c++src",
1212
"name": "C++",
13-
"version": "23"
13+
"version": "cxx23"
1414
}
1515
},
1616
"nbformat_minor": 5,

notebooks/xeus-cpp.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@
886886
"file_extension": ".cpp",
887887
"mimetype": "text/x-c++src",
888888
"name": "C++",
889-
"version": "20"
889+
"version": "cxx20"
890890
}
891891
},
892892
"nbformat": 4,

src/xinterpreter.cpp

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,34 +74,57 @@ namespace xcpp
7474
{
7575
xeus::register_interpreter(this);
7676
}
77-
78-
static std::string get_stdopt()
77+
static std::string get_stdopt()
78+
{
79+
switch (Cpp::GetLanguageStandard(nullptr))
7980
{
80-
// We need to find what's the C++ version the interpreter runs with.
81-
const char* code = R"(
82-
int __get_cxx_version () {
83-
#if __cplusplus > 202302L
84-
return 26;
85-
#elif __cplusplus > 202002L
86-
return 23;
87-
#elif __cplusplus > 201703L
88-
return 20;
89-
#elif __cplusplus > 201402L
90-
return 17;
91-
#elif __cplusplus > 201103L || (defined(_WIN32) && _MSC_VER >= 1900)
92-
return 14;
93-
#elif __cplusplus >= 201103L
94-
return 11;
95-
#else
96-
return 0;
97-
#endif
98-
}
99-
__get_cxx_version ()
100-
)";
101-
auto cxx_version = Cpp::Evaluate(code);
102-
return std::to_string(cxx_version);
81+
case Cpp::InterpreterLanguageStandard::c89: return "c89";
82+
case Cpp::InterpreterLanguageStandard::c94: return "c94";
83+
case Cpp::InterpreterLanguageStandard::gnu89: return "gnu89";
84+
case Cpp::InterpreterLanguageStandard::c99: return "c99";
85+
case Cpp::InterpreterLanguageStandard::gnu99: return "gnu99";
86+
case Cpp::InterpreterLanguageStandard::c11: return "c11";
87+
case Cpp::InterpreterLanguageStandard::gnu11: return "gnu11";
88+
case Cpp::InterpreterLanguageStandard::c17: return "c17";
89+
case Cpp::InterpreterLanguageStandard::gnu17: return "gnu17";
90+
case Cpp::InterpreterLanguageStandard::c23: return "c23";
91+
case Cpp::InterpreterLanguageStandard::gnu23: return "gnu23";
92+
case Cpp::InterpreterLanguageStandard::c2y: return "c2y";
93+
case Cpp::InterpreterLanguageStandard::gnu2y: return "gnu2y";
94+
case Cpp::InterpreterLanguageStandard::cxx98: return "cxx98";
95+
case Cpp::InterpreterLanguageStandard::gnucxx98: return "gnucxx98";
96+
case Cpp::InterpreterLanguageStandard::cxx11: return "cxx11";
97+
case Cpp::InterpreterLanguageStandard::gnucxx11: return "gnucxx11";
98+
case Cpp::InterpreterLanguageStandard::cxx14: return "cxx14";
99+
case Cpp::InterpreterLanguageStandard::gnucxx14: return "gnucxx14";
100+
case Cpp::InterpreterLanguageStandard::cxx17: return "cxx17";
101+
case Cpp::InterpreterLanguageStandard::gnucxx17: return "gnucxx17";
102+
case Cpp::InterpreterLanguageStandard::cxx20: return "cxx20";
103+
case Cpp::InterpreterLanguageStandard::gnucxx20: return "gnucxx20";
104+
case Cpp::InterpreterLanguageStandard::cxx23: return "cxx23";
105+
case Cpp::InterpreterLanguageStandard::gnucxx23: return "gnucxx23";
106+
case Cpp::InterpreterLanguageStandard::cxx26: return "cxx26";
107+
case Cpp::InterpreterLanguageStandard::gnucxx26: return "gnucxx26";
108+
case Cpp::InterpreterLanguageStandard::opencl10: return "opencl10";
109+
case Cpp::InterpreterLanguageStandard::opencl11: return "opencl11";
110+
case Cpp::InterpreterLanguageStandard::opencl12: return "opencl12";
111+
case Cpp::InterpreterLanguageStandard::opencl20: return "opencl20";
112+
case Cpp::InterpreterLanguageStandard::opencl30: return "opencl30";
113+
case Cpp::InterpreterLanguageStandard::openclcpp10: return "openclcpp10";
114+
case Cpp::InterpreterLanguageStandard::openclcpp2021: return "openclcpp2021";
115+
case Cpp::InterpreterLanguageStandard::hlsl: return "hlsl";
116+
case Cpp::InterpreterLanguageStandard::hlsl2015: return "hlsl2015";
117+
case Cpp::InterpreterLanguageStandard::hlsl2016: return "hlsl2016";
118+
case Cpp::InterpreterLanguageStandard::hlsl2017: return "hlsl2017";
119+
case Cpp::InterpreterLanguageStandard::hlsl2018: return "hlsl2018";
120+
case Cpp::InterpreterLanguageStandard::hlsl2021: return "hlsl2021";
121+
case Cpp::InterpreterLanguageStandard::hlsl202x: return "hlsl202x";
122+
case Cpp::InterpreterLanguageStandard::hlsl202y: return "hlsl202y";
123+
case Cpp::InterpreterLanguageStandard::lang_unspecified: return "lang_unspecified";
103124
}
104125

126+
return "unknown";
127+
}
105128
interpreter::interpreter(int argc, const char* const* argv) :
106129
xmagics()
107130
, p_cout_strbuf(nullptr)

test/test_interpreter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ TEST_SUITE("kernel_info_request")
407407
REQUIRE(result["language_info"]["mimetype"] == "text/x-c++src");
408408
REQUIRE(result["language_info"]["codemirror_mode"] == "text/x-c++src");
409409
REQUIRE(result["language_info"]["file_extension"] == ".cpp");
410-
REQUIRE(result["language_info"]["version"] == "23");
410+
REQUIRE(result["language_info"]["version"] == "cxx23");
411411
REQUIRE(result["status"] == "ok");
412412
}
413413

0 commit comments

Comments
 (0)