Changeset cd7ef0b for src


Ignore:
Timestamp:
Aug 10, 2017, 3:39:11 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
38d70ab
Parents:
275f4b4 (diff), e1780a2 (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
4 added
46 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/ExceptTranslate.cc

    r275f4b4 rcd7ef0b  
    1010// Created On       : Wed Jun 14 16:49:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 18 10:09:00 2017
    13 // Update Count     : 4
     12// Last Modified On : Tus Aug  8 16:54:00 2017
     13// Update Count     : 7
    1414//
    1515
     
    2121#include "SynTree/Type.h"
    2222#include "SynTree/Attribute.h"
     23#include "SynTree/VarExprReplacer.h"
    2324
    2425namespace ControlStruct {
    2526
    26         // This (large) section could probably be moved out of the class
    27         // and be static helpers instead.
    28 
    29         // Type(Qualifiers &, false, std::list<Attribute *> &)
    30 
    31         // void (*function)();
    32         static FunctionType try_func_t(Type::Qualifiers(), false);
    33         // void (*function)(int, exception);
    34         static FunctionType catch_func_t(Type::Qualifiers(), false);
    35         // int (*function)(exception);
    36         static FunctionType match_func_t(Type::Qualifiers(), false);
    37         // bool (*function)(exception);
    38         static FunctionType handle_func_t(Type::Qualifiers(), false);
    39         // void (*function)(__attribute__((unused)) void *);
    40         static FunctionType finally_func_t(Type::Qualifiers(), false);
    41 
    42         static void init_func_types() {
    43                 static bool init_complete = false;
    44                 if (init_complete) {
    45                         return;
    46                 }
     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
     120                void premutate( CatchStmt *catchStmt );
     121                void premutate( StructDecl *structDecl );
     122                Statement * postmutate( ThrowStmt *throwStmt );
     123                Statement * postmutate( TryStmt *tryStmt );
     124        };
     125
     126        void ExceptionMutatorCore::init_func_types() {
     127                assert( except_decl );
     128
    47129                ObjectDecl index_obj(
    48130                        "__handler_index",
     
    60142                        new PointerType(
    61143                                noQualifiers,
    62                                 new BasicType( noQualifiers, BasicType::SignedInt )
     144                                new StructInstType( noQualifiers, except_decl )
    63145                                ),
    64146                        /*init*/ NULL
     
    69151                        LinkageSpec::Cforall,
    70152                        /*bitfieldWidth*/ NULL,
    71                         new BasicType(noQualifiers, BasicType::Bool),
     153                        new BasicType( noQualifiers, BasicType::Bool ),
    72154                        /*init*/ NULL
    73155                        );
     
    82164                                        noQualifiers
    83165                                        ),
    84                                 std::list<Attribute *>{new Attribute("unused")}
     166                                std::list<Attribute *>{ new Attribute( "unused" ) }
    85167                                ),
    86168                        NULL
     
    94176                handle_func_t.get_parameters().push_back( exception_obj.clone() );
    95177                finally_func_t.get_parameters().push_back( voidptr_obj.clone() );
    96 
    97                 init_complete = true;
    98         }
    99 
    100         // Buricratic Helpers (Not having to do with the paritular operation.)
    101 
    102         typedef std::list<CatchStmt*> CatchList;
    103 
    104         void split( CatchList& allHandlers, CatchList& terHandlers,
    105                                 CatchList& resHandlers ) {
    106                 while ( !allHandlers.empty() ) {
    107                         CatchStmt * stmt = allHandlers.front();
    108                         allHandlers.pop_front();
    109                         if (CatchStmt::Terminate == stmt->get_kind()) {
    110                                 terHandlers.push_back(stmt);
    111                         } else {
    112                                 resHandlers.push_back(stmt);
    113                         }
    114                 }
    115         }
    116 
    117         template<typename T>
    118         void free_all( std::list<T *> &list ) {
    119                 typename std::list<T *>::iterator it;
    120                 for ( it = list.begin() ; it != list.end() ; ++it ) {
    121                         delete *it;
    122                 }
    123                 list.clear();
    124         }
    125 
    126         void appendDeclStmt( CompoundStmt * block, Declaration * item ) {
    127                 block->push_back(new DeclStmt(noLabels, item));
    128         }
    129 
    130         Expression * nameOf( DeclarationWithType * decl ) {
    131                 return new VariableExpr( decl );
    132178        }
    133179
    134180        // ThrowStmt Mutation Helpers
    135181
    136         Statement * create_given_throw(
     182        Statement * ExceptionMutatorCore::create_given_throw(
    137183                        const char * throwFunc, ThrowStmt * throwStmt ) {
    138                 // { int NAME = EXPR; throwFunc( &NAME ); }
    139                 CompoundStmt * result = new CompoundStmt( noLabels );
    140                 ObjectDecl * local = new ObjectDecl(
    141                         "__local_exception_copy",
    142                         Type::StorageClasses(),
    143                         LinkageSpec::Cforall,
    144                         NULL,
    145                         new BasicType( noQualifiers, BasicType::SignedInt ),
    146                         new SingleInit( throwStmt->get_expr() )
    147                         );
    148                 appendDeclStmt( result, local );
     184                // `throwFunc`( `throwStmt->get_name` );
    149185                UntypedExpr * call = new UntypedExpr( new NameExpr( throwFunc ) );
    150                 call->get_args().push_back( new AddressExpr( nameOf( local ) ) );
    151                 result->push_back( new ExprStmt( throwStmt->get_labels(), call ) );
     186                call->get_args().push_back( throwStmt->get_expr() );
    152187                throwStmt->set_expr( nullptr );
    153188                delete throwStmt;
    154                 return result;
    155         }
    156 
    157         Statement * create_terminate_throw( ThrowStmt *throwStmt ) {
    158                 // { int NAME = EXPR; __throw_terminate( &NAME ); }
     189                return new ExprStmt( noLabels, call );
     190        }
     191
     192        Statement * ExceptionMutatorCore::create_terminate_throw(
     193                        ThrowStmt *throwStmt ) {
     194                // __throw_terminate( `throwStmt->get_name()` ); }
    159195                return create_given_throw( "__cfaehm__throw_terminate", throwStmt );
    160196        }
    161         Statement * create_terminate_rethrow( ThrowStmt *throwStmt ) {
    162                 // __rethrow_terminate();
     197
     198        Statement * ExceptionMutatorCore::create_terminate_rethrow(
     199                        ThrowStmt *throwStmt ) {
     200                // { `handler_except_decl` = NULL; __rethrow_terminate(); }
    163201                assert( nullptr == throwStmt->get_expr() );
    164                 Statement * result = new ExprStmt(
    165                         throwStmt->get_labels(),
     202                assert( handler_except_decl );
     203
     204                CompoundStmt * result = new CompoundStmt( throwStmt->get_labels() );
     205                result->push_back( new ExprStmt( noLabels, UntypedExpr::createAssign(
     206                        nameOf( handler_except_decl ),
     207                        new ConstantExpr( Constant::null(
     208                                new PointerType(
     209                                        noQualifiers,
     210                                        handler_except_decl->get_type()->clone()
     211                                        )
     212                                ) )
     213                        ) ) );
     214                result->push_back( new ExprStmt(
     215                        noLabels,
    166216                        new UntypedExpr( new NameExpr( "__cfaehm__rethrow_terminate" ) )
    167                         );
     217                        ) );
    168218                delete throwStmt;
    169219                return result;
    170220        }
    171         Statement * create_resume_throw( ThrowStmt *throwStmt ) {
    172                 // __throw_resume( EXPR );
     221
     222        Statement * ExceptionMutatorCore::create_resume_throw(
     223                        ThrowStmt *throwStmt ) {
     224                // __throw_resume( `throwStmt->get_name` );
    173225                return create_given_throw( "__cfaehm__throw_resume", throwStmt );
    174226        }
    175         Statement * create_resume_rethrow( ThrowStmt *throwStmt ) {
     227
     228        Statement * ExceptionMutatorCore::create_resume_rethrow(
     229                        ThrowStmt *throwStmt ) {
    176230                // return false;
    177231                Statement * result = new ReturnStmt(
     
    185239        // TryStmt Mutation Helpers
    186240
    187         CompoundStmt * take_try_block( TryStmt *tryStmt ) {
     241        CompoundStmt * ExceptionMutatorCore::take_try_block( TryStmt *tryStmt ) {
    188242                CompoundStmt * block = tryStmt->get_block();
    189243                tryStmt->set_block( nullptr );
    190244                return block;
    191245        }
    192         FunctionDecl * create_try_wrapper( CompoundStmt *body ) {
     246
     247        FunctionDecl * ExceptionMutatorCore::create_try_wrapper(
     248                        CompoundStmt *body ) {
    193249
    194250                return new FunctionDecl( "try", Type::StorageClasses(),
     
    196252        }
    197253
    198         FunctionDecl * create_terminate_catch( CatchList &handlers ) {
     254        FunctionDecl * ExceptionMutatorCore::create_terminate_catch(
     255                        CatchList &handlers ) {
    199256                std::list<CaseStmt *> handler_wrappers;
    200257
    201258                FunctionType *func_type = catch_func_t.clone();
    202259                DeclarationWithType * index_obj = func_type->get_parameters().front();
    203         //      DeclarationWithType * except_obj = func_type->get_parameters().back();
     260                DeclarationWithType * except_obj = func_type->get_parameters().back();
    204261
    205262                // Index 1..{number of handlers}
     
    210267                        CatchStmt * handler = *it;
    211268
    212                         // INTEGERconstant Version
    213269                        // case `index`:
    214270                        // {
    215                         //     `handler.body`
     271                        //     `handler.decl` = { (virtual `decl.type`)`except` };
     272                        //     `handler.body`;
    216273                        // }
    217274                        // return;
    218                         std::list<Statement *> caseBody;
    219                         caseBody.push_back( handler->get_body() );
     275                        CompoundStmt * block = new CompoundStmt( noLabels );
     276
     277                        // Just copy the exception value. (Post Validation)
     278                        ObjectDecl * handler_decl =
     279                                static_cast<ObjectDecl *>( handler->get_decl() );
     280                        ObjectDecl * local_except = handler_decl->clone();
     281                        local_except->set_init(
     282                                new ListInit({ new SingleInit(
     283                                        new VirtualCastExpr( nameOf( except_obj ),
     284                                                local_except->get_type()
     285                                                )
     286                                        ) })
     287                                );
     288                        block->push_back( new DeclStmt( noLabels, local_except ) );
     289
     290                        // Add the cleanup attribute.
     291                        local_except->get_attributes().push_back( new Attribute(
     292                                "cleanup",
     293                                { new NameExpr( "__cfaehm__cleanup_terminate" ) }
     294                                ) );
     295
     296                        // Update variables in the body to point to this local copy.
     297                        {
     298                                VarExprReplacer::DeclMap mapping;
     299                                mapping[ handler_decl ] = local_except;
     300                                VarExprReplacer mapper( mapping );
     301                                handler->get_body()->accept( mapper );
     302                        }
     303
     304                        block->push_back( handler->get_body() );
    220305                        handler->set_body( nullptr );
    221                         caseBody.push_back( new ReturnStmt( noLabels, nullptr ) );
    222 
     306
     307                        std::list<Statement *> caseBody
     308                                        { block, new ReturnStmt( noLabels, nullptr ) };
    223309                        handler_wrappers.push_back( new CaseStmt(
    224310                                noLabels,
     
    249335        // Create a single check from a moddified handler.
    250336        // except_obj is referenced, modded_handler will be freed.
    251         CompoundStmt *create_single_matcher(
     337        CompoundStmt * ExceptionMutatorCore::create_single_matcher(
    252338                        DeclarationWithType * except_obj, CatchStmt * modded_handler ) {
     339                // {
     340                //     `modded_handler.decl`
     341                //     if ( `decl.name = (virtual `decl.type`)`except`
     342                //             [&& `modded_handler.cond`] ) {
     343                //         `modded_handler.body`
     344                //     }
     345                // }
     346
    253347                CompoundStmt * block = new CompoundStmt( noLabels );
    254348
    255                 // INTEGERconstant Version
    256                 assert( nullptr == modded_handler->get_decl() );
    257                 ConstantExpr * number =
    258                         dynamic_cast<ConstantExpr*>( modded_handler->get_cond() );
    259                 assert( number );
    260                 modded_handler->set_cond( nullptr );
    261 
    262                 Expression * cond;
    263                 {
    264                         std::list<Expression *> args;
    265                         args.push_back( number );
    266 
    267                         std::list<Expression *> rhs_args;
    268                         rhs_args.push_back( nameOf( except_obj ) );
    269                         Expression * rhs = new UntypedExpr(
    270                                 new NameExpr( "*?" ), rhs_args );
    271                         args.push_back( rhs );
    272 
    273                         cond = new UntypedExpr( new NameExpr( "?==?" /*???*/), args );
    274                 }
    275 
     349                // Local Declaration
     350                ObjectDecl * local_except =
     351                        dynamic_cast<ObjectDecl *>( modded_handler->get_decl() );
     352                assert( local_except );
     353                block->push_back( new DeclStmt( noLabels, local_except ) );
     354
     355                // Check for type match.
     356                Expression * cond = UntypedExpr::createAssign( nameOf( local_except ),
     357                        new VirtualCastExpr( nameOf( except_obj ),
     358                                local_except->get_type()->clone() ) );
     359
     360                // Add the check on the conditional if it is provided.
    276361                if ( modded_handler->get_cond() ) {
    277362                        cond = new LogicalExpr( cond, modded_handler->get_cond() );
    278363                }
     364                // Construct the match condition.
    279365                block->push_back( new IfStmt( noLabels,
    280366                        cond, modded_handler->get_body(), nullptr ) );
     
    287373        }
    288374
    289         FunctionDecl * create_terminate_match( CatchList &handlers ) {
     375        FunctionDecl * ExceptionMutatorCore::create_terminate_match(
     376                        CatchList &handlers ) {
     377                // int match(exception * except) {
     378                //     HANDLER WRAPPERS { return `index`; }
     379                // }
     380
    290381                CompoundStmt * body = new CompoundStmt( noLabels );
    291382
     
    319410        }
    320411
    321         CompoundStmt * create_terminate_caller(
     412        CompoundStmt * ExceptionMutatorCore::create_terminate_caller(
    322413                        FunctionDecl * try_wrapper,
    323414                        FunctionDecl * terminate_catch,
    324                         FunctionDecl * terminate_match) {
     415                        FunctionDecl * terminate_match ) {
     416                // { __cfaehm__try_terminate(`try`, `catch`, `match`); }
    325417
    326418                UntypedExpr * caller = new UntypedExpr( new NameExpr(
     
    336428        }
    337429
    338         FunctionDecl * create_resume_handler( CatchList &handlers ) {
     430        FunctionDecl * ExceptionMutatorCore::create_resume_handler(
     431                        CatchList &handlers ) {
     432                // bool handle(exception * except) {
     433                //     HANDLER WRAPPERS { `hander->body`; return true; }
     434                // }
    339435                CompoundStmt * body = new CompoundStmt( noLabels );
    340436
     
    369465        }
    370466
    371         CompoundStmt * create_resume_wrapper(
    372                         StructDecl * node_decl,
     467        CompoundStmt * ExceptionMutatorCore::create_resume_wrapper(
    373468                        Statement * wraps,
    374469                        FunctionDecl * resume_handler ) {
     
    414509        }
    415510
    416         FunctionDecl * create_finally_wrapper( TryStmt * tryStmt ) {
     511        FunctionDecl * ExceptionMutatorCore::create_finally_wrapper(
     512                        TryStmt * tryStmt ) {
     513                // void finally() { <finally code> }
    417514                FinallyStmt * finally = tryStmt->get_finally();
    418515                CompoundStmt * body = finally->get_block();
     
    425522        }
    426523
    427         ObjectDecl * create_finally_hook(
    428                         StructDecl * hook_decl, FunctionDecl * finally_wrapper ) {
     524        ObjectDecl * ExceptionMutatorCore::create_finally_hook(
     525                        FunctionDecl * finally_wrapper ) {
    429526                // struct __cfaehm__cleanup_hook __finally_hook
    430527                //      __attribute__((cleanup( finally_wrapper )));
     
    452549        }
    453550
    454 
    455         class ExceptionMutatorCore : public WithGuards {
    456                 enum Context { NoHandler, TerHandler, ResHandler };
    457 
    458                 // Also need to handle goto, break & continue.
    459                 // They need to be cut off in a ResHandler, until we enter another
    460                 // loop, switch or the goto stays within the function.
    461 
    462                 Context cur_context;
    463 
    464                 // We might not need this, but a unique base for each try block's
    465                 // generated functions might be nice.
    466                 //std::string curFunctionName;
    467                 //unsigned int try_count = 0;
    468 
    469                 StructDecl *node_decl;
    470                 StructDecl *hook_decl;
    471 
    472         public:
    473                 ExceptionMutatorCore() :
    474                         cur_context(NoHandler),
    475                         node_decl(nullptr), hook_decl(nullptr)
    476                 {}
    477 
    478                 void premutate( CatchStmt *catchStmt );
    479                 void premutate( StructDecl *structDecl );
    480                 Statement * postmutate( ThrowStmt *throwStmt );
    481                 Statement * postmutate( TryStmt *tryStmt );
    482         };
     551        // Visiting/Mutating Functions
     552        void ExceptionMutatorCore::premutate( CatchStmt *catchStmt ) {
     553                // Validate the Statement's form.
     554                ObjectDecl * decl =
     555                        dynamic_cast<ObjectDecl *>( catchStmt->get_decl() );
     556                if ( decl && true /* check decl->get_type() */ ) {
     557                        // Pass.
     558                } else if ( CatchStmt::Terminate == catchStmt->get_kind() ) {
     559                        throw SemanticError("catch must have exception type");
     560                } else {
     561                        throw SemanticError("catchResume must have exception type");
     562                }
     563
     564                // Track the handler context.
     565                GuardValue( cur_context );
     566                if ( CatchStmt::Terminate == catchStmt->get_kind() ) {
     567                        cur_context = TerHandler;
     568
     569                        GuardValue( handler_except_decl );
     570                        handler_except_decl = decl;
     571                } else {
     572                        cur_context = ResHandler;
     573                }
     574        }
     575
     576        void ExceptionMutatorCore::premutate( StructDecl *structDecl ) {
     577                if ( !structDecl->has_body() ) {
     578                        // Skip children?
     579                        return;
     580                } else if ( structDecl->get_name() == "__cfaehm__base_exception_t" ) {
     581                        assert( nullptr == except_decl );
     582                        except_decl = structDecl;
     583                        init_func_types();
     584                } else if ( structDecl->get_name() == "__cfaehm__try_resume_node" ) {
     585                        assert( nullptr == node_decl );
     586                        node_decl = structDecl;
     587                } else if ( structDecl->get_name() == "__cfaehm__cleanup_hook" ) {
     588                        assert( nullptr == hook_decl );
     589                        hook_decl = structDecl;
     590                }
     591                // Later we might get the exception type as well.
     592        }
    483593
    484594        Statement * ExceptionMutatorCore::postmutate( ThrowStmt *throwStmt ) {
     595                assert( except_decl );
     596
    485597                // Ignoring throwStmt->get_target() for now.
    486598                if ( ThrowStmt::Terminate == throwStmt->get_kind() ) {
     
    510622
    511623        Statement * ExceptionMutatorCore::postmutate( TryStmt *tryStmt ) {
     624                assert( except_decl );
    512625                assert( node_decl );
    513626                assert( hook_decl );
     
    524637                        appendDeclStmt( block, finally_block );
    525638                        // Create and add the finally cleanup hook.
    526                         appendDeclStmt( block,
    527                                 create_finally_hook( hook_decl, finally_block ) );
     639                        appendDeclStmt( block, create_finally_hook( finally_block ) );
    528640                }
    529641
     
    539651                        appendDeclStmt( block, resume_handler );
    540652                        // Prepare hooks
    541                         inner = create_resume_wrapper( node_decl, inner, resume_handler );
     653                        inner = create_resume_wrapper( inner, resume_handler );
    542654                }
    543655
     
    560672                block->push_back( inner );
    561673
    562                 //free_all( termination_handlers );
    563                 //free_all( resumption_handlers );
    564 
    565674                return block;
    566675        }
    567676
    568         void ExceptionMutatorCore::premutate( CatchStmt *catchStmt ) {
    569                 GuardValue( cur_context );
    570                 if ( CatchStmt::Terminate == catchStmt->get_kind() ) {
    571                         cur_context = TerHandler;
    572                 } else {
    573                         cur_context = ResHandler;
    574                 }
    575         }
    576 
    577         void ExceptionMutatorCore::premutate( StructDecl *structDecl ) {
    578                 if ( !structDecl->has_body() ) {
    579                         // Skip children?
    580                         return;
    581                 } else if ( structDecl->get_name() == "__cfaehm__try_resume_node" ) {
    582                         assert( nullptr == node_decl );
    583                         node_decl = structDecl;
    584                 } else if ( structDecl->get_name() == "__cfaehm__cleanup_hook" ) {
    585                         assert( nullptr == hook_decl );
    586                         hook_decl = structDecl;
    587                 }
    588                 // Later we might get the exception type as well.
    589         }
    590 
    591677        void translateEHM( std::list< Declaration *> & translationUnit ) {
    592                 init_func_types();
    593 
    594678                PassVisitor<ExceptionMutatorCore> translator;
    595679                mutateAll( translationUnit, translator );
  • src/GenPoly/Box.cc

    r275f4b4 rcd7ef0b  
    2727#include "Box.h"
    2828#include "DeclMutator.h"
     29#include "Lvalue.h"
     30#include "FindFunction.h"
    2931#include "PolyMutator.h"
    30 #include "FindFunction.h"
    3132#include "ScopedSet.h"
    3233#include "ScrubTyVars.h"
     
    755756
    756757                void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) {
    757                         assert( arg->has_result() );
     758                        assertf( arg->has_result(), "arg does not have result: %s", toString( arg ).c_str() );
    758759                        if ( isPolyType( param, exprTyVars ) ) {
    759                                 if ( isPolyType( arg->get_result() ) ) {
     760                                Type * newType = arg->get_result()->clone();
     761                                if ( env ) env->apply( newType );
     762                                std::auto_ptr<Type> manager( newType );
     763                                if ( isPolyType( newType ) ) {
    760764                                        // if the argument's type is polymorphic, we don't need to box again!
    761765                                        return;
    762766                                } else if ( arg->get_result()->get_lvalue() ) {
    763                                         // VariableExpr and MemberExpr are lvalues; need to check this isn't coming from the second arg of a comma expression though (not an lvalue)
    764                                         // xxx - need to test that this code is still reachable
    765                                         if ( CommaExpr *commaArg = dynamic_cast< CommaExpr* >( arg ) ) {
    766                                                 commaArg->set_arg2( new AddressExpr( commaArg->get_arg2() ) );
    767                                         } else {
    768                                                 arg = new AddressExpr( arg );
    769                                         }
     767                                        // argument expression may be CFA lvalue, but not C lvalue -- apply generalizedLvalue transformations.
     768                                        arg =  generalizedLvalue( new AddressExpr( arg ) );
    770769                                        if ( ! ResolvExpr::typesCompatible( param, arg->get_result(), SymTab::Indexer() ) ) {
    771770                                                // silence warnings by casting boxed parameters when the actual type does not match up with the formal type.
     
    18791878                        return structDecl;
    18801879                }
    1881                
     1880
    18821881                Declaration *Pass3::mutate( UnionDecl *unionDecl ) {
    18831882                        stripGenericMembers( unionDecl );
  • src/GenPoly/Lvalue.cc

    r275f4b4 rcd7ef0b  
    2727#include "SynTree/Mutator.h"
    2828#include "SymTab/Indexer.h"
     29
    2930#include "ResolvExpr/Resolver.h"
     31#include "ResolvExpr/TypeEnvironment.h"
    3032#include "ResolvExpr/typeops.h"
     33#include "ResolvExpr/Unify.h"
    3134
    3235#include "Common/UniqueName.h"
     
    6063                        typedef Mutator Parent;
    6164
     65                        virtual Expression * mutate( MemberExpr * memExpr );
    6266                        virtual Expression * mutate( AddressExpr * addressExpr );
     67
     68                        template<typename Func>
     69                        Expression * applyTransformation( Expression * expr, Expression * arg, Func mkExpr );
    6370                };
    6471        } // namespace
     
    7178                acceptAll( translationUnit, p2 );
    7279                mutateAll( translationUnit, genLval );
     80        }
     81
     82        Expression * generalizedLvalue( Expression * expr ) {
     83                GeneralizedLvalue genLval;
     84                return expr->acceptMutator( genLval );
    7385        }
    7486
     
    163175                }
    164176
    165                 Expression * GeneralizedLvalue::mutate( AddressExpr * addrExpr ) {
    166                         addrExpr = safe_dynamic_cast< AddressExpr * >( Parent::mutate( addrExpr ) );
    167                         if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( addrExpr->get_arg() ) ) {
     177                template<typename Func>
     178                Expression * GeneralizedLvalue::applyTransformation( Expression * expr, Expression * arg, Func mkExpr ) {
     179                        if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( arg ) ) {
    168180                                Expression * arg1 = commaExpr->get_arg1()->clone();
    169181                                Expression * arg2 = commaExpr->get_arg2()->clone();
    170                                 delete addrExpr;
    171                                 return new CommaExpr( arg1, new AddressExpr( arg2 ) );
    172                         } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( addrExpr->get_arg() ) ) {
     182                                Expression * ret = new CommaExpr( arg1, mkExpr( arg2 ) );
     183                                ret->set_env( expr->get_env() );
     184                                expr->set_env( nullptr );
     185                                delete expr;
     186                                return ret->acceptMutator( *this );
     187                        } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( arg ) ) {
    173188                                Expression * arg1 = condExpr->get_arg1()->clone();
    174189                                Expression * arg2 = condExpr->get_arg2()->clone();
    175190                                Expression * arg3 = condExpr->get_arg3()->clone();
    176                                 delete addrExpr;
    177                                 return new ConditionalExpr( arg1, new AddressExpr( arg2 ), new AddressExpr( arg3 ) );
     191                                ConditionalExpr * ret = new ConditionalExpr( arg1, mkExpr( arg2 ), mkExpr( arg3 ) );
     192                                ret->set_env( expr->get_env() );
     193                                expr->set_env( nullptr );
     194                                delete expr;
     195
     196                                // conditional expr type may not be either of the argument types, need to unify
     197                                using namespace ResolvExpr;
     198                                Type* commonType = nullptr;
     199                                TypeEnvironment newEnv;
     200                                AssertionSet needAssertions, haveAssertions;
     201                                OpenVarSet openVars;
     202                                unify( ret->get_arg2()->get_result(), ret->get_arg3()->get_result(), newEnv, needAssertions, haveAssertions, openVars, SymTab::Indexer(), commonType );
     203                                ret->set_result( commonType ? commonType : ret->get_arg2()->get_result()->clone() );
     204                                return ret->acceptMutator( *this );
    178205                        }
    179                         return addrExpr;
     206                        return expr;
     207                }
     208
     209                Expression * GeneralizedLvalue::mutate( MemberExpr * memExpr ) {
     210                        Parent::mutate( memExpr );
     211                        return applyTransformation( memExpr, memExpr->get_aggregate(), [=]( Expression * aggr ) { return new MemberExpr( memExpr->get_member(), aggr ); } );
     212                }
     213
     214                Expression * GeneralizedLvalue::mutate( AddressExpr * addrExpr ) {
     215                        addrExpr = safe_dynamic_cast< AddressExpr * >( Parent::mutate( addrExpr ) );
     216                        return applyTransformation( addrExpr, addrExpr->get_arg(), []( Expression * arg ) { return new AddressExpr( arg ); } );
    180217                }
    181218        } // namespace
  • src/GenPoly/Lvalue.h

    r275f4b4 rcd7ef0b  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Lvalue.h -- 
     7// Lvalue.h --
    88//
    99// Author           : Richard C. Bilson
     
    2323        /// replaces return type of `lvalue T` with `T*`, along with appropriate address-of and dereference operators
    2424        void convertLvalue( std::list< Declaration* >& translationUnit );
     25
     26        /// applies transformations that allow GCC to accept more complicated lvalue expressions, e.g. &(a, b)
     27        Expression * generalizedLvalue( Expression * expr );
    2528} // namespace GenPoly
    2629
  • src/Makefile.am

    r275f4b4 rcd7ef0b  
    4343cfa_cpplib_PROGRAMS = driver/cfa-cpp
    4444driver_cfa_cpp_SOURCES = ${SRC}
    45 driver_cfa_cpp_LDADD = ${LEXLIB} -ldl                   # yywrap
     45driver_cfa_cpp_LDADD = -ldl                     # yywrap
    4646driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -Wextra -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
    4747driver_cfa_cpp_LDFLAGS = -Xlinker -export-dynamic
  • src/Makefile.in

    r275f4b4 rcd7ef0b  
    262262am_driver_cfa_cpp_OBJECTS = $(am__objects_1)
    263263driver_cfa_cpp_OBJECTS = $(am_driver_cfa_cpp_OBJECTS)
    264 am__DEPENDENCIES_1 =
    265 driver_cfa_cpp_DEPENDENCIES = $(am__DEPENDENCIES_1)
     264driver_cfa_cpp_DEPENDENCIES =
    266265driver_cfa_cpp_LINK = $(CXXLD) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) \
    267266        $(driver_cfa_cpp_LDFLAGS) $(LDFLAGS) -o $@
     
    548547cfa_cpplibdir = ${CFA_LIBDIR}
    549548driver_cfa_cpp_SOURCES = ${SRC}
    550 driver_cfa_cpp_LDADD = ${LEXLIB} -ldl                   # yywrap
     549driver_cfa_cpp_LDADD = -ldl                     # yywrap
    551550driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -Wextra -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14
    552551driver_cfa_cpp_LDFLAGS = -Xlinker -export-dynamic
  • src/Parser/ExpressionNode.cc

    r275f4b4 rcd7ef0b  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 25 10:11:00 2017
    13 // Update Count     : 551
    14 //
    15 
    16 #include <cassert>
    17 #include <cctype>
    18 #include <climits>
    19 #include <cstdio>
    20 #include <algorithm>
     12// Last Modified On : Wed Aug  2 11:12:00 2017
     13// Update Count     : 568
     14//
     15
     16#include <climits>                                                                              // access INT_MAX, UINT_MAX, LONG_MAX, ULONG_MAX, LLONG_MAX
    2117#include <sstream>
    2218
     
    2622#include "SynTree/Expression.h"
    2723#include "SynTree/Declaration.h"
    28 #include "Common/UnimplementedError.h"
    2924#include "parserutility.h"
    30 #include "Common/utility.h"
    3125
    3226using namespace std;
     
    4640// type.
    4741
    48 Type::Qualifiers noQualifiers;                          // no qualifiers on constants
     42extern const Type::Qualifiers noQualifiers;             // no qualifiers on constants
    4943
    5044static inline bool checkU( char c ) { return c == 'u' || c == 'U'; }
     
    5549static inline bool checkX( char c ) { return c == 'x' || c == 'X'; }
    5650
    57 Expression *build_constantInteger( const std::string & str ) {
     51Expression * build_constantInteger( const std::string & str ) {
    5852        static const BasicType::Kind kind[2][3] = {
    5953                { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt },
     
    6256        bool dec = true, Unsigned = false;                                      // decimal, unsigned constant
    6357        int size;                                                                                       // 0 => int, 1 => long, 2 => long long
    64         unsigned long long int v;                                                               // converted integral value
     58        unsigned long long int v;                                                       // converted integral value
    6559        size_t last = str.length() - 1;                                         // last character of constant
    66 
     60        Expression * ret;
     61
     62        // special constants
     63        if ( str == "0" ) {
     64                ret = new ConstantExpr( Constant( (Type *)new ZeroType( noQualifiers ), str, (unsigned long long int)0 ) );
     65                goto CLEANUP;
     66        } // if
     67        if ( str == "1" ) {
     68                ret = new ConstantExpr( Constant( (Type *)new OneType( noQualifiers ), str, (unsigned long long int)1 ) );
     69                goto CLEANUP;
     70        } // if
     71       
    6772        if ( str[0] == '0' ) {                                                          // octal/hex constant ?
    6873                dec = false;
     
    118123        } // if
    119124
    120         Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) );
     125        ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) );
     126  CLEANUP:
    121127        delete &str;                                                                            // created by lex
    122128        return ret;
    123129} // build_constantInteger
    124130
    125 Expression *build_constantFloat( const std::string & str ) {
     131Expression * build_constantFloat( const std::string & str ) {
    126132        static const BasicType::Kind kind[2][3] = {
    127133                { BasicType::Float, BasicType::Double, BasicType::LongDouble },
     
    158164} // build_constantFloat
    159165
    160 Expression *build_constantChar( const std::string & str ) {
     166Expression * build_constantChar( const std::string & str ) {
    161167        Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) );
    162168        delete &str;                                                                            // created by lex
     
    164170} // build_constantChar
    165171
    166 ConstantExpr *build_constantStr( const std::string & str ) {
     172ConstantExpr * build_constantStr( const std::string & str ) {
    167173        // string should probably be a primitive type
    168         ArrayType *at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
    169                                                                    new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ),  // +1 for '\0' and -2 for '"'
     174        ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),
     175                                                                   new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"'
    170176                                                                   false, false );
    171         // constant 0 is ignored for pure string value
    172         ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) );
     177        ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value
    173178        delete &str;                                                                            // created by lex
    174179        return ret;
    175180} // build_constantStr
    176 
    177 Expression *build_constantZeroOne( const std::string & str ) {
    178         Expression * ret = new ConstantExpr( Constant( str == "0" ? (Type *)new ZeroType( noQualifiers ) : (Type*)new OneType( noQualifiers ), str,
    179                                                                                                    str == "0" ? (unsigned long long int)0 : (unsigned long long int)1 ) );
    180         delete &str;                                                                            // created by lex
    181         return ret;
    182 } // build_constantChar
    183181
    184182Expression * build_field_name_FLOATINGconstant( const std::string & str ) {
     
    209207} // build_field_name_fraction_constants
    210208
    211 
    212 
    213209Expression * build_field_name_REALFRACTIONconstant( const std::string & str ) {
    214210        if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str );
     
    225221} // build_field_name_REALDECIMALconstant
    226222
    227 NameExpr * build_varref( const string *name ) {
    228         NameExpr *expr = new NameExpr( *name, nullptr );
     223NameExpr * build_varref( const string * name ) {
     224        NameExpr * expr = new NameExpr( *name, nullptr );
    229225        delete name;
    230226        return expr;
    231 }
    232 
    233 // Must harmonize with OperKinds.
    234 static const char *OperName[] = {
     227} // build_varref
     228
     229
     230static const char * OperName[] = {                                              // must harmonize with OperKinds
    235231        // diadic
    236232        "SizeOf", "AlignOf", "OffsetOf", "?+?", "?-?", "?\\?", "?*?", "?/?", "?%?", "||", "&&",
     
    240236        // monadic
    241237        "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", "&&"
    242 };
    243 
    244 Expression *build_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) {
    245         Type *targetType = maybeMoveBuildType( decl_node );
     238}; // OperName
     239
     240Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
     241        Type * targetType = maybeMoveBuildType( decl_node );
    246242        if ( dynamic_cast< VoidType * >( targetType ) ) {
    247243                delete targetType;
     
    250246                return new CastExpr( maybeMoveBuild< Expression >(expr_node), targetType );
    251247        } // if
    252 }
    253 
    254 
    255 Expression *build_virtual_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) {
    256         Type *targetType = maybeMoveBuildType( decl_node );
    257         Expression *castArg = maybeMoveBuild< Expression >( expr_node );
     248} // build_cast
     249
     250Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) {
     251        Type * targetType = maybeMoveBuildType( decl_node );
     252        Expression * castArg = maybeMoveBuild< Expression >( expr_node );
    258253        return new VirtualCastExpr( castArg, targetType );
    259 }
    260 
    261 Expression *build_fieldSel( ExpressionNode *expr_node, Expression *member ) {
    262         UntypedMemberExpr *ret = new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) );
    263         return ret;
    264 }
    265 
    266 Expression *build_pfieldSel( ExpressionNode *expr_node, Expression *member ) {
    267         UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
     254} // build_virtual_cast
     255
     256Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ) {
     257        UntypedMemberExpr * ret = new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) );
     258        return ret;
     259} // build_fieldSel
     260
     261Expression * build_pfieldSel( ExpressionNode * expr_node, Expression * member ) {
     262        UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) );
    268263        deref->location = expr_node->location;
    269264        deref->get_args().push_back( maybeMoveBuild< Expression >(expr_node) );
    270         UntypedMemberExpr *ret = new UntypedMemberExpr( member, deref );
    271         return ret;
    272 }
    273 
    274 Expression *build_addressOf( ExpressionNode *expr_node ) {
     265        UntypedMemberExpr * ret = new UntypedMemberExpr( member, deref );
     266        return ret;
     267} // build_pfieldSel
     268
     269Expression * build_addressOf( ExpressionNode * expr_node ) {
    275270                return new AddressExpr( maybeMoveBuild< Expression >(expr_node) );
    276 }
    277 Expression *build_sizeOfexpr( ExpressionNode *expr_node ) {
     271} // build_addressOf
     272
     273Expression * build_sizeOfexpr( ExpressionNode * expr_node ) {
    278274        return new SizeofExpr( maybeMoveBuild< Expression >(expr_node) );
    279 }
    280 Expression *build_sizeOftype( DeclarationNode *decl_node ) {
     275} // build_sizeOfexpr
     276
     277Expression * build_sizeOftype( DeclarationNode * decl_node ) {
    281278        return new SizeofExpr( maybeMoveBuildType( decl_node ) );
    282 }
    283 Expression *build_alignOfexpr( ExpressionNode *expr_node ) {
     279} // build_sizeOftype
     280
     281Expression * build_alignOfexpr( ExpressionNode * expr_node ) {
    284282        return new AlignofExpr( maybeMoveBuild< Expression >(expr_node) );
    285 }
    286 Expression *build_alignOftype( DeclarationNode *decl_node ) {
     283} // build_alignOfexpr
     284
     285Expression * build_alignOftype( DeclarationNode * decl_node ) {
    287286        return new AlignofExpr( maybeMoveBuildType( decl_node) );
    288 }
    289 Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member ) {
     287} // build_alignOftype
     288
     289Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member ) {
    290290        Expression * ret = new UntypedOffsetofExpr( maybeMoveBuildType( decl_node ), member->get_name() );
    291291        delete member;
    292292        return ret;
    293 }
    294 
    295 Expression *build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ) {
     293} // build_offsetOf
     294
     295Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode * expr_node2, bool kind ) {
    296296        return new LogicalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), notZeroExpr( maybeMoveBuild< Expression >(expr_node2) ), kind );
    297 }
    298 
    299 Expression *build_unary_val( OperKinds op, ExpressionNode *expr_node ) {
     297} // build_and_or
     298
     299Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ) {
    300300        std::list< Expression * > args;
    301301        args.push_back( maybeMoveBuild< Expression >(expr_node) );
    302302        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    303 }
    304 Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ) {
     303} // build_unary_val
     304
     305Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) {
    305306        std::list< Expression * > args;
    306307        args.push_back( new AddressExpr( maybeMoveBuild< Expression >(expr_node) ) );
    307308        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    308 }
    309 Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
     309} // build_unary_ptr
     310
     311Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
    310312        std::list< Expression * > args;
    311313        args.push_back( maybeMoveBuild< Expression >(expr_node1) );
    312314        args.push_back( maybeMoveBuild< Expression >(expr_node2) );
    313315        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    314 }
    315 Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
     316} // build_binary_val
     317
     318Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
    316319        std::list< Expression * > args;
    317320        args.push_back( new AddressExpr( maybeMoveBuild< Expression >(expr_node1) ) );
    318321        args.push_back( maybeMoveBuild< Expression >(expr_node2) );
    319322        return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args );
    320 }
    321 
    322 Expression *build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ) {
     323} // build_binary_ptr
     324
     325Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 ) {
    323326        return new ConditionalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), maybeMoveBuild< Expression >(expr_node2), maybeMoveBuild< Expression >(expr_node3) );
    324 }
    325 
    326 Expression *build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {
     327} // build_cond
     328
     329Expression * build_comma( ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) {
    327330        return new CommaExpr( maybeMoveBuild< Expression >(expr_node1), maybeMoveBuild< Expression >(expr_node2) );
    328 }
    329 
    330 Expression *build_attrexpr( NameExpr *var, ExpressionNode * expr_node ) {
     331} // build_comma
     332
     333Expression * build_attrexpr( NameExpr * var, ExpressionNode * expr_node ) {
    331334        return new AttrExpr( var, maybeMoveBuild< Expression >(expr_node) );
    332 }
    333 Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ) {
     335} // build_attrexpr
     336
     337Expression * build_attrtype( NameExpr * var, DeclarationNode * decl_node ) {
    334338        return new AttrExpr( var, maybeMoveBuildType( decl_node ) );
    335 }
    336 
    337 Expression *build_tuple( ExpressionNode * expr_node ) {
     339} // build_attrtype
     340
     341Expression * build_tuple( ExpressionNode * expr_node ) {
    338342        std::list< Expression * > exprs;
    339343        buildMoveList( expr_node, exprs );
    340344        return new UntypedTupleExpr( exprs );;
    341 }
    342 
    343 Expression *build_func( ExpressionNode * function, ExpressionNode * expr_node ) {
     345} // build_tuple
     346
     347Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ) {
    344348        std::list< Expression * > args;
    345349        buildMoveList( expr_node, args );
    346350        return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr );
    347 }
    348 
    349 Expression *build_range( ExpressionNode * low, ExpressionNode *high ) {
     351} // build_func
     352
     353Expression * build_range( ExpressionNode * low, ExpressionNode * high ) {
    350354        return new RangeExpr( maybeMoveBuild< Expression >( low ), maybeMoveBuild< Expression >( high ) );
    351 }
    352 
    353 Expression *build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ) {
     355} // build_range
     356
     357Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr * constraint, ExpressionNode * operand ) {
    354358        return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) );
    355 }
    356 
    357 Expression *build_valexpr( StatementNode *s ) {
     359} // build_asmexpr
     360
     361Expression * build_valexpr( StatementNode * s ) {
    358362        return new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(s) ) );
    359 }
    360 Expression *build_typevalue( DeclarationNode *decl ) {
     363} // build_valexpr
     364
     365Expression * build_typevalue( DeclarationNode * decl ) {
    361366        return new TypeExpr( maybeMoveBuildType( decl ) );
    362 }
    363 
    364 Expression *build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ) {
     367} // build_typevalue
     368
     369Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids ) {
    365370        Declaration * newDecl = maybeBuild< Declaration >(decl_node); // compound literal type
    366371        if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type
     
    388393                assert( false );
    389394        } // if
    390 }
     395} // build_compoundLiteral
    391396
    392397// Local Variables: //
  • src/Parser/InitializerNode.cc

    r275f4b4 rcd7ef0b  
    1010// Created On       : Sat May 16 13:20:24 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Oct  1 23:09:51 2016
    13 // Update Count     : 21
     12// Last Modified On : Fri Jul 28 23:27:20 2017
     13// Update Count     : 26
    1414//
    1515
     
    2222#include "SynTree/Initializer.h"
    2323
    24 InitializerNode::InitializerNode( ExpressionNode *_expr, bool aggrp, ExpressionNode *des )
    25                 : expr( _expr ), aggregate( aggrp ), designator( des ), kids( 0 ), maybeConstructed( true ) {
     24InitializerNode::InitializerNode( ExpressionNode * _expr, bool aggrp, ExpressionNode * des )
     25                : expr( _expr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) {
    2626        if ( aggrp )
    2727                kids = dynamic_cast< InitializerNode * >( get_next() );
    2828
    29         if ( kids != 0 )
    30                 set_last( 0 );
    31 }
     29        if ( kids )
     30                set_last( nullptr );
     31} // InitializerNode::InitializerNode
    3232
    33 InitializerNode::InitializerNode( InitializerNode *init, bool aggrp, ExpressionNode *des )
    34                 : expr( 0 ), aggregate( aggrp ), designator( des ), kids( 0 ), maybeConstructed( true ) {
    35         if ( init != 0 )
     33InitializerNode::InitializerNode( InitializerNode * init, bool aggrp, ExpressionNode * des )
     34                : expr( nullptr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) {
     35        if ( init )
    3636                set_last( init );
    3737
     
    3939                kids = dynamic_cast< InitializerNode * >( get_next() );
    4040
    41         if ( kids != 0 )
    42                 set_next( 0 );
    43 }
     41        if ( kids )
     42                set_next( nullptr );
     43} // InitializerNode::InitializerNode
    4444
    4545InitializerNode::~InitializerNode() {
     
    4747        delete designator;
    4848        delete kids;
    49 }
     49} // InitializerNode::~InitializerNode
    5050
    5151void InitializerNode::print( std::ostream &os, int indent ) const {
    5252        os << std::string( indent, ' ' ) << "Initializer expression" << std::endl;
    53 }
     53} // InitializerNode::print
    5454
    5555void InitializerNode::printOneLine( std::ostream &os ) const {
    5656        if ( ! aggregate ) {
    57                 if ( designator != 0 ) {
     57                if ( designator ) {
    5858                        os << "designated by: (";
    5959                        ExpressionNode *curdes = designator;
    60                         while ( curdes != 0) {
     60                        while ( curdes != nullptr) {
    6161                                curdes->printOneLine(os);
    6262                                curdes = (ExpressionNode *)(curdes->get_next());
     
    6565                        os << ")";
    6666                } // if
    67                 if ( expr ) expr->printOneLine(os);
     67                if ( expr ) expr->printOneLine( os );
    6868        } else {  // It's an aggregate
    6969                os << "[--";
    70                 if ( next_init() != 0 )
    71                         next_init()->printOneLine(os);
     70                if ( next_init() != nullptr )
     71                        next_init()->printOneLine( os );
    7272                if (aggregate) os << "--]";
    7373        } // if
     
    7676        if ( (moreInit = dynamic_cast< InitializerNode * >( get_next() ) ) ) {
    7777                moreInit->printOneLine( os );
    78         }
    79 }
     78        } // if
     79} // InitializerNode::printOneLine
    8080
    81 Initializer *InitializerNode::build() const {
     81Initializer * InitializerNode::build() const {
    8282        if ( aggregate ) {
    8383                // steal designators from children
     
    9393                return new ListInit( initlist, designlist, maybeConstructed );
    9494        } else {
    95                 if ( get_expression() != 0) {
     95                if ( get_expression() ) {
    9696                        return new SingleInit( maybeBuild< Expression >( get_expression() ), maybeConstructed );
    97                 }
     97                } // if
    9898        } // if
    99         return 0;
    100 }
     99        return nullptr;
     100} // InitializerNode::build
    101101
    102102// Local Variables: //
  • src/Parser/ParseNode.h

    r275f4b4 rcd7ef0b  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:28:16 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 25 10:09:00 2017
    13 // Update Count     : 787
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Jul 27 12:08:08 2017
     13// Update Count     : 788
    1414//
    1515
     
    159159Expression * build_constantFloat( const std::string &str );
    160160Expression * build_constantChar( const std::string &str );
    161 Expression * build_constantZeroOne( const std::string &str );
    162161ConstantExpr * build_constantStr( const std::string &str );
    163162Expression * build_field_name_FLOATINGconstant( const std::string & str );
  • src/Parser/TypeData.cc

    r275f4b4 rcd7ef0b  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 18 10:10:00 2017
    13 // Update Count     : 566
     12// Last Modified On : Wed Aug  9 13:50:00 2017
     13// Update Count     : 567
    1414//
    1515
     
    748748} // buildAggInst
    749749
    750 NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, Type::StorageClasses scs ) {
     750NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage ) {
    751751        assert( td->kind == TypeData::Symbolic );
    752752        NamedTypeDecl * ret;
    753753        assert( td->base );
    754754        if ( td->symbolic.isTypedef ) {
    755                 ret = new TypedefDecl( name, scs, typebuild( td->base ) );
     755                ret = new TypedefDecl( name, scs, typebuild( td->base ), linkage );
    756756        } else {
    757757                ret = new TypeDecl( name, scs, typebuild( td->base ), TypeDecl::Any );
     
    817817                return buildEnum( td, attributes );
    818818        } else if ( td->kind == TypeData::Symbolic ) {
    819                 return buildSymbolic( td, name, scs );
     819                return buildSymbolic( td, name, scs, linkage );
    820820        } else {
    821821                return (new ObjectDecl( name, scs, linkage, bitfieldWidth, typebuild( td ), init, attributes ))->set_asmName( asmName );
  • src/Parser/lex.ll

    r275f4b4 rcd7ef0b  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Mon Jul 24 08:27:23 2017
    13  * Update Count     : 545
     12 * Last Modified On : Thu Jul 27 21:46:06 2017
     13 * Update Count     : 550
    1414 */
    1515
    1616%option yylineno
     17%option noyywrap
    1718%option nounput
    1819
     
    288289
    289290                                /* numeric constants */
    290 "0"                             { NUMERIC_RETURN(ZERO); }                               // CFA
    291 "1"                             { NUMERIC_RETURN(ONE); }                                // CFA
    292291{decimal_constant} { NUMERIC_RETURN(INTEGERconstant); }
    293292{octal_constant} { NUMERIC_RETURN(INTEGERconstant); }
     
    420419
    421420                                /* unknown characters */
    422 .                       { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }
     421.                               { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }
    423422
    424423%%
  • src/Parser/parser.yy

    r275f4b4 rcd7ef0b  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 25 10:07:00 2017
    13 // Update Count     : 2464
     12// Last Modified On : Wed Aug  4 13:33:00 2017
     13// Update Count     : 2475
    1414//
    1515
     
    142142// converted into the tuple index (.)(1). e.g., 3.x
    143143%token<tok>     REALDECIMALconstant     REALFRACTIONconstant    FLOATINGconstant
    144 %token<tok> ZERO                                ONE                                             // CFA
    145144
    146145// multi-character operators
     
    159158%token ATassign                                                                                 // @=
    160159
    161 %type<tok> identifier  no_attr_identifier  zero_one
     160%type<tok> identifier  no_attr_identifier
    162161%type<tok> identifier_or_type_name  no_attr_identifier_or_type_name  attr_name
    163162%type<constant> string_literal
     
    183182%type<en> asm_clobbers_list_opt
    184183%type<flag> asm_volatile_opt
     184%type<en> handler_predicate_opt
    185185
    186186// statements
     
    360360        ;
    361361
    362 zero_one:                                                                                               // CFA
    363         ZERO
    364         | ONE
    365         ;
    366 
    367362string_literal:
    368363        string_literal_list                                                     { $$ = build_constantStr( *$1 ); }
     
    384379        IDENTIFIER                                                                                      // typedef name cannot be used as a variable name
    385380                { $$ = new ExpressionNode( build_varref( $1 ) ); }
    386         | zero_one
    387                 { $$ = new ExpressionNode( build_constantZeroOne( *$1 ) ); }
    388381        | tuple
    389382        | '(' comma_expression ')'
     
    485478                        $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );
    486479                }
    487         | zero_one fraction_constants
    488                 {
    489                         $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantZeroOne( *$1 ), $2 ) );
    490                 }
    491480        ;
    492481
     
    539528        | ALIGNOF unary_expression                                                      // GCC, variable alignment
    540529                { $$ = new ExpressionNode( build_alignOfexpr( $2 ) ); }
    541         | ALIGNOF '(' type_no_function ')'                              // GCC, type alignment
     530        | ALIGNOF '(' type_no_function ')'                                      // GCC, type alignment
    542531                { $$ = new ExpressionNode( build_alignOftype( $3 ) ); }
    543532        | OFFSETOF '(' type_no_function ',' no_attr_identifier ')'
     
    980969
    981970handler_clause:
    982         // TEMPORARY, TEST EXCEPTIONS
    983         handler_key '(' push push INTEGERconstant pop ')' compound_statement pop
    984                 { $$ = new StatementNode( build_catch( $1, nullptr, new ExpressionNode( build_constantInteger( *$5 ) ), $8 ) ); }
    985         | handler_clause handler_key '(' push push INTEGERconstant pop ')' compound_statement pop
    986                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, nullptr, new ExpressionNode( build_constantInteger( *$6 ) ), $9 ) ) ); }
    987 
    988         | handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    989                 { $$ = new StatementNode( build_catch( $1, $5, nullptr, $9 ) ); }
     971        handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
     972                { $$ = new StatementNode( build_catch( $1, $5, $7, $9 ) ); }
    990973        | handler_clause handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop
    991                 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, nullptr, $10 ) ) ); }
     974                { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, $8, $10 ) ) ); }
    992975        ;
    993976
    994977handler_predicate_opt:
    995978        //empty
     979                { $$ = nullptr; }
    996980        | ';' conditional_expression
     981                { $$ = $2; }
    997982        ;
    998983
     
    16861671        | aggregate_key attribute_list_opt typegen_name         // CFA
    16871672                { $$ = $3->addQualifiers( $2 ); }
    1688 
    1689 // Temp, testing TreeStruct
    1690     | STRUCT TRY attribute_list_opt no_attr_identifier_or_type_name
    1691         {
    1692             typedefTable.makeTypedef( *$4 );            // create typedef
    1693             if ( forall ) typedefTable.changeKind( *$4, TypedefTable::TG ); // $
    1694             forall = false;                             // reset
    1695         }
    1696       '{' field_declaration_list '}'
    1697         {
    1698             $$ = DeclarationNode::newTreeStruct( DeclarationNode::Struct,
    1699                 $4, nullptr, nullptr, $7, true )->addQualifiers( $3 );
    1700         }
    1701     | STRUCT TRY attribute_list_opt no_attr_identifier_or_type_name TYPEDEFname
    1702         {
    1703             typedefTable.makeTypedef( *$4 );            // create typedef
    1704             if ( forall ) typedefTable.changeKind( *$4, TypedefTable::TG ); // $
    1705             forall = false;                             // reset
    1706         }
    1707       '{' field_declaration_list '}'
    1708         {
    1709             $$ = DeclarationNode::newTreeStruct( DeclarationNode::Struct,
    1710                 $4, $5, nullptr, $8, true )->addQualifiers( $3 );
    1711         }
    17121673        ;
    17131674
     
    19691930        | '=' initializer
    19701931                { $$ = $2; }
     1932        | '=' VOID
     1933                { $$ = nullptr; }
    19711934        | ATassign initializer
    19721935                { $$ = $2->set_maybeConstructed( false ); }
  • src/ResolvExpr/CurrentObject.cc

    r275f4b4 rcd7ef0b  
    3636                                return constExpr->get_constant()->get_ival();
    3737                        } else {
    38                                 assertf( false, "Non-integer constant expression in getConstValue", toString( constExpr ).c_str() ); // xxx - might be semantic error
     38                                assertf( false, "Non-integer constant expression in getConstValue %s", toString( constExpr ).c_str() ); // xxx - might be semantic error
    3939                        }
    4040                } else if ( dynamic_cast< OneType * >( constExpr->get_result() ) ) {
     
    176176                                setPosition( castExpr->get_arg() );
    177177                        } else if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( expr ) ) {
    178                                 assertf( dynamic_cast<EnumInstType *> ( varExpr->get_result() ), "ArrayIterator given variable that isn't an enum constant", toString( expr ).c_str() );
     178                                assertf( dynamic_cast<EnumInstType *> ( varExpr->get_result() ), "ArrayIterator given variable that isn't an enum constant : %s", toString( expr ).c_str() );
    179179                                index = 0; // xxx - get actual value of enum constant
    180180                        } else if ( dynamic_cast< SizeofExpr * >( expr ) || dynamic_cast< AlignofExpr * >( expr ) ) {
     
    518518                        curTypes = newTypes;
    519519                        newTypes.clear();
    520                         assertf( desigAlts.size() == curTypes.size(), "Designator alternatives (%d) and current types (%d) out of sync", desigAlts.size(), curTypes.size() );
     520                        assertf( desigAlts.size() == curTypes.size(), "Designator alternatives (%zu) and current types (%zu) out of sync", desigAlts.size(), curTypes.size() );
    521521                } // for
    522522                if ( desigAlts.size() > 1 ) {
  • src/ResolvExpr/Resolver.cc

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 12:17:01 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 23 17:23:14 2017
    13 // Update Count     : 211
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tus Aug  8 16:06:00 2017
     13// Update Count     : 212
    1414//
    1515
     
    7171                virtual void visit( ReturnStmt *returnStmt ) override;
    7272                virtual void visit( ThrowStmt *throwStmt ) override;
     73                virtual void visit( CatchStmt *catchStmt ) override;
    7374
    7475                virtual void visit( SingleInit *singleInit ) override;
     
    368369
    369370        void Resolver::visit( ThrowStmt *throwStmt ) {
     371                // TODO: Replace *exception type with &exception type.
    370372                if ( throwStmt->get_expr() ) {
    371                         Expression * wrapped = new CastExpr( throwStmt->get_expr(), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) );
     373                        StructDecl * exception_decl =
     374                                lookupStruct( "__cfaehm__base_exception_t" );
     375                        assert( exception_decl );
     376                        Expression * wrapped = new CastExpr(
     377                                throwStmt->get_expr(),
     378                                new PointerType(
     379                                        noQualifiers,
     380                                        new StructInstType(
     381                                                noQualifiers,
     382                                                exception_decl
     383                                                )
     384                                        )
     385                                );
    372386                        Expression * newExpr = findSingleExpression( wrapped, *this );
    373387                        throwStmt->set_expr( newExpr );
     388                }
     389        }
     390
     391        void Resolver::visit( CatchStmt *catchStmt ) {
     392                if ( catchStmt->get_cond() ) {
     393                        Expression * wrapped = new CastExpr(
     394                                catchStmt->get_cond(),
     395                                new BasicType( noQualifiers, BasicType::Bool )
     396                                );
     397                        catchStmt->set_cond( findSingleExpression( wrapped, *this ) );
    374398                }
    375399        }
  • src/SymTab/Validate.cc

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:50:04 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 30 16:50:13 2017
    13 // Update Count     : 357
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tus Aug  8 13:27:00 2017
     13// Update Count     : 358
    1414//
    1515
     
    686686                Type *designatorType = tyDecl->get_base()->stripDeclarator();
    687687                if ( StructInstType *aggDecl = dynamic_cast< StructInstType * >( designatorType ) ) {
    688                         return new StructDecl( aggDecl->get_name() );
     688                        return new StructDecl( aggDecl->get_name(), DeclarationNode::Struct, noAttributes, tyDecl->get_linkage() );
    689689                } else if ( UnionInstType *aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) {
    690                         return new UnionDecl( aggDecl->get_name() );
     690                        return new UnionDecl( aggDecl->get_name(), noAttributes, tyDecl->get_linkage() );
    691691                } else if ( EnumInstType *enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) {
    692                         return new EnumDecl( enumDecl->get_name() );
     692                        return new EnumDecl( enumDecl->get_name(), noAttributes, tyDecl->get_linkage() );
    693693                } else {
    694694                        return ret->clone();
     
    783783                                type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() );
    784784                        } // if
    785                         TypedefDeclPtr tyDecl( new TypedefDecl( aggDecl->get_name(), Type::StorageClasses(), type ) );
     785                        TypedefDeclPtr tyDecl( new TypedefDecl( aggDecl->get_name(), Type::StorageClasses(), type, aggDecl->get_linkage() ) );
    786786                        typedefNames[ aggDecl->get_name() ] = std::make_pair( std::move( tyDecl ), scopeLevel );
    787787                } // if
     
    903903                FunctionType * ftype = functionDecl->get_functionType();
    904904                std::list< DeclarationWithType * > & retVals = ftype->get_returnVals();
    905                 assertf( retVals.size() == 0 || retVals.size() == 1, "Function %s has too many return values: %d", functionDecl->get_name().c_str(), retVals.size() );
     905                assertf( retVals.size() == 0 || retVals.size() == 1, "Function %s has too many return values: %zu", functionDecl->get_name().c_str(), retVals.size() );
    906906                if ( retVals.size() == 1 ) {
    907907                        // ensure all function return values have a name - use the name of the function to disambiguate (this also provides a nice bit of help for debugging).
  • src/SynTree/AggregateDecl.cc

    r275f4b4 rcd7ef0b  
    1010// Created On       : Sun May 17 23:56:39 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jun 27 15:30:00 2017
    13 // Update Count     : 21
     12// Last Modified On : Fri Aug  4 14:22:00 2017
     13// Update Count     : 22
    1414//
    1515
     
    4040        using std::endl;
    4141
    42         os << typeString() << " " << get_name();
    43         os << string( indent+2, ' ' ) << "with body " << has_body() << endl;
     42        os << typeString() << " " << get_name() << ":";
     43        if ( get_linkage() != LinkageSpec::Cforall ) {
     44                os << " " << LinkageSpec::linkageName( get_linkage() );
     45        } // if
     46        os << " with body " << has_body() << endl;
    4447
    4548        if ( ! parameters.empty() ) {
  • src/SynTree/Declaration.cc

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 07:49:18 2017
    13 // Update Count     : 24
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  9 14:38:00 2017
     13// Update Count     : 25
    1414//
    1515
     
    2828
    2929Declaration::Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage )
    30                 : name( name ), storageClasses( scs ), linkage( linkage ), uniqueId( 0 ) {
     30                : name( name ), linkage( linkage ), storageClasses( scs ), uniqueId( 0 ) {
    3131}
    3232
    3333Declaration::Declaration( const Declaration &other )
    34         : BaseSyntaxNode( other ), name( other.name ), storageClasses( other.storageClasses ), linkage( other.linkage ), uniqueId( other.uniqueId ) {
     34        : BaseSyntaxNode( other ), name( other.name ), linkage( other.linkage ), extension( other.extension ), storageClasses( other.storageClasses ), uniqueId( other.uniqueId ) {
    3535}
    3636
  • src/SynTree/Declaration.h

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:52:59 2017
    13 // Update Count     : 124
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  9 14:45:00 2017
     13// Update Count     : 126
    1414//
    1515
     
    2727class Declaration : public BaseSyntaxNode {
    2828  public:
     29        std::string name;
     30        LinkageSpec::Spec linkage;
     31        bool extension = false;
     32
    2933        Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage );
    3034        Declaration( const Declaration &other );
     
    5357        static void dumpIds( std::ostream &os );
    5458        static Declaration *declFromId( UniqueId id );
    55   private:
    56         std::string name;
     59
     60  private:
    5761        Type::StorageClasses storageClasses;
    58         LinkageSpec::Spec linkage;
    5962        UniqueId uniqueId;
    60         bool extension = false;
    6163};
    6264
    6365class DeclarationWithType : public Declaration {
    6466  public:
    65         DeclarationWithType( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs );
    66         DeclarationWithType( const DeclarationWithType &other );
    67         virtual ~DeclarationWithType();
    68 
    69         std::string get_mangleName() const { return mangleName; }
    70         DeclarationWithType * set_mangleName( std::string newValue ) { mangleName = newValue; return this; }
    71 
    72         std::string get_scopedMangleName() const { return mangleName + "_" + std::to_string(scopeLevel); }
    73 
    74         int get_scopeLevel() const { return scopeLevel; }
    75         DeclarationWithType * set_scopeLevel( int newValue ) { scopeLevel = newValue; return this; }
    76 
    77         ConstantExpr *get_asmName() const { return asmName; }
    78         DeclarationWithType * set_asmName( ConstantExpr *newValue ) { asmName = newValue; return this; }
    79 
    80         std::list< Attribute * >& get_attributes() { return attributes; }
    81         const std::list< Attribute * >& get_attributes() const { return attributes; }
    82 
    83         Type::FuncSpecifiers get_funcSpec() const { return fs; }
    84         //void set_functionSpecifiers( Type::FuncSpecifiers newValue ) { fs = newValue; }
    85 
    86         virtual DeclarationWithType *clone() const = 0;
    87         virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
    88 
    89         virtual Type *get_type() const = 0;
    90         virtual void set_type(Type *) = 0;
    91   private:
    9267        // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2
    9368        std::string mangleName;
     
    9772        ConstantExpr *asmName;
    9873        std::list< Attribute * > attributes;
     74
     75        DeclarationWithType( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs );
     76        DeclarationWithType( const DeclarationWithType &other );
     77        virtual ~DeclarationWithType();
     78
     79        std::string get_mangleName() const { return mangleName; }
     80        DeclarationWithType * set_mangleName( std::string newValue ) { mangleName = newValue; return this; }
     81
     82        std::string get_scopedMangleName() const { return mangleName + "_" + std::to_string(scopeLevel); }
     83
     84        int get_scopeLevel() const { return scopeLevel; }
     85        DeclarationWithType * set_scopeLevel( int newValue ) { scopeLevel = newValue; return this; }
     86
     87        ConstantExpr *get_asmName() const { return asmName; }
     88        DeclarationWithType * set_asmName( ConstantExpr *newValue ) { asmName = newValue; return this; }
     89
     90        std::list< Attribute * >& get_attributes() { return attributes; }
     91        const std::list< Attribute * >& get_attributes() const { return attributes; }
     92
     93        Type::FuncSpecifiers get_funcSpec() const { return fs; }
     94        //void set_functionSpecifiers( Type::FuncSpecifiers newValue ) { fs = newValue; }
     95
     96        virtual DeclarationWithType *clone() const = 0;
     97        virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;
     98
     99        virtual Type *get_type() const = 0;
     100        virtual void set_type(Type *) = 0;
     101
     102  private:
    99103        Type::FuncSpecifiers fs;
    100104};
     
    103107        typedef DeclarationWithType Parent;
    104108  public:
     109        Type *type;
     110        Initializer *init;
     111        Expression *bitfieldWidth;
     112
    105113        ObjectDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Expression *bitfieldWidth, Type *type, Initializer *init,
    106114                                const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() );
     
    122130        virtual void print( std::ostream &os, int indent = 0 ) const;
    123131        virtual void printShort( std::ostream &os, int indent = 0 ) const;
    124   private:
    125         Type *type;
    126         Initializer *init;
    127         Expression *bitfieldWidth;
    128132};
    129133
     
    131135        typedef DeclarationWithType Parent;
    132136  public:
     137        FunctionType *type;
     138        CompoundStmt *statements;
     139
    133140        FunctionDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements,
    134141                                  const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() );
     
    149156        virtual void print( std::ostream &os, int indent = 0 ) const;
    150157        virtual void printShort( std::ostream &os, int indent = 0 ) const;
    151   private:
    152         FunctionType *type;
    153         CompoundStmt *statements;
    154158};
    155159
     
    157161        typedef Declaration Parent;
    158162  public:
     163        Type *base;
     164        std::list< TypeDecl* > parameters;
     165        std::list< DeclarationWithType* > assertions;
     166
    159167        NamedTypeDecl( const std::string &name, Type::StorageClasses scs, Type *type );
    160168        NamedTypeDecl( const NamedTypeDecl &other );
     
    171179        virtual void print( std::ostream &os, int indent = 0 ) const;
    172180        virtual void printShort( std::ostream &os, int indent = 0 ) const;
    173   protected:
    174   private:
    175         Type *base;
    176         std::list< TypeDecl* > parameters;
    177         std::list< DeclarationWithType* > assertions;
    178181};
    179182
     
    182185  public:
    183186        enum Kind { Any, Dtype, Ftype, Ttype };
     187
     188        Type * init;
     189        bool sized;
     190
    184191        /// Data extracted from a type decl
    185192        struct Data {
     
    216223  private:
    217224        Kind kind;
    218         Type * init;
    219         bool sized;
    220225};
    221226
     
    223228        typedef NamedTypeDecl Parent;
    224229  public:
    225         TypedefDecl( const std::string &name, Type::StorageClasses scs, Type *type ) : Parent( name, scs, type ) {}
     230        TypedefDecl( const std::string &name, Type::StorageClasses scs, Type *type, LinkageSpec::Spec spec = LinkageSpec::Cforall ) : Parent( name, scs, type ) { set_linkage( spec ); }
    226231        TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
    227232
     
    237242        typedef Declaration Parent;
    238243  public:
    239         AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );
    240         AggregateDecl( const AggregateDecl &other );
    241         virtual ~AggregateDecl();
    242 
    243         std::list<Declaration*>& get_members() { return members; }
    244         std::list<TypeDecl*>& get_parameters() { return parameters; }
    245 
    246         std::list< Attribute * >& get_attributes() { return attributes; }
    247         const std::list< Attribute * >& get_attributes() const { return attributes; }
    248 
    249         bool has_body() const { return body; }
    250         AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
    251 
    252         virtual void print( std::ostream &os, int indent = 0 ) const;
    253         virtual void printShort( std::ostream &os, int indent = 0 ) const;
    254   protected:
    255         virtual std::string typeString() const = 0;
    256 
    257   private:
    258244        std::list<Declaration*> members;
    259245        std::list<TypeDecl*> parameters;
    260246        bool body;
    261247        std::list< Attribute * > attributes;
     248
     249        AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );
     250        AggregateDecl( const AggregateDecl &other );
     251        virtual ~AggregateDecl();
     252
     253        std::list<Declaration*>& get_members() { return members; }
     254        std::list<TypeDecl*>& get_parameters() { return parameters; }
     255
     256        std::list< Attribute * >& get_attributes() { return attributes; }
     257        const std::list< Attribute * >& get_attributes() const { return attributes; }
     258
     259        bool has_body() const { return body; }
     260        AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
     261
     262        virtual void print( std::ostream &os, int indent = 0 ) const;
     263        virtual void printShort( std::ostream &os, int indent = 0 ) const;
     264  protected:
     265        virtual std::string typeString() const = 0;
    262266};
    263267
     
    333337class AsmDecl : public Declaration {
    334338  public:
     339        AsmStmt *stmt;
     340
    335341        AsmDecl( AsmStmt *stmt );
    336342        AsmDecl( const AsmDecl &other );
     
    345351        virtual void print( std::ostream &os, int indent = 0 ) const;
    346352        virtual void printShort( std::ostream &os, int indent = 0 ) const;
    347   private:
    348         AsmStmt *stmt;
    349353};
    350354
  • src/SynTree/Expression.h

    r275f4b4 rcd7ef0b  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Jul 24 16:27:00 2017
    13 // Update Count     : 43
     12// Last Modified On : Fri Aug  8 11:54:00 2017
     13// Update Count     : 44
    1414//
    1515
     
    2929class Expression : public BaseSyntaxNode{
    3030  public:
     31        Type * result;
     32        TypeSubstitution * env;
     33        Expression * argName; // if expression is used as an argument, it can be "designated" by this name
     34        bool extension = false;
     35
    3136        Expression( Expression * _aname = nullptr );
    3237        Expression( const Expression & other );
     
    4954        virtual Expression * acceptMutator( Mutator & m ) = 0;
    5055        virtual void print( std::ostream & os, int indent = 0 ) const;
    51   protected:
    52         Type * result;
    53         TypeSubstitution * env;
    54         Expression * argName; // if expression is used as an argument, it can be "designated" by this name
    55         bool extension = false;
    5656};
    5757
     
    7979class ApplicationExpr : public Expression {
    8080  public:
     81        Expression * function;
     82
    8183        ApplicationExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() );
    8284        ApplicationExpr( const ApplicationExpr & other );
     
    9294        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    9395        virtual void print( std::ostream & os, int indent = 0 ) const;
     96
    9497  private:
    95         Expression * function;
    9698        std::list<Expression *> args;
    9799        InferredParams inferParams;
     
    103105class UntypedExpr : public Expression {
    104106  public:
     107        Expression * function;
     108        std::list<Expression*> args;
     109
    105110        UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >(), Expression *_aname = nullptr );
    106111        UntypedExpr( const UntypedExpr & other );
     
    123128        virtual void print( std::ostream & os, int indent = 0 ) const;
    124129        virtual void printArgs(std::ostream & os, int indent = 0) const;
    125   private:
    126         Expression * function;
    127         std::list<Expression*> args;
    128130};
    129131
     
    131133class NameExpr : public Expression {
    132134  public:
     135        std::string name;
     136
    133137        NameExpr( std::string name, Expression *_aname = nullptr );
    134138        NameExpr( const NameExpr & other );
     
    142146        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    143147        virtual void print( std::ostream & os, int indent = 0 ) const;
    144   private:
    145         std::string name;
    146148};
    147149
     
    152154class AddressExpr : public Expression {
    153155  public:
     156        Expression * arg;
     157
    154158        AddressExpr( Expression * arg, Expression *_aname = nullptr );
    155159        AddressExpr( const AddressExpr & other );
     
    163167        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    164168        virtual void print( std::ostream & os, int indent = 0 ) const;
    165   private:
    166         Expression * arg;
    167169};
    168170
     
    170172class LabelAddressExpr : public Expression {
    171173  public:
     174        Expression * arg;
     175
    172176        LabelAddressExpr( Expression * arg );
    173177        LabelAddressExpr( const LabelAddressExpr & other );
     
    181185        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    182186        virtual void print( std::ostream & os, int indent = 0 ) const;
    183   private:
    184         Expression * arg;
    185187};
    186188
     
    188190class CastExpr : public Expression {
    189191  public:
     192        Expression * arg;
     193
    190194        CastExpr( Expression * arg, Expression *_aname = nullptr );
    191195        CastExpr( Expression * arg, Type * toType, Expression *_aname = nullptr );
     
    200204        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    201205        virtual void print( std::ostream & os, int indent = 0 ) const;
    202   private:
    203         Expression * arg;
    204206};
    205207
     
    207209class VirtualCastExpr : public Expression {
    208210  public:
     211        Expression * arg;
     212
    209213        VirtualCastExpr( Expression * arg, Type * toType );
    210214        VirtualCastExpr( const VirtualCastExpr & other );
     
    218222        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    219223        virtual void print( std::ostream & os, int indent = 0 ) const;
    220   private:
    221         Expression * arg;
    222224};
    223225
     
    225227class UntypedMemberExpr : public Expression {
    226228  public:
     229        Expression * member;
     230        Expression * aggregate;
     231
    227232        UntypedMemberExpr( Expression * member, Expression * aggregate, Expression *_aname = nullptr );
    228233        UntypedMemberExpr( const UntypedMemberExpr & other );
     
    238243        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    239244        virtual void print( std::ostream & os, int indent = 0 ) const;
    240   private:
    241         Expression * member;
    242         Expression * aggregate;
    243245};
    244246
     
    247249class MemberExpr : public Expression {
    248250  public:
     251        DeclarationWithType * member;
     252        Expression * aggregate;
     253
    249254        MemberExpr( DeclarationWithType * member, Expression * aggregate, Expression *_aname = nullptr );
    250255        MemberExpr( const MemberExpr & other );
     
    260265        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    261266        virtual void print( std::ostream & os, int indent = 0 ) const;
    262   private:
    263         DeclarationWithType * member;
    264         Expression * aggregate;
    265267};
    266268
     
    269271class VariableExpr : public Expression {
    270272  public:
     273        DeclarationWithType * var;
     274
    271275        VariableExpr( DeclarationWithType * var, Expression *_aname = nullptr );
    272276        VariableExpr( const VariableExpr & other );
     
    280284        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    281285        virtual void print( std::ostream & os, int indent = 0 ) const;
    282   private:
    283         DeclarationWithType * var;
    284286};
    285287
     
    287289class ConstantExpr : public Expression {
    288290  public:
     291        Constant constant;
     292
    289293        ConstantExpr( Constant constant, Expression *_aname = nullptr );
    290294        ConstantExpr( const ConstantExpr & other );
     
    298302        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    299303        virtual void print( std::ostream & os, int indent = 0 ) const;
    300   private:
    301         Constant constant;
    302304};
    303305
     
    305307class SizeofExpr : public Expression {
    306308  public:
     309        Expression * expr;
     310        Type * type;
     311        bool isType;
     312
    307313        SizeofExpr( Expression * expr, Expression *_aname = nullptr );
    308314        SizeofExpr( const SizeofExpr & other );
     
    321327        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    322328        virtual void print( std::ostream & os, int indent = 0 ) const;
    323   private:
     329};
     330
     331/// AlignofExpr represents an alignof expression
     332class AlignofExpr : public Expression {
     333  public:
    324334        Expression * expr;
    325335        Type * type;
    326336        bool isType;
    327 };
    328 
    329 /// AlignofExpr represents an alignof expression
    330 class AlignofExpr : public Expression {
    331   public:
     337
    332338        AlignofExpr( Expression * expr, Expression *_aname = nullptr );
    333339        AlignofExpr( const AlignofExpr & other );
     
    346352        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    347353        virtual void print( std::ostream & os, int indent = 0 ) const;
    348   private:
    349         Expression * expr;
    350         Type * type;
    351         bool isType;
    352354};
    353355
     
    355357class UntypedOffsetofExpr : public Expression {
    356358  public:
     359        Type * type;
     360        std::string member;
     361
    357362        UntypedOffsetofExpr( Type * type, const std::string & member, Expression *_aname = nullptr );
    358363        UntypedOffsetofExpr( const UntypedOffsetofExpr & other );
     
    368373        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    369374        virtual void print( std::ostream & os, int indent = 0 ) const;
    370   private:
    371         Type * type;
    372         std::string member;
    373375};
    374376
     
    376378class OffsetofExpr : public Expression {
    377379  public:
     380        Type * type;
     381        DeclarationWithType * member;
     382
    378383        OffsetofExpr( Type * type, DeclarationWithType * member, Expression *_aname = nullptr );
    379384        OffsetofExpr( const OffsetofExpr & other );
     
    389394        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    390395        virtual void print( std::ostream & os, int indent = 0 ) const;
    391   private:
    392         Type * type;
    393         DeclarationWithType * member;
    394396};
    395397
     
    397399class OffsetPackExpr : public Expression {
    398400public:
     401        StructInstType * type;
     402
    399403        OffsetPackExpr( StructInstType * type_, Expression * aname_ = 0 );
    400404        OffsetPackExpr( const OffsetPackExpr & other );
     
    407411        virtual void accept( Visitor & v ) { v.visit( this ); }
    408412        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    409 
    410         virtual void print( std::ostream & os, int indent = 0 ) const;
    411 
    412 private:
    413         StructInstType * type;
     413        virtual void print( std::ostream & os, int indent = 0 ) const;
    414414};
    415415
     
    417417class AttrExpr : public Expression {
    418418  public:
     419        Expression * attr;
     420        Expression * expr;
     421        Type * type;
     422        bool isType;
     423
    419424        AttrExpr(Expression * attr, Expression * expr, Expression *_aname = nullptr );
    420425        AttrExpr( const AttrExpr & other );
     
    435440        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    436441        virtual void print( std::ostream & os, int indent = 0 ) const;
    437   private:
    438         Expression * attr;
    439         Expression * expr;
    440         Type * type;
    441         bool isType;
    442442};
    443443
     
    445445class LogicalExpr : public Expression {
    446446  public:
     447        Expression * arg1;
     448        Expression * arg2;
     449
    447450        LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true, Expression *_aname = nullptr );
    448451        LogicalExpr( const LogicalExpr & other );
     
    459462        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    460463        virtual void print( std::ostream & os, int indent = 0 ) const;
     464
    461465  private:
     466        bool isAnd;
     467};
     468
     469/// ConditionalExpr represents the three-argument conditional ( p ? a : b )
     470class ConditionalExpr : public Expression {
     471  public:
    462472        Expression * arg1;
    463473        Expression * arg2;
    464         bool isAnd;
    465 };
    466 
    467 /// ConditionalExpr represents the three-argument conditional ( p ? a : b )
    468 class ConditionalExpr : public Expression {
    469   public:
     474        Expression * arg3;
     475
    470476        ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3, Expression *_aname = nullptr );
    471477        ConditionalExpr( const ConditionalExpr & other );
     
    483489        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    484490        virtual void print( std::ostream & os, int indent = 0 ) const;
    485   private:
     491};
     492
     493/// CommaExpr represents the sequence operator ( a, b )
     494class CommaExpr : public Expression {
     495  public:
    486496        Expression * arg1;
    487497        Expression * arg2;
    488         Expression * arg3;
    489 };
    490 
    491 /// CommaExpr represents the sequence operator ( a, b )
    492 class CommaExpr : public Expression {
    493   public:
     498
    494499        CommaExpr( Expression * arg1, Expression * arg2, Expression *_aname = nullptr );
    495500        CommaExpr( const CommaExpr & other );
     
    505510        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    506511        virtual void print( std::ostream & os, int indent = 0 ) const;
    507   private:
    508         Expression * arg1;
    509         Expression * arg2;
    510512};
    511513
     
    513515class TypeExpr : public Expression {
    514516  public:
     517        Type * type;
     518
    515519        TypeExpr( Type * type );
    516520        TypeExpr( const TypeExpr & other );
     
    524528        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    525529        virtual void print( std::ostream & os, int indent = 0 ) const;
    526   private:
    527         Type * type;
    528530};
    529531
     
    531533class AsmExpr : public Expression {
    532534  public:
     535        Expression * inout;
     536        ConstantExpr * constraint;
     537        Expression * operand;
     538
    533539        AsmExpr( Expression * inout, ConstantExpr * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {}
    534540        AsmExpr( const AsmExpr & other );
     
    548554        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    549555        virtual void print( std::ostream & os, int indent = 0 ) const;
    550   private:
     556
    551557        // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints
    552         Expression * inout;
    553         ConstantExpr * constraint;
    554         Expression * operand;
    555558};
    556559
     
    559562class ImplicitCopyCtorExpr : public Expression {
    560563public:
    561         ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
    562         ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
    563         virtual ~ImplicitCopyCtorExpr();
    564 
    565         ApplicationExpr * get_callExpr() const { return callExpr; }
    566         void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
    567 
    568         std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
    569         std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
    570         std::list< Expression * > & get_dtors() { return dtors; }
    571 
    572         virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
    573         virtual void accept( Visitor & v ) { v.visit( this ); }
    574         virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    575         virtual void print( std::ostream & os, int indent = 0 ) const;
    576   private:
    577564        ApplicationExpr * callExpr;
    578565        std::list< ObjectDecl * > tempDecls;
    579566        std::list< ObjectDecl * > returnDecls;
    580567        std::list< Expression * > dtors;
     568
     569        ImplicitCopyCtorExpr( ApplicationExpr * callExpr );
     570        ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );
     571        virtual ~ImplicitCopyCtorExpr();
     572
     573        ApplicationExpr * get_callExpr() const { return callExpr; }
     574        void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }
     575
     576        std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }
     577        std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }
     578        std::list< Expression * > & get_dtors() { return dtors; }
     579
     580        virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }
     581        virtual void accept( Visitor & v ) { v.visit( this ); }
     582        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
     583        virtual void print( std::ostream & os, int indent = 0 ) const;
    581584};
    582585
     
    584587class ConstructorExpr : public Expression {
    585588public:
     589        Expression * callExpr;
     590
    586591        ConstructorExpr( Expression * callExpr );
    587592        ConstructorExpr( const ConstructorExpr & other );
     
    595600        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    596601        virtual void print( std::ostream & os, int indent = 0 ) const;
    597 private:
    598         Expression * callExpr;
    599602};
    600603
     
    602605class CompoundLiteralExpr : public Expression {
    603606  public:
     607        Initializer * initializer;
     608
    604609        CompoundLiteralExpr( Type * type, Initializer * initializer );
    605610        CompoundLiteralExpr( const CompoundLiteralExpr & other );
     
    613618        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    614619        virtual void print( std::ostream & os, int indent = 0 ) const;
    615   private:
    616         Initializer * initializer;
    617620};
    618621
     
    620623class RangeExpr : public Expression {
    621624  public:
     625        Expression * low, * high;
     626
    622627        RangeExpr( Expression * low, Expression * high );
    623628        RangeExpr( const RangeExpr & other );
     
    632637        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    633638        virtual void print( std::ostream & os, int indent = 0 ) const;
    634   private:
    635         Expression * low, * high;
    636639};
    637640
     
    639642class UntypedTupleExpr : public Expression {
    640643  public:
     644        std::list<Expression*> exprs;
     645
    641646        UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
    642647        UntypedTupleExpr( const UntypedTupleExpr & other );
     
    649654        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    650655        virtual void print( std::ostream & os, int indent = 0 ) const;
    651   private:
    652         std::list<Expression*> exprs;
    653656};
    654657
     
    656659class TupleExpr : public Expression {
    657660  public:
     661        std::list<Expression*> exprs;
     662
    658663        TupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr );
    659664        TupleExpr( const TupleExpr & other );
     
    666671        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    667672        virtual void print( std::ostream & os, int indent = 0 ) const;
    668   private:
    669         std::list<Expression*> exprs;
    670673};
    671674
     
    673676class TupleIndexExpr : public Expression {
    674677  public:
     678        Expression * tuple;
     679        unsigned int index;
     680
    675681        TupleIndexExpr( Expression * tuple, unsigned int index );
    676682        TupleIndexExpr( const TupleIndexExpr & other );
     
    686692        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    687693        virtual void print( std::ostream & os, int indent = 0 ) const;
    688   private:
    689         Expression * tuple;
    690         unsigned int index;
    691694};
    692695
     
    694697class TupleAssignExpr : public Expression {
    695698  public:
     699        StmtExpr * stmtExpr = nullptr;
     700
    696701        TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr );
    697702        TupleAssignExpr( const TupleAssignExpr & other );
     
    705710        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    706711        virtual void print( std::ostream & os, int indent = 0 ) const;
    707   private:
    708         StmtExpr * stmtExpr = nullptr;
    709712};
    710713
     
    712715class StmtExpr : public Expression {
    713716public:
     717        CompoundStmt * statements;
     718        std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
     719        std::list< Expression * > dtors; // destructor(s) for return variable(s)
     720
    714721        StmtExpr( CompoundStmt * statements );
    715722        StmtExpr( const StmtExpr & other );
     
    726733        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    727734        virtual void print( std::ostream & os, int indent = 0 ) const;
    728 private:
    729         CompoundStmt * statements;
    730         std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression
    731         std::list< Expression * > dtors; // destructor(s) for return variable(s)
    732735};
    733736
    734737class UniqueExpr : public Expression {
    735738public:
     739        Expression * expr;
     740        ObjectDecl * object;
     741        VariableExpr * var;
     742
    736743        UniqueExpr( Expression * expr, long long idVal = -1 );
    737744        UniqueExpr( const UniqueExpr & other );
     
    753760        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    754761        virtual void print( std::ostream & os, int indent = 0 ) const;
     762
    755763private:
    756         Expression * expr;
    757         ObjectDecl * object;
    758         VariableExpr * var;
    759764        int id;
    760765        static long long count;
     
    773778class UntypedInitExpr : public Expression {
    774779public:
     780        Expression * expr;
     781        std::list<InitAlternative> initAlts;
     782
    775783        UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts );
    776784        UntypedInitExpr( const UntypedInitExpr & other );
     
    786794        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    787795        virtual void print( std::ostream & os, int indent = 0 ) const;
    788 private:
    789         Expression * expr;
    790         std::list<InitAlternative> initAlts;
    791796};
    792797
    793798class InitExpr : public Expression {
    794799public:
     800        Expression * expr;
     801        Designation * designation;
     802
    795803        InitExpr( Expression * expr, Designation * designation );
    796804        InitExpr( const InitExpr & other );
     
    807815        virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }
    808816        virtual void print( std::ostream & os, int indent = 0 ) const;
    809 private:
    810         Expression * expr;
    811         Designation * designation;
    812817};
    813818
  • src/SynTree/Initializer.cc

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri May 13 13:23:03 2016
    13 // Update Count     : 28
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Aug  3 11:33:00 2016
     13// Update Count     : 29
    1414//
    1515
     
    7474                        }
    7575                }
    76                 assertf( initializers.size() == designations.size(), "Created ListInit with mismatching initializers (%d) and designations (%d)", initializers.size(), designations.size() );
     76                assertf( initializers.size() == designations.size(), "Created ListInit with mismatching initializers (%lu) and designations (%lu)", initializers.size(), designations.size() );
    7777}
    7878
  • src/SynTree/Initializer.h

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:52:02 2017
    13 // Update Count     : 21
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  9 10:19:00 2017
     13// Update Count     : 22
    1414//
    1515
     
    2727class Designation : public BaseSyntaxNode {
    2828public:
     29        std::list< Expression * > designators;
     30
    2931        Designation( const std::list< Expression * > & designators );
    3032        Designation( const Designation & other );
     
    3739        virtual Designation * acceptMutator( Mutator &m ) { return m.mutate( this ); }
    3840        virtual void print( std::ostream &os, int indent = 0 ) const;
    39 private:
    40         std::list< Expression * > designators;
    4141};
    4242
     
    6363class SingleInit : public Initializer {
    6464  public:
     65        //Constant *value;
     66        Expression *value;      // has to be a compile-time constant
     67
    6568        SingleInit( Expression *value, bool maybeConstructed = false );
    6669        SingleInit( const SingleInit &other );
     
    7477        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    7578        virtual void print( std::ostream &os, int indent = 0 ) const;
    76   private:
    77         //Constant *value;
    78         Expression *value;      // has to be a compile-time constant
    7979};
    8080
     
    8383class ListInit : public Initializer {
    8484  public:
     85        std::list<Initializer *> initializers;  // order *is* important
     86        std::list<Designation *> designations;  // order/length is consistent with initializers
     87
    8588        ListInit( const std::list<Initializer*> &initializers,
    8689                          const std::list<Designation *> &designators = {}, bool maybeConstructed = false );
     
    102105        virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    103106        virtual void print( std::ostream &os, int indent = 0 ) const;
    104   private:
    105         std::list<Initializer *> initializers;  // order *is* important
    106         std::list<Designation *> designations;  // order/length is consistent with initializers
    107107};
    108108
     
    113113class ConstructorInit : public Initializer {
    114114  public:
     115        Statement * ctor;
     116        Statement * dtor;
     117
    115118        ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init );
    116119        ConstructorInit( const ConstructorInit &other );
     
    130133
    131134  private:
    132         Statement * ctor;
    133         Statement * dtor;
    134135        // C-style initializer made up of SingleInit and ListInit nodes to use as a fallback
    135136        // if an appropriate constructor definition is not found by the resolver
  • src/SynTree/NamedTypeDecl.cc

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 07:49:44 2017
    13 // Update Count     : 13
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  9 13:28:00 2017
     13// Update Count     : 14
    1414//
    1515
     
    3838        if ( get_name() != "" ) {
    3939                os << get_name() << ": ";
     40        } // if
     41        if ( get_linkage() != LinkageSpec::Cforall ) {
     42                os << LinkageSpec::linkageName( get_linkage() ) << " ";
    4043        } // if
    4144        get_storageClasses().print( os );
  • src/SynTree/Statement.h

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:54:32 2017
    13 // Update Count     : 68
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Aug  3 14:08:00 2017
     13// Update Count     : 69
    1414//
    1515
     
    2626class Statement : public BaseSyntaxNode {
    2727  public:
     28        std::list<Label> labels;
     29
    2830        Statement( std::list<Label> labels );
    2931        virtual ~Statement();
     
    3638        virtual Statement *acceptMutator( Mutator &m ) = 0;
    3739        virtual void print( std::ostream &os, int indent = 0 ) const;
    38   protected:
    39         std::list<Label> labels;
    4040};
    4141
    4242class CompoundStmt : public Statement {
    4343  public:
     44        std::list<Statement*> kids;
     45
    4446        CompoundStmt( std::list<Label> labels );
    4547        CompoundStmt( const CompoundStmt &other );
     
    5456        virtual CompoundStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    5557        virtual void print( std::ostream &os, int indent = 0 ) const;
    56   private:
    57         std::list<Statement*> kids;
    5858};
    5959
     
    6767        virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    6868        virtual void print( std::ostream &os, int indent = 0 ) const;
    69 
    70   private:
    7169};
    7270
    7371class ExprStmt : public Statement {
    7472  public:
     73        Expression *expr;
     74
    7575        ExprStmt( std::list<Label> labels, Expression *expr );
    7676        ExprStmt( const ExprStmt &other );
     
    8484        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    8585        virtual void print( std::ostream &os, int indent = 0 ) const;
    86   private:
    87         Expression *expr;
    8886};
    8987
    9088class AsmStmt : public Statement {
    9189  public:
     90        bool voltile;
     91        ConstantExpr *instruction;
     92        std::list<Expression *> output, input;
     93        std::list<ConstantExpr *> clobber;
     94        std::list<Label> gotolabels;
     95
    9296        AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr *instruction, std::list<Expression *> input, std::list<Expression *> output, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );
    9397        AsmStmt( const AsmStmt &other );
     
    111115        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    112116        virtual void print( std::ostream &os, int indent = 0 ) const;
    113   private:
    114         bool voltile;
    115         ConstantExpr *instruction;
    116         std::list<Expression *> output, input;
    117         std::list<ConstantExpr *> clobber;
    118         std::list<Label> gotolabels;
    119117};
    120118
    121119class IfStmt : public Statement {
    122120  public:
     121        Expression *condition;
     122        Statement *thenPart;
     123        Statement *elsePart;
     124
    123125        IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart );
    124126        IfStmt( const IfStmt &other );
     
    136138        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    137139        virtual void print( std::ostream &os, int indent = 0 ) const;
    138   private:
    139         Expression *condition;
    140         Statement *thenPart;
    141         Statement *elsePart;
    142140};
    143141
    144142class SwitchStmt : public Statement {
    145143  public:
     144        Expression * condition;
     145
    146146        SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements );
    147147        SwitchStmt( const SwitchStmt &other );
     
    159159        virtual void print( std::ostream &os, int indent = 0 ) const;
    160160  private:
     161        std::list<Statement *> statements;
     162};
     163
     164class CaseStmt : public Statement {
     165  public:
    161166        Expression * condition;
    162         std::list<Statement *> statements;
    163 };
    164 
    165 class CaseStmt : public Statement {
    166   public:
     167        std::list<Statement *> stmts;
     168
    167169        CaseStmt( std::list<Label> labels, Expression *conditions, std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError);
    168170        CaseStmt( const CaseStmt &other );
     
    186188        virtual void print( std::ostream &os, int indent = 0 ) const;
    187189  private:
    188         Expression * condition;
    189         std::list<Statement *> stmts;
    190190        bool _isDefault;
    191191};
     
    193193class WhileStmt : public Statement {
    194194  public:
     195        Expression *condition;
     196        Statement *body;
     197        bool isDoWhile;
     198
    195199        WhileStmt( std::list<Label> labels, Expression *condition,
    196200               Statement *body, bool isDoWhile = false );
     
    209213        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    210214        virtual void print( std::ostream &os, int indent = 0 ) const;
    211   private:
     215};
     216
     217class ForStmt : public Statement {
     218  public:
     219        std::list<Statement *> initialization;
    212220        Expression *condition;
     221        Expression *increment;
    213222        Statement *body;
    214         bool isDoWhile;
    215 };
    216 
    217 class ForStmt : public Statement {
    218   public:
     223
    219224        ForStmt( std::list<Label> labels, std::list<Statement *> initialization,
    220225             Expression *condition = 0, Expression *increment = 0, Statement *body = 0 );
     
    235240        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    236241        virtual void print( std::ostream &os, int indent = 0 ) const;
    237   private:
    238         std::list<Statement *> initialization;
    239         Expression *condition;
    240         Expression *increment;
    241         Statement *body;
    242242};
    243243
     
    245245  public:
    246246        enum Type { Goto = 0, Break, Continue };
     247
     248        // originalTarget kept for error messages.
     249        const Label originalTarget;
     250        Label target;
     251        Expression *computedTarget;
     252        Type type;
    247253
    248254        BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError);
     
    265271  private:
    266272        static const char *brType[];
    267         Label originalTarget;  // can give better error messages if we remember the label name that the user entered
    268         Label target;
    269         Expression *computedTarget;
    270         Type type;
    271273};
    272274
    273275class ReturnStmt : public Statement {
    274276  public:
     277        Expression *expr;
     278
    275279        ReturnStmt( std::list<Label> labels, Expression *expr );
    276280        ReturnStmt( const ReturnStmt &other );
     
    284288        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    285289        virtual void print( std::ostream &os, int indent = 0 ) const;
    286   private:
    287         Expression *expr;
    288290};
    289291
     
    291293  public:
    292294        enum Kind { Terminate, Resume };
     295
     296        const Kind kind;
     297        Expression * expr;
     298        Expression * target;
    293299
    294300        ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target = nullptr );
     
    306312        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    307313        virtual void print( std::ostream &os, int indent = 0 ) const;
    308   private:
    309         Kind kind;
    310         Expression * expr;
    311         Expression * target;
    312314};
    313315
    314316class TryStmt : public Statement {
    315317  public:
     318        CompoundStmt *block;
     319        std::list<CatchStmt *> handlers;
     320        FinallyStmt *finallyBlock;
     321
    316322        TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );
    317323        TryStmt( const TryStmt &other );
     
    329335        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    330336        virtual void print( std::ostream &os, int indent = 0 ) const;
    331 
    332   private:
    333         CompoundStmt *block;
    334         std::list<CatchStmt *> handlers;
    335         FinallyStmt *finallyBlock;
    336337};
    337338
     
    339340  public:
    340341        enum Kind { Terminate, Resume };
     342
     343        const Kind kind;
     344        Declaration *decl;
     345        Expression *cond;
     346        Statement *body;
    341347
    342348        CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl,
     
    357363        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    358364        virtual void print( std::ostream &os, int indent = 0 ) const;
    359 
    360   private:
    361         Kind kind;
    362         Declaration *decl;
    363         Expression *cond;
    364         Statement *body;
    365365};
    366366
    367367class FinallyStmt : public Statement {
    368368  public:
     369        CompoundStmt *block;
     370
    369371        FinallyStmt( std::list<Label> labels, CompoundStmt *block );
    370372        FinallyStmt( const FinallyStmt &other );
     
    378380        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    379381        virtual void print( std::ostream &os, int indent = 0 ) const;
    380   private:
    381         CompoundStmt *block;
    382382};
    383383
     
    386386class DeclStmt : public Statement {
    387387  public:
     388        Declaration *decl;
     389
    388390        DeclStmt( std::list<Label> labels, Declaration *decl );
    389391        DeclStmt( const DeclStmt &other );
     
    397399        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    398400        virtual void print( std::ostream &os, int indent = 0 ) const;
    399   private:
    400         Declaration *decl;
    401401};
    402402
     
    407407class ImplicitCtorDtorStmt : public Statement {
    408408  public:
     409        // Non-owned pointer to the constructor/destructor statement
     410        Statement * callStmt;
     411
    409412        ImplicitCtorDtorStmt( Statement * callStmt );
    410413        ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other );
     
    418421        virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); }
    419422        virtual void print( std::ostream &os, int indent = 0 ) const;
    420 
    421   private:
    422         // Non-owned pointer to the constructor/destructor statement
    423         Statement * callStmt;
    424423};
    425424
  • src/SynTree/Type.cc

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 17 08:42:47 2017
    13 // Update Count     : 28
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  2 11:11:00 2017
     13// Update Count     : 29
    1414//
    1515
     
    8888}
    8989
     90// Empty Variable declarations:
     91const Type::FuncSpecifiers noFuncSpecifiers;
     92const Type::StorageClasses noStorageClasses;
     93const Type::Qualifiers noQualifiers;
     94
    9095std::ostream & operator<<( std::ostream & out, const Type * type ) {
    9196        if ( type ) {
  • src/SynTree/Type.h

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:53:29 2017
    13 // Update Count     : 151
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  9 14:25:00 2017
     13// Update Count     : 152
    1414//
    1515
     
    127127        }; // Qualifiers
    128128
     129        typedef std::list<TypeDecl *> ForallList;
     130
     131        Qualifiers tq;
     132        ForallList forall;
     133        std::list< Attribute * > attributes;
     134
    129135        Type( const Qualifiers & tq, const std::list< Attribute * > & attributes );
    130136        Type( const Type & other );
     
    145151        void set_atomic( bool newValue ) { tq.is_atomic = newValue; }
    146152
    147         typedef std::list<TypeDecl *> ForallList;
    148153        ForallList& get_forall() { return forall; }
    149154
     
    165170        virtual Type *acceptMutator( Mutator & m ) = 0;
    166171        virtual void print( std::ostream & os, int indent = 0 ) const;
    167   private:
    168         Qualifiers tq;
    169         ForallList forall;
    170         std::list< Attribute * > attributes;
    171 };
    172 
    173 extern Type::Qualifiers noQualifiers;                           // no qualifiers on constants
     172};
     173
     174extern const Type::FuncSpecifiers noFuncSpecifiers;
     175extern const Type::StorageClasses noStorageClasses;
     176extern const Type::Qualifiers noQualifiers;                     // no qualifiers on constants
    174177
    175178class VoidType : public Type {
     
    211214                LongDoubleImaginary,
    212215                NUMBER_OF_BASIC_TYPES
    213         };
     216        } kind;
    214217
    215218        static const char *typeNames[];                                         // string names for basic types, MUST MATCH with Kind
     
    226229
    227230        bool isInteger() const;
    228   private:
    229         Kind kind;
    230231};
    231232
    232233class PointerType : public Type {
    233234  public:
     235        Type *base;
     236
     237        // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
     238        Expression *dimension;
     239        bool isVarLen;
     240        bool isStatic;
     241
    234242        PointerType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    235243        PointerType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
     
    252260        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
    253261        virtual void print( std::ostream & os, int indent = 0 ) const;
    254   private:
     262};
     263
     264class ArrayType : public Type {
     265  public:
    255266        Type *base;
    256 
    257         // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )
    258267        Expression *dimension;
    259268        bool isVarLen;
    260269        bool isStatic;
    261 };
    262 
    263 class ArrayType : public Type {
    264   public:
     270
    265271        ArrayType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    266272        ArrayType( const ArrayType& );
     
    282288        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
    283289        virtual void print( std::ostream & os, int indent = 0 ) const;
    284   private:
    285         Type *base;
    286         Expression *dimension;
    287         bool isVarLen;
    288         bool isStatic;
    289290};
    290291
    291292class FunctionType : public Type {
    292293  public:
     294        std::list<DeclarationWithType*> returnVals;
     295        std::list<DeclarationWithType*> parameters;
     296
     297        // Does the function accept a variable number of arguments following the arguments specified in the parameters list.
     298        // This could be because of
     299        // - an ellipsis in a prototype declaration
     300        // - an unprototyped declaration
     301        bool isVarArgs;
     302
    293303        FunctionType( const Type::Qualifiers & tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    294304        FunctionType( const FunctionType& );
     
    305315        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
    306316        virtual void print( std::ostream & os, int indent = 0 ) const;
    307   private:
    308         std::list<DeclarationWithType*> returnVals;
    309         std::list<DeclarationWithType*> parameters;
    310 
    311         // Does the function accept a variable number of arguments following the arguments specified in the parameters list.
    312         // This could be because of
    313         // - an ellipsis in a prototype declaration
    314         // - an unprototyped declaration
    315         bool isVarArgs;
    316317};
    317318
    318319class ReferenceToType : public Type {
    319320  public:
     321        std::list< Expression* > parameters;
     322        std::string name;
     323        bool hoistType;
     324
    320325        ReferenceToType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes );
    321326        ReferenceToType( const ReferenceToType & other );
     
    336341  protected:
    337342        virtual std::string typeString() const = 0;
    338         std::list< Expression* > parameters;
    339         std::string name;
    340   private:
    341         bool hoistType;
    342343};
    343344
     
    345346        typedef ReferenceToType Parent;
    346347  public:
     348        // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
     349        // where the structure used in this type is actually defined
     350        StructDecl *baseStruct;
     351
    347352        StructInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseStruct( 0 ) {}
    348353        StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
     
    368373  private:
    369374        virtual std::string typeString() const;
    370 
    371         // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,
    372         // where the structure used in this type is actually defined
    373         StructDecl *baseStruct;
    374375};
    375376
     
    377378        typedef ReferenceToType Parent;
    378379  public:
     380        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
     381        // where the union used in this type is actually defined
     382        UnionDecl *baseUnion;
     383
    379384        UnionInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ), baseUnion( 0 ) {}
    380385        UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
     
    400405  private:
    401406        virtual std::string typeString() const;
    402 
     407};
     408
     409class EnumInstType : public ReferenceToType {
     410        typedef ReferenceToType Parent;
     411  public:
    403412        // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
    404413        // where the union used in this type is actually defined
    405         UnionDecl *baseUnion;
    406 };
    407 
    408 class EnumInstType : public ReferenceToType {
    409         typedef ReferenceToType Parent;
    410   public:
     414        EnumDecl *baseEnum = nullptr;
     415
    411416        EnumInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ) {}
    412417        EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
     
    423428  private:
    424429        virtual std::string typeString() const;
    425 
    426         // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,
    427         // where the union used in this type is actually defined
    428         EnumDecl *baseEnum = nullptr;
    429430};
    430431
     
    432433        typedef ReferenceToType Parent;
    433434  public:
     435        // this member is filled in by the validate pass, which instantiates the members of the correponding
     436        // aggregate with the actual type parameters specified for this use of the context
     437        std::list< Declaration* > members;
     438
    434439        TraitInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >()  ) : Parent( tq, name, attributes ) {}
    435440        TraitInstType( const TraitInstType & other );
     
    445450  private:
    446451        virtual std::string typeString() const;
    447 
    448         // this member is filled in by the validate pass, which instantiates the members of the correponding
    449         // aggregate with the actual type parameters specified for this use of the context
    450         std::list< Declaration* > members;
    451452};
    452453
     
    454455        typedef ReferenceToType Parent;
    455456  public:
     457        // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
     458        // where the type used here is actually defined
     459        TypeDecl *baseType;
     460        bool isFtype;
     461
    456462        TypeInstType( const Type::Qualifiers & tq, const std::string & name, TypeDecl *baseType, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
    457463        TypeInstType( const Type::Qualifiers & tq, const std::string & name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
     
    472478  private:
    473479        virtual std::string typeString() const;
    474         // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,
    475         // where the type used here is actually defined
    476         TypeDecl *baseType;
    477         bool isFtype;
    478480};
    479481
    480482class TupleType : public Type {
    481483  public:
     484        std::list<Type *> types;
     485        std::list<Declaration *> members;
     486
    482487        TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
    483488        TupleType( const TupleType& );
     
    508513        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
    509514        virtual void print( std::ostream & os, int indent = 0 ) const;
    510   private:
    511         std::list<Type *> types;
    512         std::list<Declaration *> members;
    513515};
    514516
    515517class TypeofType : public Type {
    516518  public:
     519        Expression *expr;
     520
    517521        TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
    518522        TypeofType( const TypeofType& );
     
    528532        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
    529533        virtual void print( std::ostream & os, int indent = 0 ) const;
    530   private:
     534};
     535
     536class AttrType : public Type {
     537  public:
     538        std::string name;
    531539        Expression *expr;
    532 };
    533 
    534 class AttrType : public Type {
    535   public:
     540        Type *type;
     541        bool isType;
     542
    536543        AttrType( const Type::Qualifiers & tq, const std::string & name, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() );
    537544        AttrType( const Type::Qualifiers & tq, const std::string & name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >()  );
     
    554561        virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); }
    555562        virtual void print( std::ostream & os, int indent = 0 ) const;
    556   private:
    557         std::string name;
    558         Expression *expr;
    559         Type *type;
    560         bool isType;
    561563};
    562564
  • src/SynTree/TypeDecl.cc

    r275f4b4 rcd7ef0b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 07:49:58 2017
    13 // Update Count     : 5
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Wed Aug  9 14:35:00 2017
     13// Update Count     : 6
    1414//
    1515
     
    1818#include "Common/utility.h"
    1919
    20 TypeDecl::TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, Type * init ) : Parent( name, scs, type ), kind( kind ), init( init ), sized( kind == Any || kind == Ttype ) {
     20TypeDecl::TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, Type * init ) : Parent( name, scs, type ), init( init ), sized( kind == Any || kind == Ttype ), kind( kind ) {
    2121}
    2222
    23 TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), kind( other.kind ), init( maybeClone( other.init ) ), sized( other.sized ) {
     23TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), init( maybeClone( other.init ) ), sized( other.sized ), kind( other.kind ) {
    2424}
    2525
  • src/SynTree/TypeExpr.cc

    r275f4b4 rcd7ef0b  
    2121}
    2222
    23 TypeExpr::TypeExpr( const TypeExpr &other ) : type( maybeClone( other.type ) ) {
     23TypeExpr::TypeExpr( const TypeExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) {
    2424}
    2525
  • src/Tuples/TupleExpansion.cc

    r275f4b4 rcd7ef0b  
    6666                };
    6767
    68                 class TupleTypeReplacer : public GenPoly::DeclMutator {
    69                   public:
    70                         typedef GenPoly::DeclMutator Parent;
    71                         using Parent::mutate;
    72 
    73                         virtual Type * mutate( TupleType * tupleType ) override;
    74 
    75                         virtual CompoundStmt * mutate( CompoundStmt * stmt ) override {
    76                                 typeMap.beginScope();
    77                                 stmt = Parent::mutate( stmt );
    78                                 typeMap.endScope();
    79                                 return stmt;
     68                struct TupleTypeReplacer : public WithDeclsToAdd, public WithGuards, public WithTypeSubstitution {
     69                        Type * postmutate( TupleType * tupleType );
     70
     71                        void premutate( CompoundStmt * ) {
     72                                GuardScope( typeMap );
    8073                        }
    8174                  private:
     
    111104                mutateAll( translationUnit, assnExpander );
    112105
    113                 TupleTypeReplacer replacer;
    114                 replacer.mutateDeclarationList( translationUnit );
     106                PassVisitor<TupleTypeReplacer> replacer;
     107                mutateAll( translationUnit, replacer );
    115108
    116109                PassVisitor<TupleIndexExpander> idxExpander;
     
    218211        }
    219212
    220         Type * TupleTypeReplacer::mutate( TupleType * tupleType ) {
    221                 tupleType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) );
     213        Type * TupleTypeReplacer::postmutate( TupleType * tupleType ) {
    222214                unsigned tupleSize = tupleType->size();
    223215                if ( ! typeMap.count( tupleSize ) ) {
     
    226218                        decl->set_body( true );
    227219                        for ( size_t i = 0; i < tupleSize; ++i ) {
    228                                 TypeDecl * tyParam = new TypeDecl( toString( "tuple_param_", i ), Type::StorageClasses(), nullptr, TypeDecl::Any );
     220                                TypeDecl * tyParam = new TypeDecl( toString( "tuple_param_", tupleSize, "_", i ), Type::StorageClasses(), nullptr, TypeDecl::Any );
    229221                                decl->get_members().push_back( new ObjectDecl( toString("field_", i ), Type::StorageClasses(), LinkageSpec::C, nullptr, new TypeInstType( Type::Qualifiers(), tyParam->get_name(), tyParam ), nullptr ) );
    230222                                decl->get_parameters().push_back( tyParam );
     
    235227                        }
    236228                        typeMap[tupleSize] = decl;
    237                         addDeclaration( decl );
     229                        declsToAddBefore.push_back( decl );
    238230                }
    239231                Type::Qualifiers qualifiers = tupleType->get_qualifiers();
     
    241233                StructDecl * decl = typeMap[tupleSize];
    242234                StructInstType * newType = new StructInstType( qualifiers, decl );
    243                 for ( Type * t : *tupleType ) {
     235                for ( auto p : group_iterate( tupleType->get_types(), decl->get_parameters() ) ) {
     236                        Type * t = std::get<0>(p);
     237                        TypeDecl * td = std::get<1>(p);
    244238                        newType->get_parameters().push_back( new TypeExpr( t->clone() ) );
     239                        if ( env ) {
     240                                // add bindings to the type environment.
     241                                // xxx - This may not be sufficient, it may be necessary to rename type variables on StructInstType?
     242                                env->add( td->get_name(), t->clone() );
     243                        }
    245244                }
    246245                delete tupleType;
  • src/Virtual/ExpandCasts.cc

    r275f4b4 rcd7ef0b  
    1010// Created On       : Mon Jul 24 13:59:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Jul 26 14:16:00 2017
    13 // Update Count     : 0
     12// Last Modified On : Tus Aug  2 14:59:00 2017
     13// Update Count     : 1
    1414//
    1515
     
    7878
    7979        void VirtualCastCore::premutate( FunctionDecl * functionDecl ) {
    80                 if ( (! vcast_decl) && functionDecl->get_statements() &&
     80                if ( (! vcast_decl) &&
    8181                     functionDecl->get_name() == "__cfa__virtual_cast" ) {
    8282                        vcast_decl = functionDecl;
     
    101101                assertf( castExpr->get_result(), "Virtual Cast target not found before expansion." );
    102102
    103                 //assert( vcast_decl );
     103                assert( vcast_decl );
    104104                assert( pvt_decl );
    105105
    106106                // May only cast to a pointer or reference type.
    107107                // A earlier validation should give a syntax error, this is
    108                 // just to make sure errors don't creep in.
     108                // just to make sure errors don't creep during translation.
     109                // Move to helper with more detailed error messages.
    109110                PointerType * target_type =
    110111                        dynamic_cast<PointerType *>( castExpr->get_result() );
    111         assert( target_type );
     112                assert( target_type );
    112113
    113114                StructInstType * target_struct =
    114115                        dynamic_cast<StructInstType *>( target_type->get_base() );
     116                assert( target_struct );
     117
    115118                StructDecl * target_decl = target_struct->get_baseStruct();
    116119
     
    124127
    125128                Expression * result = new CastExpr(
    126                         //new ApplicationExpr( new VariableExpr( vcast_decl ), {
     129                        //new ApplicationExpr(
     130                                //new AddressExpr( new VariableExpr( vcast_decl ) ),
     131                                //new CastExpr( new VariableExpr( vcast_decl ),
     132                                //      new PointerType( noQualifiers,
     133                                //              vcast_decl->get_type()->clone()
     134                                //              )
     135                                //      ),
    127136                        new UntypedExpr( new NameExpr( "__cfa__virtual_cast" ), {
    128                                 new CastExpr(
    129                                         new AddressExpr( new VariableExpr( table ) ),
    130                                         pointer_to_pvt(1)
    131                                         ),
    132                                 new CastExpr(
    133                                         castExpr->get_arg(),
    134                                         pointer_to_pvt(2)
    135                                         ) }
    136                                 ),
    137                         castExpr->get_result()
     137                                        new CastExpr(
     138                                                new AddressExpr( new VariableExpr( table ) ),
     139                                                pointer_to_pvt(1)
     140                                                ),
     141                                        new CastExpr(
     142                                                castExpr->get_arg(),
     143                                                pointer_to_pvt(2)
     144                                                )
     145                                } ),
     146                        castExpr->get_result()->clone()
    138147                        );
    139148
  • src/driver/cfa.cc

    r275f4b4 rcd7ef0b  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 20 15:54:45 2017
    13 // Update Count     : 156
     12// Last Modified On : Fri Jan 20 14:38:45 2017
     13// Update Count     : 155
    1414//
    1515
     
    7676        bool cpp_flag = false;                                                          // -E or -M flag, preprocessor only
    7777        bool std_flag = false;                                                          // -std= flag
     78        bool noincstd_flag = false;                                                     // -no-include-stdhdr= flag
    7879        bool debugging __attribute(( unused )) = false;         // -g flag
    7980
     
    133134                        } else if ( arg == "-nohelp" ) {
    134135                                help = false;                                                   // strip the nohelp flag
     136                        } else if ( arg == "-no-include-stdhdr" ) {
     137                                noincstd_flag = true;                                   // strip the no-include-stdhdr flag
    135138                        } else if ( arg == "-compiler" ) {
    136139                                // use the user specified compiler
     
    231234        args[nargs] = "-I" CFA_INCDIR;
    232235        nargs += 1;
    233         args[nargs] = "-I" CFA_INCDIR "/stdhdr";
    234         nargs += 1;
     236        if ( ! noincstd_flag ) {                                                        // do not use during build
     237                args[nargs] = "-I" CFA_INCDIR "/stdhdr";
     238                nargs += 1;
     239        } // if
    235240        args[nargs] = "-I" CFA_INCDIR "/concurrency";
    236241        nargs += 1;
  • src/include/cassert

    r275f4b4 rcd7ef0b  
    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
     
    1818// IWYU pragma: private, include <cassert>
    1919
    20 #include_next <assert.h>
     20#include_next <cassert>
    2121
    22 #define __STRINGIFY__(str) #str
    23 #define __VSTRINGIFY__(str) __STRINGIFY__(str)
    24 #define assertf(expr, fmt, ...) ((expr) ? static_cast<void>(0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ ))
     22#ifdef NDEBUG
    2523
    26 void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) __attribute__((noreturn));
     24#define assertf(expr, fmt, ...) (__ASSERT_VOID_ASSERT (0))
     25
     26#else
     27
     28#define assertf(expr, fmt, ...) ((expr) \
     29        ? (__ASSERT_VOID_CAST (0)) \
     30        : __assert_fail_f( #expr, __FILE__, __LINE__, \
     31        __ASSERT_FUNCTION, fmt, ## __VA_ARGS__ ))
     32
     33void __assert_fail_f(   const char *assertion, const char *file,
     34                                                unsigned int line, const char *function,
     35                                                const char *fmt, ...
     36        ) __attribute__((noreturn, format(printf, 5, 6)));
     37
     38#endif
    2739
    2840template<typename T, typename U>
    29 static inline T safe_dynamic_cast(const U& src) {
     41static inline T safe_dynamic_cast( const U & src ) {
    3042        T ret = dynamic_cast<T>(src);
    3143        assert(ret);
  • src/libcfa/Makefile.am

    r275f4b4 rcd7ef0b  
    3939
    4040AM_CCASFLAGS = @CFA_FLAGS@
    41 CFLAGS = -quiet -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS}
     41
     42#CFLAGS for most libcfa src
     43#use -no-include-stdhdr to prevent rebuild cycles
     44#The built sources must not depend on the installed headers
     45CFLAGS = -quiet -no-include-stdhdr -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS}
    4246CC = ${abs_top_srcdir}/src/driver/cfa
    4347
  • src/libcfa/Makefile.in

    r275f4b4 rcd7ef0b  
    308308CFA_NAME = @CFA_NAME@
    309309CFA_PREFIX = @CFA_PREFIX@
    310 CFLAGS = -quiet -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS}
     310
     311#CFLAGS for most libcfa src
     312#use -no-include-stdhdr to prevent rebuild cycles
     313#The built sources must not depend on the installed headers
     314CFLAGS = -quiet -no-include-stdhdr -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS}
    311315CPP = @CPP@
    312316CPPFLAGS = @CPPFLAGS@
  • src/libcfa/concurrency/monitor.c

    r275f4b4 rcd7ef0b  
    1010// Created On       : Thd Feb 23 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:37:11 2017
    13 // Update Count     : 1
     12// Last Modified On : Mon Jul 31 14:59:05 2017
     13// Update Count     : 3
    1414//
    1515
     
    484484        if( !this->monitors ) {
    485485                // LIB_DEBUG_PRINT_SAFE("Branding\n");
    486                 assertf( thrd->current_monitors != NULL, "No current monitor to brand condition", thrd->current_monitors );
     486                assertf( thrd->current_monitors != NULL, "No current monitor to brand condition %p", thrd->current_monitors );
    487487                this->monitor_count = thrd->current_monitor_count;
    488488
  • src/libcfa/exception.c

    r275f4b4 rcd7ef0b  
    99// Author           : Andrew Beach
    1010// Created On       : Mon Jun 26 15:13:00 2017
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 26 10:37:51 2017
    13 // Update Count     : 2
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Aug  4 15:20:00 2017
     13// Update Count     : 6
    1414//
     15
     16#include <stddef.h> // for size_t
    1517
    1618#include "exception.h"
     
    3234#include "lsda.h"
    3335
     36
     37// Base exception vtable is abstract, you should not have base exceptions.
     38struct __cfaehm__base_exception_t_vtable
     39                ___cfaehm__base_exception_t_vtable_instance = {
     40        .parent = NULL,
     41        .size = 0,
     42        .copy = NULL,
     43        .free = NULL,
     44        .msg = NULL
     45};
     46
     47
    3448// Temperary global exception context. Does not work with concurency.
    35 struct shared_stack_t {
     49struct exception_context_t {
    3650    struct __cfaehm__try_resume_node * top_resume;
    3751    struct __cfaehm__try_resume_node * current_resume;
    3852
    39     exception current_exception;
     53    exception * current_exception;
    4054    int current_handler_index;
    4155} shared_stack = {NULL, NULL, 0, 0};
    4256
     57// Get the current exception context.
     58// There can be a single global until multithreading occurs, then each stack
     59// needs its own. It will have to be updated to handle that.
     60struct exception_context_t * this_exception_context() {
     61        return &shared_stack;
     62}
     63//#define SAVE_EXCEPTION_CONTEXT(to_name)
     64//struct exception_context_t * to_name = this_exception_context();
     65//exception * this_exception() {
     66//    return this_exception_context()->current_exception;
     67//}
    4368
    4469
     
    5580
    5681        // DEBUG
    57         printf("Throwing resumption exception %d\n", *except);
     82        printf("Throwing resumption exception\n");
    5883
    5984        struct __cfaehm__try_resume_node * original_head = shared_stack.current_resume;
     
    6994        }
    7095
    71         printf("Unhandled exception %d\n", *except);
     96        printf("Unhandled exception\n");
    7297        shared_stack.current_resume = original_head;
    7398
     
    94119// TERMINATION ===============================================================
    95120
    96 // Requires -fexceptions to work.
    97 
    98 // Global which defines the current exception.  Currently an int just to make matching easier.
    99 //int this_exception; (became shared_stack.current_exception)
     121// MEMORY MANAGEMENT (still for integers)
     122// May have to move to cfa for constructors and destructors (references).
     123
     124struct __cfaehm__node {
     125        struct __cfaehm__node * next;
     126};
     127
     128#define NODE_TO_EXCEPT(node) ((exception *)(1 + (node)))
     129#define EXCEPT_TO_NODE(except) ((struct __cfaehm__node *)(except) - 1)
     130
     131// Creates a copy of the indicated exception and sets current_exception to it.
     132static void __cfaehm__allocate_exception( exception * except ) {
     133        struct exception_context_t * context = this_exception_context();
     134
     135        // Allocate memory for the exception.
     136        struct __cfaehm__node * store = malloc(
     137                sizeof( struct __cfaehm__node ) + except->virtual_table->size );
     138
     139        if ( ! store ) {
     140                // Failure: cannot allocate exception. Terminate thread.
     141                abort(); // <- Although I think it might be the process.
     142        }
     143
     144        // Add the node to the list:
     145        store->next = EXCEPT_TO_NODE(context->current_exception);
     146        context->current_exception = NODE_TO_EXCEPT(store);
     147
     148        // Copy the exception to storage.
     149        except->virtual_table->copy( context->current_exception, except );
     150}
     151
     152// Delete the provided exception, unsetting current_exception if relivant.
     153static void __cfaehm__delete_exception( exception * except ) {
     154        struct exception_context_t * context = this_exception_context();
     155
     156        // DEBUG
     157        printf( "Deleting Exception\n");
     158
     159        // Remove the exception from the list.
     160        struct __cfaehm__node * to_free = EXCEPT_TO_NODE(except);
     161        struct __cfaehm__node * node;
     162
     163        if ( context->current_exception == except ) {
     164                node = to_free->next;
     165                context->current_exception = (node) ? NODE_TO_EXCEPT(node) : 0;
     166        } else {
     167                node = EXCEPT_TO_NODE(context->current_exception);
     168                // It may always be in the first or second position.
     169                while( to_free != node->next ) {
     170                        node = node->next;
     171                }
     172                node->next = to_free->next;
     173        }
     174
     175        // Free the old exception node.
     176        except->virtual_table->free( except );
     177        free( to_free );
     178}
     179
     180// If this isn't a rethrow (*except==0), delete the provided exception.
     181void __cfaehm__cleanup_terminate( void * except ) {
     182        if ( *(void**)except ) __cfaehm__delete_exception( *(exception**)except );
     183}
     184
    100185
    101186// We need a piece of storage to raise the exception
     
    117202}
    118203
    119 void __cfaehm__throw_terminate( exception * val ) {
    120         // Store the current exception
    121         shared_stack.current_exception = *val;
    122 
    123         // DEBUG
    124         printf("Throwing termination exception %d\n", *val);
     204// The exception that is being thrown must already be stored.
     205__attribute__((noreturn)) void __cfaehm__begin_unwind(void) {
     206        if ( ! this_exception_context()->current_exception ) {
     207                printf("UNWIND ERROR missing exception in begin unwind\n");
     208                abort();
     209        }
     210
    125211
    126212        // Call stdlibc to raise the exception
     
    148234}
    149235
    150 // Nesting this the other way would probably be faster.
     236void __cfaehm__throw_terminate( exception * val ) {
     237        // DEBUG
     238        printf("Throwing termination exception\n");
     239
     240        __cfaehm__allocate_exception( val );
     241        __cfaehm__begin_unwind();
     242}
     243
    151244void __cfaehm__rethrow_terminate(void) {
    152245        // DEBUG
    153246        printf("Rethrowing termination exception\n");
    154247
    155         __cfaehm__throw_terminate(&shared_stack.current_exception);
     248        __cfaehm__begin_unwind();
    156249}
    157250
     
    263356                                        _Unwind_Reason_Code (*matcher)(exception *) =
    264357                                                MATCHER_FROM_CONTEXT(context);
    265                                         int index = matcher(&shared_stack.current_exception);
     358                                        int index = matcher(shared_stack.current_exception);
    266359                                        _Unwind_Reason_Code ret = (0 == index)
    267360                                                ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
     
    359452        // Exception handler
    360453        catch_block( shared_stack.current_handler_index,
    361                     &shared_stack.current_exception );
     454                     shared_stack.current_exception );
    362455}
    363456
  • src/libcfa/exception.h

    r275f4b4 rcd7ef0b  
    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 : Sat Jul 22 09:57:02 2017
    13 // Update Count     : 3
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Aug  4 15:20:00 2017
     13// Update Count     : 5
    1414//
    1515
    1616#pragma once
    1717
    18 // Later to be a special structure type.
    19 typedef int exception;
    2018
    2119#ifdef __CFORALL__
    2220extern "C" {
    2321#endif
     22
     23struct __cfaehm__base_exception_t;
     24typedef struct __cfaehm__base_exception_t exception;
     25struct __cfaehm__base_exception_t_vtable {
     26        const struct __cfaehm__base_exception_t_vtable * parent;
     27        size_t size;
     28        void (*copy)(struct __cfaehm__base_exception_t *this,
     29                     struct __cfaehm__base_exception_t * other);
     30        void (*free)(struct __cfaehm__base_exception_t *this);
     31        const char (*msg)(struct __cfaehm__base_exception_t *this);
     32};
     33struct __cfaehm__base_exception_t {
     34        struct __cfaehm__base_exception_t_vtable const * virtual_table;
     35};
     36extern struct __cfaehm__base_exception_t_vtable
     37        ___cfaehm__base_exception_t_vtable_instance;
     38
    2439
    2540// Used in throw statement translation.
     
    3449    int (*match_block)(exception * except));
    3550
     51// Clean-up the exception in catch blocks.
     52void __cfaehm__cleanup_terminate(void * except);
     53
    3654// Data structure creates a list of resume handlers.
    3755struct __cfaehm__try_resume_node {
     
    4058};
    4159
     60// These act as constructor and destructor for the resume node.
    4261void __cfaehm__try_resume_setup(
    4362    struct __cfaehm__try_resume_node * node,
     
    4766
    4867// Check for a standard way to call fake deconstructors.
    49 struct __cfaehm__cleanup_hook {
    50 };
     68struct __cfaehm__cleanup_hook {};
    5169
    5270#ifdef __CFORALL__
  • src/libcfa/iostream

    r275f4b4 rcd7ef0b  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul  7 08:35:59 2017
    13 // Update Count     : 118
     12// Last Modified On : Wed Aug  9 16:42:47 2017
     13// Update Count     : 131
    1414//
    1515
     
    4646}; // ostream
    4747
    48 trait writeable( otype T ) {
    49         forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T );
     48// trait writeable( otype T ) {
     49//      forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T );
     50// }; // writeable
     51
     52trait writeable( otype T, dtype ostype | ostream( ostype ) ) {
     53        ostype * ?|?( ostype *, T );
    5054}; // writeable
    5155
     
    7781
    7882// tuples
    79 forall( dtype ostype, otype T, ttype Params | ostream( ostype ) | writeable( T ) | { ostype * ?|?( ostype *, Params ); } ) ostype * ?|?( ostype * os, T arg, Params rest );
     83forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype * ?|?( ostype *, Params ); } )
     84ostype * ?|?( ostype * os, T arg, Params rest );
    8085
    8186// manipulators
     
    9095
    9196// writes the range [begin, end) to the given stream
    92 forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )
    93 void write( iterator_type begin, iterator_type end, os_type *os );
     97forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) )
     98void write( iterator_type begin, iterator_type end, ostype * os );
    9499
    95 forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )
    96 void write_reverse( iterator_type begin, iterator_type end, os_type *os );
     100forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) )
     101void write_reverse( iterator_type begin, iterator_type end, ostype * os );
    97102
    98103//---------------------------------------
  • src/libcfa/iostream.c

    r275f4b4 rcd7ef0b  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Jul 16 21:12:03 2017
    13 // Update Count     : 398
     12// Last Modified On : Wed Aug  9 16:46:51 2017
     13// Update Count     : 401
    1414//
    1515
     
    193193
    194194// tuples
    195 forall( dtype ostype, otype T, ttype Params | ostream( ostype ) | writeable( T ) | { ostype * ?|?( ostype *, Params ); } )
     195forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype * ?|?( ostype *, Params ); } )
    196196ostype * ?|?( ostype * os, T arg, Params rest ) {
    197197        os | arg;                                                                                       // print first argument
     
    256256//---------------------------------------
    257257
    258 forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )
    259 void write( iteratortype begin, iteratortype end, ostype * os ) {
    260         void print( elttype i ) { os | i; }
     258forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) )
     259void write( iterator_type begin, iterator_type end, ostype * os ) {
     260        void print( elt_type i ) { os | i; }
    261261        for_each( begin, end, print );
    262262} // ?|?
    263263
    264 forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )
    265 void write_reverse( iteratortype begin, iteratortype end, ostype * os ) {
    266         void print( elttype i ) { os | i; }
     264forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) )
     265void write_reverse( iterator_type begin, iterator_type end, ostype * os ) {
     266        void print( elt_type i ) { os | i; }
    267267        for_each_reverse( begin, end, print );
    268268} // ?|?
  • src/libcfa/math

    r275f4b4 rcd7ef0b  
    1010// Created On       : Mon Apr 18 23:37:04 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 17:03:13 2017
    13 // Update Count     : 101
     12// Last Modified On : Mon Aug  7 07:51:15 2017
     13// Update Count     : 108
    1414//
    1515
     
    1818#include <math.h>
    1919#include <complex.h>
     20
     21//---------------------- General ----------------------
    2022
    2123static inline float ?%?( float x, float y ) { return fmodf( x, y ); }
     
    3739static inline [ int, long double ] remquo( long double x, long double y ) { int quo; x = remquol( x, y, &quo ); return [ quo, x ]; }
    3840
    39 // alternative name for remquo
    40 static inline float div( float x, float y, int * quo ) { return remquof( x, y, quo ); }
    41 static inline double div( double x, double y, int * quo ) { return remquo( x, y, quo ); }
    42 static inline long double div( long double x, long double y, int * quo ) { return remquol( x, y, quo ); }
    43 static inline [ int, float ] div( float x, float y ) { int quo; x = remquof( x, y, &quo ); return [ quo, x ]; }
    44 static inline [ int, double ] div( double x, double y ) { int quo; x = remquo( x, y, &quo ); return [ quo, x ]; }
    45 static inline [ int, long double ] div( long double x, long double y ) { int quo; x = remquol( x, y, &quo ); return [ quo, x ]; }
     41static inline [ float, float ] div( float x, float y ) { y = modff( x / y, &x ); return [ x, y ]; }
     42static inline [ double, double ] div( double x, double y ) { y = modf( x / y, &x ); return [ x, y ]; }
     43static inline [ long double, long double ] div( long double x, long double y ) { y = modfl( x / y, &x ); return [ x, y ]; }
    4644
    4745static inline float fma( float x, float y, float z ) { return fmaf( x, y, z ); }
  • src/libcfa/stdhdr/assert.h

    r275f4b4 rcd7ef0b  
    1010// Created On       : Mon Jul  4 23:25:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 20 21:06:48 2017
    13 // Update Count     : 11
     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));
     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
  • src/libcfa/stdlib

    r275f4b4 rcd7ef0b  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 20 14:32:37 2017
    13 // Update Count     : 220
     12// Last Modified On : Mon Aug  7 11:19:07 2017
     13// Update Count     : 223
    1414//
    1515
     
    183183//---------------------------------------
    184184
     185[ int, int ] div( int num, int denom );
     186[ long int, long int ] div( long int num, long int denom );
     187[ long long int, long long int ] div( long long int num, long long int denom );
    185188forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
    186 [ T, T ] div( T t1, T t2 );
     189[ T, T ] div( T num, T demon );
    187190
    188191//---------------------------------------
  • src/libcfa/stdlib.c

    r275f4b4 rcd7ef0b  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 20 16:01:40 2017
    13 // Update Count     : 282
     12// Last Modified On : Tue Aug  8 17:31:13 2017
     13// Update Count     : 291
    1414//
    1515
     
    255255//---------------------------------------
    256256
     257[ int, int ] div( int num, int denom ) { div_t qr = div( num, denom ); return [ qr.quot, qr.rem ]; }
     258[ long int, long int ] div( long int num, long int denom ) { ldiv_t qr = ldiv( num, denom ); return [ qr.quot, qr.rem ]; }
     259[ long long int, long long int ] div( long long int num, long long int denom ) { lldiv_t qr = lldiv( num, denom ); return [ qr.quot, qr.rem ]; }
    257260forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } )
    258 [ T, T ] div( T t1, T t2 ) { return [ t1 / t2, t1 % t2 ]; }
     261[ T, T ] div( T num, T denom ) { return [ num / denom, num % denom ]; }
    259262
    260263//---------------------------------------
  • src/tests/.expect/32/math.txt

    r275f4b4 rcd7ef0b  
    22remainder:-1 -1 -1
    33remquo:7 0.0999999 7 0.1 7 0.0999999999999999999
    4 div:7 0.0999999 7 0.1 7 0.0999999999999999999
     4div:7, 0.2 7, 0.2 7, 0.2
    55fma:-2 -2 -2
    66fdim:2 2 2
     
    5555frexp:0.5 3 0.5 3 0.5 3
    5656ldexp:8 8 8
    57 modf:2 0.3 2 0.3 2 0.3 nextafter:2 2 2
     57modf:2 0.3 2 0.3 2 0.3
     58modf:2, 0.3 2, 0.3 2, 0.3
     59nextafter:2 2 2
    5860nexttoward:2 2 2
    5961scalbn:16 16 16
  • src/tests/.expect/64/math.txt

    r275f4b4 rcd7ef0b  
    22remainder:-1 -1 -1
    33remquo:7 0.0999999 7 0.1 7 0.0999999999999999999
    4 div:7 0.0999999 7 0.1 7 0.0999999999999999999
     4div:7, 0.2 7, 0.2 7, 0.2
    55fma:-2 -2 -2
    66fdim:2 2 2
     
    5555frexp:0.5 3 0.5 3 0.5 3
    5656ldexp:8 8 8
    57 modf:2 0.3 2 0.3 2 0.3 nextafter:2 2 2
     57modf:2 0.3 2 0.3 2 0.3
     58modf:2, 0.3 2, 0.3 2, 0.3
     59nextafter:2 2 2
    5860nexttoward:2 2 2
    5961scalbn:16 16 16
  • src/tests/designations.c

    r275f4b4 rcd7ef0b  
    99// Author           : Rob Schluntz
    1010// Created On       : Thu Jun 29 15:26:36 2017
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Thu Jun 29 15:27:05 2017
    13 // Update Count     : 2
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Jul 27 11:46:35 2017
     13// Update Count     : 3
    1414//
    1515
     
    8989};
    9090
     91struct Fred {
     92    double i[3];
     93    int j;
     94    struct Mary {
     95        struct Jane {
     96            double j;
     97        } j;
     98        double i;
     99    } m;
     100};
     101struct Fred s1 @= { .m.j : 3 };
     102struct Fred s2 @= { .i : { [2] : 2 } };
     103
    91104int main() {
    92105        // simple designation case - starting from beginning of structure, leaves ptr default-initialized (zero)
     
    199212        };
    200213#endif
    201 
     214        // array designation
     215        int i[2] = { [1] : 3 };
    202216        // allowed to have 'too many' initialized lists - essentially they are ignored.
    203217        int i1 = { 3 };
     
    240254        const char * str0 = "hello";
    241255        char str1[] = "hello";
     256        const char c1[] = "abc";
     257        const char c2[] = { 'a', 'b', 'c' };
     258        const char c3[][2] = { { 'a', 'b' }, { 'c', 'd'}, { 'c', 'd'} };
    242259}
    243260
  • src/tests/except-0.c

    r275f4b4 rcd7ef0b  
    66#include <stdbool.h>
    77
     8// Local type to mark exits from scopes. (see ERROR)
    89struct signal_exit {
    910        const char * area;
     
    1920}
    2021
    21 void terminate(int except_value) {
     22
     23// Local Exception Types and manual vtable types.
     24//#define TRIVIAL_EXCEPTION(name) //TRIVAL_EXCEPTION(yin)
     25struct yin;
     26struct yin_vtable {
     27        struct exception_t_vtable const * parent;
     28        size_t size;
     29    void (*copy)(yin *this, yin * other);
     30    void (*free)(yin *this);
     31    const char (*msg)(yin *this);
     32};
     33struct yin {
     34        struct yin_vtable const * parent;
     35};
     36void yin_msg(yin) {
     37        return "in";
     38}
     39yin_vtable _yin_vtable_instance = {
     40        &_exception_t_vtable_instance, sizeof(yin), ?{}, ^?{}, yin_msg
     41}
     42
     43
     44void terminate(exception * except_value) {
    2245        signal_exit a = {"terminate function"};
    2346        throw except_value;
     
    2548}
    2649
    27 void resume(int except_value) {
     50void resume(exception * except_value) {
    2851        signal_exit a = {"resume function"};
    2952        throwResume except_value;
  • src/tests/math.c

    r275f4b4 rcd7ef0b  
    1010// Created On       : Fri Apr 22 14:59:21 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 10:32:04 2017
    13 // Update Count     : 73
     12// Last Modified On : Wed Aug  9 07:20:49 2017
     13// Update Count     : 77
    1414//
    1515
     
    3131        l = remquo( 3.6L, 0.5L, &quot );
    3232        sout | quot | l | endl;
    33         f = div( 3.6F, 0.5F, &quot );
    34         sout | "div:" | quot | f;
    35         d = div( 3.6D, 0.5F, &quot );
    36         sout | quot | d;
    37         l = div( 3.6L, 0.5L, &quot );
    38         sout | quot | l | endl;
     33        sout | "div:" | div( 3.6F, 0.5F ) | div( 3.6D, 0.5D ) | div( 3.6L, 0.5L ) | endl;
    3934        sout | "fma:" | fma( 3.0F, -1.0F, 1.0F ) | fma( 3.0D, -1.0D, 1.0D ) | fma( 3.0L, -1.0L, , 1.0L ) | endl;
    4035        sout | "fdim:" | fdim( 1.0F, -1.0F ) | fdim( 1.0D, -1.0D ) | fdim( 1.0L, -1.0L ) | endl;
     
    137132        sout | di | d;
    138133        l = modf( 2.3L, &ldi );
    139         sout | ldi | l;
     134        sout | ldi | l | endl;
     135        sout | "modf:" | modf( 2.3F ) | modf( 2.3D ) | modf( 2.3L ) | endl;
    140136        sout | "nextafter:" | nextafter( 2.0F, 3.0F ) | nextafter( 2.0D, 3.0D ) | nextafter( 2.0L, 3.0L ) | endl;
    141137        sout | "nexttoward:" | nexttoward( 2.0F, 3.0F ) | nexttoward( 2.0D, 3.0D ) | nexttoward( 2.0L, 3.0L ) | endl;
Note: See TracChangeset for help on using the changeset viewer.