Skip to content

Commit de2ab7b

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

5 files changed

Lines changed: 95 additions & 28 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: 91 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,31 +77,98 @@ namespace xcpp
7777

7878
static std::string get_stdopt()
7979
{
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);
103-
}
80+
switch (Cpp::GetLanguageStandard(nullptr))
81+
{
82+
case Cpp::InterpreterLanguageStandard::c89:
83+
return "c89";
84+
case Cpp::InterpreterLanguageStandard::c94:
85+
return "c94";
86+
case Cpp::InterpreterLanguageStandard::gnu89:
87+
return "gnu89";
88+
case Cpp::InterpreterLanguageStandard::c99:
89+
return "c99";
90+
case Cpp::InterpreterLanguageStandard::gnu99:
91+
return "gnu99";
92+
case Cpp::InterpreterLanguageStandard::c11:
93+
return "c11";
94+
case Cpp::InterpreterLanguageStandard::gnu11:
95+
return "gnu11";
96+
case Cpp::InterpreterLanguageStandard::c17:
97+
return "c17";
98+
case Cpp::InterpreterLanguageStandard::gnu17:
99+
return "gnu17";
100+
case Cpp::InterpreterLanguageStandard::c23:
101+
return "c23";
102+
case Cpp::InterpreterLanguageStandard::gnu23:
103+
return "gnu23";
104+
case Cpp::InterpreterLanguageStandard::c2y:
105+
return "c2y";
106+
case Cpp::InterpreterLanguageStandard::gnu2y:
107+
return "gnu2y";
108+
case Cpp::InterpreterLanguageStandard::cxx98:
109+
return "cxx98";
110+
case Cpp::InterpreterLanguageStandard::gnucxx98:
111+
return "gnucxx98";
112+
case Cpp::InterpreterLanguageStandard::cxx11:
113+
return "cxx11";
114+
case Cpp::InterpreterLanguageStandard::gnucxx11:
115+
return "gnucxx11";
116+
case Cpp::InterpreterLanguageStandard::cxx14:
117+
return "cxx14";
118+
case Cpp::InterpreterLanguageStandard::gnucxx14:
119+
return "gnucxx14";
120+
case Cpp::InterpreterLanguageStandard::cxx17:
121+
return "cxx17";
122+
case Cpp::InterpreterLanguageStandard::gnucxx17:
123+
return "gnucxx17";
124+
case Cpp::InterpreterLanguageStandard::cxx20:
125+
return "cxx20";
126+
case Cpp::InterpreterLanguageStandard::gnucxx20:
127+
return "gnucxx20";
128+
case Cpp::InterpreterLanguageStandard::cxx23:
129+
return "cxx23";
130+
case Cpp::InterpreterLanguageStandard::gnucxx23:
131+
return "gnucxx23";
132+
case Cpp::InterpreterLanguageStandard::cxx26:
133+
return "cxx26";
134+
case Cpp::InterpreterLanguageStandard::gnucxx26:
135+
return "gnucxx26";
136+
case Cpp::InterpreterLanguageStandard::opencl10:
137+
return "opencl10";
138+
case Cpp::InterpreterLanguageStandard::opencl11:
139+
return "opencl11";
140+
case Cpp::InterpreterLanguageStandard::opencl12:
141+
return "opencl12";
142+
case Cpp::InterpreterLanguageStandard::opencl20:
143+
return "opencl20";
144+
case Cpp::InterpreterLanguageStandard::opencl30:
145+
return "opencl30";
146+
case Cpp::InterpreterLanguageStandard::openclcpp10:
147+
return "openclcpp10";
148+
case Cpp::InterpreterLanguageStandard::openclcpp2021:
149+
return "openclcpp2021";
150+
case Cpp::InterpreterLanguageStandard::hlsl:
151+
return "hlsl";
152+
case Cpp::InterpreterLanguageStandard::hlsl2015:
153+
return "hlsl2015";
154+
case Cpp::InterpreterLanguageStandard::hlsl2016:
155+
return "hlsl2016";
156+
case Cpp::InterpreterLanguageStandard::hlsl2017:
157+
return "hlsl2017";
158+
case Cpp::InterpreterLanguageStandard::hlsl2018:
159+
return "hlsl2018";
160+
case Cpp::InterpreterLanguageStandard::hlsl2021:
161+
return "hlsl2021";
162+
case Cpp::InterpreterLanguageStandard::hlsl202x:
163+
return "hlsl202x";
164+
case Cpp::InterpreterLanguageStandard::hlsl202y:
165+
return "hlsl202y";
166+
case Cpp::InterpreterLanguageStandard::lang_unspecified:
167+
return "lang_unspecified";
168+
}
104169

170+
return "unknown";
171+
}
105172
interpreter::interpreter(int argc, const char* const* argv) :
106173
xmagics()
107174
, 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)