Changeset f1a4ccb


Ignore:
Timestamp:
Aug 2, 2017, 4:07:51 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
4e9c7c1, 63be52c
Parents:
e59c088 (diff), 948b0c8 (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:

Cleaned-up cassert to match more closely to the c++ one

Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • doc/generic_types/generic_types.tex

    re59c088 rf1a4ccb  
    4949
    5050% Useful macros
    51 \newcommand{\CFA}{C\raisebox{\depth}{\rotatebox{180}{\textsf{A}}}\hspace{-1pt}\xspace} % Cforall symbolic name
    52 %\newcommand{\CFA}{C$\mathbf\forall$\xspace} % Cforall symbolic name
    53 \newcommand{\CC}{\rm C\kern-.1em\hbox{+\kern-.25em+}\xspace} % C++ symbolic name
    54 \newcommand{\CCeleven}{\rm C\kern-.1em\hbox{+\kern-.25em+}11\xspace} % C++11 symbolic name
    55 \newcommand{\CCfourteen}{\rm C\kern-.1em\hbox{+\kern-.25em+}14\xspace} % C++14 symbolic name
    56 \newcommand{\CCseventeen}{\rm C\kern-.1em\hbox{+\kern-.25em+}17\xspace} % C++17 symbolic name
    57 \newcommand{\CCtwenty}{\rm C\kern-.1em\hbox{+\kern-.25em+}20\xspace} % C++20 symbolic name
     51\newcommand{\CFAIcon}{\textsf{C}\raisebox{\depth}{\rotatebox{180}{\textsf{A}}}\xspace} % Cforall symbolic name
     52\newcommand{\CFA}{\protect\CFAIcon} % safe for section/caption
     53\newcommand{\CC}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}\xspace} % C++ symbolic name
     54\newcommand{\CCeleven}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}11\xspace} % C++11 symbolic name
     55\newcommand{\CCfourteen}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}14\xspace} % C++14 symbolic name
     56\newcommand{\CCseventeen}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}17\xspace} % C++17 symbolic name
     57\newcommand{\CCtwenty}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}20\xspace} % C++20 symbolic name
    5858\newcommand{\CCV}{\rm C\kern-.1em\hbox{+\kern-.25em+}obj\xspace} % C++ virtual symbolic name
    5959\newcommand{\Csharp}{C\raisebox{-0.7ex}{\Large$^\sharp$}\xspace} % C# symbolic name
     
    443443This function could acquire the layout for @set(T)@ by calling its layout function with the layout of @T@ implicitly passed into the function.
    444444
    445 Whether a type is concrete, dtype-static, or dynamic is decided solely on the type parameters and @forall@ clause on a declaration.
    446 This design allows opaque forward declarations of generic types, \eg @forall(otype T) struct Box@ -- like in C, all uses of @Box(T)@ can be separately compiled, and callers from other translation units know the proper calling conventions to use.
    447 If the definition of a structure type is included in deciding whether a generic type is dynamic or concrete, some further types may be recognized as dtype-static (\eg @forall(otype T) struct unique_ptr { T * p }@ does not depend on @T@ for its layout, but the existence of an @otype@ parameter means that it \emph{could}.), but preserving separate compilation (and the associated C compatibility) in the existing design is judged to be an appropriate trade-off.
     445Whether a type is concrete, dtype-static, or dynamic is decided solely on the @forall@'s type parameters.
     446This design allows opaque forward declarations of generic types, \eg @forall(otype T)@ @struct Box@ -- like in C, all uses of @Box(T)@ can be separately compiled, and callers from other translation units know the proper calling conventions to use.
     447If the definition of a structure type is included in deciding whether a generic type is dynamic or concrete, some further types may be recognized as dtype-static (\eg @forall(otype T)@ @struct unique_ptr { T * p }@ does not depend on @T@ for its layout, but the existence of an @otype@ parameter means that it \emph{could}.), but preserving separate compilation (and the associated C compatibility) in the existing design is judged to be an appropriate trade-off.
    448448
    449449
     
    855855}
    856856\end{lstlisting}
     857\begin{sloppypar}
    857858Tuple expressions are then simply converted directly into compound literals, \eg @[5, 'x', 1.24]@ becomes @(_tuple3(int, char, double)){ 5, 'x', 1.24 }@.
     859\end{sloppypar}
    858860
    859861\begin{comment}
  • src/ControlStruct/ExceptTranslate.cc

    re59c088 rf1a4ccb  
    1010// Created On       : Wed Jun 14 16:49:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Jul 28 15:34:00 2017
    13 // Update Count     : 6
     12// Last Modified On : Wed Aug 02 12:09:00 2017
     13// Update Count     : 7
    1414//
    1515
     
    2525namespace ControlStruct {
    2626
    27         // void (*function)();
    28         static FunctionType try_func_t(noQualifiers, false);
    29         // void (*function)(int, exception);
    30         static FunctionType catch_func_t(noQualifiers, false);
    31         // int (*function)(exception);
    32         static FunctionType match_func_t(noQualifiers, false);
    33         // bool (*function)(exception);
    34         static FunctionType handle_func_t(noQualifiers, false);
    35         // void (*function)(__attribute__((unused)) void *);
    36         static FunctionType finally_func_t(noQualifiers, false);
    37 
    38         static void init_func_types() {
    39                 static bool init_complete = false;
    40                 if (init_complete) {
    41                         return;
    42                 }
     27        // Buricratic Helpers (Not having to do with the paritular operation.)
     28
     29        typedef std::list<CatchStmt*> CatchList;
     30
     31        void split( CatchList& allHandlers, CatchList& terHandlers,
     32                                CatchList& resHandlers ) {
     33                while ( !allHandlers.empty() ) {
     34                        CatchStmt * stmt = allHandlers.front();
     35                        allHandlers.pop_front();
     36                        if (CatchStmt::Terminate == stmt->get_kind()) {
     37                                terHandlers.push_back(stmt);
     38                        } else {
     39                                resHandlers.push_back(stmt);
     40                        }
     41                }
     42        }
     43
     44        void appendDeclStmt( CompoundStmt * block, Declaration * item ) {
     45                block->push_back(new DeclStmt(noLabels, item));
     46        }
     47
     48        Expression * nameOf( DeclarationWithType * decl ) {
     49                return new VariableExpr( decl );
     50        }
     51
     52        class ExceptionMutatorCore : public WithGuards {
     53                enum Context { NoHandler, TerHandler, ResHandler };
     54
     55                // Also need to handle goto, break & continue.
     56                // They need to be cut off in a ResHandler, until we enter another
     57                // loop, switch or the goto stays within the function.
     58
     59                Context cur_context;
     60
     61                // The current (innermost) termination handler exception declaration.
     62                ObjectDecl * handler_except_decl;
     63
     64                // The built in types used in translation.
     65                StructDecl * except_decl;
     66                StructDecl * node_decl;
     67                StructDecl * hook_decl;
     68
     69                // The many helper functions for code/syntree generation.
     70                Statement * create_given_throw(
     71                        const char * throwFunc, ThrowStmt * throwStmt );
     72                Statement * create_terminate_throw( ThrowStmt * throwStmt );
     73                Statement * create_terminate_rethrow( ThrowStmt * throwStmt );
     74                Statement * create_resume_throw( ThrowStmt * throwStmt );
     75                Statement * create_resume_rethrow( ThrowStmt * throwStmt );
     76                CompoundStmt * take_try_block( TryStmt * tryStmt );
     77                FunctionDecl * create_try_wrapper( CompoundStmt * body );
     78                FunctionDecl * create_terminate_catch( CatchList &handlers );
     79                CompoundStmt * create_single_matcher(
     80                        DeclarationWithType * except_obj, CatchStmt * modded_handler );
     81                FunctionDecl * create_terminate_match( CatchList &handlers );
     82                CompoundStmt * create_terminate_caller( FunctionDecl * try_wrapper,
     83                        FunctionDecl * terminate_catch, FunctionDecl * terminate_match );
     84                FunctionDecl * create_resume_handler( CatchList &handlers );
     85                CompoundStmt * create_resume_wrapper(
     86                        Statement * wraps, FunctionDecl * resume_handler );
     87                FunctionDecl * create_finally_wrapper( TryStmt * tryStmt );
     88                ObjectDecl * create_finally_hook( FunctionDecl * finally_wrapper );
     89
     90                // Types used in translation, make sure to use clone.
     91                // void (*function)();
     92                FunctionType try_func_t;
     93                // void (*function)(int, exception);
     94                FunctionType catch_func_t;
     95                // int (*function)(exception);
     96                FunctionType match_func_t;
     97                // bool (*function)(exception);
     98                FunctionType handle_func_t;
     99                // void (*function)(__attribute__((unused)) void *);
     100                FunctionType finally_func_t;
     101
     102                StructInstType * create_except_type() {
     103                        assert( except_decl );
     104                        return new StructInstType( noQualifiers, except_decl );
     105                }
     106                void init_func_types();
     107
     108        public:
     109                ExceptionMutatorCore() :
     110                        cur_context( NoHandler ),
     111                        handler_except_decl( nullptr ),
     112                        except_decl( nullptr ), node_decl( nullptr ), hook_decl( nullptr ),
     113                        try_func_t( noQualifiers, false ),
     114                        catch_func_t( noQualifiers, false ),
     115                        match_func_t( noQualifiers, false ),
     116                        handle_func_t( noQualifiers, false ),
     117                        finally_func_t( noQualifiers, false )
     118                {
     119                        init_func_types();
     120                }
     121
     122                void premutate( CatchStmt *catchStmt );
     123                void premutate( StructDecl *structDecl );
     124                Statement * postmutate( ThrowStmt *throwStmt );
     125                Statement * postmutate( TryStmt *tryStmt );
     126        };
     127
     128        void ExceptionMutatorCore::init_func_types() {
    43129                ObjectDecl index_obj(
    44130                        "__handler_index",
     
    56142                        new PointerType(
    57143                                noQualifiers,
     144                                //new StructInstType( noQualifiers, except_decl )
    58145                                new BasicType( noQualifiers, BasicType::SignedInt )
    59146                                ),
     
    65152                        LinkageSpec::Cforall,
    66153                        /*bitfieldWidth*/ NULL,
    67                         new BasicType(noQualifiers, BasicType::Bool),
     154                        new BasicType( noQualifiers, BasicType::Bool ),
    68155                        /*init*/ NULL
    69156                        );
     
    78165                                        noQualifiers
    79166                                        ),
    80                                 std::list<Attribute *>{new Attribute("unused")}
     167                                std::list<Attribute *>{ new Attribute( "unused" ) }
    81168                                ),
    82169                        NULL
     
    90177                handle_func_t.get_parameters().push_back( exception_obj.clone() );
    91178                finally_func_t.get_parameters().push_back( voidptr_obj.clone() );
    92 
    93                 init_complete = true;
    94         }
    95 
    96         // Buricratic Helpers (Not having to do with the paritular operation.)
    97 
    98         typedef std::list<CatchStmt*> CatchList;
    99 
    100         void split( CatchList& allHandlers, CatchList& terHandlers,
    101                                 CatchList& resHandlers ) {
    102                 while ( !allHandlers.empty() ) {
    103                         CatchStmt * stmt = allHandlers.front();
    104                         allHandlers.pop_front();
    105                         if (CatchStmt::Terminate == stmt->get_kind()) {
    106                                 terHandlers.push_back(stmt);
    107                         } else {
    108                                 resHandlers.push_back(stmt);
    109                         }
    110                 }
    111         }
    112 
    113         void appendDeclStmt( CompoundStmt * block, Declaration * item ) {
    114                 block->push_back(new DeclStmt(noLabels, item));
    115         }
    116 
    117         Expression * nameOf( DeclarationWithType * decl ) {
    118                 return new VariableExpr( decl );
    119179        }
    120180
    121181        // ThrowStmt Mutation Helpers
    122182
    123         Statement * create_given_throw(
     183        Statement * ExceptionMutatorCore::create_given_throw(
    124184                        const char * throwFunc, ThrowStmt * throwStmt ) {
    125185                // There is an extra copy here we might be able to remove with
     
    144204        }
    145205
    146         Statement * create_terminate_throw( ThrowStmt *throwStmt ) {
     206        Statement * ExceptionMutatorCore::create_terminate_throw(
     207                        ThrowStmt *throwStmt ) {
    147208                // { int NAME = EXPR; __throw_terminate( &NAME ); }
    148209                return create_given_throw( "__cfaehm__throw_terminate", throwStmt );
    149210        }
    150211
    151         Statement * create_terminate_rethrow( ThrowStmt *throwStmt,
    152                         ObjectDecl *handler_except_decl ) {
     212        Statement * ExceptionMutatorCore::create_terminate_rethrow(
     213                        ThrowStmt *throwStmt ) {
    153214                // { `handler_except_decl` = NULL; __rethrow_terminate(); }
    154215                assert( nullptr == throwStmt->get_expr() );
     
    173234        }
    174235
    175         Statement * create_resume_throw( ThrowStmt *throwStmt ) {
     236        Statement * ExceptionMutatorCore::create_resume_throw(
     237                        ThrowStmt *throwStmt ) {
    176238                // __throw_resume( EXPR );
    177239                return create_given_throw( "__cfaehm__throw_resume", throwStmt );
    178240        }
    179241
    180         Statement * create_resume_rethrow( ThrowStmt *throwStmt ) {
     242        Statement * ExceptionMutatorCore::create_resume_rethrow(
     243                        ThrowStmt *throwStmt ) {
    181244                // return false;
    182245                Statement * result = new ReturnStmt(
     
    190253        // TryStmt Mutation Helpers
    191254
    192         CompoundStmt * take_try_block( TryStmt *tryStmt ) {
     255        // XXX: Leave out?
     256        CompoundStmt * ExceptionMutatorCore::take_try_block( TryStmt *tryStmt ) {
    193257                CompoundStmt * block = tryStmt->get_block();
    194258                tryStmt->set_block( nullptr );
    195259                return block;
    196260        }
    197         FunctionDecl * create_try_wrapper( CompoundStmt *body ) {
     261
     262        FunctionDecl * ExceptionMutatorCore::create_try_wrapper(
     263                        CompoundStmt *body ) {
    198264
    199265                return new FunctionDecl( "try", Type::StorageClasses(),
     
    201267        }
    202268
    203         FunctionDecl * create_terminate_catch( CatchList &handlers ) {
     269        FunctionDecl * ExceptionMutatorCore::create_terminate_catch(
     270                        CatchList &handlers ) {
    204271                std::list<CaseStmt *> handler_wrappers;
    205272
     
    297364        // Create a single check from a moddified handler.
    298365        // except_obj is referenced, modded_handler will be freed.
    299         CompoundStmt *create_single_matcher(
     366        CompoundStmt * ExceptionMutatorCore::create_single_matcher(
    300367                        DeclarationWithType * except_obj, CatchStmt * modded_handler ) {
    301368                CompoundStmt * block = new CompoundStmt( noLabels );
     
    362429        }
    363430
    364         FunctionDecl * create_terminate_match( CatchList &handlers ) {
     431        FunctionDecl * ExceptionMutatorCore::create_terminate_match(
     432                        CatchList &handlers ) {
    365433                // int match(exception * except) {
    366434                //     HANDLER WRAPPERS { return `index`; }
     
    398466        }
    399467
    400         CompoundStmt * create_terminate_caller(
     468        CompoundStmt * ExceptionMutatorCore::create_terminate_caller(
    401469                        FunctionDecl * try_wrapper,
    402470                        FunctionDecl * terminate_catch,
    403                         FunctionDecl * terminate_match) {
     471                        FunctionDecl * terminate_match ) {
    404472                // { __cfaehm__try_terminate(`try`, `catch`, `match`); }
    405473
     
    416484        }
    417485
    418         FunctionDecl * create_resume_handler( CatchList &handlers ) {
     486        FunctionDecl * ExceptionMutatorCore::create_resume_handler(
     487                        CatchList &handlers ) {
    419488                // bool handle(exception * except) {
    420489                //     HANDLER WRAPPERS { `hander->body`; return true; }
     
    452521        }
    453522
    454         CompoundStmt * create_resume_wrapper(
    455                         StructDecl * node_decl,
     523        CompoundStmt * ExceptionMutatorCore::create_resume_wrapper(
    456524                        Statement * wraps,
    457525                        FunctionDecl * resume_handler ) {
     
    497565        }
    498566
    499         FunctionDecl * create_finally_wrapper( TryStmt * tryStmt ) {
     567        FunctionDecl * ExceptionMutatorCore::create_finally_wrapper(
     568                        TryStmt * tryStmt ) {
    500569                // void finally() { <finally code> }
    501570                FinallyStmt * finally = tryStmt->get_finally();
     
    509578        }
    510579
    511         ObjectDecl * create_finally_hook(
    512                         StructDecl * hook_decl, FunctionDecl * finally_wrapper ) {
     580        ObjectDecl * ExceptionMutatorCore::create_finally_hook(
     581                        FunctionDecl * finally_wrapper ) {
    513582                // struct __cfaehm__cleanup_hook __finally_hook
    514583                //      __attribute__((cleanup( finally_wrapper )));
     
    536605        }
    537606
    538 
    539         class ExceptionMutatorCore : public WithGuards {
    540                 enum Context { NoHandler, TerHandler, ResHandler };
    541 
    542                 // Also need to handle goto, break & continue.
    543                 // They need to be cut off in a ResHandler, until we enter another
    544                 // loop, switch or the goto stays within the function.
    545 
    546                 Context cur_context;
    547 
    548                 // The current (innermost) termination handler exception declaration.
    549                 ObjectDecl * handler_except_decl;
    550 
    551                 // We might not need this, but a unique base for each try block's
    552                 // generated functions might be nice.
    553                 //std::string curFunctionName;
    554                 //unsigned int try_count = 0;
    555 
    556                 StructDecl *node_decl;
    557                 StructDecl *hook_decl;
    558 
    559         public:
    560                 ExceptionMutatorCore() :
    561                         cur_context(NoHandler),
    562                         handler_except_decl( nullptr ),
    563                         node_decl( nullptr ), hook_decl( nullptr )
    564                 {}
    565 
    566                 void premutate( CatchStmt *catchStmt );
    567                 void premutate( StructDecl *structDecl );
    568                 Statement * postmutate( ThrowStmt *throwStmt );
    569                 Statement * postmutate( TryStmt *tryStmt );
    570         };
    571 
     607        // Visiting/Mutating Functions
    572608        void ExceptionMutatorCore::premutate( CatchStmt *catchStmt ) {
    573609                // Currently, we make up the declaration, as there isn't one for
    574610                // integers.
     611                assert( ! catchStmt->get_decl() );
    575612                ObjectDecl * tmp = new ObjectDecl(
    576613                        "_hidden_local",
     
    629666                                return create_terminate_throw( throwStmt );
    630667                        } else if ( TerHandler == cur_context ) {
    631                                 return create_terminate_rethrow(
    632                                         throwStmt, handler_except_decl );
     668                                return create_terminate_rethrow( throwStmt );
    633669                        } else {
    634670                                assertf(false, "Invalid throw in %s at %i\n",
     
    666702                        appendDeclStmt( block, finally_block );
    667703                        // Create and add the finally cleanup hook.
    668                         appendDeclStmt( block,
    669                                 create_finally_hook( hook_decl, finally_block ) );
     704                        appendDeclStmt( block, create_finally_hook( finally_block ) );
    670705                }
    671706
     
    681716                        appendDeclStmt( block, resume_handler );
    682717                        // Prepare hooks
    683                         inner = create_resume_wrapper( node_decl, inner, resume_handler );
     718                        inner = create_resume_wrapper( inner, resume_handler );
    684719                }
    685720
     
    706741
    707742        void translateEHM( std::list< Declaration *> & translationUnit ) {
    708                 init_func_types();
    709 
    710743                PassVisitor<ExceptionMutatorCore> translator;
    711744                mutateAll( translationUnit, translator );
  • src/include/cassert

    re59c088 rf1a4ccb  
    1010// Created On       : Thu Aug 18 13:19:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 18 13:25:55 2016
    13 // Update Count     : 4
     12// Last Modified On : Tue Aug  1 11:56:01 2017
     13// Update Count     : 16
    1414//
    1515
     
    3939
    4040template<typename T, typename U>
    41 static inline T safe_dynamic_cast(const U& src) {
     41static inline T safe_dynamic_cast( const U & src ) {
    4242        T ret = dynamic_cast<T>(src);
    4343        assert(ret);
  • src/libcfa/stdhdr/assert.h

    re59c088 rf1a4ccb  
    1010// Created On       : Mon Jul  4 23:25:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jul 31 14:52:43 2017
    13 // Update Count     : 12
     12// Last Modified On : Mon Jul 31 23:09:32 2017
     13// Update Count     : 13
    1414//
    1515
     
    2525        #define __STRINGIFY__(str) #str
    2626        #define __VSTRINGIFY__(str) __STRINGIFY__(str)
    27         #define assertf(expr, fmt, ...) ((expr) ? ((void)0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ ))
    28         void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) __attribute__((noreturn, format(printf, 5, 6)));
     27        #define assertf( expr, fmt, ... ) ((expr) ? ((void)0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ ))
     28
     29        void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) __attribute__((noreturn, format( printf, 5, 6) ));
    2930#endif
    3031
Note: See TracChangeset for help on using the changeset viewer.