Fix build errors and warnings for VS2010

This commit is contained in:
Jason Turner
2011-04-02 11:21:11 -06:00
parent 8dec35ba19
commit d22a77503c
5 changed files with 187 additions and 170 deletions

View File

@@ -17,135 +17,137 @@
namespace chaiscript namespace chaiscript
{ {
namespace detail namespace dispatch
{ {
/** namespace detail
* Used internally for handling a return value from a Proxy_Function call {
*/ /**
template<typename Ret> * Used internally for handling a return value from a Proxy_Function call
struct Handle_Return */
{ template<typename Ret>
static Boxed_Value handle(const Ret &r) struct Handle_Return
{ {
return const_var(r); static Boxed_Value handle(const Ret &r)
} {
}; return const_var(r);
}
};
template<typename Ret> template<typename Ret>
struct Handle_Return<boost::shared_ptr<Ret> &> struct Handle_Return<boost::shared_ptr<Ret> &>
{
static Boxed_Value handle(const boost::shared_ptr<Ret> &r)
{ {
return Boxed_Value(r); static Boxed_Value handle(const boost::shared_ptr<Ret> &r)
} {
}; return Boxed_Value(r);
}
};
template<typename Ret> template<typename Ret>
struct Handle_Return<boost::shared_ptr<Ret> > struct Handle_Return<boost::shared_ptr<Ret> >
{
static Boxed_Value handle(const boost::shared_ptr<Ret> &r)
{ {
return Boxed_Value(r); static Boxed_Value handle(const boost::shared_ptr<Ret> &r)
} {
}; return Boxed_Value(r);
}
};
template<typename Ret> template<typename Ret>
struct Handle_Return<const boost::shared_ptr<Ret> &> struct Handle_Return<const boost::shared_ptr<Ret> &>
{
static Boxed_Value handle(const boost::shared_ptr<Ret> &r)
{ {
return Boxed_Value(r); static Boxed_Value handle(const boost::shared_ptr<Ret> &r)
} {
}; return Boxed_Value(r);
}
};
template<typename Ret> template<typename Ret>
struct Handle_Return<const Ret &> struct Handle_Return<const Ret &>
{
static Boxed_Value handle(const Ret &r)
{ {
return Boxed_Value(boost::cref(r)); static Boxed_Value handle(const Ret &r)
} {
}; return Boxed_Value(boost::cref(r));
}
};
/** /**
* Used internally for handling a return value from a Proxy_Function call * Used internally for handling a return value from a Proxy_Function call
*/ */
template<typename Ret> template<typename Ret>
struct Handle_Return<Ret &> struct Handle_Return<Ret &>
{
static Boxed_Value handle(Ret &r)
{ {
return Boxed_Value(boost::ref(r)); static Boxed_Value handle(Ret &r)
} {
return Boxed_Value(boost::ref(r));
}
static Boxed_Value handle(const Ret &r) static Boxed_Value handle(const Ret &r)
{
return Boxed_Value(boost::cref(r));
}
};
/**
* Used internally for handling a return value from a Proxy_Function call
*/
template<>
struct Handle_Return<Boxed_Value>
{ {
return Boxed_Value(boost::cref(r)); static Boxed_Value handle(const Boxed_Value &r)
} {
}; return r;
}
};
/** /**
* Used internally for handling a return value from a Proxy_Function call * Used internally for handling a return value from a Proxy_Function call
*/ */
template<> template<>
struct Handle_Return<Boxed_Value> struct Handle_Return<const Boxed_Value>
{
static Boxed_Value handle(const Boxed_Value &r)
{ {
return r; static Boxed_Value handle(const Boxed_Value &r)
} {
}; return r;
}
};
/** /**
* Used internally for handling a return value from a Proxy_Function call * Used internally for handling a return value from a Proxy_Function call
*/ */
template<> template<>
struct Handle_Return<const Boxed_Value> struct Handle_Return<Boxed_Value &>
{
static Boxed_Value handle(const Boxed_Value &r)
{ {
return r; static Boxed_Value handle(const Boxed_Value &r)
} {
}; return r;
}
};
/** /**
* Used internally for handling a return value from a Proxy_Function call * Used internally for handling a return value from a Proxy_Function call
*/ */
template<> template<>
struct Handle_Return<Boxed_Value &> struct Handle_Return<const Boxed_Value &>
{
static Boxed_Value handle(const Boxed_Value &r)
{ {
return r; static Boxed_Value handle(const Boxed_Value &r)
} {
}; return r;
}
};
/**
* Used internally for handling a return value from a Proxy_Function call /**
*/ * Used internally for handling a return value from a Proxy_Function call
template<> */
struct Handle_Return<const Boxed_Value &> template<>
{ struct Handle_Return<void>
static Boxed_Value handle(const Boxed_Value &r)
{ {
return r; static Boxed_Value handle()
} {
}; return Boxed_Value(Boxed_Value::Void_Type());
}
};
/** }
* Used internally for handling a return value from a Proxy_Function call
*/
template<>
struct Handle_Return<void>
{
static Boxed_Value handle()
{
return Boxed_Value(Boxed_Value::Void_Type());
}
};
} }
} }

