Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
exception338 linesDownload Raw Back to include
1// -*- C++ -*-2//===-------------------------- exception ---------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCUDACXX_EXCEPTION11#define _LIBCUDACXX_EXCEPTION12 13/*14    exception synopsis15 16namespace std17{18 19class exception20{21public:22    exception() noexcept;23    exception(const exception&) noexcept;24    exception& operator=(const exception&) noexcept;25    virtual ~exception() noexcept;26    virtual const char* what() const noexcept;27};28 29class bad_exception30    : public exception31{32public:33    bad_exception() noexcept;34    bad_exception(const bad_exception&) noexcept;35    bad_exception& operator=(const bad_exception&) noexcept;36    virtual ~bad_exception() noexcept;37    virtual const char* what() const noexcept;38};39 40typedef void (*unexpected_handler)();41unexpected_handler set_unexpected(unexpected_handler  f ) noexcept;42unexpected_handler get_unexpected() noexcept;43[[noreturn]] void unexpected();44 45typedef void (*terminate_handler)();46terminate_handler set_terminate(terminate_handler  f ) noexcept;47terminate_handler get_terminate() noexcept;48[[noreturn]] void terminate() noexcept;49 50bool uncaught_exception()  noexcept;51int  uncaught_exceptions() noexcept;  // C++1752 53typedef unspecified exception_ptr;54 55exception_ptr current_exception() noexcept;56void rethrow_exception [[noreturn]] (exception_ptr p);57template<class E> exception_ptr make_exception_ptr(E e) noexcept;58 59class nested_exception60{61public:62    nested_exception() noexcept;63    nested_exception(const nested_exception&) noexcept = default;64    nested_exception& operator=(const nested_exception&) noexcept = default;65    virtual ~nested_exception() = default;66 67    // access functions68    [[noreturn]] void rethrow_nested() const;69    exception_ptr nested_ptr() const noexcept;70};71 72template <class T> [[noreturn]] void throw_with_nested(T&& t);73template <class E> void rethrow_if_nested(const E& e);74 75}  // std76 77*/78 79#ifndef __cuda_std__80#include <__config>81#endif //__cuda_std__82 83#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)84#  pragma GCC system_header85#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)86#  pragma clang system_header87#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)88#  pragma system_header89#endif // no system header90 91#include "cstddef"92#include "cstdlib"93#include "type_traits"94#include "version"95 96#if defined(_LIBCUDACXX_ABI_VCRUNTIME)97#include <vcruntime_exception.h>98#endif99_LIBCUDACXX_BEGIN_NAMESPACE_STD_NOVERSION  // purposefully not using versioning namespace100 101#if !defined(_LIBCUDACXX_ABI_VCRUNTIME) || defined(__cuda_std__)102class _LIBCUDACXX_EXCEPTION_ABI exception103{104public:105    _LIBCUDACXX_INLINE_VISIBILITY exception() noexcept {}106    _LIBCUDACXX_HOST_DEVICE virtual ~exception() noexcept;107    _LIBCUDACXX_HOST_DEVICE virtual const char* what() const noexcept;108};109 110class _LIBCUDACXX_EXCEPTION_ABI bad_exception111    : public exception112{113public:114    _LIBCUDACXX_INLINE_VISIBILITY bad_exception() noexcept {}115    _LIBCUDACXX_HOST_DEVICE virtual ~bad_exception() noexcept;116    _LIBCUDACXX_HOST_DEVICE virtual const char* what() const noexcept;117};118#else // ^^^ !_LIBCUDACXX_ABI_VCRUNTIME || __cuda_std__^^^ / vvv _LIBCUDACXX_ABI_VCRUNTIME vvv119// pull in the exception definition from vcruntime, which lives in namespace std120using ::std::exception;121#endif // !_LIBCUDACXX_ABI_VCRUNTIME122 123#if _LIBCUDACXX_STD_VER <= 14 \124    || defined(_LIBCUDACXX_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) \125    || defined(_LIBCUDACXX_BUILDING_LIBRARY)126typedef void (*unexpected_handler)();127_LIBCUDACXX_FUNC_VIS unexpected_handler set_unexpected(unexpected_handler) noexcept;128_LIBCUDACXX_FUNC_VIS unexpected_handler get_unexpected() noexcept;129_LIBCUDACXX_NORETURN _LIBCUDACXX_FUNC_VIS void unexpected();130#endif131 132typedef void (*terminate_handler)();133_LIBCUDACXX_FUNC_VIS terminate_handler set_terminate(terminate_handler) noexcept;134_LIBCUDACXX_FUNC_VIS terminate_handler get_terminate() noexcept;135_LIBCUDACXX_NORETURN _LIBCUDACXX_FUNC_VIS void terminate() noexcept;136 137_LIBCUDACXX_FUNC_VIS bool uncaught_exception() noexcept;138_LIBCUDACXX_FUNC_VIS _LIBCUDACXX_AVAILABILITY_UNCAUGHT_EXCEPTIONS int uncaught_exceptions() noexcept;139 140class _LIBCUDACXX_TYPE_VIS exception_ptr;141 142_LIBCUDACXX_FUNC_VIS exception_ptr current_exception() noexcept;143_LIBCUDACXX_NORETURN _LIBCUDACXX_FUNC_VIS void rethrow_exception(exception_ptr);144 145#ifndef _LIBCUDACXX_ABI_MICROSOFT146 147class _LIBCUDACXX_TYPE_VIS exception_ptr148{149    void* __ptr_;150public:151    _LIBCUDACXX_INLINE_VISIBILITY exception_ptr() noexcept : __ptr_() {}152    _LIBCUDACXX_INLINE_VISIBILITY exception_ptr(nullptr_t) noexcept : __ptr_() {}153 154    _LIBCUDACXX_HOST_DEVICE exception_ptr(const exception_ptr&) noexcept;155    _LIBCUDACXX_HOST_DEVICE exception_ptr& operator=(const exception_ptr&) noexcept;156    _LIBCUDACXX_HOST_DEVICE ~exception_ptr() noexcept;157 158    _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_EXPLICIT operator bool() const noexcept159    {return __ptr_ != nullptr;}160 161    friend _LIBCUDACXX_INLINE_VISIBILITY162    bool operator==(const exception_ptr& __x, const exception_ptr& __y) noexcept163        {return __x.__ptr_ == __y.__ptr_;}164 165    friend _LIBCUDACXX_INLINE_VISIBILITY166    bool operator!=(const exception_ptr& __x, const exception_ptr& __y) noexcept167        {return !(__x == __y);}168 169    friend _LIBCUDACXX_FUNC_VIS exception_ptr current_exception() noexcept;170    friend _LIBCUDACXX_FUNC_VIS void rethrow_exception(exception_ptr);171};172 173template<class _Ep>174_LIBCUDACXX_INLINE_VISIBILITY exception_ptr175make_exception_ptr(_Ep __e) noexcept176{177#ifndef _LIBCUDACXX_NO_EXCEPTIONS178    try179    {180        throw __e;181    }182    catch (...)183    {184        return current_exception();185    }186#else187    ((void)__e);188    _CUDA_VSTD::abort();189#endif190}191 192#else // _LIBCUDACXX_ABI_MICROSOFT193 194class _LIBCUDACXX_EXCEPTION_ABI exception_ptr195{196#if defined(_LIBCUDACXX_COMPILER_CLANG)197#pragma clang diagnostic push198#pragma clang diagnostic ignored "-Wunused-private-field"199#endif200    void* __ptr1_;201    void* __ptr2_;202#if defined(_LIBCUDACXX_COMPILER_CLANG)203#pragma clang diagnostic pop204#endif205public:206    exception_ptr() noexcept;207    exception_ptr(nullptr_t) noexcept;208    exception_ptr(const exception_ptr& __other) noexcept;209    exception_ptr& operator=(const exception_ptr& __other) noexcept;210    exception_ptr& operator=(nullptr_t) noexcept;211    ~exception_ptr() noexcept;212    _LIBCUDACXX_EXPLICIT operator bool() const noexcept;213};214 215_LIBCUDACXX_FUNC_VIS216bool operator==(const exception_ptr& __x, const exception_ptr& __y) noexcept;217 218inline _LIBCUDACXX_INLINE_VISIBILITY219bool operator!=(const exception_ptr& __x, const exception_ptr& __y) noexcept220    {return !(__x == __y);}221 222_LIBCUDACXX_FUNC_VIS void swap(exception_ptr&, exception_ptr&) noexcept;223 224_LIBCUDACXX_FUNC_VIS exception_ptr __copy_exception_ptr(void *__except_, const void* __ptr);225_LIBCUDACXX_FUNC_VIS exception_ptr current_exception() noexcept;226_LIBCUDACXX_NORETURN _LIBCUDACXX_FUNC_VIS void rethrow_exception(exception_ptr p);227 228// This is a built-in template function which automagically extracts the required229// information.230template <class _E> void *__GetExceptionInfo(_E);231 232template<class _Ep>233_LIBCUDACXX_INLINE_VISIBILITY exception_ptr234make_exception_ptr(_Ep __e) noexcept235{236  return __copy_exception_ptr(_CUDA_VSTD::addressof(__e), __GetExceptionInfo(__e));237}238 239#endif // _LIBCUDACXX_ABI_MICROSOFT240// nested_exception241 242class _LIBCUDACXX_EXCEPTION_ABI nested_exception243{244    exception_ptr __ptr_;245public:246    _LIBCUDACXX_HOST_DEVICE nested_exception() noexcept;247//     nested_exception(const nested_exception&) noexcept = default;248//     nested_exception& operator=(const nested_exception&) noexcept = default;249    _LIBCUDACXX_HOST_DEVICE virtual ~nested_exception() noexcept;250 251    // access functions252    _LIBCUDACXX_NORETURN _LIBCUDACXX_HOST_DEVICE void rethrow_nested() const;253    _LIBCUDACXX_INLINE_VISIBILITY exception_ptr nested_ptr() const noexcept {return __ptr_;}254};255 256template <class _Tp>257struct __nested258    : public _Tp,259      public nested_exception260{261    _LIBCUDACXX_INLINE_VISIBILITY explicit __nested(const _Tp& __t) : _Tp(__t) {}262};263 264#ifndef _LIBCUDACXX_NO_EXCEPTIONS265template <class _Tp, class _Up, bool>266struct __throw_with_nested;267 268template <class _Tp, class _Up>269struct __throw_with_nested<_Tp, _Up, true> {270    _LIBCUDACXX_NORETURN static inline _LIBCUDACXX_INLINE_VISIBILITY void271    __do_throw(_Tp&& __t)272    {273        throw __nested<_Up>(_CUDA_VSTD::forward<_Tp>(__t));274    }275};276 277template <class _Tp, class _Up>278struct __throw_with_nested<_Tp, _Up, false> {279    _LIBCUDACXX_NORETURN static inline _LIBCUDACXX_INLINE_VISIBILITY void280    __do_throw(_Tp&& __t)281    {282        throw _CUDA_VSTD::forward<_Tp>(__t);283    }284};285#endif286 287template <class _Tp>288_LIBCUDACXX_NORETURN inline _LIBCUDACXX_INLINE_VISIBILITY289void290throw_with_nested(_Tp&& __t)291{292#ifndef _LIBCUDACXX_NO_EXCEPTIONS293    typedef __decay_t<_Tp> _Up;294    static_assert( is_copy_constructible<_Up>::value, "type thrown must be CopyConstructible");295    __throw_with_nested<_Tp, _Up,296        is_class<_Up>::value &&297        !is_base_of<nested_exception, _Up>::value &&298        !__libcpp_is_final<_Up>::value>::299            __do_throw(_CUDA_VSTD::forward<_Tp>(__t));300#else301    ((void)__t);302    // FIXME: Make this abort303#endif304}305 306template <class _From, class _To>307struct __can_dynamic_cast : public308    _LIBCUDACXX_BOOL_CONSTANT(309              is_polymorphic<_From>::value &&310                 (!is_base_of<_To, _From>::value ||311                   is_convertible<const _From*, const _To*>::value))312{};313 314template <class _Ep>315inline _LIBCUDACXX_INLINE_VISIBILITY316void317rethrow_if_nested(const _Ep& __e,318                  typename enable_if< __can_dynamic_cast<_Ep, nested_exception>::value>::type* = 0)319{320#if !defined(_LIBCUDACXX_COMPILER_MSVC)321    const nested_exception* __nep = dynamic_cast<const nested_exception*>(_CUDA_VSTD::addressof(__e));322    if (__nep)323        __nep->rethrow_nested();324#endif // _LIBCUDACXX_COMPILER_MSVC325}326 327template <class _Ep>328inline _LIBCUDACXX_INLINE_VISIBILITY329void330rethrow_if_nested(const _Ep&,331                  typename enable_if<!__can_dynamic_cast<_Ep, nested_exception>::value>::type* = 0)332{333}334 335_LIBCUDACXX_END_NAMESPACE_STD_NOVERSION336 337#endif  // _LIBCUDACXX_EXCEPTION338 
codekingpro/portable-devtools · Team Ai