Merge branch 'AddMoreWarningFlags' into develop

Conflicts:
	include/chaiscript/dispatchkit/boxed_number.hpp
	include/chaiscript/dispatchkit/proxy_functions.hpp
	include/chaiscript/language/chaiscript_eval.hpp
This commit is contained in:
Jason Turner 2015-01-16 19:32:53 -07:00
commit e86fc96b2f
23 changed files with 186 additions and 91 deletions

View File

@ -21,5 +21,5 @@ compilers:
skip_packaging: true skip_packaging: true
cmake_extra_flags: -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON cmake_extra_flags: -DBUILD_SAMPLES:BOOL=ON -DBUILD_PACKAGE:BOOL=ON -DBUILD_TESTING:BOOL=ON
- name: cppcheck - name: cppcheck
compiler_extra_flags: --enable=all -I include --inline-suppr compiler_extra_flags: --enable=all -I include --inline-suppr -Umax --suppress="*:cmake*"

View File

@ -152,7 +152,13 @@ if(MSVC)
# how to workaround or fix the error. So I'm disabling it globally. # how to workaround or fix the error. So I'm disabling it globally.
add_definitions(/wd4503) add_definitions(/wd4503)
else() else()
add_definitions(-Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -pedantic ${CPP11_FLAG}) add_definitions(-Wall -Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wcast-qual -Woverloaded-virtual -pedantic ${CPP11_FLAG})
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_definitions(-Weverything -Wno-c++98-compat -Wno-documentation -Wno-switch-enum -Wno-weak-vtables -Wno-sign-conversion -Wno-missing-prototypes -Wno-padded -Wno-missing-noreturn)
else()
add_definitions(-Wnoexcept)
endif()
if(APPLE) if(APPLE)
add_definitions(-Wno-sign-compare) add_definitions(-Wno-sign-compare)

View File

@ -82,16 +82,27 @@ namespace chaiscript
t().erase(m_key); t().erase(m_key);
} }
inline T *operator->() const inline const T *operator->() const
{ {
return &(t()[m_key]); return &(t()[m_key]);
} }
inline T &operator*() const inline const T &operator*() const
{ {
return t()[m_key]; return t()[m_key];
} }
inline T *operator->()
{
return &(t()[m_key]);
}
inline T &operator*()
{
return t()[m_key];
}
void *m_key; void *m_key;
private: private:
@ -117,12 +128,22 @@ namespace chaiscript
{ {
} }
inline T *operator->() const inline const T *operator->() const
{ {
return get_tls().get(); return get_tls().get();
} }
inline T &operator*() const inline const T &operator*() const
{
return *get_tls();
}
inline T *operator->()
{
return get_tls().get();
}
inline T &operator*()
{ {
return *get_tls(); return *get_tls();
} }

View File

@ -26,6 +26,8 @@ namespace chaiscript {
{ {
} }
bad_any_cast(const bad_any_cast &) = default;
virtual ~bad_any_cast() CHAISCRIPT_NOEXCEPT {} virtual ~bad_any_cast() CHAISCRIPT_NOEXCEPT {}
/// \brief Description of what error occurred /// \brief Description of what error occurred
@ -105,7 +107,7 @@ namespace chaiscript {
} }
} }
#if _MSC_VER != 1800 #if !defined(_MSC_VER) || _MSC_VER != 1800
Any(Any &&) = default; Any(Any &&) = default;
Any &operator=(Any &&t_any) = default; Any &operator=(Any &&t_any) = default;
#endif #endif

View File

@ -45,7 +45,8 @@ namespace chaiscript
{ {
} }
virtual ~bad_boxed_cast() CHAISCRIPT_NOEXCEPT {} bad_boxed_cast(const bad_boxed_cast &) = default;
virtual ~bad_boxed_cast() CHAISCRIPT_NOEXCEPT {}
/// \brief Description of what error occurred /// \brief Description of what error occurred
virtual const char * what() const CHAISCRIPT_NOEXCEPT CHAISCRIPT_OVERRIDE virtual const char * what() const CHAISCRIPT_NOEXCEPT CHAISCRIPT_OVERRIDE

View File