View File

@@ -20,7 +20,7 @@
namespace chaiscript namespace chaiscript
{ {
struct Boxed_POD_Value; class Boxed_POD_Value;
struct AST_Node; struct AST_Node;
typedef boost::shared_ptr<struct AST_Node> AST_NodePtr; typedef boost::shared_ptr<struct AST_Node> AST_NodePtr;
@@ -141,7 +141,7 @@ namespace chaiscript
|| (!bv.get_type_info().is_undef() || (!bv.get_type_info().is_undef()
&& (ti.bare_equal(user_type<Boxed_POD_Value>()) && (ti.bare_equal(user_type<Boxed_POD_Value>())
|| ti.bare_equal(bv.get_type_info()) || ti.bare_equal(bv.get_type_info())
|| detail::dynamic_cast_converts(ti, bv.get_type_info()) || chaiscript::detail::dynamic_cast_converts(ti, bv.get_type_info())
|| bv.get_type_info().bare_equal(user_type<boost::shared_ptr<const Proxy_Function_Base> >()) || bv.get_type_info().bare_equal(user_type<boost::shared_ptr<const Proxy_Function_Base> >())
) )
) )
@@ -289,13 +289,13 @@ namespace chaiscript
std::vector<Type_Info> types; std::vector<Type_Info> types;
// For the return type // For the return type
types.push_back(detail::Get_Type_Info<Boxed_Value>::get()); types.push_back(chaiscript::detail::Get_Type_Info<Boxed_Value>::get());
if (arity >= 0) if (arity >= 0)
{ {
for (int i = 0; i < arity; ++i) for (int i = 0; i < arity; ++i)
{ {
types.push_back(detail::Get_Type_Info<Boxed_Value>::get()); types.push_back(chaiscript::detail::Get_Type_Info<Boxed_Value>::get());
} }
} }
@@ -371,7 +371,7 @@ namespace chaiscript
while (!(parg == params.end() && barg == m_args.end())) while (!(parg == params.end() && barg == m_args.end()))
{ {
while (barg != m_args.end() while (barg != m_args.end()
&& !(barg->get_type_info() == detail::Get_Type_Info<Placeholder_Object>::get())) && !(barg->get_type_info() == chaiscript::detail::Get_Type_Info<Placeholder_Object>::get()))
{ {
args.push_back(*barg); args.push_back(*barg);
++barg; ++barg;
@@ -384,7 +384,7 @@ namespace chaiscript
} }
if (barg != m_args.end() if (barg != m_args.end()
&& barg->get_type_info() == detail::Get_Type_Info<Placeholder_Object>::get()) && barg->get_type_info() == chaiscript::detail::Get_Type_Info<Placeholder_Object>::get())
{ {
++barg; ++barg;
} }
@@ -416,7 +416,7 @@ namespace chaiscript
retval.push_back(types[0]); retval.push_back(types[0]);
for (size_t i = 0; i < types.size()-1; ++i) for (size_t i = 0; i < types.size()-1; ++i)
{ {
if (t_args[i].get_type_info() == detail::Get_Type_Info<Placeholder_Object>::get()) if (t_args[i].get_type_info() == chaiscript::detail::Get_Type_Info<Placeholder_Object>::get())
{ {
retval.push_back(types[i+1]); retval.push_back(types[i+1]);
} }

View File

@@ -6,7 +6,7 @@
#include <boost/preprocessor.hpp> #include <boost/preprocessor.hpp>
#define gettypeinfo(z,n,text) ti.push_back(detail::Get_Type_Info<Param ## n>::get()); #define gettypeinfo(z,n,text) ti.push_back(chaiscript::detail::Get_Type_Info<Param ## n>::get());
#define casthelper(z,n,text) BOOST_PP_COMMA_IF(n) chaiscript::boxed_cast< Param ## n >(params[n]) #define casthelper(z,n,text) BOOST_PP_COMMA_IF(n) chaiscript::boxed_cast< Param ## n >(params[n])
#define trycast(z,n,text) chaiscript::boxed_cast<Param ## n>(params[n]); #define trycast(z,n,text) chaiscript::boxed_cast<Param ## n>(params[n]);
@@ -62,58 +62,61 @@ namespace chaiscript
namespace chaiscript namespace chaiscript
{ {
namespace detail namespace dispatch
{ {
/** namespace detail
* Used by Proxy_Function_Impl to return a list of all param types {
* it contains. /**
*/ * Used by Proxy_Function_Impl to return a list of all param types
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) > * it contains.
std::vector<Type_Info> build_param_type_list(Ret (*)(BOOST_PP_ENUM_PARAMS(n, Param))) */
{ template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param) >
std::vector<Type_Info> ti; std::vector<Type_Info> build_param_type_list(Ret (*)(BOOST_PP_ENUM_PARAMS(n, Param)))
ti.push_back(detail::Get_Type_Info<Ret>::get());
BOOST_PP_REPEAT(n, gettypeinfo, ~)
return ti;
}
/**
* Used by Proxy_Function_Impl to perform typesafe execution of a function.
* The function attempts to unbox each paramter to the expected type.
* if any unboxing fails the execution of the function fails and
* the bad_boxed_cast is passed up to the caller.
*/
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param)>
Ret call_func(const boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))> &f,
const std::vector<Boxed_Value> &params)
{
if (params.size() != n)
{ {
throw exception::arity_error(static_cast<int>(params.size()), n); std::vector<Type_Info> ti;
} else { ti.push_back(chaiscript::detail::Get_Type_Info<Ret>::get());
return f(BOOST_PP_REPEAT(n, casthelper, ~));
}
}
/** BOOST_PP_REPEAT(n, gettypeinfo, ~)
* Used by Proxy_Function_Impl to determine if it is equivalent to another
* Proxy_Function_Impl object. This function is primarly used to prevent return ti;
* registration of two functions with the exact same signatures
*/
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param)>
bool compare_types_cast(Ret (*)(BOOST_PP_ENUM_PARAMS(n, Param)),
const std::vector<Boxed_Value> & BOOST_PP_IF(n, params, ))
{
try {
BOOST_PP_REPEAT(n, trycast, ~);
} catch (const exception::bad_boxed_cast &) {
return false;
} }
return true; /**
} * Used by Proxy_Function_Impl to perform typesafe execution of a function.
* The function attempts to unbox each paramter to the expected type.
* if any unboxing fails the execution of the function fails and
* the bad_boxed_cast is passed up to the caller.
*/
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param)>
Ret call_func(const boost::function<Ret (BOOST_PP_ENUM_PARAMS(n, Param))> &f,
const std::vector<Boxed_Value> &params)
{
if (params.size() != n)
{
throw exception::arity_error(static_cast<int>(params.size()), n);
} else {
return f(BOOST_PP_REPEAT(n, casthelper, ~));
}
}
/**
* Used by Proxy_Function_Impl to determine if it is equivalent to another
* Proxy_Function_Impl object. This function is primarly used to prevent
* registration of two functions with the exact same signatures
*/
template<typename Ret BOOST_PP_COMMA_IF(n) BOOST_PP_ENUM_PARAMS(n, typename Param)>
bool compare_types_cast(Ret (*)(BOOST_PP_ENUM_PARAMS(n, Param)),
const std::vector<Boxed_Value> & BOOST_PP_IF(n, params, ))
{
try {
BOOST_PP_REPEAT(n, trycast, ~);
} catch (const exception::bad_boxed_cast &) {
return false;
}
return true;
}
}
} }
} }
@@ -126,15 +129,17 @@ namespace chaiscript
namespace chaiscript namespace chaiscript
{ {
namespace detail namespace dispatch
{ {
namespace detail
{
template<typename Ret> template<typename Ret>
struct Do_Call struct Do_Call
{ {
template<typename Fun> template<typename Fun>
static Boxed_Value go(const boost::function<Fun> &fun, const std::vector<Boxed_Value> &params) static Boxed_Value go(const boost::function<Fun> &fun, const std::vector<Boxed_Value> &params)
{ {
return Handle_Return<Ret>::handle(chaiscript::detail::call_func(fun, params)); return Handle_Return<Ret>::handle(call_func(fun, params));
} }
}; };
@@ -144,10 +149,11 @@ namespace chaiscript
template<typename Fun> template<typename Fun>
static Boxed_Value go(const boost::function<Fun> &fun, const std::vector<Boxed_Value> &params) static Boxed_Value go(const boost::function<Fun> &fun, const std::vector<Boxed_Value> &params)
{ {
chaiscript::detail::call_func(fun, params); call_func(fun, params);
return Handle_Return<void>::handle(); return Handle_Return<void>::handle();
} }
}; };
}
} }
} }

