mirror of
https://github.com/ChaiScript/ChaiScript.git
synced 2026-04-30 19:09:26 +08:00
Fix warnings as errors for GCC and clang
This commit is contained in:
parent
1b6515ebd4
commit
c0b3183b13
@ -178,7 +178,7 @@ else()
|
||||
add_definitions(-Werror -Wall -Wextra -Wconversion -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wcast-qual -Wunused -Woverloaded-virtual -Wno-noexcept-type -Wpedantic -Werror=return-type)
|
||||
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
|
||||
add_definitions(-Weverything -Wno-c++98-compat-pedantic -Wno-c++98-compat -Wno-documentation -Wno-switch-enum -Wno-weak-vtables -Wno-missing-prototypes -Wno-padded -Wno-missing-noreturn -Wno-exit-time-destructors -Wno-documentation-unknown-command -Wno-unused-template -Wno-undef -Wno-double-promotion)
|
||||
add_definitions(-Weverything -Wno-c++98-compat-pedantic -Wno-c++98-compat -Wno-documentation -Wno-switch-enum -Wno-weak-vtables -Wno-missing-prototypes -Wno-padded -Wno-missing-noreturn -Wno-exit-time-destructors -Wno-documentation-unknown-command -Wno-unused-template -Wno-undef -Wno-double-promotion -Wno-switch-default -Wno-nrvo -Wno-shadow-uncaptured-local -Wno-unsafe-buffer-usage-in-libc-call -Wno-c++20-extensions)
|
||||
else()
|
||||
add_definitions(-Wnoexcept)
|
||||
endif()
|
||||
@ -394,6 +394,9 @@ if(BUILD_TESTING)
|
||||
if(NOT MSVC)
|
||||
target_compile_options(catch2 PRIVATE -Wno-conversion -Wno-noexcept -Wno-maybe-uninitialized)
|
||||
endif()
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
|
||||
target_compile_options(catch2 PUBLIC -Wno-unknown-warning-option -Wno-covered-switch-default -Wno-disabled-macro-expansion -Wno-unsafe-buffer-usage -Wno-unused-macros)
|
||||
endif()
|
||||
|
||||
add_executable(compiled_tests unittests/compiled_tests.cpp)
|
||||
target_link_libraries(compiled_tests catch2 ${LIBS} ${CHAISCRIPT_LIBS})
|
||||
|
||||
@ -26,7 +26,7 @@ namespace chaiscript::bootstrap {
|
||||
throw std::range_error("Array index out of range. Received: " + std::to_string(index) + " expected < "
|
||||
+ std::to_string(extent));
|
||||
} else {
|
||||
return t[index];
|
||||
return *std::next(t, static_cast<std::ptrdiff_t>(index));
|
||||
}
|
||||
}),
|
||||
"[]");
|
||||
@ -37,7 +37,7 @@ namespace chaiscript::bootstrap {
|
||||
throw std::range_error("Array index out of range. Received: " + std::to_string(index) + " expected < "
|
||||
+ std::to_string(extent));
|
||||
} else {
|
||||
return t[index];
|
||||
return *std::next(t, static_cast<std::ptrdiff_t>(index));
|
||||
}
|
||||
}),
|
||||
"[]");
|
||||
|
||||
@ -34,7 +34,6 @@
|
||||
#include "dynamic_object.hpp"
|
||||
#include "proxy_constructors.hpp"
|
||||
#include "proxy_functions.hpp"
|
||||
#include "short_alloc.hpp"
|
||||
#include "type_conversions.hpp"
|
||||
#include "type_info.hpp"
|
||||
|
||||
@ -318,9 +317,6 @@ namespace chaiscript {
|
||||
|
||||
namespace detail {
|
||||
struct Stack_Holder {
|
||||
// template <class T, std::size_t BufSize = sizeof(T)*20000>
|
||||
// using SmallVector = std::vector<T, short_alloc<T, BufSize>>;
|
||||
|
||||
template<class T>
|
||||
using SmallVector = std::vector<T>;
|
||||
|
||||
@ -377,8 +373,8 @@ namespace chaiscript {
|
||||
|
||||
Dispatch_Engine(const Dispatch_Engine &) = delete;
|
||||
Dispatch_Engine &operator=(const Dispatch_Engine &) = delete;
|
||||
Dispatch_Engine(Dispatch_Engine &&) = default;
|
||||
Dispatch_Engine &operator=(Dispatch_Engine &&) = default;
|
||||
Dispatch_Engine(Dispatch_Engine &&) = delete;
|
||||
Dispatch_Engine &operator=(Dispatch_Engine &&) = delete;
|
||||
|
||||
#ifndef CHAISCRIPT_NO_THREADS
|
||||
/// Track an async thread so it can be joined during destruction
|
||||
@ -790,13 +786,13 @@ namespace chaiscript {
|
||||
t_loc = uint_fast32_t(funs.first);
|
||||
}
|
||||
|
||||
const auto do_attribute_call = [this](int l_num_params,
|
||||
const auto do_attribute_call = [this](std::size_t l_num_params,
|
||||
Function_Params l_params,
|
||||
const std::vector<Proxy_Function> &l_funs,
|
||||
const Type_Conversions_State &l_conversions) -> Boxed_Value {
|
||||
Function_Params attr_params(l_params.begin(), l_params.begin() + l_num_params);
|
||||
Function_Params attr_params(l_params.first(l_num_params));
|
||||
Boxed_Value bv = dispatch::dispatch(l_funs, attr_params, l_conversions);
|
||||
if (l_num_params < int(l_params.size()) || bv.get_type_info().bare_equal(user_type<dispatch::Proxy_Function_Base>())) {
|
||||
if (l_num_params < l_params.size() || bv.get_type_info().bare_equal(user_type<dispatch::Proxy_Function_Base>())) {
|
||||
struct This_Foist {
|
||||
This_Foist(Dispatch_Engine &e, const Boxed_Value &t_bv)
|
||||
: m_e(e) {
|
||||
@ -814,16 +810,16 @@ namespace chaiscript {
|
||||
try {
|
||||
auto func = boxed_cast<const dispatch::Proxy_Function_Base *>(bv);
|
||||
try {
|
||||
return (*func)({l_params.begin() + l_num_params, l_params.end()}, l_conversions);
|
||||
return (*func)(l_params.subspan(l_num_params), l_conversions);
|
||||
} catch (const chaiscript::exception::bad_boxed_cast &) {
|
||||
} catch (const chaiscript::exception::arity_error &) {
|
||||
} catch (const chaiscript::exception::guard_error &) {
|
||||
}
|
||||
throw chaiscript::exception::dispatch_error({l_params.begin() + l_num_params, l_params.end()},
|
||||
throw chaiscript::exception::dispatch_error(l_params.subspan(l_num_params),
|
||||
std::vector<Const_Proxy_Function>{boxed_cast<Const_Proxy_Function>(bv)});
|
||||
} catch (const chaiscript::exception::bad_boxed_cast &) {
|
||||
// unable to convert bv into a Proxy_Function_Base
|
||||
throw chaiscript::exception::dispatch_error({l_params.begin() + l_num_params, l_params.end()},
|
||||
throw chaiscript::exception::dispatch_error(l_params.subspan(l_num_params),
|
||||
std::vector<Const_Proxy_Function>(l_funs.begin(), l_funs.end()));
|
||||
}
|
||||
} else {
|
||||
@ -873,7 +869,7 @@ namespace chaiscript {
|
||||
if (!functions.empty()) {
|
||||
try {
|
||||
if (is_no_param) {
|
||||
auto tmp_params = params.to_vector();
|
||||
auto tmp_params = std::vector<Boxed_Value>(params.begin(), params.end());
|
||||
tmp_params.insert(tmp_params.begin() + 1, var(t_name));
|
||||
return do_attribute_call(2, Function_Params(tmp_params), functions, t_conversions);
|
||||
} else {
|
||||
@ -948,7 +944,7 @@ namespace chaiscript {
|
||||
const auto &f = this->boxed_cast<Const_Proxy_Function>(params[0]);
|
||||
const Type_Conversions_State convs(m_conversions, m_conversions.conversion_saves());
|
||||
|
||||
return const_var(f->call_match(Function_Params(params.begin() + 1, params.end()), convs));
|
||||
return const_var(f->call_match(Function_Params(params.subspan(1)), convs));
|
||||
}
|
||||
|
||||
/// Dump all system info to stdout
|
||||
|
||||
@ -12,55 +12,11 @@
|
||||
|
||||
#include "boxed_value.hpp"
|
||||
|
||||
#include <span>
|
||||
|
||||
namespace chaiscript {
|
||||
class Function_Params {
|
||||
public:
|
||||
constexpr Function_Params(const Boxed_Value *const t_begin, const Boxed_Value *const t_end)
|
||||
: m_begin(t_begin)
|
||||
, m_end(t_end) {
|
||||
}
|
||||
|
||||
explicit Function_Params(const Boxed_Value &bv)
|
||||
: m_begin(&bv)
|
||||
, m_end(m_begin + 1) {
|
||||
}
|
||||
|
||||
explicit Function_Params(const std::vector<Boxed_Value> &vec)
|
||||
: m_begin(vec.empty() ? nullptr : &vec.front())
|
||||
, m_end(vec.empty() ? nullptr : &vec.front() + vec.size()) {
|
||||
}
|
||||
|
||||
template<size_t Size>
|
||||
constexpr explicit Function_Params(const std::array<Boxed_Value, Size> &a)
|
||||
: m_begin(&a.front())
|
||||
, m_end(&a.front() + Size) {
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr const Boxed_Value &operator[](const std::size_t t_i) const noexcept { return m_begin[t_i]; }
|
||||
|
||||
[[nodiscard]] constexpr const Boxed_Value *begin() const noexcept { return m_begin; }
|
||||
|
||||
[[nodiscard]] constexpr const Boxed_Value &front() const noexcept { return *m_begin; }
|
||||
|
||||
[[nodiscard]] constexpr const Boxed_Value *end() const noexcept { return m_end; }
|
||||
|
||||
[[nodiscard]] constexpr std::size_t size() const noexcept { return std::size_t(m_end - m_begin); }
|
||||
|
||||
[[nodiscard]] std::vector<Boxed_Value> to_vector() const { return std::vector<Boxed_Value>{m_begin, m_end}; }
|
||||
|
||||
[[nodiscard]] constexpr bool empty() const noexcept { return m_begin == m_end; }
|
||||
|
||||
private:
|
||||
const Boxed_Value *m_begin = nullptr;
|
||||
const Boxed_Value *m_end = nullptr;
|
||||
};
|
||||
|
||||
// Constructor specialization for array of size 0
|
||||
template<>
|
||||
constexpr Function_Params::Function_Params(const std::array<Boxed_Value, size_t{0}> & /* a */)
|
||||
: m_begin(nullptr)
|
||||
, m_end(nullptr) {
|
||||
}
|
||||
using Function_Params = std::span<const Boxed_Value>;
|
||||
|
||||
} // namespace chaiscript
|
||||
|
||||
|
||||
@ -65,7 +65,7 @@ namespace chaiscript {
|
||||
bool operator==(const Param_Types &t_rhs) const noexcept { return m_types == t_rhs.m_types; }
|
||||
|
||||
std::vector<Boxed_Value> convert(Function_Params t_params, const Type_Conversions_State &t_conversions) const {
|
||||
auto vals = t_params.to_vector();
|
||||
auto vals = std::vector<Boxed_Value>{t_params.begin(), t_params.end()};
|
||||
const auto dynamic_object_type_info = user_type<Dynamic_Object>();
|
||||
for (size_t i = 0; i < vals.size(); ++i) {
|
||||
const auto &name = m_types[i].first;
|
||||
@ -682,13 +682,13 @@ namespace chaiscript {
|
||||
public:
|
||||
dispatch_error(const Function_Params &t_parameters, std::vector<Const_Proxy_Function> t_functions)
|
||||
: std::runtime_error("Error with function dispatch")
|
||||
, parameters(t_parameters.to_vector())
|
||||
, parameters(t_parameters.begin(), t_parameters.end())
|
||||
, functions(std::move(t_functions)) {
|
||||
}
|
||||
|
||||
dispatch_error(const Function_Params &t_parameters, std::vector<Const_Proxy_Function> t_functions, const std::string &t_desc)
|
||||
: std::runtime_error(t_desc)
|
||||
, parameters(t_parameters.to_vector())
|
||||
, parameters(t_parameters.begin(), t_parameters.end())
|
||||
, functions(std::move(t_functions)) {
|
||||
}
|
||||
|
||||
|
||||
@ -1,137 +0,0 @@
|
||||
#ifndef SHORT_ALLOC_H
|
||||
#define SHORT_ALLOC_H
|
||||
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2015 Howard Hinnant
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
||||
template<std::size_t N, std::size_t alignment = alignof(std::max_align_t)>
|
||||
class arena {
|
||||
alignas(alignment) char buf_[N];
|
||||
char *ptr_;
|
||||
|
||||
public:
|
||||
~arena() { ptr_ = nullptr; }
|
||||
arena() noexcept
|
||||
: ptr_(buf_) {
|
||||
}
|
||||
arena(const arena &) = delete;
|
||||
arena &operator=(const arena &) = delete;
|
||||
|
||||
template<std::size_t ReqAlign>
|
||||
char *allocate(std::size_t n);
|
||||
void deallocate(char *p, std::size_t n) noexcept;
|
||||
|
||||
static constexpr std::size_t size() noexcept { return N; }
|
||||
std::size_t used() const noexcept { return static_cast<std::size_t>(ptr_ - buf_); }
|
||||
void reset() noexcept { ptr_ = buf_; }
|
||||
|
||||
private:
|
||||
static std::size_t align_up(std::size_t n) noexcept { return (n + (alignment - 1)) & ~(alignment - 1); }
|
||||
|
||||
bool pointer_in_buffer(char *p) noexcept { return buf_ <= p && p <= buf_ + N; }
|
||||
};
|
||||
|
||||
template<std::size_t N, std::size_t alignment>
|
||||
template<std::size_t ReqAlign>
|
||||
char *arena<N, alignment>::allocate(std::size_t n) {
|
||||
static_assert(ReqAlign <= alignment, "alignment is too small for this arena");
|
||||
assert(pointer_in_buffer(ptr_) && "short_alloc has outlived arena");
|
||||
auto const aligned_n = align_up(n);
|
||||
if (static_cast<decltype(aligned_n)>(buf_ + N - ptr_) >= aligned_n) {
|
||||
char *r = ptr_;
|
||||
ptr_ += aligned_n;
|
||||
return r;
|
||||
}
|
||||
|
||||
static_assert(alignment <= alignof(std::max_align_t),
|
||||
"you've chosen an "
|
||||
"alignment that is larger than alignof(std::max_align_t), and "
|
||||
"cannot be guaranteed by normal operator new");
|
||||
return static_cast<char *>(::operator new(n));
|
||||
}
|
||||
|
||||
template<std::size_t N, std::size_t alignment>
|
||||
void arena<N, alignment>::deallocate(char *p, std::size_t n) noexcept {
|
||||
assert(pointer_in_buffer(ptr_) && "short_alloc has outlived arena");
|
||||
if (pointer_in_buffer(p)) {
|
||||
n = align_up(n);
|
||||
if (p + n == ptr_) {
|
||||
ptr_ = p;
|
||||
}
|
||||
} else {
|
||||
::operator delete(p);
|
||||
}
|
||||
}
|
||||
|
||||
template<class T, std::size_t N, std::size_t Align = alignof(std::max_align_t)>
|
||||
class short_alloc {
|
||||
public:
|
||||
using value_type = T;
|
||||
static auto constexpr alignment = Align;
|
||||
static auto constexpr size = N;
|
||||
using arena_type = arena<size, alignment>;
|
||||
|
||||
private:
|
||||
arena_type &a_;
|
||||
|
||||
public:
|
||||
short_alloc(const short_alloc &) = default;
|
||||
short_alloc &operator=(const short_alloc &) = delete;
|
||||
|
||||
explicit short_alloc(arena_type &a) noexcept
|
||||
: a_(a) {
|
||||
static_assert(size % alignment == 0, "size N needs to be a multiple of alignment Align");
|
||||
}
|
||||
template<class U>
|
||||
explicit short_alloc(const short_alloc<U, N, alignment> &a) noexcept
|
||||
: a_(a.a_) {
|
||||
}
|
||||
|
||||
template<class _Up>
|
||||
struct rebind {
|
||||
using other = short_alloc<_Up, N, alignment>;
|
||||
};
|
||||
|
||||
T *allocate(std::size_t n) { return reinterpret_cast<T *>(a_.template allocate<alignof(T)>(n * sizeof(T))); }
|
||||
void deallocate(T *p, std::size_t n) noexcept { a_.deallocate(reinterpret_cast<char *>(p), n * sizeof(T)); }
|
||||
|
||||
template<class T1, std::size_t N1, std::size_t A1, class U, std::size_t M, std::size_t A2>
|
||||
friend bool operator==(const short_alloc<T1, N1, A1> &x, const short_alloc<U, M, A2> &y) noexcept;
|
||||
|
||||
template<class U, std::size_t M, std::size_t A>
|
||||
friend class short_alloc;
|
||||
};
|
||||
|
||||
template<class T, std::size_t N, std::size_t A1, class U, std::size_t M, std::size_t A2>
|
||||
inline bool operator==(const short_alloc<T, N, A1> &x, const short_alloc<U, M, A2> &y) noexcept {
|
||||
return N == M && A1 == A2 && &x.a_ == &y.a_;
|
||||
}
|
||||
|
||||
template<class T, std::size_t N, std::size_t A1, class U, std::size_t M, std::size_t A2>
|
||||
inline bool operator!=(const short_alloc<T, N, A1> &x, const short_alloc<U, M, A2> &y) noexcept {
|
||||
return !(x == y);
|
||||
}
|
||||
|
||||
#endif // SHORT_ALLOC_HPP
|
||||
@ -12,6 +12,7 @@
|
||||
|
||||
#include "../utility/hash.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
namespace chaiscript {
|
||||
@ -52,10 +53,10 @@ namespace chaiscript {
|
||||
invalid
|
||||
};
|
||||
|
||||
constexpr static const char *to_string(Opers t_oper) noexcept {
|
||||
constexpr const char *opers[]
|
||||
constexpr static std::string_view to_string(Opers t_oper) noexcept {
|
||||
constexpr const std::array opers
|
||||
= {"", "==", "<", ">", "<=", ">=", "!=", "", "=", "++", "--", "*=", "+=", "/=", "-=", "", "&=", "|=", "<<=", ">>=", "%=", "^=", "", "<<", ">>", "%", "&", "|", "^", "~", "", "+", "/", "*", "-", "+", "-", ""};
|
||||
return opers[static_cast<int>(t_oper)];
|
||||
return opers[static_cast<std::size_t>(t_oper)];
|
||||
}
|
||||
|
||||
constexpr static Opers to_operator(std::string_view t_str, bool t_is_unary = false) noexcept {
|
||||
|
||||
@ -130,9 +130,9 @@ namespace chaiscript {
|
||||
namespace {
|
||||
/// Helper lookup to get the name of each node type
|
||||
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", "Assign_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", "Logical_And", "Logical_Or", "Reference", "Switch", "Case", "Default", "Noop", "Class", "Binary", "Arg", "Global_Decl", "Constant", "Compiled", "Const_Var_Decl", "Const_Assign_Decl", "Using", "Enum", "Namespace_Block"};
|
||||
constexpr std::array ast_node_types = {"Id", "Fun_Call", "Unused_Return_Fun_Call", "Arg_List", "Equation", "Var_Decl", "Assign_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", "Logical_And", "Logical_Or", "Reference", "Switch", "Case", "Default", "Noop", "Class", "Binary", "Arg", "Global_Decl", "Constant", "Compiled", "Const_Var_Decl", "Const_Assign_Decl", "Using", "Enum", "Namespace_Block"};
|
||||
|
||||
return ast_node_types[static_cast<int>(ast_node_type)];
|
||||
return ast_node_types[static_cast<std::size_t>(ast_node_type)];
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
@ -1246,7 +1246,7 @@ namespace chaiscript {
|
||||
const auto &ns_name = this->children[0]->text;
|
||||
|
||||
auto ns_name_bv = const_var(ns_name);
|
||||
t_ss->call_function("namespace", m_ns_loc, Function_Params{ns_name_bv}, t_ss.conversions());
|
||||
t_ss->call_function("namespace", m_ns_loc, Function_Params{&ns_name_bv, 1}, t_ss.conversions());
|
||||
|
||||
std::vector<std::string> parts;
|
||||
{
|
||||
@ -1350,7 +1350,7 @@ namespace chaiscript {
|
||||
};
|
||||
|
||||
const auto call_function = [&t_ss](const auto &t_funcs, const Boxed_Value &t_param) {
|
||||
return dispatch::dispatch(*t_funcs, Function_Params{t_param}, t_ss.conversions());
|
||||
return dispatch::dispatch(*t_funcs, Function_Params{&t_param, 1}, t_ss.conversions());
|
||||
};
|
||||
|
||||
const std::string &loop_var_name = this->children[0]->text;
|
||||
@ -1646,8 +1646,8 @@ namespace chaiscript {
|
||||
return Boxed_Number::do_oper(m_oper, bv);
|
||||
} else {
|
||||
chaiscript::eval::detail::Function_Push_Pop fpp(t_ss);
|
||||
fpp.save_params(Function_Params{bv});
|
||||
return t_ss->call_function(this->text, m_loc, Function_Params{bv}, t_ss.conversions());
|
||||
fpp.save_params(Function_Params{&bv, 1});
|
||||
return t_ss->call_function(this->text, m_loc, Function_Params{&bv, 1}, t_ss.conversions());
|
||||
}
|
||||
} catch (const exception::dispatch_error &e) {
|
||||
throw exception::eval_error("Error with prefix operator evaluation: '" + this->text + "'", e.parameters, e.functions, false, *t_ss);
|
||||
@ -1755,7 +1755,7 @@ namespace chaiscript {
|
||||
|
||||
if (dispatch::Param_Types(
|
||||
std::vector<std::pair<std::string, Type_Info>>{Arg_List_AST_Node<T>::get_arg_type(*catch_block.children[0], t_ss)})
|
||||
.match(Function_Params{t_except}, t_ss.conversions())
|
||||
.match(Function_Params{&t_except, 1}, t_ss.conversions())
|
||||
.first) {
|
||||
t_ss.add_object(name, t_except);
|
||||
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@ -109,9 +110,7 @@ namespace chaiscript {
|
||||
|
||||
template<typename Array2D, typename First, typename Second>
|
||||
constexpr static void set_alphabet(Array2D &array, const First first, const Second second) noexcept {
|
||||
auto *first_ptr = &std::get<0>(array) + static_cast<std::size_t>(first);
|
||||
auto *second_ptr = &std::get<0>(*first_ptr) + static_cast<std::size_t>(second);
|
||||
*second_ptr = true;
|
||||
array[static_cast<std::size_t>(first)][static_cast<std::size_t>(second)] = true;
|
||||
}
|
||||
|
||||
constexpr static std::array<std::array<bool, detail::lengthof_alphabet>, detail::max_alphabet> build_alphabet() noexcept {
|
||||
@ -341,13 +340,13 @@ namespace chaiscript {
|
||||
++col;
|
||||
}
|
||||
|
||||
++m_pos;
|
||||
std::advance(m_pos, 1);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Position &operator--() noexcept {
|
||||
--m_pos;
|
||||
std::advance(m_pos, -1);
|
||||
if (*m_pos == '\n') {
|
||||
--line;
|
||||
col = m_last_col;
|
||||
@ -490,7 +489,7 @@ namespace chaiscript {
|
||||
if (m_position.remaining() >= len) {
|
||||
const char *file_pos = &(*m_position);
|
||||
for (size_t pos = 0; pos < len; ++pos) {
|
||||
if (sym.c_str()[pos] != file_pos[pos]) {
|
||||
if (sym[pos] != *std::next(file_pos, static_cast<ssize_t>(pos))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1498,7 +1497,7 @@ namespace chaiscript {
|
||||
if (m_position.remaining() >= len) {
|
||||
auto tmp = m_position;
|
||||
for (size_t i = 0; tmp.has_more() && i < len; ++i) {
|
||||
if (*tmp != t_s.c_str()[i]) {
|
||||
if (*tmp != t_s[i]) {
|
||||
return false;
|
||||
}
|
||||
++tmp;
|
||||
@ -2942,7 +2941,7 @@ namespace chaiscript {
|
||||
/// Parses the given input string, tagging parsed ast_nodes with the given m_filename.
|
||||
AST_NodePtr parse_internal(const std::string &t_input, std::string t_fname) {
|
||||
const auto begin = t_input.empty() ? nullptr : &t_input.front();
|
||||
const auto end = begin == nullptr ? nullptr : begin + t_input.size();
|
||||
const auto end = begin == nullptr ? nullptr : std::next(begin, std::ssize(t_input));
|
||||
m_position = Position(begin, end);
|
||||
m_filename = std::make_shared<std::string>(std::move(t_fname));
|
||||
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
#define CHAISCRIPT_UTILITY_FNV1A_HPP_
|
||||
|
||||
#include "../chaiscript_defines.hpp"
|
||||
|
||||
#include <iterator>
|
||||
#include <cstdint>
|
||||
|
||||
namespace chaiscript {
|
||||
@ -28,7 +30,7 @@ namespace chaiscript {
|
||||
|
||||
while (begin != end) {
|
||||
h = (h ^ (*begin)) * 0x01000193;
|
||||
++begin;
|
||||
std::advance(begin, 1);
|
||||
}
|
||||
return h;
|
||||
|
||||
@ -43,7 +45,7 @@ namespace chaiscript {
|
||||
|
||||
template<size_t N>
|
||||
static constexpr std::uint32_t hash(const char (&str)[N]) noexcept {
|
||||
return hash(std::begin(str), std::end(str) - 1);
|
||||
return hash(std::begin(str), std::prev(std::end(str)));
|
||||
}
|
||||
|
||||
static constexpr std::uint32_t hash(std::string_view sv) noexcept {
|
||||
@ -64,7 +66,7 @@ namespace chaiscript {
|
||||
hash += std::uint32_t(*begin);
|
||||
hash += hash << 10;
|
||||
hash ^= hash >> 6;
|
||||
++begin;
|
||||
std::advance(begin, 1);
|
||||
}
|
||||
|
||||
hash += hash << 3;
|
||||
|
||||
@ -159,7 +159,9 @@ namespace chaiscript::json {
|
||||
|
||||
JSON(initializer_list<JSON> list)
|
||||
: internal(Class::Object) {
|
||||
for (auto i = list.begin(), e = list.end(); i != e; ++i, ++i) {
|
||||
for (auto i = list.begin(), e = list.end();
|
||||
i != e;
|
||||
std::advance(i, 2)) {
|
||||
operator[](i->to_string()) = *std::next(i);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
#ifndef CHAISCRIPT_UTILITY_STATIC_STRING_HPP_
|
||||
#define CHAISCRIPT_UTILITY_STATIC_STRING_HPP_
|
||||
|
||||
#include <iterator>
|
||||
|
||||
namespace chaiscript::utility {
|
||||
struct Static_String {
|
||||
template<size_t N>
|
||||
@ -21,30 +23,17 @@ namespace chaiscript::utility {
|
||||
|
||||
constexpr auto begin() const noexcept { return data; }
|
||||
|
||||
constexpr auto end() const noexcept { return data + m_size; }
|
||||
constexpr auto end() const noexcept { return std::next(data, static_cast<std::ptrdiff_t>(m_size)); }
|
||||
|
||||
constexpr bool operator==(std::string_view other) const noexcept {
|
||||
// return std::string_view(data, m_size) == other;
|
||||
auto b1 = begin();
|
||||
const auto e1 = end();
|
||||
auto b2 = other.begin();
|
||||
const auto e2 = other.end();
|
||||
|
||||
if (e1 - b1 != e2 - b2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (b1 != e1) {
|
||||
if (*b1 != *b2) {
|
||||
return false;
|
||||
}
|
||||
++b1;
|
||||
++b2;
|
||||
}
|
||||
return true;
|
||||
constexpr auto operator[](const std::size_t idx) const noexcept {
|
||||
return *std::next(data, static_cast<std::ptrdiff_t>(idx));
|
||||
}
|
||||
|
||||
bool operator==(const std::string &t_str) const noexcept { return std::equal(begin(), end(), std::cbegin(t_str), std::cend(t_str)); }
|
||||
constexpr bool operator==(std::string_view other) const noexcept {
|
||||
return std::string_view(data, m_size) == other;
|
||||
}
|
||||
|
||||
constexpr bool operator==(const std::string &t_str) const noexcept { return std::equal(begin(), end(), std::cbegin(t_str), std::cend(t_str)); }
|
||||
|
||||
const size_t m_size;
|
||||
const char *data = nullptr;
|
||||
|
||||
@ -32,7 +32,7 @@ char *mystrdup(const char *s) {
|
||||
#else
|
||||
strncpy(d, s, len); // Copy the characters
|
||||
#endif
|
||||
d[len] = '\0';
|
||||
*std::next(d, static_cast<std::ptrdiff_t>(len)) = '\0';
|
||||
return d; // Return the new string
|
||||
}
|
||||
|
||||
@ -297,7 +297,7 @@ int main(int argc, char *argv[]) {
|
||||
++i;
|
||||
}
|
||||
|
||||
std::string arg(i ? argv[i] : "--interactive");
|
||||
std::string arg(i ? *std::next(argv, i) : "--interactive");
|
||||
|
||||
enum {
|
||||
eInteractive,
|
||||
@ -311,7 +311,7 @@ int main(int argc, char *argv[]) {
|
||||
std::cout << "insufficient input following " << arg << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
} else {
|
||||
arg = argv[++i];
|
||||
arg = *std::next(argv, ++i);
|
||||
}
|
||||
} else if (arg == "-" || arg == "--stdin") {
|
||||
arg = "";
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <regex>
|
||||
@ -36,7 +37,7 @@ char *mystrdup(const char *s) {
|
||||
#else
|
||||
strncpy(d, s, len); // Copy the characters
|
||||
#endif
|
||||
d[len] = '\0';
|
||||
*std::next(d, static_cast<std::ptrdiff_t>(len)) = '\0';
|
||||
return d; // Return the new string
|
||||
}
|
||||
|
||||
@ -283,7 +284,7 @@ int main(int argc, char *argv[]) {
|
||||
++i;
|
||||
}
|
||||
|
||||
std::string arg(i != 0 ? argv[i] : "--interactive");
|
||||
std::string arg(i != 0 ? *std::next(argv, i) : "--interactive");
|
||||
|
||||
enum {
|
||||
eInteractive,
|
||||
@ -297,7 +298,7 @@ int main(int argc, char *argv[]) {
|
||||
std::cout << "insufficient input following " << arg << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
arg = argv[++i];
|
||||
arg = *std::next(argv, ++i);
|
||||
|
||||
} else if (arg == "-" || arg == "--stdin") {
|
||||
arg = "";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user