Skip to content
Snippets Groups Projects
Commit 598e2e85 authored by Axel Naumann's avatar Axel Naumann
Browse files

Enable simplistic cast also for objects, enum constants.

Simplify it (o no, cling is shrinking *again*!)


git-svn-id: http://root.cern.ch/svn/root/trunk@43960 27541ba8-7e3a-0410-8455-c3a389f83636
parent 498f275e
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "llvm/ExecutionEngine/GenericValue.h" #include "llvm/ExecutionEngine/GenericValue.h"
#include "clang/AST/Type.h" #include "clang/AST/Type.h"
#include "clang/AST/CanonicalType.h"
namespace clang { namespace clang {
class ASTContext; class ASTContext;
...@@ -75,7 +76,8 @@ namespace cling { ...@@ -75,7 +76,8 @@ namespace cling {
/// \brief Get the value. /// \brief Get the value.
// //
/// Get the value cast to T. This is similar to reinterpret_cast<T>(value), /// Get the value cast to T. This is similar to reinterpret_cast<T>(value),
/// but only works for builtin types and pointers. /// casting the value of builtins (except void), enums and pointers.
/// Values referencing an object are treated as pointers to the object.
template <typename T> template <typename T>
T simplisticCastAs() const; T simplisticCastAs() const;
}; };
...@@ -112,7 +114,9 @@ namespace cling { ...@@ -112,7 +114,9 @@ namespace cling {
CLING_VALUE_TYPEDACCESS_UNSIGNED(TYPE); CLING_VALUE_TYPEDACCESS_UNSIGNED(TYPE);
CLING_VALUE_TYPEDACCESS(double, DoubleVal); CLING_VALUE_TYPEDACCESS(double, DoubleVal);
//CLING_VALUE_TYPEDACCESS(long double, ???);
CLING_VALUE_TYPEDACCESS(float, FloatVal); CLING_VALUE_TYPEDACCESS(float, FloatVal);
CLING_VALUE_TYPEDACCESS(bool, IntVal.getBoolValue()); CLING_VALUE_TYPEDACCESS(bool, IntVal.getBoolValue());
CLING_VALUE_TYPEDACCESS_BOTHSIGNS(char) CLING_VALUE_TYPEDACCESS_BOTHSIGNS(char)
...@@ -134,31 +138,20 @@ namespace cling { ...@@ -134,31 +138,20 @@ namespace cling {
} }
template <typename T> template <typename T>
T Value::simplisticCastAs() const { T Value::simplisticCastAs() const {
const clang::Type* desugared = type->getUnqualifiedDesugaredType(); const clang::Type* desugCanon = type->getUnqualifiedDesugaredType();
if (desugared->getTypeClass() == clang::Type::Builtin) { desugCanon = desugCanon->getCanonicalTypeUnqualified()->getTypePtr()->getUnqualifiedDesugaredType();
switch (desugared->getAs<clang::BuiltinType>()->getKind()) { if (desugCanon->isSignedIntegerOrEnumerationType()) {
case clang::BuiltinType::Bool: return (T) getAs<bool>(); return (T) getAs<signed long long>();
case clang::BuiltinType::Char_U: return (T) getAs<char>(); } else if (desugCanon->isUnsignedIntegerOrEnumerationType()) {
case clang::BuiltinType::UChar: return (T) getAs<unsigned char>(); return (T) getAs<unsigned long long>();
case clang::BuiltinType::UShort: return (T) getAs<unsigned short>(); } else if (desugCanon->isRealFloatingType()) {
case clang::BuiltinType::UInt: return (T) getAs<unsigned int>(); const clang::BuiltinType* BT = desugCanon->getAs<clang::BuiltinType>();
case clang::BuiltinType::ULong: return (T) getAs<unsigned long>(); if (BT->getKind() == clang::BuiltinType::Double) return (T) getAs<double>();
case clang::BuiltinType::ULongLong: return (T) getAs<unsigned long long>(); else if (BT->getKind() == clang::BuiltinType::Float) return (T) getAs<float>();
/* not yet supported in JIT:
case clang::BuiltinType::Char_S: return (T) getAs<char>(); else if (BT->getKind() == clang::BuiltinType::LongDouble) return (T) getAs<long double>();
case clang::BuiltinType::SChar: return (T) getAs<signed char>(); */
case clang::BuiltinType::Short: return (T) getAs<signed short>(); } else if (desugCanon->isPointerType() || desugCanon->isObjectType()) {
case clang::BuiltinType::Int: return (T) getAs<signed int>();
case clang::BuiltinType::Long: return (T) getAs<signed long>();
case clang::BuiltinType::LongLong: return (T) getAs<signed long long>();
case clang::BuiltinType::Float: return (T) getAs<float>();
case clang::BuiltinType::Double: return (T) getAs<double>();
default:
assert("Cannot cast simplistically from value's type!" && 0);
return T();
}
} else if (desugared->getTypeClass() == clang::Type::Pointer) {
return (T) getAs<void*>(); return (T) getAs<void*>();
} }
assert("unsupported type in Value, cannot cast simplistically!" && 0); assert("unsupported type in Value, cannot cast simplistically!" && 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment