Fix debug/clang build issues

This commit is contained in:
Jason Turner
2016-06-29 17:27:07 -06:00
parent b0f07cbe5d
commit e44724c780
7 changed files with 38 additions and 37 deletions

View File

@@ -231,8 +231,8 @@ namespace chaiscript
auto pointer_sentinel(std::shared_ptr<T> &ptr) const auto pointer_sentinel(std::shared_ptr<T> &ptr) const
{ {
struct Sentinel { struct Sentinel {
Sentinel(std::shared_ptr<T> &ptr, Data &data) Sentinel(std::shared_ptr<T> &t_ptr, Data &data)
: m_ptr(ptr), m_data(data) : m_ptr(t_ptr), m_data(data)
{ {
} }

View File

@@ -1404,7 +1404,7 @@ namespace chaiscript
static typename Container::const_iterator find_keyed_value(const Container &t_c, const Key &t_key, const size_t t_hint) static typename Container::const_iterator find_keyed_value(const Container &t_c, const Key &t_key, const size_t t_hint)
{ {
if (t_c.size() > t_hint && t_c[t_hint].first == t_key) { if (t_c.size() > t_hint && t_c[t_hint].first == t_key) {
return std::next(t_c.begin(), t_hint); return std::next(t_c.begin(), static_cast<typename std::iterator_traits<typename Container::const_iterator>::difference_type>(t_hint));
} else { } else {
return find_keyed_value(t_c, t_key); return find_keyed_value(t_c, t_key);
} }

View File

@@ -26,30 +26,31 @@ struct AST_Node;
namespace chaiscript namespace chaiscript
{ {
static bool is_reserved_word(const std::string &name) struct Name_Validator {
{ static bool is_reserved_word(const std::string &name)
static const std::set<std::string> m_reserved_words {
= {"def", "fun", "while", "for", "if", "else", "&&", "||", ",", "auto", static const std::set<std::string> m_reserved_words
"return", "break", "true", "false", "class", "attr", "var", "global", "GLOBAL", "_"}; = {"def", "fun", "while", "for", "if", "else", "&&", "||", ",", "auto",
return m_reserved_words.count(name) > 0; "return", "break", "true", "false", "class", "attr", "var", "global", "GLOBAL", "_"};
} return m_reserved_words.count(name) > 0;
static bool valid_object_name(const std::string &name)
{
return name.find("::") == std::string::npos && !is_reserved_word(name);
}
static void validate_object_name(const std::string &name)
{
if (is_reserved_word(name)) {
throw exception::reserved_word_error(name);
} }
if (name.find("::") != std::string::npos) { static bool valid_object_name(const std::string &name)
throw exception::illegal_name_error(name); {
return name.find("::") == std::string::npos && !is_reserved_word(name);
} }
}
static void validate_object_name(const std::string &name)
{
if (is_reserved_word(name)) {
throw exception::reserved_word_error(name);
}
if (name.find("::") != std::string::npos) {
throw exception::illegal_name_error(name);
}
}
};
/// Signature of module entry point that all binary loadable modules must implement. /// Signature of module entry point that all binary loadable modules must implement.
typedef ModulePtr (*Create_Module_Func)(); typedef ModulePtr (*Create_Module_Func)();
@@ -577,7 +578,7 @@ namespace chaiscript
T &get_tracer() T &get_tracer()
{ {
// to do type check this somehow? // to do type check this somehow?
return static_cast<T&>(*get_tracer_ptr()); return *static_cast<T*>(get_tracer_ptr());
} }
protected: protected:

View File

@@ -387,7 +387,7 @@ namespace chaiscript
/// \sa Boxed_Value::is_const /// \sa Boxed_Value::is_const
ChaiScript &add_global_const(const Boxed_Value &t_bv, const std::string &t_name) ChaiScript &add_global_const(const Boxed_Value &t_bv, const std::string &t_name)
{ {
validate_object_name(t_name); Name_Validator::validate_object_name(t_name);
m_engine.add_global_const(t_bv, t_name); m_engine.add_global_const(t_bv, t_name);
return *this; return *this;
} }
@@ -399,14 +399,14 @@ namespace chaiscript
/// ChaiScript is thread-safe but provides no threading locking mechanism to the script /// ChaiScript is thread-safe but provides no threading locking mechanism to the script
ChaiScript &add_global(const Boxed_Value &t_bv, const std::string &t_name) ChaiScript &add_global(const Boxed_Value &t_bv, const std::string &t_name)
{ {
validate_object_name(t_name); Name_Validator::validate_object_name(t_name);
m_engine.add_global(t_bv, t_name); m_engine.add_global(t_bv, t_name);
return *this; return *this;
} }
ChaiScript &set_global(const Boxed_Value &t_bv, const std::string &t_name) ChaiScript &set_global(const Boxed_Value &t_bv, const std::string &t_name)
{ {
validate_object_name(t_name); Name_Validator::validate_object_name(t_name);
m_engine.set_global(t_bv, t_name); m_engine.set_global(t_bv, t_name);
return *this; return *this;
} }
@@ -506,7 +506,7 @@ namespace chaiscript
template<typename T> template<typename T>
ChaiScript &add(const T &t_t, const std::string &t_name) ChaiScript &add(const T &t_t, const std::string &t_name)
{ {
validate_object_name(t_name); Name_Validator::validate_object_name(t_name);
m_engine.add(t_t, t_name); m_engine.add(t_t, t_name);
return *this; return *this;
} }

View File

@@ -436,7 +436,7 @@ namespace chaiscript
Equation_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) : Equation_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) :
AST_Node_Impl<T>(std::move(t_ast_node_text), AST_Node_Type::Equation, std::move(t_loc), std::move(t_children)), AST_Node_Impl<T>(std::move(t_ast_node_text), AST_Node_Type::Equation, std::move(t_loc), std::move(t_children)),
m_oper(Operators::to_operator(this->text)) m_oper(Operators::to_operator(this->text))
{ assert(children.size() == 2); } { assert(this->children.size() == 2); }
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override { Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
@@ -1011,7 +1011,7 @@ private:
struct Case_AST_Node final : AST_Node_Impl<T> { struct Case_AST_Node final : AST_Node_Impl<T> {
Case_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) : Case_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) :
AST_Node_Impl<T>(std::move(t_ast_node_text), AST_Node_Type::Case, std::move(t_loc), std::move(t_children)) AST_Node_Impl<T>(std::move(t_ast_node_text), AST_Node_Type::Case, std::move(t_loc), std::move(t_children))
{ assert(children.size() == 2); /* how many children does it have? */ } { assert(this->children.size() == 2); /* how many children does it have? */ }
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override { Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss); chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
@@ -1026,7 +1026,7 @@ private:
struct Default_AST_Node final : AST_Node_Impl<T> { struct Default_AST_Node final : AST_Node_Impl<T> {
Default_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) : Default_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) :
AST_Node_Impl<T>(std::move(t_ast_node_text), AST_Node_Type::Default, std::move(t_loc), std::move(t_children)) AST_Node_Impl<T>(std::move(t_ast_node_text), AST_Node_Type::Default, std::move(t_loc), std::move(t_children))
{ assert(children.size() == 1); } { assert(this->children.size() == 1); }
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override { Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override {
chaiscript::eval::detail::Scope_Push_Pop spp(t_ss); chaiscript::eval::detail::Scope_Push_Pop spp(t_ss);
@@ -1141,7 +1141,7 @@ private:
struct Reference_AST_Node final : AST_Node_Impl<T> { struct Reference_AST_Node final : AST_Node_Impl<T> {
Reference_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) : Reference_AST_Node(std::string t_ast_node_text, Parse_Location t_loc, std::vector<AST_Node_Impl_Ptr<T>> t_children) :
AST_Node_Impl<T>(std::move(t_ast_node_text), AST_Node_Type::Reference, std::move(t_loc), std::move(t_children)) AST_Node_Impl<T>(std::move(t_ast_node_text), AST_Node_Type::Reference, std::move(t_loc), std::move(t_children))
{ assert(children.size() == 1); } { assert(this->children.size() == 1); }
Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{ Boxed_Value eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const override{
Boxed_Value bv; Boxed_Value bv;

View File

@@ -262,7 +262,7 @@ namespace chaiscript {
} else if (lhs.get_type_info().bare_equal_type_info(typeid(bool)) && oper == "!") { } else if (lhs.get_type_info().bare_equal_type_info(typeid(bool)) && oper == "!") {
return chaiscript::make_shared<eval::AST_Node_Impl<T>, eval::Constant_AST_Node<T>>(std::move(match), node->location, Boxed_Value(!boxed_cast<bool>(lhs))); return chaiscript::make_shared<eval::AST_Node_Impl<T>, eval::Constant_AST_Node<T>>(std::move(match), node->location, Boxed_Value(!boxed_cast<bool>(lhs)));
} }
} catch (const std::exception &e) { } catch (const std::exception &) {
//failure to fold, that's OK //failure to fold, that's OK
} }
} else if ((node->identifier == AST_Node_Type::Logical_And || node->identifier == AST_Node_Type::Logical_Or) } else if ((node->identifier == AST_Node_Type::Logical_And || node->identifier == AST_Node_Type::Logical_Or)

View File

@@ -113,7 +113,7 @@ namespace chaiscript
template<typename Tracer, typename Optimizer> template<typename Tracer, typename Optimizer>
class ChaiScript_Parser final : public ChaiScript_Parser_Base { class ChaiScript_Parser final : public ChaiScript_Parser_Base {
void *get_tracer_ptr() { void *get_tracer_ptr() override {
return &m_tracer; return &m_tracer;
} }
@@ -339,7 +339,7 @@ namespace chaiscript
void validate_object_name(const std::string &name) const void validate_object_name(const std::string &name) const
{ {
if (!valid_object_name(name)) { if (!Name_Validator::valid_object_name(name)) {
throw exception::eval_error("Invalid Object Name: " + name, File_Position(m_position.line, m_position.col), *m_filename); throw exception::eval_error("Invalid Object Name: " + name, File_Position(m_position.line, m_position.col), *m_filename);
} }
} }
@@ -2256,8 +2256,8 @@ namespace chaiscript
build_match<eval::Logical_Or_AST_Node<Tracer>>(prev_stack_top, oper); build_match<eval::Logical_Or_AST_Node<Tracer>>(prev_stack_top, oper);
break; break;
default: // default:
throw exception::eval_error("Internal error: unhandled ast_node", File_Position(m_position.line, m_position.col), *m_filename); // throw exception::eval_error("Internal error: unhandled ast_node", File_Position(m_position.line, m_position.col), *m_filename);
} }
} }
} }