mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2025-12-07 09:16:53 +08:00
Initial simple application of constexpr to API
This commit is contained in:
parent
58f740844d
commit
ddb2f352cd
@ -75,13 +75,13 @@ static_assert(_MSC_FULL_VER >= 190024210, "Visual C++ 2015 Update 3 or later req
|
||||
#include <cmath>
|
||||
|
||||
namespace chaiscript {
|
||||
static const int version_major = 6;
|
||||
static const int version_minor = 0;
|
||||
static const int version_patch = 0;
|
||||
constexpr static const int version_major = 6;
|
||||
constexpr static const int version_minor = 0;
|
||||
constexpr static const int version_patch = 0;
|
||||
|
||||
static const char *compiler_version = CHAISCRIPT_COMPILER_VERSION;
|
||||
static const char *compiler_name = CHAISCRIPT_COMPILER_NAME;
|
||||
static const bool debug_build = CHAISCRIPT_DEBUG;
|
||||
constexpr static const char *compiler_version = CHAISCRIPT_COMPILER_VERSION;
|
||||
constexpr static const char *compiler_name = CHAISCRIPT_COMPILER_NAME;
|
||||
constexpr static const bool debug_build = CHAISCRIPT_DEBUG;
|
||||
|
||||
template<typename B, typename D, typename ...Arg>
|
||||
inline std::shared_ptr<B> make_shared(Arg && ... arg)
|
||||
@ -104,17 +104,17 @@ namespace chaiscript {
|
||||
}
|
||||
|
||||
struct Build_Info {
|
||||
static int version_major() noexcept
|
||||
constexpr static int version_major() noexcept
|
||||
{
|
||||
return chaiscript::version_major;
|
||||
}
|
||||
|
||||
static int version_minor() noexcept
|
||||
constexpr static int version_minor() noexcept
|
||||
{
|
||||
return chaiscript::version_minor;
|
||||
}
|
||||
|
||||
static int version_patch() noexcept
|
||||
constexpr static int version_patch() noexcept
|
||||
{
|
||||
return chaiscript::version_patch;
|
||||
}
|
||||
@ -144,7 +144,7 @@ namespace chaiscript {
|
||||
return chaiscript::compiler_name;
|
||||
}
|
||||
|
||||
static bool debug_build() noexcept
|
||||
constexpr static bool debug_build() noexcept
|
||||
{
|
||||
return chaiscript::debug_build;
|
||||
}
|
||||
@ -152,7 +152,7 @@ namespace chaiscript {
|
||||
|
||||
|
||||
template<typename T>
|
||||
auto parse_num(const char *t_str) noexcept -> typename std::enable_if<std::is_integral<T>::value, T>::type
|
||||
constexpr auto parse_num(const char *t_str) noexcept -> typename std::enable_if<std::is_integral<T>::value, T>::type
|
||||
{
|
||||
T t = 0;
|
||||
for (char c = *t_str; (c = *t_str) != 0; ++t_str) {
|
||||
|
||||
@ -116,25 +116,25 @@ namespace chaiscript
|
||||
class unique_lock
|
||||
{
|
||||
public:
|
||||
explicit unique_lock(T &) noexcept {}
|
||||
void lock() noexcept {}
|
||||
void unlock() noexcept {}
|
||||
constexpr explicit unique_lock(T &) noexcept {}
|
||||
constexpr void lock() noexcept {}
|
||||
constexpr void unlock() noexcept {}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class shared_lock
|
||||
{
|
||||
public:
|
||||
explicit shared_lock(T &) noexcept {}
|
||||
void lock() noexcept {}
|
||||
void unlock() noexcept {}
|
||||
constexpr explicit shared_lock(T &) noexcept {}
|
||||
constexpr void lock() noexcept {}
|
||||
constexpr void unlock() noexcept {}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class lock_guard
|
||||
{
|
||||
public:
|
||||
explicit lock_guard(T &) noexcept {}
|
||||
constexpr explicit lock_guard(T &) noexcept {}
|
||||
};
|
||||
|
||||
class shared_mutex { };
|
||||
@ -146,16 +146,16 @@ namespace chaiscript
|
||||
class Thread_Storage
|
||||
{
|
||||
public:
|
||||
explicit Thread_Storage() noexcept
|
||||
constexpr explicit Thread_Storage() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
inline T *operator->() const noexcept
|
||||
constexpr inline T *operator->() const noexcept
|
||||
{
|
||||
return &obj;
|
||||
}
|
||||
|
||||
inline T &operator*() const noexcept
|
||||
constexpr inline T &operator*() const noexcept
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ namespace chaiscript {
|
||||
private:
|
||||
struct Data
|
||||
{
|
||||
explicit Data(const std::type_info &t_type) noexcept
|
||||
constexpr explicit Data(const std::type_info &t_type) noexcept
|
||||
: m_type(t_type)
|
||||
{
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ namespace chaiscript
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
T* get_pointer(T *t) noexcept
|
||||
constexpr T* get_pointer(T *t) noexcept
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
@ -46,17 +46,17 @@ namespace chaiscript
|
||||
{
|
||||
typedef Container container_type;
|
||||
|
||||
Bidir_Range(Container &c)
|
||||
constexpr Bidir_Range(Container &c)
|
||||
: m_begin(c.begin()), m_end(c.end())
|
||||
{
|
||||
}
|
||||
|
||||
bool empty() const noexcept
|
||||
constexpr bool empty() const noexcept
|
||||
{
|
||||
return m_begin == m_end;
|
||||
}
|
||||
|
||||
void pop_front()
|
||||
constexpr void pop_front()
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
@ -65,7 +65,7 @@ namespace chaiscript
|
||||
++m_begin;
|
||||
}
|
||||
|
||||
void pop_back()
|
||||
constexpr void pop_back()
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
@ -74,7 +74,7 @@ namespace chaiscript
|
||||
--m_end;
|
||||
}
|
||||
|
||||
decltype(auto) front() const
|
||||
constexpr decltype(auto) front() const
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
@ -83,7 +83,7 @@ namespace chaiscript
|
||||
return (*m_begin);
|
||||
}
|
||||
|
||||
decltype(auto) back() const
|
||||
constexpr decltype(auto) back() const
|
||||
{
|
||||
if (empty())
|
||||
{
|
||||
|
||||
@ -27,7 +27,7 @@ namespace chaiscript
|
||||
// Cast_Helper_Inner helper classes
|
||||
|
||||
template<typename T>
|
||||
T* throw_if_null(T *t)
|
||||
constexpr T* throw_if_null(T *t)
|
||||
{
|
||||
if (t) { return t; }
|
||||
throw std::runtime_error("Attempted to dereference null Boxed_Value");
|
||||
|
||||
@ -80,7 +80,7 @@ namespace chaiscript
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
static inline void check_divide_by_zero(T t, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr)
|
||||
constexpr static inline void check_divide_by_zero(T t, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr)
|
||||
{
|
||||
#ifndef CHAISCRIPT_NO_PROTECT_DIVIDEBYZERO
|
||||
if (t == 0) {
|
||||
@ -90,11 +90,11 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static inline void check_divide_by_zero(T, typename std::enable_if<std::is_floating_point<T>::value>::type* = nullptr) noexcept
|
||||
constexpr static inline void check_divide_by_zero(T, typename std::enable_if<std::is_floating_point<T>::value>::type* = nullptr) noexcept
|
||||
{
|
||||
}
|
||||
|
||||
static Common_Types get_common_type(size_t t_size, bool t_signed) noexcept
|
||||
constexpr static Common_Types get_common_type(size_t t_size, bool t_signed) noexcept
|
||||
{
|
||||
return (t_size == 1 && t_signed)?(Common_Types::t_int8)
|
||||
:(t_size == 1)?(Common_Types::t_uint8)
|
||||
@ -161,7 +161,7 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static bool boolean_go(Operators::Opers t_oper, const T &t, const T &u) noexcept
|
||||
constexpr static bool boolean_go(Operators::Opers t_oper, const T &t, const T &u) noexcept
|
||||
{
|
||||
switch (t_oper)
|
||||
{
|
||||
@ -184,7 +184,7 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static void unary_go(Operators::Opers t_oper, T &t) noexcept
|
||||
constexpr static void unary_go(Operators::Opers t_oper, T &t) noexcept
|
||||
{
|
||||
switch (t_oper)
|
||||
{
|
||||
@ -200,7 +200,7 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
static void binary_go(Operators::Opers t_oper, T &t, const U &u)
|
||||
constexpr static void binary_go(Operators::Opers t_oper, T &t, const U &u)
|
||||
noexcept(noexcept(check_divide_by_zero(u)))
|
||||
{
|
||||
switch (t_oper)
|
||||
@ -227,7 +227,7 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
static void binary_int_go(Operators::Opers t_oper, T &t, const U &u) noexcept
|
||||
constexpr static void binary_int_go(Operators::Opers t_oper, T &t, const U &u) noexcept
|
||||
{
|
||||
switch (t_oper)
|
||||
{
|
||||
@ -257,7 +257,7 @@ namespace chaiscript
|
||||
|
||||
|
||||
template<typename T>
|
||||
static auto const_binary_int_go(Operators::Opers t_oper, T t, T u)
|
||||
constexpr static auto const_binary_int_go(Operators::Opers t_oper, T t, T u)
|
||||
noexcept(noexcept(check_divide_by_zero(u)))
|
||||
{
|
||||
switch (t_oper)
|
||||
@ -282,7 +282,7 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static auto const_unary_go(Operators::Opers t_oper, T t) noexcept
|
||||
constexpr static auto const_unary_go(Operators::Opers t_oper, T t) noexcept
|
||||
{
|
||||
switch (t_oper)
|
||||
{
|
||||
@ -297,7 +297,7 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static auto const_binary_go(Operators::Opers t_oper, T t, T u)
|
||||
constexpr static auto const_binary_go(Operators::Opers t_oper, T t, T u)
|
||||
noexcept(noexcept(check_divide_by_zero(u)))
|
||||
{
|
||||
switch (t_oper)
|
||||
|
||||
@ -33,7 +33,7 @@ namespace chaiscript
|
||||
class Type_Info
|
||||
{
|
||||
public:
|
||||
Type_Info(const bool t_is_const, const bool t_is_reference, const bool t_is_pointer, const bool t_is_void,
|
||||
constexpr Type_Info(const bool t_is_const, const bool t_is_reference, const bool t_is_pointer, const bool t_is_void,
|
||||
const bool t_is_arithmetic, const std::type_info *t_ti, const std::type_info *t_bare_ti)
|
||||
: m_type_info(t_ti), m_bare_type_info(t_bare_ti),
|
||||
m_flags((static_cast<unsigned int>(t_is_const) << is_const_flag)
|
||||
@ -44,51 +44,51 @@ namespace chaiscript
|
||||
{
|
||||
}
|
||||
|
||||
Type_Info() = default;
|
||||
constexpr Type_Info() = default;
|
||||
|
||||
bool operator<(const Type_Info &ti) const noexcept
|
||||
constexpr bool operator<(const Type_Info &ti) const noexcept
|
||||
{
|
||||
return m_type_info < ti.m_type_info;
|
||||
}
|
||||
|
||||
bool operator!=(const Type_Info &ti) const noexcept
|
||||
constexpr bool operator!=(const Type_Info &ti) const noexcept
|
||||
{
|
||||
return !(operator==(ti));
|
||||
}
|
||||
|
||||
bool operator!=(const std::type_info &ti) const noexcept
|
||||
constexpr bool operator!=(const std::type_info &ti) const noexcept
|
||||
{
|
||||
return !(operator==(ti));
|
||||
}
|
||||
|
||||
bool operator==(const Type_Info &ti) const noexcept
|
||||
constexpr bool operator==(const Type_Info &ti) const noexcept
|
||||
{
|
||||
return ti.m_type_info == m_type_info
|
||||
|| *ti.m_type_info == *m_type_info;
|
||||
}
|
||||
|
||||
bool operator==(const std::type_info &ti) const noexcept
|
||||
constexpr bool operator==(const std::type_info &ti) const noexcept
|
||||
{
|
||||
return !is_undef() && (*m_type_info) == ti;
|
||||
}
|
||||
|
||||
bool bare_equal(const Type_Info &ti) const noexcept
|
||||
constexpr bool bare_equal(const Type_Info &ti) const noexcept
|
||||
{
|
||||
return ti.m_bare_type_info == m_bare_type_info
|
||||
|| *ti.m_bare_type_info == *m_bare_type_info;
|
||||
}
|
||||
|
||||
bool bare_equal_type_info(const std::type_info &ti) const noexcept
|
||||
constexpr bool bare_equal_type_info(const std::type_info &ti) const noexcept
|
||||
{
|
||||
return !is_undef() && (*m_bare_type_info) == ti;
|
||||
}
|
||||
|
||||
bool is_const() const noexcept { return (m_flags & (1 << is_const_flag)) != 0; }
|
||||
bool is_reference() const noexcept { return (m_flags & (1 << is_reference_flag)) != 0; }
|
||||
bool is_void() const noexcept { return (m_flags & (1 << is_void_flag)) != 0; }
|
||||
bool is_arithmetic() const noexcept { return (m_flags & (1 << is_arithmetic_flag)) != 0; }
|
||||
bool is_undef() const noexcept { return (m_flags & (1 << is_undef_flag)) != 0; }
|
||||
bool is_pointer() const noexcept { return (m_flags & (1 << is_pointer_flag)) != 0; }
|
||||
constexpr bool is_const() const noexcept { return (m_flags & (1 << is_const_flag)) != 0; }
|
||||
constexpr bool is_reference() const noexcept { return (m_flags & (1 << is_reference_flag)) != 0; }
|
||||
constexpr bool is_void() const noexcept { return (m_flags & (1 << is_void_flag)) != 0; }
|
||||
constexpr bool is_arithmetic() const noexcept { return (m_flags & (1 << is_arithmetic_flag)) != 0; }
|
||||
constexpr bool is_undef() const noexcept { return (m_flags & (1 << is_undef_flag)) != 0; }
|
||||
constexpr bool is_pointer() const noexcept { return (m_flags & (1 << is_pointer_flag)) != 0; }
|
||||
|
||||
const char * name() const noexcept
|
||||
{
|
||||
@ -110,7 +110,7 @@ namespace chaiscript
|
||||
}
|
||||
}
|
||||
|
||||
const std::type_info *bare_type_info() const noexcept
|
||||
constexpr const std::type_info *bare_type_info() const noexcept
|
||||
{
|
||||
return m_bare_type_info;
|
||||
}
|
||||
@ -135,7 +135,7 @@ namespace chaiscript
|
||||
template<typename T>
|
||||
struct Get_Type_Info
|
||||
{
|
||||
static Type_Info get() noexcept
|
||||
constexpr static Type_Info get() noexcept
|
||||
{
|
||||
return Type_Info(std::is_const<typename std::remove_pointer<typename std::remove_reference<T>::type>::type>::value,
|
||||
std::is_reference<T>::value, std::is_pointer<T>::value,
|
||||
@ -152,7 +152,7 @@ namespace chaiscript
|
||||
{
|
||||
// typedef T type;
|
||||
|
||||
static Type_Info get() noexcept
|
||||
constexpr static Type_Info get() noexcept
|
||||
{
|
||||
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
|
||||
std::is_void<T>::value,
|
||||
@ -170,7 +170,7 @@ namespace chaiscript
|
||||
template<typename T>
|
||||
struct Get_Type_Info<const std::shared_ptr<T> &>
|
||||
{
|
||||
static Type_Info get() noexcept
|
||||
constexpr static Type_Info get() noexcept
|
||||
{
|
||||
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
|
||||
std::is_void<T>::value,
|
||||
@ -183,7 +183,7 @@ namespace chaiscript
|
||||
template<typename T>
|
||||
struct Get_Type_Info<std::reference_wrapper<T> >
|
||||
{
|
||||
static Type_Info get() noexcept
|
||||
constexpr static Type_Info get() noexcept
|
||||
{
|
||||
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
|
||||
std::is_void<T>::value,
|
||||
@ -196,7 +196,7 @@ namespace chaiscript
|
||||
template<typename T>
|
||||
struct Get_Type_Info<const std::reference_wrapper<T> &>
|
||||
{
|
||||
static Type_Info get() noexcept
|
||||
constexpr static Type_Info get() noexcept
|
||||
{
|
||||
return Type_Info(std::is_const<T>::value, std::is_reference<T>::value, std::is_pointer<T>::value,
|
||||
std::is_void<T>::value,
|
||||
@ -218,7 +218,7 @@ namespace chaiscript
|
||||
/// chaiscript::Type_Info ti = chaiscript::user_type(i);
|
||||
/// \endcode
|
||||
template<typename T>
|
||||
Type_Info user_type(const T &/*t*/) noexcept
|
||||
constexpr Type_Info user_type(const T &/*t*/) noexcept
|
||||
{
|
||||
return detail::Get_Type_Info<T>::get();
|
||||
}
|
||||
@ -233,7 +233,7 @@ namespace chaiscript
|
||||
/// chaiscript::Type_Info ti = chaiscript::user_type<int>();
|
||||
/// \endcode
|
||||
template<typename T>
|
||||
Type_Info user_type() noexcept
|
||||
constexpr Type_Info user_type() noexcept
|
||||
{
|
||||
return detail::Get_Type_Info<T>::get();
|
||||
}
|
||||
|
||||
@ -36,8 +36,8 @@ namespace chaiscript
|
||||
invalid
|
||||
};
|
||||
|
||||
static const char *to_string(Opers t_oper) noexcept {
|
||||
static const char *opers[] = {
|
||||
constexpr static const char *to_string(Opers t_oper) noexcept {
|
||||
constexpr const char *opers[] = {
|
||||
"",
|
||||
"==", "<", ">", "<=", ">=", "!=",
|
||||
"",
|
||||
|
||||
@ -81,8 +81,8 @@ namespace chaiscript
|
||||
namespace
|
||||
{
|
||||
/// Helper lookup to get the name of each node type
|
||||
inline const char *ast_node_type_to_string(AST_Node_Type ast_node_type) noexcept {
|
||||
static const char * const ast_node_types[] = { "Id", "Fun_Call", "Unused_Return_Fun_Call", "Arg_List", "Equation", "Var_Decl",
|
||||
constexpr const char *ast_node_type_to_string(AST_Node_Type ast_node_type) noexcept {
|
||||
constexpr const char * const ast_node_types[] = { "Id", "Fun_Call", "Unused_Return_Fun_Call", "Arg_List", "Equation", "Var_Decl",
|
||||
"Array_Call", "Dot_Access",
|
||||
"Lambda", "Block", "Scopeless_Block", "Def", "While", "If", "For", "Ranged_For", "Inline_Array", "Inline_Map", "Return", "File", "Prefix", "Break", "Continue", "Map_Pair", "Value_Range",
|
||||
"Inline_Range", "Try", "Catch", "Finally", "Method", "Attr_Decl",
|
||||
@ -97,10 +97,10 @@ namespace chaiscript
|
||||
int line = 0;
|
||||
int column = 0;
|
||||
|
||||
File_Position(int t_file_line, int t_file_column) noexcept
|
||||
constexpr File_Position(int t_file_line, int t_file_column) noexcept
|
||||
: line(t_file_line), column(t_file_column) { }
|
||||
|
||||
File_Position() noexcept = default;
|
||||
constexpr File_Position() noexcept = default;
|
||||
};
|
||||
|
||||
struct Parse_Location {
|
||||
|
||||
@ -197,18 +197,18 @@ namespace chaiscript
|
||||
struct Array_View
|
||||
{
|
||||
template<std::size_t Len>
|
||||
Array_View(const std::array<utility::Static_String, Len> &data) noexcept
|
||||
: m_begin(&(*std::begin(data))),
|
||||
m_end(&(*std::end(data)))
|
||||
constexpr Array_View(const std::array<utility::Static_String, Len> &data) noexcept
|
||||
: m_begin(&data.front()),
|
||||
m_end(m_begin + Len)
|
||||
{
|
||||
}
|
||||
|
||||
auto begin() const noexcept
|
||||
constexpr auto begin() const noexcept
|
||||
{
|
||||
return m_begin;
|
||||
}
|
||||
|
||||
auto end() const noexcept
|
||||
constexpr auto end() const noexcept
|
||||
{
|
||||
return m_end;
|
||||
}
|
||||
@ -237,19 +237,19 @@ namespace chaiscript
|
||||
m_0, m_1, m_2, m_3, m_4, m_5, m_6, m_7, m_8, m_9, m_10, m_11
|
||||
}};
|
||||
|
||||
Operator_Matches() {}
|
||||
constexpr Operator_Matches() noexcept {}
|
||||
|
||||
auto begin() const noexcept
|
||||
constexpr auto begin() const noexcept
|
||||
{
|
||||
return all_data.begin();
|
||||
}
|
||||
|
||||
auto end() const noexcept
|
||||
constexpr auto end() const noexcept
|
||||
{
|
||||
return all_data.end();
|
||||
}
|
||||
|
||||
decltype(auto) operator[](const std::size_t pos) const noexcept {
|
||||
constexpr decltype(auto) operator[](const std::size_t pos) const noexcept {
|
||||
return (all_data[pos]);
|
||||
}
|
||||
|
||||
@ -319,9 +319,9 @@ namespace chaiscript
|
||||
|
||||
struct Position
|
||||
{
|
||||
Position() = default;
|
||||
constexpr Position() = default;
|
||||
|
||||
Position(std::string::const_iterator t_pos, std::string::const_iterator t_end) noexcept
|
||||
constexpr Position(std::string::const_iterator t_pos, std::string::const_iterator t_end) noexcept
|
||||
: line(1), col(1), m_pos(t_pos), m_end(t_end), m_last_col(1)
|
||||
{
|
||||
}
|
||||
@ -344,7 +344,7 @@ namespace chaiscript
|
||||
return *this;
|
||||
}
|
||||
|
||||
Position &operator--() noexcept {
|
||||
constexpr Position &operator--() noexcept {
|
||||
--m_pos;
|
||||
if (*m_pos == '\n') {
|
||||
--line;
|
||||
@ -355,12 +355,12 @@ namespace chaiscript
|
||||
return *this;
|
||||
}
|
||||
|
||||
Position &operator+=(size_t t_distance) noexcept {
|
||||
constexpr Position &operator+=(size_t t_distance) noexcept {
|
||||
*this = (*this) + t_distance;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Position operator+(size_t t_distance) const noexcept {
|
||||
constexpr Position operator+(size_t t_distance) const noexcept {
|
||||
Position ret(*this);
|
||||
for (size_t i = 0; i < t_distance; ++i) {
|
||||
++ret;
|
||||
@ -368,12 +368,12 @@ namespace chaiscript
|
||||
return ret;
|
||||
}
|
||||
|
||||
Position &operator-=(size_t t_distance) noexcept {
|
||||
constexpr Position &operator-=(size_t t_distance) noexcept {
|
||||
*this = (*this) - t_distance;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Position operator-(size_t t_distance) const noexcept {
|
||||
constexpr Position operator-(size_t t_distance) const noexcept {
|
||||
Position ret(*this);
|
||||
for (size_t i = 0; i < t_distance; ++i) {
|
||||
--ret;
|
||||
@ -381,15 +381,15 @@ namespace chaiscript
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool operator==(const Position &t_rhs) const noexcept {
|
||||
constexpr bool operator==(const Position &t_rhs) const noexcept {
|
||||
return m_pos == t_rhs.m_pos;
|
||||
}
|
||||
|
||||
bool operator!=(const Position &t_rhs) const noexcept {
|
||||
constexpr bool operator!=(const Position &t_rhs) const noexcept {
|
||||
return m_pos != t_rhs.m_pos;
|
||||
}
|
||||
|
||||
bool has_more() const noexcept {
|
||||
constexpr bool has_more() const noexcept {
|
||||
return m_pos != m_end;
|
||||
}
|
||||
|
||||
@ -397,10 +397,9 @@ namespace chaiscript
|
||||
return static_cast<size_t>(std::distance(m_pos, m_end));
|
||||
}
|
||||
|
||||
const char& operator*() const noexcept {
|
||||
constexpr const char& operator*() const noexcept {
|
||||
if (m_pos == m_end) {
|
||||
static const char ktmp ='\0';
|
||||
return ktmp;
|
||||
return ""[0];
|
||||
} else {
|
||||
return *m_pos;
|
||||
}
|
||||
@ -427,7 +426,7 @@ namespace chaiscript
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
public:
|
||||
explicit ChaiScript_Parser(Tracer tracer = Tracer(), Optimizer optimizer=Optimizer())
|
||||
: m_tracer(std::move(tracer)),
|
||||
m_optimizer(std::move(optimizer))
|
||||
@ -451,7 +450,7 @@ namespace chaiscript
|
||||
ChaiScript_Parser &operator=(ChaiScript_Parser &&) = delete;
|
||||
|
||||
/// test a char in an m_alphabet
|
||||
bool char_in_alphabet(char c, detail::Alphabet a) const noexcept { return m_alphabet[a][static_cast<uint8_t>(c)]; }
|
||||
constexpr bool char_in_alphabet(char c, detail::Alphabet a) const noexcept { return m_alphabet[a][static_cast<uint8_t>(c)]; }
|
||||
|
||||
/// Prints the parsed ast_nodes as a tree
|
||||
void debug_print(const AST_Node &t, std::string prepend = "") const override {
|
||||
|
||||
@ -14,7 +14,7 @@ namespace chaiscript {
|
||||
struct Noop_Tracer_Detail
|
||||
{
|
||||
template<typename T>
|
||||
void trace(const chaiscript::detail::Dispatch_State &, const AST_Node_Impl<T> *) noexcept
|
||||
constexpr void trace(const chaiscript::detail::Dispatch_State &, const AST_Node_Impl<T> *) noexcept
|
||||
{
|
||||
}
|
||||
};
|
||||
@ -23,7 +23,7 @@ namespace chaiscript {
|
||||
struct Tracer : T...
|
||||
{
|
||||
Tracer() = default;
|
||||
explicit Tracer(T ... t)
|
||||
constexpr explicit Tracer(T ... t)
|
||||
: T(std::move(t))...
|
||||
{
|
||||
}
|
||||
|
||||
@ -15,16 +15,16 @@ namespace chaiscript
|
||||
struct Static_String
|
||||
{
|
||||
template<size_t N>
|
||||
Static_String(const char (&str)[N]) noexcept
|
||||
constexpr Static_String(const char (&str)[N]) noexcept
|
||||
: m_size(N-1), data(&str[0])
|
||||
{
|
||||
}
|
||||
|
||||
size_t size() const noexcept {
|
||||
constexpr size_t size() const noexcept {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
const char *c_str() const noexcept {
|
||||
constexpr const char *c_str() const noexcept {
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user