diff --git a/parser_native/include/functors.h b/parser_native/include/functors.h index 0994c168c..971961fe3 100644 --- a/parser_native/include/functors.h +++ b/parser_native/include/functors.h @@ -15,6 +15,7 @@ #include #include "return_type.h" +#include "type_name.h" /* * Various functors used for datums. Unlike the standard functor, these are @@ -88,7 +89,7 @@ struct invalid_binary_operator { operator() (T, U) const { std::string s(str(boost::format( "operator %s cannot be applied to the types ('%s', '%s')") - % opname_ % typeid(T).name() % typeid(U).name())); + % opname_ % type_name::name() % type_name::name())); throw type_error(s); } diff --git a/parser_native/include/type_name.h b/parser_native/include/type_name.h new file mode 100644 index 000000000..fd98573b9 --- /dev/null +++ b/parser_native/include/type_name.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2008 Andrew Garrett. + * Copyright (c) 2008 River Tarnell + * Derived from public domain code contributed by Victor Vasiliev. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely. This software is provided 'as-is', without any express or + * implied warranty. + */ + +#ifndef TYPE_NAME_H +#define TYPE_NAME_H + +#include +#include + +#include "fray.h" + +/* + * A helper class to provide nicer names for types than the compiler-generated + * ones, which look like 10__gmp_exprIA1_12__mpz_structS1_E. + */ +namespace afp { + +template +struct type_name { + static std::string name() { + return typeid(T).name(); + } +}; + +template<> +struct type_name { + static std::string name() { + return "float"; + } +}; + +template<> +struct type_name { + static std::string name() { + return "integer"; + } +}; + +template<> +struct type_name { + static std::string name() { + return "datetime"; + } +}; + +template<> +struct type_name { + static std::string name() { + return "time_duration"; + } +}; + +template<> +struct type_name { + static std::string name() { + return "string"; + } +}; + +} // namespace afp + +#endif /* !TYPE_NAME_H */