View File

@@ -163,6 +163,11 @@ namespace chaiscript
{ {
throw std::runtime_error("Undispatched ast_node (internal error)"); throw std::runtime_error("Undispatched ast_node (internal error)");
} }
private:
// Copy and assignment explicitly unimplemented
AST_Node(const AST_Node &);
AST_Node& operator=(const AST_Node &);
}; };
@@ -203,6 +208,10 @@ namespace chaiscript
private: private:
// explicitly unimplemented copy and assignment
Scope_Push_Pop(const Scope_Push_Pop &);
Scope_Push_Pop& operator=(const Scope_Push_Pop &);
chaiscript::detail::Dispatch_Engine &m_de; chaiscript::detail::Dispatch_Engine &m_de;
}; };

View File

@@ -70,7 +70,7 @@ namespace chaiscript
public: public:
Int_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Int, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Int_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Int, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col), AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col),
m_value(const_var(int(atoi(this->text.c_str())))) { } m_value(const_var(int(atoi(t_ast_node_text.c_str())))) { }
virtual ~Int_AST_Node() {} virtual ~Int_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &){ virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &){
return m_value; return m_value;
@@ -85,7 +85,7 @@ namespace chaiscript
public: public:
Float_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Float, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Float_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Float, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col), AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col),
m_value(const_var(double(atof(this->text.c_str())))) { } m_value(const_var(double(atof(t_ast_node_text.c_str())))) { }
virtual ~Float_AST_Node() {} virtual ~Float_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &){ virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &){
return m_value; return m_value;
@@ -200,7 +200,7 @@ namespace chaiscript
throw; throw;
} }
} }
catch(exception::eval_error &ee) { catch(exception::eval_error &) {
t_ss.set_stack(prev_stack); t_ss.set_stack(prev_stack);
throw; throw;
} }
@@ -438,7 +438,7 @@ namespace chaiscript
public: public:
Quoted_String_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Quoted_String, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Quoted_String_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Quoted_String, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col), AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col),
m_value(const_var(this->text)) { } m_value(const_var(t_ast_node_text)) { }
virtual ~Quoted_String_AST_Node() {} virtual ~Quoted_String_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &) { virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &) {
return m_value; return m_value;
@@ -453,7 +453,7 @@ namespace chaiscript
public: public:
Single_Quoted_String_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Single_Quoted_String, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) : Single_Quoted_String_AST_Node(const std::string &t_ast_node_text = "", int t_id = AST_Node_Type::Single_Quoted_String, const boost::shared_ptr<std::string> &t_fname=boost::shared_ptr<std::string>(), int t_start_line = 0, int t_start_col = 0, int t_end_line = 0, int t_end_col = 0) :
AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col), AST_Node(t_ast_node_text, t_id, t_fname, t_start_line, t_start_col, t_end_line, t_end_col),
m_value(const_var(char(this->text[0]))) { } m_value(const_var(char(t_ast_node_text.at(0)))) { }
virtual ~Single_Quoted_String_AST_Node() {} virtual ~Single_Quoted_String_AST_Node() {}
virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &){ virtual Boxed_Value eval_internal(chaiscript::detail::Dispatch_Engine &){
return m_value; return m_value;
@@ -850,7 +850,7 @@ namespace chaiscript
try { try {
retval = this->children[0]->eval(t_ss); retval = this->children[0]->eval(t_ss);
} }
catch (exception::eval_error &ee) { catch (exception::eval_error &) {
if (this->children.back()->identifier == AST_Node_Type::Finally) { if (this->children.back()->identifier == AST_Node_Type::Finally) {
this->children.back()->children[0]->eval(t_ss); this->children.back()->children[0]->eval(t_ss);
} }