Home | History | Annotate | Download | only in runtime
      1 // -*- C++ -*-
      2 //===----------------------------------------------------------------------===//
      3 //
      4 //                     The LLVM Compiler Infrastructure
      5 //
      6 // This file is dual licensed under the MIT and the University of Illinois Open
      7 // Source Licenses. See LICENSE.TXT for details.
      8 //
      9 //===----------------------------------------------------------------------===//
     10 
     11 #include <stdio.h>
     12 #include <stdlib.h>
     13 
     14 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCreate(void*);
     15 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrDestroy(void*);
     16 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCopy(void*, const void*);
     17 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrAssign(void*, const void*);
     18 _LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrCompare(const void*, const void*);
     19 _LIBCPP_CRT_FUNC bool __cdecl __ExceptionPtrToBool(const void*);
     20 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrSwap(void*, void*);
     21 _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCurrentException(void*);
     22 [[noreturn]] _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrRethrow(const void*);
     23 _LIBCPP_CRT_FUNC void __cdecl
     24 __ExceptionPtrCopyException(void*, const void*, const void*);
     25 
     26 namespace std {
     27 
     28 exception_ptr::exception_ptr() _NOEXCEPT { __ExceptionPtrCreate(this); }
     29 exception_ptr::exception_ptr(nullptr_t) _NOEXCEPT { __ExceptionPtrCreate(this); }
     30 
     31 exception_ptr::exception_ptr(const exception_ptr& __other) _NOEXCEPT {
     32   __ExceptionPtrCopy(this, &__other);
     33 }
     34 exception_ptr& exception_ptr::operator=(const exception_ptr& __other) _NOEXCEPT {
     35   __ExceptionPtrAssign(this, &__other);
     36   return *this;
     37 }
     38 
     39 exception_ptr& exception_ptr::operator=(nullptr_t) _NOEXCEPT {
     40   exception_ptr dummy;
     41   __ExceptionPtrAssign(this, &dummy);
     42   return *this;
     43 }
     44 
     45 exception_ptr::~exception_ptr() _NOEXCEPT { __ExceptionPtrDestroy(this); }
     46 
     47 exception_ptr::operator bool() const _NOEXCEPT {
     48   return __ExceptionPtrToBool(this);
     49 }
     50 
     51 bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {
     52   return __ExceptionPtrCompare(&__x, &__y);
     53 }
     54 
     55 
     56 void swap(exception_ptr& lhs, exception_ptr& rhs) _NOEXCEPT {
     57   __ExceptionPtrSwap(&rhs, &lhs);
     58 }
     59 
     60 exception_ptr __copy_exception_ptr(void* __except, const void* __ptr) {
     61   exception_ptr __ret = nullptr;
     62   if (__ptr)
     63     __ExceptionPtrCopyException(&__ret, __except, __ptr);
     64   return __ret;
     65 }
     66 
     67 exception_ptr current_exception() _NOEXCEPT {
     68   exception_ptr __ret;
     69   __ExceptionPtrCurrentException(&__ret);
     70   return __ret;
     71 }
     72 
     73 _LIBCPP_NORETURN
     74 void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); }
     75 
     76 nested_exception::nested_exception() _NOEXCEPT : __ptr_(current_exception()) {}
     77 
     78 nested_exception::~nested_exception() _NOEXCEPT {}
     79 
     80 _LIBCPP_NORETURN
     81 void nested_exception::rethrow_nested() const {
     82   if (__ptr_ == nullptr)
     83     terminate();
     84   rethrow_exception(__ptr_);
     85 }
     86 
     87 } // namespace std
     88