2010-05-12 03:42:16 +08:00
|
|
|
// -*- C++ -*-
|
|
|
|
//===-------------------------- typeinfo ----------------------------------===//
|
|
|
|
//
|
2010-05-12 05:36:01 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
2010-11-17 06:09:02 +08:00
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
2010-05-12 03:42:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef __LIBCPP_TYPEINFO
|
|
|
|
#define __LIBCPP_TYPEINFO
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
typeinfo synopsis
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
|
|
|
|
class type_info
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~type_info();
|
2010-08-22 08:02:43 +08:00
|
|
|
|
2011-05-27 02:23:59 +08:00
|
|
|
bool operator==(const type_info& rhs) const noexcept;
|
|
|
|
bool operator!=(const type_info& rhs) const noexcept;
|
2010-08-22 08:02:43 +08:00
|
|
|
|
2011-05-27 02:23:59 +08:00
|
|
|
bool before(const type_info& rhs) const noexcept;
|
|
|
|
size_t hash_code() const noexcept;
|
|
|
|
const char* name() const noexcept;
|
2010-08-22 08:02:43 +08:00
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
type_info(const type_info& rhs) = delete;
|
|
|
|
type_info& operator=(const type_info& rhs) = delete;
|
|
|
|
};
|
|
|
|
|
|
|
|
class bad_cast
|
|
|
|
: public exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-27 02:23:59 +08:00
|
|
|
bad_cast() noexcept;
|
|
|
|
bad_cast(const bad_cast&) noexcept;
|
|
|
|
bad_cast& operator=(const bad_cast&) noexcept;
|
|
|
|
virtual const char* what() const noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class bad_typeid
|
|
|
|
: public exception
|
|
|
|
{
|
|
|
|
public:
|
2011-05-27 02:23:59 +08:00
|
|
|
bad_typeid() noexcept;
|
|
|
|
bad_typeid(const bad_typeid&) noexcept;
|
|
|
|
bad_typeid& operator=(const bad_typeid&) noexcept;
|
|
|
|
virtual const char* what() const noexcept;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // std
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <__config>
|
|
|
|
#include <exception>
|
|
|
|
#include <cstddef>
|
2014-03-30 19:34:26 +08:00
|
|
|
#include <cstdint>
|
2016-09-07 05:25:27 +08:00
|
|
|
#ifdef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
#include <cstdlib>
|
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2011-10-18 04:05:10 +08:00
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
2010-05-12 03:42:16 +08:00
|
|
|
#pragma GCC system_header
|
2011-10-18 04:05:10 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2017-01-06 05:22:22 +08:00
|
|
|
#if defined(_LIBCPP_NONUNIQUE_RTTI_BIT)
|
|
|
|
#define _LIBCPP_HAS_NONUNIQUE_TYPEINFO
|
|
|
|
#else
|
|
|
|
#define _LIBCPP_HAS_UNIQUE_TYPEINFO
|
|
|
|
#endif
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
namespace std // purposefully not using versioning namespace
|
|
|
|
{
|
|
|
|
|
2010-08-22 08:02:43 +08:00
|
|
|
class _LIBCPP_EXCEPTION_ABI type_info
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
type_info& operator=(const type_info&);
|
|
|
|
type_info(const type_info&);
|
2016-08-30 04:43:38 +08:00
|
|
|
|
2017-01-06 05:22:22 +08:00
|
|
|
#if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
int __compare_nonunique_names(const type_info &__arg) const _NOEXCEPT
|
|
|
|
{ return __builtin_strcmp(name(), __arg.name()); }
|
|
|
|
#endif
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
protected:
|
2017-01-06 05:22:22 +08:00
|
|
|
#if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
|
2014-03-30 19:34:26 +08:00
|
|
|
// A const char* with the non-unique RTTI bit possibly set.
|
|
|
|
uintptr_t __type_name;
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-24 02:58:28 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-01-06 05:22:22 +08:00
|
|
|
type_info(const char* __n) : __type_name(reinterpret_cast<uintptr_t>(__n)) {}
|
2014-03-30 19:34:26 +08:00
|
|
|
#else
|
2017-01-06 05:22:22 +08:00
|
|
|
const char *__type_name;
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
type_info(const char* __n) : __type_name(__n) {}
|
2014-03-30 19:34:26 +08:00
|
|
|
#endif
|
2010-05-12 03:42:16 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~type_info();
|
|
|
|
|
2017-01-06 05:22:22 +08:00
|
|
|
#if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
|
2010-09-24 02:58:28 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2014-03-30 19:34:26 +08:00
|
|
|
const char* name() const _NOEXCEPT
|
2017-01-06 05:22:22 +08:00
|
|
|
{
|
|
|
|
return reinterpret_cast<const char*>(__type_name &
|
|
|
|
~_LIBCPP_NONUNIQUE_RTTI_BIT);
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-24 02:58:28 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 02:23:59 +08:00
|
|
|
bool before(const type_info& __arg) const _NOEXCEPT
|
2017-01-06 05:22:22 +08:00
|
|
|
{
|
|
|
|
if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
|
|
|
|
return __type_name < __arg.__type_name;
|
|
|
|
return __compare_nonunique_names(__arg) < 0;
|
|
|
|
}
|
2014-03-30 19:34:26 +08:00
|
|
|
|
2010-09-24 02:58:28 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 02:23:59 +08:00
|
|
|
size_t hash_code() const _NOEXCEPT
|
2017-01-06 05:22:22 +08:00
|
|
|
{
|
|
|
|
if (!(__type_name & _LIBCPP_NONUNIQUE_RTTI_BIT))
|
|
|
|
return __type_name;
|
|
|
|
|
|
|
|
const char* __ptr = name();
|
|
|
|
size_t __hash = 5381;
|
|
|
|
while (unsigned char __c = static_cast<unsigned char>(*__ptr++))
|
|
|
|
__hash = (__hash * 33) ^ __c;
|
|
|
|
return __hash;
|
|
|
|
}
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2010-09-24 02:58:28 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2011-05-27 02:23:59 +08:00
|
|
|
bool operator==(const type_info& __arg) const _NOEXCEPT
|
2017-01-06 05:22:22 +08:00
|
|
|
{
|
|
|
|
if (__type_name == __arg.__type_name)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!((__type_name & __arg.__type_name) & _LIBCPP_NONUNIQUE_RTTI_BIT))
|
|
|
|
return false;
|
|
|
|
return __compare_nonunique_names(__arg) == 0;
|
|
|
|
}
|
2014-03-30 19:34:26 +08:00
|
|
|
#else
|
2010-09-24 02:58:28 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-01-06 05:22:22 +08:00
|
|
|
const char* name() const _NOEXCEPT
|
|
|
|
{ return __type_name; }
|
2010-05-12 03:42:16 +08:00
|
|
|
|
2014-03-30 19:34:26 +08:00
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
2017-01-06 05:22:22 +08:00
|
|
|
bool before(const type_info& __arg) const _NOEXCEPT
|
|
|
|
{ return __type_name < __arg.__type_name; }
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
size_t hash_code() const _NOEXCEPT
|
|
|
|
{ return reinterpret_cast<size_t>(__type_name); }
|
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool operator==(const type_info& __arg) const _NOEXCEPT
|
|
|
|
{ return __type_name == __arg.__type_name; }
|
2014-03-30 19:34:26 +08:00
|
|
|
#endif
|
2017-01-06 05:22:22 +08:00
|
|
|
|
|
|
|
_LIBCPP_INLINE_VISIBILITY
|
|
|
|
bool operator!=(const type_info& __arg) const _NOEXCEPT
|
|
|
|
{ return !operator==(__arg); }
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2010-05-15 04:19:37 +08:00
|
|
|
class _LIBCPP_EXCEPTION_ABI bad_cast
|
2010-08-22 08:02:43 +08:00
|
|
|
: public exception
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
public:
|
2011-05-27 02:23:59 +08:00
|
|
|
bad_cast() _NOEXCEPT;
|
|
|
|
virtual ~bad_cast() _NOEXCEPT;
|
|
|
|
virtual const char* what() const _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
2010-05-15 04:19:37 +08:00
|
|
|
class _LIBCPP_EXCEPTION_ABI bad_typeid
|
2010-08-22 08:02:43 +08:00
|
|
|
: public exception
|
2010-05-12 03:42:16 +08:00
|
|
|
{
|
|
|
|
public:
|
2011-05-27 02:23:59 +08:00
|
|
|
bad_typeid() _NOEXCEPT;
|
|
|
|
virtual ~bad_typeid() _NOEXCEPT;
|
|
|
|
virtual const char* what() const _NOEXCEPT;
|
2010-05-12 03:42:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // std
|
|
|
|
|
2016-08-25 23:09:01 +08:00
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
|
|
|
|
void __throw_bad_cast()
|
|
|
|
{
|
|
|
|
#ifndef _LIBCPP_NO_EXCEPTIONS
|
|
|
|
throw bad_cast();
|
|
|
|
#else
|
|
|
|
_VSTD::abort();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
|
2010-05-12 03:42:16 +08:00
|
|
|
#endif // __LIBCPP_TYPEINFO
|