diff --git a/notebooks/hello_world.ipynb b/notebooks/hello_world.ipynb index 7a62ea8d..93cc7b71 100644 --- a/notebooks/hello_world.ipynb +++ b/notebooks/hello_world.ipynb @@ -73,7 +73,7 @@ "file_extension": ".cpp", "mimetype": "text/x-c++src", "name": "C++", - "version": "23" + "version": "cxx23" } }, "nbformat": 4, diff --git a/notebooks/tinyraytracer.ipynb b/notebooks/tinyraytracer.ipynb index 543eff08..943b0c11 100644 --- a/notebooks/tinyraytracer.ipynb +++ b/notebooks/tinyraytracer.ipynb @@ -10,7 +10,7 @@ "file_extension": ".cpp", "mimetype": "text/x-c++src", "name": "C++", - "version": "23" + "version": "cxx23" } }, "nbformat_minor": 5, diff --git a/notebooks/xeus-cpp-lite-demo.ipynb b/notebooks/xeus-cpp-lite-demo.ipynb index b32f7837..073340a4 100644 --- a/notebooks/xeus-cpp-lite-demo.ipynb +++ b/notebooks/xeus-cpp-lite-demo.ipynb @@ -10,7 +10,7 @@ "file_extension": ".cpp", "mimetype": "text/x-c++src", "name": "C++", - "version": "23" + "version": "cxx23" } }, "nbformat_minor": 5, diff --git a/notebooks/xeus-cpp.ipynb b/notebooks/xeus-cpp.ipynb index b670b566..940979b9 100644 --- a/notebooks/xeus-cpp.ipynb +++ b/notebooks/xeus-cpp.ipynb @@ -886,7 +886,7 @@ "file_extension": ".cpp", "mimetype": "text/x-c++src", "name": "C++", - "version": "20" + "version": "cxx20" } }, "nbformat": 4, diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index 2f60cc1c..4c5a6e14 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -101,31 +101,101 @@ namespace xcpp xeus::register_interpreter(this); } + // FIXME: This function should be upstreamed to CppInterOp. See + // https://github.com/compiler-research/CppInterOp/issues/879 static std::string get_stdopt() { - // We need to find what's the C++ version the interpreter runs with. - const char* code = R"( -int __get_cxx_version () { -#if __cplusplus > 202302L - return 26; -#elif __cplusplus > 202002L - return 23; -#elif __cplusplus > 201703L - return 20; -#elif __cplusplus > 201402L - return 17; -#elif __cplusplus > 201103L || (defined(_WIN32) && _MSC_VER >= 1900) - return 14; -#elif __cplusplus >= 201103L - return 11; -#else - return 0; -#endif - } -__get_cxx_version () - )"; - auto cxx_version = Cpp::Evaluate(code); - return std::to_string(cxx_version); + switch (Cpp::GetLanguageStandard(nullptr)) + { + case Cpp::InterpreterLanguageStandard::c89: + return "c89"; + case Cpp::InterpreterLanguageStandard::c94: + return "c94"; + case Cpp::InterpreterLanguageStandard::gnu89: + return "gnu89"; + case Cpp::InterpreterLanguageStandard::c99: + return "c99"; + case Cpp::InterpreterLanguageStandard::gnu99: + return "gnu99"; + case Cpp::InterpreterLanguageStandard::c11: + return "c11"; + case Cpp::InterpreterLanguageStandard::gnu11: + return "gnu11"; + case Cpp::InterpreterLanguageStandard::c17: + return "c17"; + case Cpp::InterpreterLanguageStandard::gnu17: + return "gnu17"; + case Cpp::InterpreterLanguageStandard::c23: + return "c23"; + case Cpp::InterpreterLanguageStandard::gnu23: + return "gnu23"; + case Cpp::InterpreterLanguageStandard::c2y: + return "c2y"; + case Cpp::InterpreterLanguageStandard::gnu2y: + return "gnu2y"; + case Cpp::InterpreterLanguageStandard::cxx98: + return "cxx98"; + case Cpp::InterpreterLanguageStandard::gnucxx98: + return "gnucxx98"; + case Cpp::InterpreterLanguageStandard::cxx11: + return "cxx11"; + case Cpp::InterpreterLanguageStandard::gnucxx11: + return "gnucxx11"; + case Cpp::InterpreterLanguageStandard::cxx14: + return "cxx14"; + case Cpp::InterpreterLanguageStandard::gnucxx14: + return "gnucxx14"; + case Cpp::InterpreterLanguageStandard::cxx17: + return "cxx17"; + case Cpp::InterpreterLanguageStandard::gnucxx17: + return "gnucxx17"; + case Cpp::InterpreterLanguageStandard::cxx20: + return "cxx20"; + case Cpp::InterpreterLanguageStandard::gnucxx20: + return "gnucxx20"; + case Cpp::InterpreterLanguageStandard::cxx23: + return "cxx23"; + case Cpp::InterpreterLanguageStandard::gnucxx23: + return "gnucxx23"; + case Cpp::InterpreterLanguageStandard::cxx26: + return "cxx26"; + case Cpp::InterpreterLanguageStandard::gnucxx26: + return "gnucxx26"; + case Cpp::InterpreterLanguageStandard::opencl10: + return "opencl10"; + case Cpp::InterpreterLanguageStandard::opencl11: + return "opencl11"; + case Cpp::InterpreterLanguageStandard::opencl12: + return "opencl12"; + case Cpp::InterpreterLanguageStandard::opencl20: + return "opencl20"; + case Cpp::InterpreterLanguageStandard::opencl30: + return "opencl30"; + case Cpp::InterpreterLanguageStandard::openclcpp10: + return "openclcpp10"; + case Cpp::InterpreterLanguageStandard::openclcpp2021: + return "openclcpp2021"; + case Cpp::InterpreterLanguageStandard::hlsl: + return "hlsl"; + case Cpp::InterpreterLanguageStandard::hlsl2015: + return "hlsl2015"; + case Cpp::InterpreterLanguageStandard::hlsl2016: + return "hlsl2016"; + case Cpp::InterpreterLanguageStandard::hlsl2017: + return "hlsl2017"; + case Cpp::InterpreterLanguageStandard::hlsl2018: + return "hlsl2018"; + case Cpp::InterpreterLanguageStandard::hlsl2021: + return "hlsl2021"; + case Cpp::InterpreterLanguageStandard::hlsl202x: + return "hlsl202x"; + case Cpp::InterpreterLanguageStandard::hlsl202y: + return "hlsl202y"; + case Cpp::InterpreterLanguageStandard::lang_unspecified: + return "lang_unspecified"; + } + + return "unknown"; } // FIXME: This function should be upstreamed to CppInterOp. See diff --git a/test/test_interpreter.cpp b/test/test_interpreter.cpp index 085c15f3..4b19ae26 100644 --- a/test/test_interpreter.cpp +++ b/test/test_interpreter.cpp @@ -407,7 +407,7 @@ TEST_SUITE("kernel_info_request") REQUIRE(result["language_info"]["mimetype"] == "text/x-c++src"); REQUIRE(result["language_info"]["codemirror_mode"] == "text/x-c++src"); REQUIRE(result["language_info"]["file_extension"] == ".cpp"); - REQUIRE(result["language_info"]["version"] == "23"); + REQUIRE(result["language_info"]["version"] == "cxx23"); REQUIRE(result["status"] == "ok"); }