Ignore:
Timestamp:
Jan 7, 2021, 2:55:57 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
58fe85a
Parents:
bdfc032 (diff), 44e37ef (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into dkobets-vector

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/exception.h

    rbdfc032 reef8dfb  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // exception.h -- Builtins for exception handling.
     7// exception.h -- Internal exception handling definitions.
    88//
    99// Author           : Andrew Beach
    1010// Created On       : Mon Jun 26 15:11:00 2017
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb 22 18:11:15 2018
    13 // Update Count     : 8
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue Oct 27 14:45:00 2020
     13// Update Count     : 11
    1414//
    1515
    1616#pragma once
    1717
     18// This could be considered several headers. All are internal to the exception
     19// system but needed to depending on whether they are C/Cforall code and
     20// whether or not they are part of the builtins.
    1821
    1922#ifdef __cforall
     
    2124#endif
    2225
    23 struct __cfaabi_ehm__base_exception_t;
    24 typedef struct __cfaabi_ehm__base_exception_t exception_t;
    25 struct __cfaabi_ehm__base_exception_t_vtable {
    26         const struct __cfaabi_ehm__base_exception_t_vtable * parent;
     26// Included in C code or the built-ins.
     27#if !defined(__cforall) || defined(__cforall_builtins__)
     28
     29struct __cfaehm_base_exception_t;
     30typedef struct __cfaehm_base_exception_t exception_t;
     31struct __cfaehm_base_exception_t_vtable {
     32        const struct __cfaehm_base_exception_t_vtable * parent;
    2733        size_t size;
    28         void (*copy)(struct __cfaabi_ehm__base_exception_t *this,
    29                      struct __cfaabi_ehm__base_exception_t * other);
    30         void (*free)(struct __cfaabi_ehm__base_exception_t *this);
    31         const char * (*msg)(struct __cfaabi_ehm__base_exception_t *this);
     34        void (*copy)(struct __cfaehm_base_exception_t *this,
     35                     struct __cfaehm_base_exception_t * other);
     36        void (*free)(struct __cfaehm_base_exception_t *this);
     37        const char * (*msg)(struct __cfaehm_base_exception_t *this);
    3238};
    33 struct __cfaabi_ehm__base_exception_t {
    34         struct __cfaabi_ehm__base_exception_t_vtable const * virtual_table;
     39struct __cfaehm_base_exception_t {
     40        struct __cfaehm_base_exception_t_vtable const * virtual_table;
    3541};
    36 extern struct __cfaabi_ehm__base_exception_t_vtable
    37         ___cfaabi_ehm__base_exception_t_vtable_instance;
     42extern struct __cfaehm_base_exception_t_vtable
     43        ___cfaehm_base_exception_t_vtable_instance;
    3844
    3945
     46void __cfaehm_cancel_stack(exception_t * except) __attribute__((noreturn));
     47
    4048// Used in throw statement translation.
    41 void __cfaabi_ehm__throw_terminate(exception_t * except) __attribute__((noreturn));
    42 void __cfaabi_ehm__rethrow_terminate() __attribute__((noreturn));
    43 void __cfaabi_ehm__throw_resume(exception_t * except);
     49void __cfaehm_throw_terminate(exception_t * except, void (*)(exception_t *));
     50void __cfaehm_rethrow_terminate() __attribute__((noreturn));
     51void __cfaehm_throw_resume(exception_t * except, void (*)(exception_t *));
    4452
    4553// Function catches termination exceptions.
    46 void __cfaabi_ehm__try_terminate(
    47     void (*try_block)(),
    48     void (*catch_block)(int index, exception_t * except),
    49     int (*match_block)(exception_t * except));
     54void __cfaehm_try_terminate(
     55        void (*try_block)(),
     56        void (*catch_block)(int index, exception_t * except),
     57        int (*match_block)(exception_t * except));
    5058
    5159// Clean-up the exception in catch blocks.
    52 void __cfaabi_ehm__cleanup_terminate(void * except);
     60void __cfaehm_cleanup_terminate(void * except);
    5361
    5462// Data structure creates a list of resume handlers.
    55 struct __cfaabi_ehm__try_resume_node {
    56     struct __cfaabi_ehm__try_resume_node * next;
    57     _Bool (*handler)(exception_t * except);
     63struct __cfaehm_try_resume_node {
     64        struct __cfaehm_try_resume_node * next;
     65        _Bool (*handler)(exception_t * except);
    5866};
    5967
    6068// These act as constructor and destructor for the resume node.
    61 void __cfaabi_ehm__try_resume_setup(
    62     struct __cfaabi_ehm__try_resume_node * node,
    63     _Bool (*handler)(exception_t * except));
    64 void __cfaabi_ehm__try_resume_cleanup(
    65     struct __cfaabi_ehm__try_resume_node * node);
     69void __cfaehm_try_resume_setup(
     70        struct __cfaehm_try_resume_node * node,
     71        _Bool (*handler)(exception_t * except));
     72void __cfaehm_try_resume_cleanup(
     73        struct __cfaehm_try_resume_node * node);
    6674
    6775// Check for a standard way to call fake deconstructors.
    68 struct __cfaabi_ehm__cleanup_hook {};
     76struct __cfaehm_cleanup_hook {};
     77
     78#endif
     79
     80// Included in C code and the library.
     81#if !defined(__cforall) || !defined(__cforall_builtins__)
     82struct __cfaehm_node {
     83        struct _Unwind_Exception unwind_exception;
     84        struct __cfaehm_node * next;
     85        int handler_index;
     86};
     87
     88static inline exception_t * __cfaehm_cancellation_exception(
     89                struct _Unwind_Exception * unwind_exception ) {
     90        return (exception_t *)(1 + (struct __cfaehm_node *)unwind_exception);
     91}
     92#endif
    6993
    7094#ifdef __cforall
    7195}
     96
     97// Built-ins not visible in C.
     98#if defined(__cforall_builtins__)
     99
     100// Not all the built-ins can be expressed in C. These can't be
     101// implemented in the .c file either so they all have to be inline.
     102
     103trait is_exception(dtype exceptT, dtype virtualT) {
     104        /* The first field must be a pointer to a virtual table.
     105         * That virtual table must be a decendent of the base exception virtual table.
     106         */
     107        virtualT const & get_exception_vtable(exceptT *);
     108        // Always returns the virtual table for this type (associated types hack).
     109};
     110
     111trait is_termination_exception(dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT)) {
     112        void defaultTerminationHandler(exceptT &);
     113};
     114
     115trait is_resumption_exception(dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT)) {
     116        void defaultResumptionHandler(exceptT &);
     117};
     118
     119forall(dtype exceptT, dtype virtualT | is_termination_exception(exceptT, virtualT))
     120static inline void $throw(exceptT & except) {
     121        __cfaehm_throw_terminate(
     122                (exception_t *)&except,
     123                (void(*)(exception_t *))defaultTerminationHandler
     124        );
     125}
     126
     127forall(dtype exceptT, dtype virtualT | is_resumption_exception(exceptT, virtualT))
     128static inline void $throwResume(exceptT & except) {
     129        __cfaehm_throw_resume(
     130                (exception_t *)&except,
     131                (void(*)(exception_t *))defaultResumptionHandler
     132        );
     133}
     134
     135forall(dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT))
     136static inline void cancel_stack(exceptT & except) __attribute__((noreturn)) {
     137        __cfaehm_cancel_stack( (exception_t *)&except );
     138}
     139
     140forall(dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT))
     141static inline void defaultTerminationHandler(exceptT & except) {
     142        return cancel_stack( except );
     143}
     144
     145forall(dtype exceptT, dtype virtualT | is_exception(exceptT, virtualT))
     146static inline void defaultResumptionHandler(exceptT & except) {
     147        throw except;
     148}
     149
    72150#endif
     151
     152#endif
Note: See TracChangeset for help on using the changeset viewer.