Make sure to not deref null parse node

This commit is contained in:
Jason Turner 2017-07-20 06:10:31 -06:00
parent 14eaefdceb
commit f465d2ceca
3 changed files with 17 additions and 4 deletions

View File

@ -354,6 +354,7 @@ namespace chaiscript
m_param_types(std::move(t_param_types)),
m_guard(std::move(t_guard)), m_parsenode(std::move(t_parsenode))
{
// assert(t_parsenode);
}
@ -379,9 +380,17 @@ namespace chaiscript
return m_guard;
}
bool has_parse_tree() const {
return static_cast<bool>(m_parsenode);
}
const AST_Node &get_parse_tree() const
{
return *m_parsenode;
if (m_parsenode) {
return *m_parsenode;
} else {
throw std::runtime_error("Dynamic_Proxy_Function does not have parse_tree");
}
}

View File

@ -262,6 +262,7 @@ namespace chaiscript
bool t_dot_notation,
const chaiscript::detail::Dispatch_Engine &t_ss)
{
assert(t_func);
int arity = t_func->get_arity();
std::vector<Type_Info> types = t_func->get_param_types();
@ -310,14 +311,14 @@ namespace chaiscript
std::shared_ptr<const dispatch::Dynamic_Proxy_Function> dynfun
= std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(t_func);
if (dynfun)
if (dynfun && dynfun->has_parse_tree())
{
Proxy_Function f = dynfun->get_guard();
if (f)
{
auto dynfunguard = std::dynamic_pointer_cast<const dispatch::Dynamic_Proxy_Function>(f);
if (dynfunguard)
if (dynfunguard && dynfunguard->has_parse_tree())
{
retval += " : " + format_guard(dynfunguard->get_parse_tree());
}
@ -350,6 +351,7 @@ namespace chaiscript
std::stringstream ss;
if (t_functions.size() == 1)
{
assert(t_functions[0]);
ss << " Expected: " << format_types(t_functions[0], t_dot_notation, t_ss) << '\n';
} else {
ss << " " << t_functions.size() << " overloads available:\n";

View File

@ -288,7 +288,9 @@ namespace chaiscript
template<typename T>
struct Fun_Call_AST_Node : AST_Node_Impl<T> {
Fun_Call_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::Fun_Call, std::move(t_loc), std::move(t_children)) { }
AST_Node_Impl<T>(std::move(t_ast_node_text), AST_Node_Type::Fun_Call, std::move(t_loc), std::move(t_children)) {
assert(!this->children.empty());
}
template<bool Save_Params>
Boxed_Value do_eval_internal(const chaiscript::detail::Dispatch_State &t_ss) const