|
|
|
@ -11,7 +11,9 @@ |
|
|
|
|
#include <any> |
|
|
|
|
#include <cassert> |
|
|
|
|
#include <cctype> |
|
|
|
|
#if __has_include(<charconv>) |
|
|
|
|
#include <charconv> |
|
|
|
|
#endif |
|
|
|
|
#include <cstring> |
|
|
|
|
#include <functional> |
|
|
|
|
#include <initializer_list> |
|
|
|
@ -478,6 +480,7 @@ struct SemanticValues : protected std::vector<std::any> { |
|
|
|
|
|
|
|
|
|
template <typename T> T token_to_number() const { |
|
|
|
|
T n = 0; |
|
|
|
|
#if __has_include(<charconv>) |
|
|
|
|
if constexpr (std::is_floating_point<T>::value) { |
|
|
|
|
// TODO: The following code should be removed eventually.
|
|
|
|
|
std::istringstream ss(token_to_string()); |
|
|
|
@ -488,6 +491,11 @@ struct SemanticValues : protected std::vector<std::any> { |
|
|
|
|
std::from_chars(sv.data(), sv.data() + sv.size(), n); |
|
|
|
|
return n; |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
std::istringstream ss(token_to_string()); |
|
|
|
|
ss >> n; |
|
|
|
|
return n; |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Transform the semantic value vector to another vector
|
|
|
|
@ -3770,6 +3778,7 @@ template <typename Annotation> struct AstBase : public Annotation { |
|
|
|
|
|
|
|
|
|
template <typename T> T token_to_number() const { |
|
|
|
|
T n = 0; |
|
|
|
|
#if __has_include(<charconv>) |
|
|
|
|
if constexpr (std::is_floating_point<T>::value) { |
|
|
|
|
// TODO: The following code should be removed eventually.
|
|
|
|
|
std::istringstream ss(token_to_string()); |
|
|
|
@ -3780,6 +3789,11 @@ template <typename Annotation> struct AstBase : public Annotation { |
|
|
|
|
std::from_chars(token.data(), token.data() + token.size(), n); |
|
|
|
|
return n; |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
std::istringstream ss(token_to_string()); |
|
|
|
|
ss >> n; |
|
|
|
|
return n; |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|