Changeset c715e5f


Ignore:
Timestamp:
May 25, 2022, 5:51:24 PM (22 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
c3b9d639
Parents:
5024df4
Message:

Removed most of the exception macros (EHM_ group). Made changes to the exception declaration pass to do so.

Files:
11 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/clib/cfathread.cfa

    r5024df4 rc715e5f  
    237237
    238238typedef ThreadCancelled(cfathread_object) cfathread_exception;
    239 typedef ThreadCancelled_vtable(cfathread_object) cfathread_vtable;
     239typedef vtable(ThreadCancelled(cfathread_object)) cfathread_vtable;
    240240
    241241void defaultResumptionHandler(ThreadCancelled(cfathread_object) & except) {
     
    283283
    284284typedef ThreadCancelled(__cfainit) __cfainit_exception;
    285 typedef ThreadCancelled_vtable(__cfainit) __cfainit_vtable;
     285typedef vtable(ThreadCancelled(__cfainit)) __cfainit_vtable;
    286286
    287287void defaultResumptionHandler(ThreadCancelled(__cfainit) & except) {
  • libcfa/src/concurrency/coroutine.hfa

    r5024df4 rc715e5f  
    2222//-----------------------------------------------------------------------------
    2323// Exception thrown from resume when a coroutine stack is cancelled.
    24 EHM_FORALL_EXCEPTION(CoroutineCancelled, (coroutine_t &), (coroutine_t)) (
     24forall(coroutine_t &)
     25exception CoroutineCancelled {
    2526        coroutine_t * the_coroutine;
    2627        exception_t * the_exception;
    27 );
     28};
    2829
    2930forall(T &)
  • libcfa/src/concurrency/thread.hfa

    r5024df4 rc715e5f  
    3232};
    3333
    34 EHM_FORALL_EXCEPTION(ThreadCancelled, (thread_t &), (thread_t)) (
     34forall(thread_t &)
     35exception ThreadCancelled {
    3536        thread_t * the_thread;
    3637        exception_t * the_exception;
    37 );
     38};
    3839
    3940forall(T &)
  • libcfa/src/exception.hfa

    r5024df4 rc715e5f  
    1010// Created On       : Thu Apr  7 10:25:00 2020
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Apr  8 15:16:00 2021
    13 // Update Count     : 4
     12// Last Modified On : Wed May 25 17:20:00 2022
     13// Update Count     : 5
    1414//
    1515
     
    1818// -----------------------------------------------------------------------------------------------
    1919
    20 // EHM_EXCEPTION(exception_name)(fields...);
    21 // Create an exception (a virtual structure that inherits from exception_t)
    22 // with the given name and fields.
    23 #define EHM_EXCEPTION(exception_name) \
    24         _EHM_TYPE_ID_STRUCT(exception_name, ); \
    25         _EHM_TYPE_ID_VALUE(exception_name, ); \
    26         _EHM_VIRTUAL_TABLE_STRUCT(exception_name, , ); \
    27         _EHM_EXCEPTION_STRUCT(exception_name, , )
    28 
    29 // EHM_EXTERN_VTABLE(exception_name, table_name);
    30 // Forward declare a virtual table called table_name for exception_name type.
    31 #define EHM_EXTERN_VTABLE(exception_name, table_name) \
    32         _EHM_EXTERN_VTABLE(exception_name, , table_name)
    33 
    34 // EHM_VIRTUAL_TABLE(exception_name, table_name);
    35 // Define a virtual table called table_name for exception_name type.
    36 #define EHM_VIRTUAL_TABLE(exception_name, table_name) \
    37         _EHM_DEFINE_COPY(exception_name, ) \
    38         _EHM_DEFINE_MSG(exception_name, ) \
    39         _EHM_VIRTUAL_TABLE(exception_name, , table_name)
    40 
    41 // EHM_FORALL_EXCEPTION(exception_name, (assertions), (parameters))(fields...);
    42 // As EHM_EXCEPTION but for polymorphic types instead of monomorphic ones.
    43 // The assertions list should include all polymorphic parameters and
    44 // assertions inside a parentisized list. Parameters should include all the
    45 // polymorphic parameter names inside a parentisized list (same order).
    46 #define EHM_FORALL_EXCEPTION(exception_name, assertions, parameters) \
    47         _EHM_TYPE_ID_STRUCT(exception_name, forall assertions); \
    48         _EHM_VIRTUAL_TABLE_STRUCT(exception_name, forall assertions, parameters); \
    49         _EHM_EXCEPTION_STRUCT(exception_name, forall assertions, parameters)
    50 
    51 // EHM_FORALL_EXTERN_VTABLE(exception_name, (arguments), table_name);
    52 // As EHM_EXTERN_VTABLE but for polymorphic types instead of monomorphic ones.
    53 // Arguments should be the parentisized list of polymorphic arguments.
    54 #define EHM_FORALL_EXTERN_VTABLE(exception_name, arguments, table_name) \
    55         _EHM_EXTERN_VTABLE(exception_name, arguments, table_name)
    56 
    57 // EHM_FORALL_VIRTUAL_TABLE(exception_name, (arguments), table_name);
    58 // As EHM_VIRTUAL_TABLE but for polymorphic types instead of monomorphic ones.
    59 // Arguments should be the parentisized list of polymorphic arguments.
    60 #define EHM_FORALL_VIRTUAL_TABLE(exception_name, arguments, table_name) \
    61         _EHM_TYPE_ID_VALUE(exception_name, arguments); \
    62         _EHM_DEFINE_COPY(exception_name, arguments) \
    63         _EHM_DEFINE_MSG(exception_name, arguments) \
    64         _EHM_VIRTUAL_TABLE(exception_name, arguments, table_name)
    65 
    6620// EHM_DEFAULT_VTABLE(exception_name, (arguments))
    6721// Create a declaration for a (possibly polymorphic) default vtable.
    6822#define EHM_DEFAULT_VTABLE(exception_name, arguments) \
    69         _EHM_VTABLE_TYPE(exception_name) arguments & const _default_vtable
     23        vtable(exception_name arguments) & const _default_vtable
    7024
    7125// IS_EXCEPTION(exception_name [, (...parameters)])
     
    7731#define IS_RESUMPTION_EXCEPTION(...) _IS_EXCEPTION(is_resumption_exception, __VA_ARGS__, , ~)
    7832#define IS_TERMINATION_EXCEPTION(...) _IS_EXCEPTION(is_termination_exception, __VA_ARGS__, , ~)
    79 
    80 // Macros starting with a leading underscore are internal.
    81 
    82 // Create an exception type definition. must be tailing, can be polymorphic.
    83 #define _EHM_EXCEPTION_STRUCT(exception_name, forall_clause, parameters) \
    84         forall_clause struct exception_name { \
    85                 _EHM_VTABLE_TYPE(exception_name) parameters const * virtual_table; \
    86                 _CLOSE
    87 
    88 // Create a (possibly polymorphic) virtual table forward declaration.
    89 #define _EHM_EXTERN_VTABLE(exception_name, arguments, table_name) \
    90         extern const _EHM_VTABLE_TYPE(exception_name) arguments table_name
    91 
    92 // Create a (possibly polymorphic) virtual table definition.
    93 #define _EHM_VIRTUAL_TABLE(exception_type, arguments, table_name) \
    94         const _EHM_VTABLE_TYPE(exception_type) arguments table_name @= { \
    95                 .__cfavir_typeid : &_EHM_TYPE_ID_NAME(exception_type), \
    96                 .size : sizeof(struct exception_type arguments), \
    97                 .copy : copy, \
    98                 .^?{} : ^?{}, \
    99                 .msg : msg, \
    100         }
    101 
    102 // Create a (possibly polymorphic) copy function from an assignment operator.
    103 #define _EHM_DEFINE_FORALL_COPY(exception_name, forall_clause, parameters) \
    104         forall_clause void copy(exception_name parameters * this, \
    105                         exception_name parameters * that) { \
    106                 *this = *that; \
    107         }
    108 
    109 #define _EHM_DEFINE_COPY(exception_name, arguments) \
    110         void copy(exception_name arguments * this, exception_name arguments * that) { \
    111                 *this = *that; \
    112         }
    113 
    114 // Create a (possibly polymorphic) msg function
    115 #define _EHM_DEFINE_FORALL_MSG(exception_name, forall_clause, parameters) \
    116         forall_clause const char * msg(exception_name parameters * this) { \
    117                 return #exception_name #parameters; \
    118         }
    119 
    120 #define _EHM_DEFINE_MSG(exception_name, arguments) \
    121         const char * msg(exception_name arguments * this) { \
    122                 return #exception_name #arguments; \
    123         }
    124 
    125 // Produces the C compatable name of the virtual table type for a virtual type.
    126 #define _EHM_VTABLE_TYPE(type_name) struct _GLUE2(type_name,_vtable)
    127 
    128 // Create the vtable type for exception name.
    129 #define _EHM_VIRTUAL_TABLE_STRUCT(exception_name, forall_clause, parameters) \
    130         forall_clause struct exception_name; \
    131         forall_clause _EHM_VTABLE_TYPE(exception_name) { \
    132                 _EHM_TYPE_ID_TYPE(exception_name) parameters const * __cfavir_typeid; \
    133                 size_t size; \
    134                 void (*copy)(exception_name parameters * this, exception_name parameters * other); \
    135                 void (*^?{})(exception_name parameters & this); \
    136                 const char * (*msg)(exception_name parameters * this); \
    137         }
    138 
    139 // Define the function required to satify the trait for exceptions.
    140 #define _EHM_TRAIT_FUNCTION(exception_name, forall_clause, parameters) \
    141         forall_clause inline void mark_exception( \
    142                 exception_name parameters const &, \
    143                 _EHM_VTABLE_TYPE(exception_name) parameters const &) {} \
    144 
    145 #define __EHM_TRAIT_FUNCTION(exception_name, forall_clause, parameters) \
    146         forall_clause inline _EHM_VTABLE_TYPE(exception_name) parameters const & \
    147                         get_exception_vtable(exception_name parameters const & this) { \
    148                 /* This comes before the structure definition, but we know the offset. */ \
    149                 /* return (_EHM_VTABLE_TYPE(exception_name) parameters const &)this; */ \
    150                 assert(false); \
    151         }
    152 
    153 // Generates a new type-id structure. This is used to mangle the name of the
    154 // type-id instance so it also includes polymorphic information. Must be the
    155 // direct decendent of exception_t.
    156 // The second field is used to recover type information about the exception.
    157 #define _EHM_TYPE_ID_STRUCT(exception_name, forall_clause) \
    158         forall_clause _EHM_TYPE_ID_TYPE(exception_name) { \
    159                 __cfavir_type_info const * parent; \
    160         }
    161 
    162 // Generate a new type-id value.
    163 #define _EHM_TYPE_ID_VALUE(exception_name, arguments) \
    164         __attribute__((cfa_linkonce)) \
    165         _EHM_TYPE_ID_TYPE(exception_name) arguments const \
    166                         _EHM_TYPE_ID_NAME(exception_name) = { \
    167                 &__cfatid_exception_t, \
    168         }
    169 
    170 // _EHM_TYPE_ID_STRUCT and _EHM_TYPE_ID_VALUE are the two that would need to
    171 // be updated to extend the hierarchy if we are still using macros when that
    172 // is added.
    173 
    174 // Produce the C compatable name of the type-id type for an exception type.
    175 #define _EHM_TYPE_ID_TYPE(exception_name) \
    176         struct _GLUE2(__cfatid_struct_, exception_name)
    177 
    178 // Produce the name of the instance of the type-id for an exception type.
    179 #define _EHM_TYPE_ID_NAME(exception_name) _GLUE2(__cfatid_,exception_name)
    180 
    18133#define _IS_EXCEPTION(kind, exception_name, parameters, ...) \
    182         kind(exception_name parameters, _EHM_VTABLE_TYPE(exception_name) parameters)
    183 
    184 // Internal helper macros:
    185 #define _CLOSE(...) __VA_ARGS__ }
    186 #define _GLUE2(left, right) left##right
     34        kind(exception_name parameters, vtable(exception_name parameters))
  • src/CodeGen/GenType.cc

    r5024df4 rc715e5f  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed May  1 15:24:00 2019
    13 // Update Count     : 23
     12// Last Modified On : Fri May 20 11:18:00 2022
     13// Update Count     : 24
    1414//
    1515#include "GenType.h"
     
    5050                void postvisit( TraitInstType * inst );
    5151                void postvisit( TypeofType * typeof );
     52                void postvisit( VTableType * vtable );
    5253                void postvisit( QualifiedType * qualType );
    5354
     
    259260                        if ( options.genC ) {
    260261                                typeString = "enum " + typeString;
    261                         } 
    262                 } 
     262                        }
     263                }
    263264                handleQualifiers( enumInst );
    264265        }
    265266
    266267        void GenType::postvisit( TypeInstType * typeInst ) {
     268                assertf( ! options.genC, "Type instance types should not reach code generation." );
    267269                typeString = typeInst->name + " " + typeString;
    268270                handleQualifiers( typeInst );
     
    320322        }
    321323
     324        void GenType::postvisit( VTableType * vtable ) {
     325                assertf( ! options.genC, "Virtual table types should not reach code generation." );
     326                std::ostringstream os;
     327                os << "vtable(" << genType( vtable->base, "", options ) << ") " << typeString;
     328                typeString = os.str();
     329                handleQualifiers( vtable );
     330        }
     331
    322332        void GenType::postvisit( QualifiedType * qualType ) {
    323333                assertf( ! options.genC, "Qualified types should not reach code generation." );
  • src/ControlStruct/ExceptDecl.cc

    r5024df4 rc715e5f  
    99// Author           : Henry Xue
    1010// Created On       : Tue Jul 20 04:10:50 2021
    11 // Last Modified By : Henry Xue
    12 // Last Modified On : Tue Aug 03 10:42:26 2021
    13 // Update Count     : 4
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed May 25 16:43:00 2022
     13// Update Count     : 5
    1414//
    1515
     
    3939}
    4040
    41 TypeInstType * makeExceptInstType(
    42         const std::string & exceptionName,
    43         const std::list< Expression *> & parameters
    44 ) {
    45         TypeInstType * exceptInstType = new TypeInstType(
     41StructInstType * makeExceptInstType(
     42        const std::string & exceptionName,
     43        const std::list< Expression *> & parameters
     44) {
     45        StructInstType * exceptInstType = new StructInstType(
    4646                noQualifiers,
    47                 exceptionName,
    48                 false
     47                exceptionName
    4948        );
    5049        cloneAll( parameters, exceptInstType->parameters );
     
    151150                nullptr,
    152151                new PointerType( noQualifiers,
    153                         new TypeInstType( Type::Const, "__cfavir_type_info", false ) ),
     152                        new StructInstType( Type::Const, "__cfavir_type_info" ) ),
    154153                nullptr
    155154        ) );
     
    257256        const std::string & exceptionName,
    258257        const std::list< TypeDecl *> & forallClause,
    259         const std::list< Expression *> & parameters, 
     258        const std::list< Expression *> & parameters,
    260259        const std::list< Declaration *> & members
    261260) {
     
    302301ObjectDecl * ehmExternVtable(
    303302        const std::string & exceptionName,
    304         const std::list< Expression *> & parameters, 
     303        const std::list< Expression *> & parameters,
    305304        const std::string & tableName
    306305) {
     
    457456}
    458457
     458class VTableCore : public WithDeclsToAdd {
     459public:
     460        // Remove any remaining vtable type nodes in the tree.
     461        Type * postmutate( VTableType * vtableType );
     462};
     463
     464Type * VTableCore::postmutate( VTableType * vtableType ) {
     465        auto inst = strict_dynamic_cast<ReferenceToType *>( vtableType->base );
     466
     467        std::string vtableName = Virtual::vtableTypeName( inst->name );
     468        StructInstType * newType = new StructInstType( noQualifiers, vtableName );
     469        cloneAll( inst->parameters, newType->parameters );
     470
     471        delete vtableType;
     472        return newType;
     473}
     474
    459475void translateExcept( std::list< Declaration *> & translationUnit ) {
    460476        PassVisitor<ExceptDeclCore> translator;
    461477        mutateAll( translationUnit, translator );
    462 }
    463 
    464 }
     478        PassVisitor<VTableCore> typeTranslator;
     479        mutateAll( translationUnit, typeTranslator );
     480}
     481
     482}
  • tests/.expect/quasiKeyword.txt

    r5024df4 rc715e5f  
    1 quasiKeyword.cfa:54:25: warning: Compiled
     1quasiKeyword.cfa:52:25: warning: Compiled
  • tests/exceptions/defaults.cfa

    r5024df4 rc715e5f  
    22
    33#include <string.h>
    4 #include <exception.hfa>
    54
    65exception log_message {
     
    87};
    98
    10 _EHM_DEFINE_COPY(log_message, )
     9void copy(log_message * this, log_message * that) {
     10        *this = *that;
     11}
     12
    1113const char * msg(log_message * this) {
    1214        return this->msg;
    1315}
    14 _EHM_VIRTUAL_TABLE(log_message, , log_vt);
     16
     17const struct log_message_vtable log_vt @= {
     18        .__cfavir_typeid : &__cfatid_log_message,
     19        .size : sizeof(struct log_message),
     20        .copy : copy,
     21        .^?{} : ^?{},
     22        .msg : msg,
     23};
    1524
    1625// Logging messages don't have to be handled.
  • tests/linking/exception-nothreads.cfa

    r5024df4 rc715e5f  
    1515
    1616#include <stdlib.hfa>
    17 #include <exception.hfa>
    1817
    19 EHM_EXCEPTION(ping)();
    20 EHM_VIRTUAL_TABLE(ping, ping_vt);
     18exception ping {};
     19vtable(ping) ping_vt;
    2120
    2221int main(void) {
  • tests/linking/exception-withthreads.cfa

    r5024df4 rc715e5f  
    1515
    1616#include <stdlib.hfa>
    17 #include <exception.hfa>
    1817#include "../exceptions/with-threads.hfa"
    1918
    20 EHM_EXCEPTION(ping)();
    21 EHM_VIRTUAL_TABLE(ping, ping_vt);
     19exception ping {};
     20vtable(ping) ping_vt;
    2221
    2322int main(void) {
  • tests/quasiKeyword.cfa

    r5024df4 rc715e5f  
    44// quasiKeyword.cfa -- test that quasi-keywords can be used for variable and functions names, as well as keywords in
    55//                                         control structures.
    6 // 
     6//
    77// Author           : Peter A. Buhr
    88// Created On       : Wed Feb 17 10:33:49 2021
     
    1010// Last Modified On : Sat Jun  5 10:07:59 2021
    1111// Update Count     : 8
    12 // 
     12//
    1313
    14 #include <exception.hfa>
    15 
    16 EHM_EXCEPTION( E )();
     14exception E {};
    1715
    1816void catch( int i ) {}
     
    4947                } fixup ( E * ) {
    5048                } finally {
    51                 } 
     49                }
    5250        else catch = 3;
    5351
Note: See TracChangeset for help on using the changeset viewer.