@ -246,6 +246,7 @@ namespace chaiscript
template<typename ContainerType> template<typename ContainerType>
ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module())) ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
{ {
// cppcheck-suppress syntaxError
typedef typename ContainerType::reference(ContainerType::*indexoper)(size_t); typedef typename ContainerType::reference(ContainerType::*indexoper)(size_t);
typedef typename ContainerType::const_reference(ContainerType::*constindexoper)(size_t) const; typedef typename ContainerType::const_reference(ContainerType::*constindexoper)(size_t) const;

View File

@ -45,6 +45,15 @@ namespace chaiscript
#pragma warning(disable : 4244 4018 4389 4146 4365) #pragma warning(disable : 4244 4018 4389 4146 4365)
#endif #endif
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wfloat-equal"
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
/// \brief Represents any numeric type, generically. Used internally for generic operations between POD values /// \brief Represents any numeric type, generically. Used internally for generic operations between POD values
class Boxed_Number class Boxed_Number
{ {
@ -67,9 +76,6 @@ namespace chaiscript
struct boolean struct boolean
{ {
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wsign-compare"
#endif
template<typename T, typename U> template<typename T, typename U>
static Boxed_Value go(Operators::Opers t_oper, const T &t, const U &u, const Boxed_Value &) static Boxed_Value go(Operators::Opers t_oper, const T &t, const U &u, const Boxed_Value &)
{ {
@ -370,6 +376,13 @@ namespace chaiscript
validate_boxed_number(bv); validate_boxed_number(bv);
} }
Boxed_Number(const Boxed_Number &) = default;
#if !defined(_MSC_VER) || _MSC_VER != 1800
Boxed_Number(Boxed_Number &&) = default;
Boxed_Number& operator=(Boxed_Number &&) = default;
#endif
template<typename T> explicit Boxed_Number(T t) template<typename T> explicit Boxed_Number(T t)
: bv(Boxed_Value(t)) : bv(Boxed_Value(t))
{ {
@ -577,6 +590,7 @@ namespace chaiscript
} }
} }
// cppcheck-suppress operatorEq
Boxed_Number operator=(const Boxed_Value &v) Boxed_Number operator=(const Boxed_Value &v)
{ {
validate_boxed_number(v); validate_boxed_number(v);
@ -584,6 +598,7 @@ namespace chaiscript
return *this; return *this;
} }
// cppcheck-suppress operatorEq
Boxed_Number operator=(const Boxed_Number &t_rhs) const Boxed_Number operator=(const Boxed_Number &t_rhs) const
{ {
return oper(Operators::assign, this->bv, t_rhs.bv); return oper(Operators::assign, this->bv, t_rhs.bv);
@ -881,6 +896,10 @@ namespace chaiscript
}; };
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifdef CHAISCRIPT_MSVC #ifdef CHAISCRIPT_MSVC
#pragma warning(pop) #pragma warning(pop)
#endif #endif

View File

@ -72,8 +72,8 @@ namespace chaiscript
chaiscript::detail::Any m_obj; chaiscript::detail::Any m_obj;
void *m_data_ptr; void *m_data_ptr;
const void *m_const_data_ptr; const void *m_const_data_ptr;
bool m_is_ref;
std::unique_ptr<std::map<std::string, Boxed_Value>> m_attrs; std::unique_ptr<std::map<std::string, Boxed_Value>> m_attrs;
bool m_is_ref;
}; };
struct Object_Data struct Object_Data

View File

@ -62,6 +62,8 @@ namespace chaiscript
{ {
} }
reserved_word_error(const reserved_word_error &) = default;
virtual ~reserved_word_error() CHAISCRIPT_NOEXCEPT {} virtual ~reserved_word_error() CHAISCRIPT_NOEXCEPT {}
std::string word() const std::string word() const
@ -82,6 +84,8 @@ namespace chaiscript
{ {
} }
illegal_name_error(const illegal_name_error &) = default;
virtual ~illegal_name_error() CHAISCRIPT_NOEXCEPT {} virtual ~illegal_name_error() CHAISCRIPT_NOEXCEPT {}
std::string name() const std::string name() const
@ -103,6 +107,8 @@ namespace chaiscript
{ {
} }
name_conflict_error(const name_conflict_error &) = default;
virtual ~name_conflict_error() CHAISCRIPT_NOEXCEPT {} virtual ~name_conflict_error() CHAISCRIPT_NOEXCEPT {}
std::string name() const std::string name() const
@ -125,6 +131,7 @@ namespace chaiscript
{ {
} }
global_non_const(const global_non_const &) = default;
virtual ~global_non_const() CHAISCRIPT_NOEXCEPT {} virtual ~global_non_const() CHAISCRIPT_NOEXCEPT {}
}; };
} }
@ -389,6 +396,8 @@ namespace chaiscript
std::set<std::string> m_reserved_words; std::set<std::string> m_reserved_words;
State &operator=(const State &) = default; State &operator=(const State &) = default;
State() = default;
State(const State &) = default;
}; };
Dispatch_Engine() Dispatch_Engine()
@ -445,7 +454,7 @@ namespace chaiscript
/// Adds a named object to the current scope /// Adds a named object to the current scope
/// \warning This version does not check the validity of the name /// \warning This version does not check the validity of the name
/// it is meant for internal use only /// it is meant for internal use only
void add_object(const std::string &name, const Boxed_Value &obj) const void add_object(const std::string &name, const Boxed_Value &obj)
{ {
if (!get_stack_data().back().insert(std::make_pair(name, obj)).second) if (!get_stack_data().back().insert(std::make_pair(name, obj)).second)
{ {
@ -695,10 +704,10 @@ namespace chaiscript
/// ///
std::map<std::string, Boxed_Value> get_scripting_objects() const std::map<std::string, Boxed_Value> get_scripting_objects() const
{ {
Stack_Holder &s = *m_stack_holder; const Stack_Holder &s = *m_stack_holder;
// We don't want the current context, but one up if it exists // We don't want the current context, but one up if it exists
StackData &stack = (s.stacks.size()==1)?(s.stacks.back()):(s.stacks[s.stacks.size()-2]); const StackData &stack = (s.stacks.size()==1)?(s.stacks.back()):(s.stacks[s.stacks.size()-2]);
std::map<std::string, Boxed_Value> retval; std::map<std::string, Boxed_Value> retval;
@ -965,7 +974,12 @@ namespace chaiscript
private: private:
/// Returns the current stack /// Returns the current stack
/// make const/non const versions /// make const/non const versions
StackData &get_stack_data() const const StackData &get_stack_data() const
{
return m_stack_holder->stacks.back();
}
StackData &get_stack_data()
{ {
return m_stack_holder->stacks.back(); return m_stack_holder->stacks.back();
} }

View File

@ -219,7 +219,7 @@ namespace chaiscript
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions &t_conversions) const = 0; virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions &t_conversions) const = 0;
Proxy_Function_Base(std::vector<Type_Info> t_types, int t_arity) Proxy_Function_Base(std::vector<Type_Info> t_types, int t_arity)
: m_types(std::move(t_types)), m_has_arithmetic_param(false), m_arity(t_arity) : m_types(std::move(t_types)), m_arity(t_arity), m_has_arithmetic_param(false)
{ {
for (size_t i = 1; i < m_types.size(); ++i) for (size_t i = 1; i < m_types.size(); ++i)
{ {
@ -265,8 +265,8 @@ namespace chaiscript
} }
std::vector<Type_Info> m_types; std::vector<Type_Info> m_types;
bool m_has_arithmetic_param;
int m_arity; int m_arity;
bool m_has_arithmetic_param;
}; };
} }
@ -287,6 +287,8 @@ namespace chaiscript
: std::runtime_error("Guard evaluation failed") : std::runtime_error("Guard evaluation failed")
{ } { }
guard_error(const guard_error &) = default;
virtual ~guard_error() CHAISCRIPT_NOEXCEPT virtual ~guard_error() CHAISCRIPT_NOEXCEPT
{ } { }
}; };
@ -309,8 +311,9 @@ namespace chaiscript
std::string t_description = "", std::string t_description = "",
Proxy_Function t_guard = Proxy_Function()) Proxy_Function t_guard = Proxy_Function())
: Proxy_Function_Base(build_param_type_list(t_param_types), t_arity), : Proxy_Function_Base(build_param_type_list(t_param_types), t_arity),
m_f(std::move(t_f)), m_arity(t_arity), m_param_types(std::move(t_param_types)), m_param_types(std::move(t_param_types)),
m_description(std::move(t_description)), m_guard(std::move(t_guard)), m_parsenode(std::move(t_parsenode)) m_guard(std::move(t_guard)), m_parsenode(std::move(t_parsenode)), m_description(std::move(t_description)),
m_f(std::move(t_f))
{ {
} }
@ -402,12 +405,11 @@ namespace chaiscript
return types; return types;
} }
std::function<Boxed_Value (const std::vector<Boxed_Value> &)> m_f;
int m_arity;
Param_Types m_param_types; Param_Types m_param_types;
std::string m_description;
Proxy_Function m_guard; Proxy_Function m_guard;
AST_NodePtr m_parsenode; AST_NodePtr m_parsenode;
std::string m_description;
std::function<Boxed_Value (const std::vector<Boxed_Value> &)> m_f;
}; };
/** /**
@ -654,7 +656,7 @@ namespace chaiscript
} }
} else { } else {
throw exception::arity_error(static_cast<int>(params.size()), 1); throw exception::arity_error(static_cast<int>(params.size()), 1);
} }
} }
private: private:
@ -683,6 +685,7 @@ namespace chaiscript
{ {
} }
dispatch_error(const dispatch_error &) = default;
virtual ~dispatch_error() CHAISCRIPT_NOEXCEPT {} virtual ~dispatch_error() CHAISCRIPT_NOEXCEPT {}
std::vector<Boxed_Value> parameters; std::vector<Boxed_Value> parameters;

View File

@ -42,6 +42,8 @@ namespace chaiscript
{ {
} }
arity_error(const arity_error &) = default;
virtual ~arity_error() CHAISCRIPT_NOEXCEPT {} virtual ~arity_error() CHAISCRIPT_NOEXCEPT {}
int got; int got;
@ -72,7 +74,7 @@ namespace chaiscript
template<typename Param, typename ... Rest> template<typename Param, typename ... Rest>
struct Try_Cast<Param, Rest...> struct Try_Cast<Param, Rest...>
{ {
static void do_try(const std::vector<Boxed_Value> &params, int generation, const Type_Conversions &t_conversions) static void do_try(const std::vector<Boxed_Value> &params, size_t generation, const Type_Conversions &t_conversions)
{ {
boxed_cast<Param>(params[generation], &t_conversions); boxed_cast<Param>(params[generation], &t_conversions);
Try_Cast<Rest...>::do_try(params, generation+1, t_conversions); Try_Cast<Rest...>::do_try(params, generation+1, t_conversions);
@ -83,7 +85,7 @@ namespace chaiscript
template<> template<>
struct Try_Cast<> struct Try_Cast<>
{ {
static void do_try(const std::vector<Boxed_Value> &, int, const Type_Conversions &) static void do_try(const std::vector<Boxed_Value> &, size_t, const Type_Conversions &)
{ {
} }
}; };

View File

@ -44,6 +44,8 @@ namespace chaiscript
{ {
} }
bad_boxed_dynamic_cast(const bad_boxed_dynamic_cast &) = default;
virtual ~bad_boxed_dynamic_cast() CHAISCRIPT_NOEXCEPT {} virtual ~bad_boxed_dynamic_cast() CHAISCRIPT_NOEXCEPT {}
}; };
@ -66,6 +68,8 @@ namespace chaiscript
{ {
} }
bad_boxed_type_cast(const bad_boxed_type_cast &) = default;
virtual ~bad_boxed_type_cast() CHAISCRIPT_NOEXCEPT {} virtual ~bad_boxed_type_cast() CHAISCRIPT_NOEXCEPT {}
}; };
} }
@ -213,14 +217,20 @@ namespace chaiscript
}; };
Type_Conversions() Type_Conversions()
: m_num_types(0), : m_mutex(),
m_conversions(),
m_convertableTypes(),
m_num_types(0),
m_thread_cache(this), m_thread_cache(this),
m_conversion_saves(this) m_conversion_saves(this)
{ {
} }
Type_Conversions(const Type_Conversions &t_other) Type_Conversions(const Type_Conversions &t_other)
: m_conversions(t_other.get_conversions()), m_num_types(m_conversions.size()), : m_mutex(),
m_conversions(t_other.get_conversions()),
m_convertableTypes(),
m_num_types(m_conversions.size()),
m_thread_cache(this), m_thread_cache(this),
m_conversion_saves(this) m_conversion_saves(this)
@ -366,8 +376,8 @@ namespace chaiscript
std::set<std::shared_ptr<detail::Type_Conversion_Base>> m_conversions; std::set<std::shared_ptr<detail::Type_Conversion_Base>> m_conversions;
std::set<const std::type_info *, Less_Than> m_convertableTypes; std::set<const std::type_info *, Less_Than> m_convertableTypes;
std::atomic_size_t m_num_types; std::atomic_size_t m_num_types;
chaiscript::detail::threading::Thread_Storage<std::set<const std::type_info *, Less_Than>> m_thread_cache; mutable chaiscript::detail::threading::Thread_Storage<std::set<const std::type_info *, Less_Than>> m_thread_cache;
chaiscript::detail::threading::Thread_Storage<Conversion_Saves> m_conversion_saves; mutable chaiscript::detail::threading::Thread_Storage<Conversion_Saves> m_conversion_saves;
}; };
typedef std::shared_ptr<chaiscript::detail::Type_Conversion_Base> Type_Conversion; typedef std::shared_ptr<chaiscript::detail::Type_Conversion_Base> Type_Conversion;

View File

@ -112,6 +112,8 @@ namespace chaiscript
reason(t_why) reason(t_why)
{} {}
eval_error(const eval_error &) = default;
std::string pretty_print() const std::string pretty_print() const
{ {
std::ostringstream ss; std::ostringstream ss;
@ -395,6 +397,7 @@ namespace chaiscript
: std::runtime_error("File Not Found: " + t_filename) : std::runtime_error("File Not Found: " + t_filename)
{ } { }
file_not_found_error(const file_not_found_error &) = default;
virtual ~file_not_found_error() CHAISCRIPT_NOEXCEPT {} virtual ~file_not_found_error() CHAISCRIPT_NOEXCEPT {}
}; };

View File

@ -61,9 +61,8 @@ namespace chaiscript
{ {
} }
virtual ~load_module_error() CHAISCRIPT_NOEXCEPT load_module_error(const load_module_error &) = default;
{ virtual ~load_module_error() CHAISCRIPT_NOEXCEPT {}
}
}; };
} }
@ -371,10 +370,10 @@ namespace chaiscript
m_engine.add(fun(&ChaiScript::internal_eval, this), "eval"); m_engine.add(fun(&ChaiScript::internal_eval, this), "eval");
m_engine.add(fun(&ChaiScript::internal_eval_ast, this), "eval"); m_engine.add(fun(&ChaiScript::internal_eval_ast, this), "eval");
m_engine.add(fun(&ChaiScript::version_major, this), "version_major"); m_engine.add(fun(&ChaiScript::version_major), "version_major");
m_engine.add(fun(&ChaiScript::version_minor, this), "version_minor"); m_engine.add(fun(&ChaiScript::version_minor), "version_minor");
m_engine.add(fun(&ChaiScript::version_patch, this), "version_patch"); m_engine.add(fun(&ChaiScript::version_patch), "version_patch");
m_engine.add(fun(&ChaiScript::version, this), "version"); m_engine.add(fun(&ChaiScript::version), "version");
m_engine.add(fun(&ChaiScript::add_global_const, this), "add_global_const"); m_engine.add(fun(&ChaiScript::add_global_const, this), "add_global_const");
m_engine.add(fun(&ChaiScript::add_global, this), "add_global"); m_engine.add(fun(&ChaiScript::add_global, this), "add_global");
@ -491,22 +490,22 @@ namespace chaiscript
build_eval_system(ModulePtr()); build_eval_system(ModulePtr());
} }
int version_major() const static int version_major()
{ {
return chaiscript::version_major; return chaiscript::version_major;
} }
int version_minor() const static int version_minor()
{ {
return chaiscript::version_minor; return chaiscript::version_minor;
} }
int version_patch() const static int version_patch()
{ {
return chaiscript::version_patch; return chaiscript::version_patch;
} }
std::string version() const static std::string version()
{ {
std::stringstream ss; std::stringstream ss;
ss << version_major() << "." << version_minor() << "." << version_patch(); ss << version_major() << "." << version_minor() << "." << version_patch();
@ -605,7 +604,7 @@ namespace chaiscript
/// chaiscript::ChaiScript chai; /// chaiscript::ChaiScript chai;
/// chaiscript::ChaiScript::State s = chai.get_state(); // represents bootstrapped initial state /// chaiscript::ChaiScript::State s = chai.get_state(); // represents bootstrapped initial state
/// \endcode /// \endcode
State get_state() State get_state() const
{ {
chaiscript::detail::threading::lock_guard<chaiscript::detail::threading::recursive_mutex> l(m_use_mutex); chaiscript::detail::threading::lock_guard<chaiscript::detail::threading::recursive_mutex> l(m_use_mutex);
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l2(m_mutex); chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l2(m_mutex);

View File

@ -1380,30 +1380,29 @@ namespace chaiscript
AST_NodePtr guardnode; AST_NodePtr guardnode;
auto d = t_ss.get_parent_locals(); const auto d = t_ss.get_parent_locals();
auto itr = d.find("_current_class_name"); const auto itr = d.find("_current_class_name");
int class_offset = 0; const auto class_offset = (itr != d.end())?-1:0;
if (itr != d.end()) class_offset = -1;
const std::string & class_name = (itr != d.end())?std::string(boxed_cast<std::string>(itr->second)):this->children[0]->text; const std::string & class_name = (itr != d.end())?std::string(boxed_cast<std::string>(itr->second)):this->children[0]->text;
//The first param of a method is always the implied this ptr. //The first param of a method is always the implied this ptr.
std::vector<std::string> t_param_names{"this"}; std::vector<std::string> t_param_names{"this"};
dispatch::Param_Types param_types; dispatch::Param_Types param_types;
if ((this->children.size() > static_cast<size_t>(3 + class_offset)) && (this->children[(2 + class_offset)]->identifier == AST_Node_Type::Arg_List)) { if ((this->children.size() > static_cast<size_t>(3 + class_offset)) && (this->children[static_cast<size_t>(2 + class_offset)]->identifier == AST_Node_Type::Arg_List)) {
auto args = Arg_List_AST_Node::get_arg_names(this->children[(2 + class_offset)]); auto args = Arg_List_AST_Node::get_arg_names(this->children[static_cast<size_t>(2 + class_offset)]);
t_param_names.insert(t_param_names.end(), args.begin(), args.end()); t_param_names.insert(t_param_names.end(), args.begin(), args.end());
param_types = Arg_List_AST_Node::get_arg_types(this->children[(2 + class_offset)], t_ss); param_types = Arg_List_AST_Node::get_arg_types(this->children[static_cast<size_t>(2 + class_offset)], t_ss);
if (this->children.size() > static_cast<size_t>(4 + class_offset)) { if (this->children.size() > static_cast<size_t>(4 + class_offset)) {
guardnode = this->children[(3 + class_offset)]; guardnode = this->children[static_cast<size_t>(3 + class_offset)];
} }
} }
else { else {
//no parameters //no parameters
if (this->children.size() > static_cast<size_t>(3 + class_offset)) { if (this->children.size() > static_cast<size_t>(3 + class_offset)) {
guardnode = this->children[(2 + class_offset)]; guardnode = this->children[static_cast<size_t>(2 + class_offset)];
} }
} }
@ -1420,7 +1419,7 @@ namespace chaiscript
try { try {
const std::string & l_annotation = this->annotation?this->annotation->text:""; const std::string & l_annotation = this->annotation?this->annotation->text:"";
const std::string & function_name = this->children[(1 + class_offset)]->text; const std::string & function_name = this->children[static_cast<size_t>(1 + class_offset)]->text;
if (function_name == class_name) { if (function_name == class_name) {
param_types.push_front(class_name, Type_Info()); param_types.push_front(class_name, Type_Info());
@ -1474,24 +1473,23 @@ namespace chaiscript
{ {
const auto &d = t_ss.get_parent_locals(); const auto &d = t_ss.get_parent_locals();
const auto itr = d.find("_current_class_name"); const auto itr = d.find("_current_class_name");
int class_offset = 0; const auto class_offset = (itr != d.end())?-1:0;
if (itr != d.end()) class_offset = -1;
std::string class_name = (itr != d.end())?std::string(boxed_cast<std::string>(itr->second)):this->children[0]->text; std::string class_name = (itr != d.end())?std::string(boxed_cast<std::string>(itr->second)):this->children[0]->text;
try { try {
t_ss.add( t_ss.add(
std::make_shared<dispatch::detail::Dynamic_Object_Function>( std::make_shared<dispatch::detail::Dynamic_Object_Function>(
class_name, std::move(class_name),
fun(std::function<Boxed_Value (dispatch::Dynamic_Object &)>(std::bind(&dispatch::Dynamic_Object::get_attr, fun(std::function<Boxed_Value (dispatch::Dynamic_Object &)>(std::bind(&dispatch::Dynamic_Object::get_attr,
std::placeholders::_1, std::placeholders::_1,
this->children[(1 + class_offset)]->text this->children[static_cast<size_t>(1 + class_offset)]->text
)) ))
) )
), this->children[(1 + class_offset)]->text); ), this->children[static_cast<size_t>(1 + class_offset)]->text);
} }
catch (const exception::reserved_word_error &) { catch (const exception::reserved_word_error &) {
throw exception::eval_error("Reserved word used as attribute '" + this->children[(1 + class_offset)]->text + "'"); throw exception::eval_error("Reserved word used as attribute '" + this->children[static_cast<size_t>(1 + class_offset)]->text + "'");
} catch (const exception::name_conflict_error &e) { } catch (const exception::name_conflict_error &e) {
throw exception::eval_error("Attribute redefined '" + e.name() + "'"); throw exception::eval_error("Attribute redefined '" + e.name() + "'");
} }

View File

@ -223,8 +223,8 @@ namespace chaiscript
t_t->end.column = pos_col_stop; t_t->end.column = pos_col_stop;
if (is_deep) { if (is_deep) {
t_t->children.assign(m_match_stack.begin() + t_match_start, m_match_stack.end()); t_t->children.assign(m_match_stack.begin() + static_cast<int>(t_match_start), m_match_stack.end());
m_match_stack.erase(m_match_stack.begin() + t_match_start, m_match_stack.end()); m_match_stack.erase(m_match_stack.begin() + static_cast<int>(t_match_start), m_match_stack.end());
} }
/// \todo fix the fact that a successful match that captured no ast_nodes doesn't have any real start position /// \todo fix the fact that a successful match that captured no ast_nodes doesn't have any real start position
@ -1956,6 +1956,7 @@ namespace chaiscript
case(AST_Node_Type::Bitwise_Xor) : case(AST_Node_Type::Bitwise_Xor) :
case(AST_Node_Type::Bitwise_Or) : case(AST_Node_Type::Bitwise_Or) :
case(AST_Node_Type::Comparison) : case(AST_Node_Type::Comparison) :
assert(m_match_stack.size() > 1);
m_match_stack.erase(m_match_stack.begin() + m_match_stack.size() - 2, m_match_stack.begin() + m_match_stack.size() - 1); m_match_stack.erase(m_match_stack.begin() + m_match_stack.size() - 2, m_match_stack.begin() + m_match_stack.size() - 1);
build_match(std::make_shared<eval::Binary_Operator_AST_Node>(oper->text), prev_stack_top); build_match(std::make_shared<eval::Binary_Operator_AST_Node>(oper->text), prev_stack_top);
break; break;

View File

@ -8,7 +8,10 @@
#include <list> #include <list>
#include <regex> #include <regex>
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#endif
#include <chaiscript/chaiscript.hpp> #include <chaiscript/chaiscript.hpp>
#include <chaiscript/chaiscript_stdlib.hpp> #include <chaiscript/chaiscript_stdlib.hpp>
@ -154,10 +157,6 @@ void help(int n) {
} }
} }
void version(int){
std::cout << "chai: compiled " << __TIME__ << " " << __DATE__ << std::endl;
}
std::string helloWorld(const std::string &t_name) std::string helloWorld(const std::string &t_name)
{ {
return "Hello " + t_name + "!"; return "Hello " + t_name + "!";
@ -297,7 +296,6 @@ int main(int argc, char *argv[])
chai.add(chaiscript::fun(&myexit), "exit"); chai.add(chaiscript::fun(&myexit), "exit");
chai.add(chaiscript::fun(&myexit), "quit"); chai.add(chaiscript::fun(&myexit), "quit");
chai.add(chaiscript::fun(&help), "help"); chai.add(chaiscript::fun(&help), "help");
chai.add(chaiscript::fun(&version), "version");
chai.add(chaiscript::fun(&throws_exception), "throws_exception"); chai.add(chaiscript::fun(&throws_exception), "throws_exception");
chai.add(chaiscript::fun(&get_eval_error), "get_eval_error"); chai.add(chaiscript::fun(&get_eval_error), "get_eval_error");
@ -356,7 +354,7 @@ int main(int argc, char *argv[])
} }
} }
else if (arg == "-v" || arg == "--version") { else if (arg == "-v" || arg == "--version") {
arg = "version(0)"; arg = "version()";
} }
else if (arg == "-h" || arg == "--help") { else if (arg == "-h" || arg == "--help") {
arg = "help(-1)"; arg = "help(-1)";
@ -388,7 +386,7 @@ int main(int argc, char *argv[])
printf("**ChaiScript::time= %.10f\n", elapsed_secs1); printf("**ChaiScript::time= %.10f\n", elapsed_secs1);
break; break;
} }
default: std::cout << "Unrecognized execution mode" << std::endl; return EXIT_FAILURE;
} }
} }
catch (const chaiscript::exception::eval_error &ee) { catch (const chaiscript::exception::eval_error &ee) {

View File

@ -8,6 +8,8 @@ class BaseClass
{ {
} }
BaseClass(const BaseClass &) = default;
virtual ~BaseClass() {} virtual ~BaseClass() {}
virtual std::string doSomething(float, double) const = 0; virtual std::string doSomething(float, double) const = 0;

View File

@ -8,7 +8,10 @@
#include <list> #include <list>
#include <regex> #include <regex>
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#endif
#include <chaiscript/chaiscript.hpp> #include <chaiscript/chaiscript.hpp>
#ifdef READLINE_AVAILABLE #ifdef READLINE_AVAILABLE
@ -18,7 +21,7 @@
char *mystrdup (const char *s) { char *mystrdup (const char *s) {
size_t len = strlen(s); // Space for length plus nul size_t len = strlen(s); // Space for length plus nul
char *d = static_cast<char*>(malloc (len+1)); char *d = static_cast<char*>(malloc (len+1));
if (d == nullptr) return nullptr; // No memory if (d == nullptr) return nullptr; // No memory
#ifdef CHAISCRIPT_MSVC #ifdef CHAISCRIPT_MSVC
strcpy_s(d, len, s); // Copy the characters strcpy_s(d, len, s); // Copy the characters
@ -152,10 +155,6 @@ void help(int n) {
} }
} }
void version(int){
std::cout << "chai: compiled " << __TIME__ << " " << __DATE__ << '\n';
}
bool throws_exception(const std::function<void ()> &f) bool throws_exception(const std::function<void ()> &f)
{ {
try { try {
@ -287,7 +286,6 @@ int main(int argc, char *argv[])
chai.add(chaiscript::fun(&myexit), "exit"); chai.add(chaiscript::fun(&myexit), "exit");
chai.add(chaiscript::fun(&myexit), "quit"); chai.add(chaiscript::fun(&myexit), "quit");
chai.add(chaiscript::fun(&help), "help"); chai.add(chaiscript::fun(&help), "help");
chai.add(chaiscript::fun(&version), "version");
chai.add(chaiscript::fun(&throws_exception), "throws_exception"); chai.add(chaiscript::fun(&throws_exception), "throws_exception");
chai.add(chaiscript::fun(&get_eval_error), "get_eval_error"); chai.add(chaiscript::fun(&get_eval_error), "get_eval_error");
@ -317,7 +315,7 @@ int main(int argc, char *argv[])
arg += line + '\n' ; arg += line + '\n' ;
} }
} else if ( arg == "-v" || arg == "--version" ) { } else if ( arg == "-v" || arg == "--version" ) {
arg = "version(0)" ; arg = "version()" ;
} else if ( arg == "-h" || arg == "--help" ) { } else if ( arg == "-h" || arg == "--help" ) {
arg = "help(-1)"; arg = "help(-1)";
} else if ( arg == "-i" || arg == "--interactive" ) { } else if ( arg == "-i" || arg == "--interactive" ) {
@ -332,10 +330,14 @@ int main(int argc, char *argv[])
chaiscript::Boxed_Value val ; chaiscript::Boxed_Value val ;
try { try {
switch ( mode ) { switch ( mode ) {
case eInteractive : interactive(chai); break; case eInteractive:
case eCommand : val = chai.eval(arg); break; interactive(chai);
case eFile : val = chai.eval_file(arg); break; break;
default : std::cout << "Unrecognized execution mode\n"; return EXIT_FAILURE; case eCommand:
val = chai.eval(arg);
break;
case eFile:
val = chai.eval_file(arg);
} }
} }
catch (const chaiscript::exception::eval_error &ee) { catch (const chaiscript::exception::eval_error &ee) {

View File

@ -9,7 +9,8 @@ class TestBaseType
public: public:
TestBaseType() : val(10), const_val(15) { } TestBaseType() : val(10), const_val(15) { }
TestBaseType(int) : val(10), const_val(15) {} TestBaseType(int) : val(10), const_val(15) {}
TestBaseType(int *) : val(10), const_val(15) {} TestBaseType(int *) : val(10), const_val(15) { }
TestBaseType(const TestBaseType &) = default;
virtual ~TestBaseType() {} virtual ~TestBaseType() {}
virtual int func() { return 0; } virtual int func() { return 0; }
@ -62,6 +63,8 @@ class TestDerivedType : public TestBaseType
{ {
public: public:
virtual ~TestDerivedType() {} virtual ~TestDerivedType() {}
TestDerivedType(const TestDerivedType &) = default;
TestDerivedType() = default;
virtual int func() CHAISCRIPT_OVERRIDE { return 1; } virtual int func() CHAISCRIPT_OVERRIDE { return 1; }
int derived_only_func() { return 19; } int derived_only_func() { return 19; }
@ -72,6 +75,8 @@ class TestDerivedType : public TestBaseType
class TestMoreDerivedType : public TestDerivedType class TestMoreDerivedType : public TestDerivedType
{ {
public: public:
TestMoreDerivedType(const TestMoreDerivedType &) = default;
TestMoreDerivedType() = default;
virtual ~TestMoreDerivedType() {} virtual ~TestMoreDerivedType() {}
}; };
@ -95,9 +100,11 @@ std::string hello_world()
return "Hello World"; return "Hello World";
} }
static int global_i = 1;
int *get_new_int() int *get_new_int()
{ {
return new int(1); return &global_i;
} }
// MSVC doesn't like that we are using C++ return types from our C declared module // MSVC doesn't like that we are using C++ return types from our C declared module

View File

@ -265,20 +265,25 @@ bool pointer_test(const T& default_value, const T& new_value)
if (p != (*result) ) { if (p != (*result) ) {
std::cerr << "Pointer passed in different than one returned\n"; std::cerr << "Pointer passed in different than one returned\n";
delete p;
return false; return false;
} }
if (*p != *(*result) ) { if (*p != *(*result) ) {
std::cerr << "Somehow dereferenced pointer values are not the same?\n"; std::cerr << "Somehow dereferenced pointer values are not the same?\n";
delete p;
return false; return false;
} }
delete p;
return true; return true;
} catch (const exception::bad_boxed_cast &) { } catch (const exception::bad_boxed_cast &) {
std::cerr << "Bad boxed cast performing ** to ** test\n"; std::cerr << "Bad boxed cast performing ** to ** test\n";
delete p;
return false; return false;
} catch (...) { } catch (...) {
std::cerr << "Unknown exception performing ** to ** test\n"; std::cerr << "Unknown exception performing ** to ** test\n";
delete p;
return false; return false;
} }

View File

@ -1,6 +1,6 @@
#include <chaiscript/utility/utility.hpp> #include <chaiscript/utility/utility.hpp>
double test_call(const std::function<double (int)> &f, int val) int test_call(const std::function<int (int)> &f, int val)
{ {
return f(val); return f(val);
} }
@ -9,15 +9,15 @@ int main()
{ {
chaiscript::ChaiScript chai; chaiscript::ChaiScript chai;
chai.add(chaiscript::fun(&test_call), "test_call"); chai.add(chaiscript::fun(&test_call), "test_call");
chai.eval("def func(i) { return i * 3.5; };"); chai.eval("def func(i) { return i * 6; };");
double d = chai.eval<double>("test_call(func, 3)"); int d = chai.eval<int>("test_call(func, 3)");
if (d == 3 * 3.5) if (d == 3 * 6)
{ {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} else { } else {
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -4,9 +4,9 @@
template<typename T> template<typename T>
struct Vector2 struct Vector2
{ {
Vector2() : x(0), y(0) {}; Vector2() : x(0), y(0) {}
Vector2(T px, T py) : x(px), y(py) {}; Vector2(T px, T py) : x(px), y(py) {}
Vector2(const Vector2& cp) : x(cp.x), y(cp.y) {}; Vector2(const Vector2& cp) : x(cp.x), y(cp.y) {}
Vector2& operator+=(const Vector2& vec_r) Vector2& operator+=(const Vector2& vec_r)
{ {
@ -20,10 +20,11 @@ struct Vector2
return Vector2(*this += vec_r); return Vector2(*this += vec_r);
} }
void operator=(const Vector2& ver_r) Vector2 &operator=(const Vector2& ver_r)
{ {
x = ver_r.x; x = ver_r.x;
y = ver_r.y; y = ver_r.y;
return *this;
} }