Changeset e50e9ff


Ignore:
Timestamp:
Aug 22, 2017, 11:42:06 AM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
90c4df0
Parents:
6ac5223 (diff), b3d413b (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:
2 added
27 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r6ac5223 re50e9ff  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 25 15:29:00 2017
    13 // Update Count     : 486
     12// Last Modified On : Fri Aug 18 15:34:00 2017
     13// Update Count     : 488
    1414//
    1515#include "CodeGenerator.h"
     
    7979        }
    8080
    81         CodeGenerator::LineMarker::LineMarker(
    82                         CodeLocation const & loc, bool toPrint) :
    83                 loc(loc), toPrint(toPrint)
    84         {}
    85 
    86         CodeGenerator::LineMarker CodeGenerator::lineDirective(
    87                         BaseSyntaxNode const * node) {
    88                 return LineMarker(node->location, lineMarks);
    89         }
    90 
    91         std::ostream & operator<<(std::ostream & out,
    92                         CodeGenerator::LineMarker const & marker) {
    93                 if (marker.toPrint && marker.loc.isSet()) {
    94                         return out << "\n# " << marker.loc.linenumber << " \""
    95                                 << marker.loc.filename << "\"\n";
    96                 } else if (marker.toPrint) {
    97                         return out << "\n/* Missing CodeLocation */\n";
    98                 } else {
    99                 return out;
     81        /* Using updateLocation at the beginning of a node and nextLine
     82         * within a node should become the method of formating.
     83         */
     84        void CodeGenerator::updateLocation( CodeLocation const & to ) {
     85                if ( !lineMarks ) {
     86                        return;
     87                } else if ( currentLocation.followedBy( to, 0 ) ) {
     88                        return;
     89                } else if ( currentLocation.followedBy( to, 1 ) ) {
     90                        output << "\n" << indent;
     91                        currentLocation.linenumber += 1;
     92                } else if ( currentLocation.followedBy( to, 2 ) ) {
     93                        output << "\n\n" << indent;
     94                        currentLocation.linenumber += 2;
     95                } else {
     96                        output << "\n# " << to.linenumber << " \"" << to.filename
     97                               << "\"\n" << indent;
     98                        currentLocation = to;
     99                }
     100                output << std::flush;
     101        }
     102
     103        void CodeGenerator::updateLocation( BaseSyntaxNode const * to ) {
     104                updateLocation( to->location );
     105        }
     106
     107        void CodeGenerator::nextLine() {
     108                if ( !lineMarks ) {
     109                        output << "\n" << indent << std::flush;
    100110                }
    101111        }
     
    194204                        ++indent;
    195205                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) {
    196                                 output << lineDirective( *i ) << indent;
     206                                updateLocation( *i );
    197207                                (*i)->accept( *this );
    198208                                output << ";" << endl;
     
    217227        void CodeGenerator::visit( EnumDecl * enumDecl ) {
    218228                extension( enumDecl );
    219                 output << lineDirective ( enumDecl );
     229                updateLocation( enumDecl );
    220230                output << "enum ";
    221231                genAttributes( enumDecl->get_attributes() );
     
    233243                                ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
    234244                                assert( obj );
    235                                 output << lineDirective( obj ) << indent << mangleName( obj );
     245                                updateLocation( obj );
     246                                output << mangleName( obj );
    236247                                if ( obj->get_init() ) {
    237248                                        output << " = ";
     
    251262        void CodeGenerator::visit( TypedefDecl * typeDecl ) {
    252263                assertf( ! genC, "Typedefs are removed and substituted in earlier passes." );
    253                 output << lineDirective( typeDecl );
     264                updateLocation( typeDecl );
    254265                output << "typedef ";
    255266                output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl;
     
    752763        void CodeGenerator::visit( StmtExpr * stmtExpr ) {
    753764                std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids();
    754                 output << lineDirective( stmtExpr) << "({" << std::endl;
     765                updateLocation( stmtExpr );
     766                output << "({" << std::endl;
    755767                ++indent;
    756768                unsigned int numStmts = stmts.size();
    757769                unsigned int i = 0;
    758770                for ( Statement * stmt : stmts ) {
    759                         output << lineDirective( stmt ) << indent;
     771                        updateLocation( stmt );
    760772            output << printLabels( stmt->get_labels() );
    761773                        if ( i+1 == numStmts ) {
     
    844856
    845857        void CodeGenerator::visit( IfStmt * ifStmt ) {
    846                 output << lineDirective( ifStmt );
     858                updateLocation( ifStmt );
    847859                output << "if ( ";
    848860                ifStmt->get_condition()->accept( *this );
     
    858870
    859871        void CodeGenerator::visit( SwitchStmt * switchStmt ) {
    860                 output << lineDirective( switchStmt );
     872                updateLocation( switchStmt );
    861873                output << "switch ( " ;
    862874                switchStmt->get_condition()->accept( *this );
     
    871883
    872884        void CodeGenerator::visit( CaseStmt * caseStmt ) {
    873                 output << lineDirective( caseStmt );
    874                 output << indent;
     885                updateLocation( caseStmt );
    875886                if ( caseStmt->isDefault()) {
    876887                        output << "default";
  • src/CodeGen/CodeGenerator.h

    r6ac5223 re50e9ff  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Jul 25 25:30:00 2017
    13 // Update Count     : 54
     12// Last Modified On : Fri Aug 18 15:40:00 2017
     13// Update Count     : 56
    1414//
    1515
     
    108108                };
    109109
    110                 struct LineMarker {
    111                         CodeLocation const & loc;
    112                         bool toPrint;
    113 
    114                         LineMarker(CodeLocation const & loc, bool toPrint);
    115                 };
    116 
    117                 LineMarker lineDirective(BaseSyntaxNode const * node);
    118 
    119110                void asmName( DeclarationWithType *decl );
    120111
    121112                void extension( Expression *expr );
    122113                void extension( Declaration *decl );
     114
     115                void updateLocation( BaseSyntaxNode const * to );
    123116          private:
    124117                Indenter indent;
     
    129122                bool genC = false;    // true if output has to be C code
    130123                bool lineMarks = false;
     124
     125                CodeLocation currentLocation;
     126                void updateLocation( CodeLocation const & to );
     127                void nextLine();
    131128
    132129                void handleStorageClass( DeclarationWithType *decl );
     
    155152        /// returns C-compatible name of declaration
    156153        std::string genName( DeclarationWithType * decl );
    157 
    158         std::ostream & operator<<(std::ostream &,
    159                 CodeGenerator::LineMarker const &);
    160154} // namespace CodeGen
    161155
  • src/CodeGen/Generate.cc

    r6ac5223 re50e9ff  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed May 19 13:05:00 2017
    13 // Update Count     : 6
     12// Last Modified On : Fri Aug 18 15:39:00 2017
     13// Update Count     : 7
    1414//
    1515#include "Generate.h"
     
    3333                for ( auto & dcl : translationUnit ) {
    3434                        if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) {
    35                                 os << cgv.lineDirective(dcl);
     35                                cgv.updateLocation( dcl );
    3636                                dcl->accept(cgv);
    3737                                if ( doSemicolon( dcl ) ) {
  • src/ControlStruct/ExceptTranslate.cc

    r6ac5223 re50e9ff  
    1010// Created On       : Wed Jun 14 16:49:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Tus Aug  8 16:54:00 2017
    13 // Update Count     : 7
     12// Last Modified On : Thr Aug 17 17:19:00 2017
     13// Update Count     : 9
    1414//
    1515
     
    166166                        /*bitfieldWidth*/ NULL,
    167167                        new BasicType( noQualifiers, BasicType::Bool ),
    168                         /*init*/ NULL
     168                        /*init*/ NULL,
     169                        std::list<Attribute *>{ new Attribute( "unused" ) }
    169170                        );
    170171                ObjectDecl voidptr_obj(
     
    183184                        );
    184185
     186                ObjectDecl * unused_index_obj = index_obj.clone();
     187                unused_index_obj->attributes.push_back( new Attribute( "unused" ) );
     188
    185189                catch_func_t.get_parameters().push_back( index_obj.clone() );
    186190                catch_func_t.get_parameters().push_back( exception_obj.clone() );
    187                 match_func_t.get_returnVals().push_back( index_obj.clone() );
     191                match_func_t.get_returnVals().push_back( unused_index_obj );
    188192                match_func_t.get_parameters().push_back( exception_obj.clone() );
    189193                handle_func_t.get_returnVals().push_back( bool_obj.clone() );
     
    417421                }
    418422
    419                 body->push_back( new ReturnStmt( noLabels, new ConstantExpr(
    420                         Constant::from_int( 0 ) ) ) );
     423                body->push_back( new ReturnStmt( noLabels,
     424                        new ConstantExpr( Constant::from_int( 0 ) ) ) );
    421425
    422426                return new FunctionDecl("match", Type::StorageClasses(),
     
    449453                CompoundStmt * body = new CompoundStmt( noLabels );
    450454
    451                 FunctionType * func_type = match_func_t.clone();
     455                FunctionType * func_type = handle_func_t.clone();
    452456                DeclarationWithType * except_obj = func_type->get_parameters().back();
    453457
     
    472476                }
    473477
    474                 body->push_back( new ReturnStmt( noLabels, new ConstantExpr(
    475                         Constant::from_bool( false ) ) ) );
     478                body->push_back( new ReturnStmt( noLabels,
     479                        new ConstantExpr( Constant::from_bool( false ) ) ) );
    476480
    477481                return new FunctionDecl("handle", Type::StorageClasses(),
  • src/ControlStruct/ForExprMutator.cc

    r6ac5223 re50e9ff  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Jul 14 12:14:44 2015
    13 // Update Count     : 10
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Aug 18 10:22:00 2017
     13// Update Count     : 12
    1414//
    1515
     
    2121
    2222namespace ControlStruct {
     23        Statement *hoist( Statement *originalStmt, std::list<Statement *> &init ) {
     24                // If no hoisting is needed, skip:
     25                if ( 0 == init.size() ) {
     26                        return originalStmt;
     27                }
     28
     29                // Create compound statement, move initializers outside,
     30                // the resut of the original stays as is.
     31                CompoundStmt *block = new CompoundStmt( std::list< Label >() );
     32                std::list<Statement *> &stmts = block->get_kids();
     33                stmts.splice( stmts.end(), init );
     34
     35                // Add for to the new block.
     36                stmts.push_back( originalStmt );
     37                return block;
     38        }
     39
     40        Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) {
     41                return hoist( ifStmt, ifStmt->initialization );
     42        }
    2343        Statement *ForExprMutator::postmutate( ForStmt *forStmt ) {
    2444                // hoist any initializer declarations to make them C89 (rather than C99)
    25                 std::list<Statement *> &init = forStmt->get_initialization();
    26                 if ( init.size() == 0 ) {
    27                         return forStmt;
    28                 } // if
    29 
    30                 // create compound statement, move initializers outside, leave _for_ as-is
    31                 CompoundStmt *block = new CompoundStmt( std::list< Label >() );
    32                 std::list<Statement *> &stmts = block->get_kids();
    33                 for ( std::list<Statement *>::iterator it = init.begin(); it != init.end(); ++it ) {
    34                         stmts.push_back( *it );
    35                 }       // for
    36 
    37                 // add for to the new block
    38                 stmts.push_back( forStmt );
    39                 forStmt->set_initialization( std::list<Statement *>() );
    40                 return block;
     45                return hoist( forStmt, forStmt->initialization );
    4146        }
    4247} // namespace ControlStruct
  • src/ControlStruct/ForExprMutator.h

    r6ac5223 re50e9ff  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:17:08 2017
    13 // Update Count     : 4
     12// Last Modified On : Thu Aug 17 15:32:48 2017
     13// Update Count     : 5
    1414//
    1515
    1616#pragma once
    1717
     18class IfStmt;
    1819class ForStmt;
    1920class Statement;
     
    2223        class ForExprMutator {
    2324          public:
     25                Statement *postmutate( IfStmt * );
    2426                Statement *postmutate( ForStmt * );
    2527        };
  • src/Parser/StatementNode.cc

    r6ac5223 re50e9ff  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 16 16:39:43 2017
    13 // Update Count     : 340
     12// Last Modified On : Thu Aug 17 16:01:31 2017
     13// Update Count     : 345
    1414//
    1515
     
    2424#include "SynTree/Expression.h"    // for Expression, ConstantExpr
    2525#include "SynTree/Label.h"         // for Label, noLabels
     26#include "SynTree/Declaration.h"
    2627#include "SynTree/Statement.h"     // for Statement, BranchStmt, CaseStmt
    2728#include "parserutility.h"         // for notZeroExpr
     
    9899        } // if
    99100
    100         return new IfStmt( noLabels, notZeroExpr(
    101                                                            /*ctl->condition
    102                                                                  ?*/ maybeMoveBuild< Expression >(ctl->condition)
    103                                                                  /*: new VariableExpr( init.end() )*/ )
    104                                                    , thenb, elseb );
    105         // ret->initialization = init;
    106         // delete ctl;
    107         // assert( ret );
    108         // return ret;
     101        Expression * cond = ctl->condition ? maybeMoveBuild< Expression >(ctl->condition) : new VariableExpr( dynamic_cast<DeclarationWithType *>( dynamic_cast<DeclStmt *>( init.back() )->decl ) );
     102        delete ctl;
     103        return new IfStmt( noLabels, notZeroExpr( cond ), thenb, elseb, init );
    109104}
    110105
  • src/Parser/parser.yy

    r6ac5223 re50e9ff  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 16 18:09:14 2017
    13 // Update Count     : 2485
     12// Last Modified On : Sun Aug 20 09:21:54 2017
     13// Update Count     : 2573
    1414//
    1515
     
    131131%token ATTRIBUTE EXTENSION                                                              // GCC
    132132%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
    133 %token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH   // CFA
     133%token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH // CFA
    134134%token ASM                                                                                              // C99, extension ISO/IEC 9899:1999 Section J.5.10(1)
    135135%token ALIGNAS ALIGNOF GENERIC STATICASSERT                             // C11
     
    796796
    797797selection_statement:
    798         IF '(' if_control_expression ')' statement                              %prec THEN
     798        IF '(' push if_control_expression ')' statement                         %prec THEN
    799799                // explicitly deal with the shift/reduce conflict on if/else
    800                 { $$ = new StatementNode( build_if( $3, $5, nullptr ) ); }
    801         | IF '(' if_control_expression ')' statement ELSE statement
    802                 { $$ = new StatementNode( build_if( $3, $5, $7 ) ); }
    803         | SWITCH '(' comma_expression ')' case_clause           // CFA
     800                { $$ = new StatementNode( build_if( $4, $6, nullptr ) ); }
     801        | IF '(' push if_control_expression ')' statement ELSE statement
     802                { $$ = new StatementNode( build_if( $4, $6, $8 ) ); }
     803        | SWITCH '(' comma_expression ')' case_clause
    804804                { $$ = new StatementNode( build_switch( $3, $5 ) ); }
    805805        | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA
     
    823823
    824824if_control_expression:
    825         comma_expression
     825        comma_expression pop
    826826                { $$ = new IfCtl( nullptr, $1 ); }
    827         | c_declaration                                                                         // no semi-coln
     827        | c_declaration pop                                                                     // no semi-colon
    828828                { $$ = new IfCtl( $1, nullptr ); }
    829         | cfa_declaration                                                                       // no semi-colon
     829        | cfa_declaration pop                                                           // no semi-colon
    830830                { $$ = new IfCtl( $1, nullptr ); }
    831         | declaration comma_expression
     831        | declaration comma_expression                                          // semi-colon separated
    832832                { $$ = new IfCtl( $1, $2 ); }
    833833        ;
     
    11041104
    11051105KR_declaration_list_opt:                                                                // used to declare parameter types in K&R style functions
    1106         pop
     1106        // empty
    11071107                { $$ = nullptr; }
    11081108        | KR_declaration_list
     
    11101110
    11111111KR_declaration_list:
    1112         c_declaration ';'
    1113         | KR_declaration_list push c_declaration ';'
     1112        push c_declaration pop ';'
     1113                { $$ = $2; }
     1114        | KR_declaration_list push c_declaration pop ';'
    11141115                { $$ = $1->appendList( $3 ); }
    11151116        ;
     
    11311132
    11321133declaration:                                                                                    // old & new style declarations
    1133         c_declaration ';'
    1134         | cfa_declaration ';'                                                           // CFA
     1134        c_declaration pop ';'
     1135        | cfa_declaration pop ';'                                                       // CFA
    11351136        ;
    11361137
     
    11471148
    11481149cfa_declaration:                                                                                // CFA
    1149         cfa_variable_declaration pop
    1150         | cfa_typedef_declaration pop
    1151         | cfa_function_declaration pop
    1152         | type_declaring_list pop
    1153         | trait_specifier pop
     1150        cfa_variable_declaration
     1151        | cfa_typedef_declaration
     1152        | cfa_function_declaration
     1153        | type_declaring_list
     1154        | trait_specifier
    11541155        ;
    11551156
     
    13511352
    13521353c_declaration:
    1353         declaration_specifier declaring_list pop
     1354        declaration_specifier declaring_list
    13541355                {
    13551356                        $$ = distAttr( $1, $2 );
    13561357                }
    1357         | typedef_declaration pop
    1358         | typedef_expression pop                                                        // GCC, naming expression type
    1359         | sue_declaration_specifier pop
     1358        | typedef_declaration
     1359        | typedef_expression                                                            // GCC, naming expression type
     1360        | sue_declaration_specifier
    13601361        ;
    13611362
     
    22302231                        $$ = $1->addFunctionBody( $2 );
    22312232                }
    2232         | KR_function_declarator push KR_declaration_list_opt compound_statement
     2233        | KR_function_declarator KR_declaration_list_opt compound_statement
    22332234                {
    22342235                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22352236                        typedefTable.leaveScope();
    2236                         $$ = $1->addOldDeclList( $3 )->addFunctionBody( $4 );
     2237                        $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 );
    22372238                }
    22382239        ;
     
    22782279
    22792280                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2280         | declaration_specifier KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2281        | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    22812282                {
    22822283                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22832284                        typedefTable.leaveScope();
    2284                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addType( $1 );
    2285                 }
    2286         | type_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2285                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addType( $1 );
     2286                }
     2287        | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    22872288                {
    22882289                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22892290                        typedefTable.leaveScope();
    2290                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $1 );
     2291                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 );
    22912292                }
    22922293
    22932294                // Old-style K&R function definition with "implicit int" type_specifier, OBSOLESCENT (see 4)
    2294         | declaration_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2295        | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    22952296                {
    22962297                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22972298                        typedefTable.leaveScope();
    2298                         $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $1 );
    2299                 }
    2300         | declaration_qualifier_list type_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
     2299                        $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 );
     2300                }
     2301        | declaration_qualifier_list type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
    23012302                {
    23022303                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    23032304                        typedefTable.leaveScope();
    2304                         $$ = $3->addOldDeclList( $5 )->addFunctionBody( $7 )->addQualifiers( $2 )->addQualifiers( $1 );
     2305                        $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 );
    23052306                }
    23062307        ;
  • src/SymTab/Indexer.cc

    r6ac5223 re50e9ff  
    1010// Created On       : Sun May 17 21:37:33 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 30 16:38:47 2017
    13 // Update Count     : 19
     12// Last Modified On : Thu Aug 17 16:08:40 2017
     13// Update Count     : 20
    1414//
    1515
     
    351351                acceptAll( compoundStmt->get_kids(), *this );
    352352                leaveScope();
     353        }
     354
     355        void Indexer::visit( IfStmt *ifStmt ) {
     356            // for statements introduce a level of scope
     357            enterScope();
     358            Visitor::visit( ifStmt );
     359            leaveScope();
    353360        }
    354361
  • src/SymTab/Indexer.h

    r6ac5223 re50e9ff  
    1010// Created On       : Sun May 17 21:38:55 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:46:34 2017
    13 // Update Count     : 7
     12// Last Modified On : Thu Aug 17 16:09:12 2017
     13// Update Count     : 8
    1414//
    1515
     
    4545
    4646                virtual void visit( CompoundStmt *compoundStmt );
     47                virtual void visit( IfStmt *ifStmt );
    4748                virtual void visit( ForStmt *forStmt );
    4849                virtual void visit( CatchStmt *catchStmt );
  • src/SynTree/Initializer.cc

    r6ac5223 re50e9ff  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug  3 11:33:00 2016
    13 // Update Count     : 29
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Aug 21 09:53:15 2017
     13// Update Count     : 30
    1414//
    1515
     
    8080                        }
    8181                }
    82                 assertf( initializers.size() == designations.size(), "Created ListInit with mismatching initializers (%lu) and designations (%lu)", initializers.size(), designations.size() );
     82                assertf( initializers.size() == designations.size(), "Created ListInit with mismatching initializers (%zd) and designations (%zd)", initializers.size(), designations.size() );
    8383}
    8484
  • src/SynTree/Mutator.cc

    r6ac5223 re50e9ff  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Jul 24 16:32:00 2017
    13 // Update Count     : 25
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Aug 17 15:39:37 2017
     13// Update Count     : 27
    1414//
    1515
     
    114114
    115115Statement *Mutator::mutate( IfStmt *ifStmt ) {
     116        mutateAll( ifStmt->get_initialization(), *this );
    116117        ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) );
    117118        ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) );
  • src/SynTree/Statement.cc

    r6ac5223 re50e9ff  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Aug 14 12:26:00 2017
    13 // Update Count     : 65
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Aug 17 16:17:20 2017
     13// Update Count     : 67
    1414//
    1515
     
    3232using std::endl;
    3333
    34 Statement::Statement( std::list<Label> _labels ) : labels( _labels ) {}
     34Statement::Statement( std::list<Label> labels ) : labels( labels ) {}
    3535
    3636void Statement::print( __attribute__((unused)) std::ostream &, __attribute__((unused)) int indent ) const {}
     
    3838Statement::~Statement() {}
    3939
    40 ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ) : Statement( _labels ), expr( _expr ) {}
     40ExprStmt::ExprStmt( std::list<Label> labels, Expression *expr ) : Statement( labels ), expr( expr ) {}
    4141
    4242ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     
    8888const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" };
    8989
    90 BranchStmt::BranchStmt( std::list<Label> labels, Label _target, Type _type ) throw ( SemanticError ) :
    91         Statement( labels ), originalTarget( _target ), target( _target ), computedTarget( NULL ), type( _type ) {
     90BranchStmt::BranchStmt( std::list<Label> labels, Label target, Type type ) throw ( SemanticError ) :
     91        Statement( labels ), originalTarget( target ), target( target ), computedTarget( NULL ), type( type ) {
    9292        //actually this is a syntactic error signaled by the parser
    9393        if ( type == BranchStmt::Goto && target.empty() )
     
    9595}
    9696
    97 BranchStmt::BranchStmt( std::list<Label> labels, Expression *_computedTarget, Type _type ) throw ( SemanticError ) :
    98         Statement( labels ), computedTarget( _computedTarget ), type( _type ) {
     97BranchStmt::BranchStmt( std::list<Label> labels, Expression *computedTarget, Type type ) throw ( SemanticError ) :
     98        Statement( labels ), computedTarget( computedTarget ), type( type ) {
    9999        if ( type != BranchStmt::Goto || computedTarget == 0 )
    100100                throw SemanticError("Computed target not valid in branch statement");
     
    105105}
    106106
    107 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr ) : Statement( labels ), expr( _expr ) {}
     107ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *expr ) : Statement( labels ), expr( expr ) {}
    108108
    109109ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     
    122122}
    123123
    124 IfStmt::IfStmt( std::list<Label> _labels, Expression *_condition, Statement *_thenPart, Statement *_elsePart ):
    125         Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart ) {}
     124IfStmt::IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart, std::list<Statement *> initialization ):
     125        Statement( labels ), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {}
    126126
    127127IfStmt::IfStmt( const IfStmt & other ) :
    128         Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {}
     128        Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {
     129        cloneAll( other.initialization, initialization );
     130}
    129131
    130132IfStmt::~IfStmt() {
     133        deleteAll( initialization );
    131134        delete condition;
    132135        delete thenPart;
     
    139142        condition->print( os, indent + 4 );
    140143
     144        if ( !initialization.empty() ) {
     145                os << string( indent + 2, ' ' ) << "initialization: \n";
     146                for ( std::list<Statement *>::const_iterator it = initialization.begin(); it != initialization.end(); ++it ) {
     147                        os << string( indent + 4, ' ' );
     148                        (*it)->print( os, indent + 4 );
     149                }
     150                os << endl;
     151        }
     152
    141153        os << string( indent+2, ' ' ) << "... then: " << endl;
    142154
     
    151163}
    152164
    153 SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_statements ):
    154         Statement( _labels ), condition( _condition ), statements( _statements ) {
     165SwitchStmt::SwitchStmt( std::list<Label> labels, Expression * condition, std::list<Statement *> &statements ):
     166        Statement( labels ), condition( condition ), statements( statements ) {
    155167}
    156168
     
    179191}
    180192
    181 CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) :
    182         Statement( _labels ), condition( _condition ), stmts( _statements ), _isDefault( deflt ) {
     193CaseStmt::CaseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) :
     194        Statement( labels ), condition( condition ), stmts( statements ), _isDefault( deflt ) {
    183195        if ( isDefault() && condition != 0 )
    184196                throw SemanticError("default with conditions");
     
    216228}
    217229
    218 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ):
    219         Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) {
     230WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition, Statement *body, bool isDoWhile ):
     231        Statement( labels ), condition( condition), body( body), isDoWhile( isDoWhile) {
    220232}
    221233
     
    238250}
    239251
    240 ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization_, Expression *condition_, Expression *increment_, Statement *body_ ):
    241         Statement( labels ), initialization( initialization_ ), condition( condition_ ), increment( increment_ ), body( body_ ) {
     252ForStmt::ForStmt( std::list<Label> labels, std::list<Statement *> initialization, Expression *condition, Expression *increment, Statement *body ):
     253        Statement( labels ), initialization( initialization ), condition( condition ), increment( increment ), body( body ) {
    242254}
    243255
     
    317329}
    318330
    319 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &_handlers, FinallyStmt *_finallyBlock ) :
    320         Statement( labels ), block( tryBlock ),  handlers( _handlers ), finallyBlock( _finallyBlock ) {
     331TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) :
     332        Statement( labels ), block( tryBlock ),  handlers( handlers ), finallyBlock( finallyBlock ) {
    321333}
    322334
     
    351363}
    352364
    353 CatchStmt::CatchStmt( std::list<Label> labels, Kind _kind, Declaration *_decl, Expression *_cond, Statement *_body ) :
    354         Statement( labels ), kind ( _kind ), decl ( _decl ), cond ( _cond ), body( _body ) {
     365CatchStmt::CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, Expression *cond, Statement *body ) :
     366        Statement( labels ), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) {
    355367}
    356368
     
    389401
    390402
    391 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : Statement( labels ), block( _block ) {
     403FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *block ) : Statement( labels ), block( block ) {
    392404        assert( labels.empty() ); // finally statement cannot be labeled
    393405}
  • src/SynTree/Statement.h

    r6ac5223 re50e9ff  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 16 16:28:55 2017
    13 // Update Count     : 70
     12// Last Modified On : Thu Aug 17 15:37:53 2017
     13// Update Count     : 72
    1414//
    1515
     
    127127class IfStmt : public Statement {
    128128  public:
    129         std::list<Statement *> initialization;
    130129        Expression *condition;
    131130        Statement *thenPart;
    132131        Statement *elsePart;
    133 
    134         IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart );
     132        std::list<Statement *> initialization;
     133
     134        IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart,
     135                        std::list<Statement *> initialization = std::list<Statement *>() );
    135136        IfStmt( const IfStmt &other );
    136137        virtual ~IfStmt();
    137138
    138139        std::list<Statement *> &get_initialization() { return initialization; }
    139         void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; }
    140140        Expression *get_condition() { return condition; }
    141141        void set_condition( Expression *newValue ) { condition = newValue; }
     
    239239
    240240        std::list<Statement *> &get_initialization() { return initialization; }
    241         void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; }
    242241        Expression *get_condition() { return condition; }
    243242        void set_condition( Expression *newValue ) { condition = newValue; }
  • src/SynTree/Visitor.cc

    r6ac5223 re50e9ff  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Jul 24 16:30:00 2017
    13 // Update Count     : 27
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Aug 17 15:39:38 2017
     13// Update Count     : 29
    1414//
    1515
     
    9999
    100100void Visitor::visit( IfStmt *ifStmt ) {
     101        acceptAll( ifStmt->get_initialization(), *this );
    101102        maybeAccept( ifStmt->get_condition(), *this );
    102103        maybeAccept( ifStmt->get_thenPart(), *this );
  • src/driver/cfa.cc

    r6ac5223 re50e9ff  
    99// Author           : Peter A. Buhr
    1010// Created On       : Tue Aug 20 13:44:49 2002
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jan 20 14:38:45 2017
    13 // Update Count     : 155
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Aug 17 15:24:00 2017
     13// Update Count     : 156
    1414//
    1515
     
    281281#endif //HAVE_LIBCFA
    282282
     283        // Add exception flags (unconditionally)
     284        args[nargs] = "-fexceptions";
     285        nargs += 1;
     286
    283287        // add the correct set of flags based on the type of compile this is
    284288
  • src/libcfa/Makefile.am

    r6ac5223 re50e9ff  
    3636         ${AM_V_GEN}@BACKEND_CC@ @CFA_FLAGS@ -D__CFA_DEBUG__ -O0 -c -o $@ $<
    3737
    38 EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function -I${abs_top_srcdir}/src/libcfa/libhdr -imacros libcfa-prelude.c @CFA_FLAGS@
     38EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function -imacros libcfa-prelude.c @CFA_FLAGS@
    3939
    4040AM_CCASFLAGS = @CFA_FLAGS@
  • src/libcfa/Makefile.in

    r6ac5223 re50e9ff  
    416416ARFLAGS = cr
    417417lib_LIBRARIES = $(am__append_1) $(am__append_2)
    418 EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function -I${abs_top_srcdir}/src/libcfa/libhdr -imacros libcfa-prelude.c @CFA_FLAGS@
     418EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function -imacros libcfa-prelude.c @CFA_FLAGS@
    419419AM_CCASFLAGS = @CFA_FLAGS@
    420420headers = fstream iostream iterator limits rational stdlib \
  • src/libcfa/exception.c

    r6ac5223 re50e9ff  
    1010// Created On       : Mon Jun 26 15:13:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug  4 15:20:00 2017
    13 // Update Count     : 6
     12// Last Modified On : Thr Aug 17 15:45:00 2017
     13// Update Count     : 7
    1414//
    1515
     
    2323#include <stdio.h>
    2424#include <unwind.h>
     25#include <libhdr/libdebug.h>
    2526
    2627// FIX ME: temporary hack to keep ARM build working
     
    7980void __cfaehm__throw_resume(exception * except) {
    8081
    81         // DEBUG
    82         printf("Throwing resumption exception\n");
     82        LIB_DEBUG_PRINT_SAFE("Throwing resumption exception\n");
    8383
    8484        struct __cfaehm__try_resume_node * original_head = shared_stack.current_resume;
     
    9494        }
    9595
    96         printf("Unhandled exception\n");
     96        LIB_DEBUG_PRINT_SAFE("Unhandled exception\n");
    9797        shared_stack.current_resume = original_head;
    9898
     
    106106
    107107void __cfaehm__try_resume_setup(struct __cfaehm__try_resume_node * node,
    108                         int (*handler)(exception * except)) {
     108                        _Bool (*handler)(exception * except)) {
    109109        node->next = shared_stack.top_resume;
    110110        node->handler = handler;
     
    154154        struct exception_context_t * context = this_exception_context();
    155155
    156         // DEBUG
    157         printf( "Deleting Exception\n");
     156        LIB_DEBUG_PRINT_SAFE("Deleting Exception\n");
    158157
    159158        // Remove the exception from the list.
     
    235234
    236235void __cfaehm__throw_terminate( exception * val ) {
    237         // DEBUG
    238         printf("Throwing termination exception\n");
     236        LIB_DEBUG_PRINT_SAFE("Throwing termination exception\n");
    239237
    240238        __cfaehm__allocate_exception( val );
     
    243241
    244242void __cfaehm__rethrow_terminate(void) {
    245         // DEBUG
    246         printf("Rethrowing termination exception\n");
     243        LIB_DEBUG_PRINT_SAFE("Rethrowing termination exception\n");
    247244
    248245        __cfaehm__begin_unwind();
     
    257254{
    258255
    259         // DEBUG
    260         //printf("CFA: 0x%lx\n", _Unwind_GetCFA(context));
    261         printf("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context);
     256        //LIB_DEBUG_PRINT_SAFE("CFA: 0x%lx\n", _Unwind_GetCFA(context));
     257        LIB_DEBUG_PRINT_SAFE("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context);
    262258
    263259        // If we've reached the end of the stack then there is nothing much we can do...
    264260        if( actions & _UA_END_OF_STACK ) return _URC_END_OF_STACK;
    265261
    266         // DEBUG
    267262        if (actions & _UA_SEARCH_PHASE) {
    268                 printf(" lookup phase");
    269         }
    270         // DEBUG
     263                LIB_DEBUG_PRINT_SAFE(" lookup phase");
     264        }
    271265        else if (actions & _UA_CLEANUP_PHASE) {
    272                 printf(" cleanup phase");
     266                LIB_DEBUG_PRINT_SAFE(" cleanup phase");
    273267        }
    274268        // Just in case, probably can't actually happen
     
    306300                // Have we reach the correct frame info yet?
    307301                if( lsd_info.Start + callsite_start + callsite_len < instruction_ptr ) {
    308                         //DEBUG BEGIN
     302#ifdef __CFA_DEBUG_PRINT__
    309303                        void * ls = (void*)lsd_info.Start;
    310304                        void * cs = (void*)callsite_start;
     
    313307                        void * ep = (void*)lsd_info.Start + callsite_start + callsite_len;
    314308                        void * ip = (void*)instruction_ptr;
    315                         printf("\nfound %p - %p (%p, %p, %p), looking for %p\n", bp, ep, ls, cs, cl, ip);
    316                         //DEBUG END
     309                        LIB_DEBUG_PRINT_SAFE("\nfound %p - %p (%p, %p, %p), looking for %p\n", bp, ep, ls, cs, cl, ip);
     310#endif // __CFA_DEBUG_PRINT__
    317311                        continue;
    318312                }
     
    362356
    363357                                        // Based on the return value, check if we matched the exception
    364                                         if( ret == _URC_HANDLER_FOUND) printf(" handler found\n");
    365                                         else printf(" no handler\n");
     358                                        if( ret == _URC_HANDLER_FOUND) {
     359                                                LIB_DEBUG_PRINT_SAFE(" handler found\n");
     360                                        } else {
     361                                                LIB_DEBUG_PRINT_SAFE(" no handler\n");
     362                                        }
    366363                                        return ret;
    367364                                }
    368365
    369366                                // This is only a cleanup handler, ignore it
    370                                 printf(" no action");
     367                                LIB_DEBUG_PRINT_SAFE(" no action");
    371368                        }
    372369                        else if (actions & _UA_CLEANUP_PHASE) {
     
    388385                                _Unwind_SetIP( context, ((lsd_info.LPStart) + (callsite_landing_pad)) );
    389386
    390                                 // DEBUG
    391                                 printf(" action\n");
     387                                LIB_DEBUG_PRINT_SAFE(" action\n");
    392388
    393389                                // Return have some action to run
     
    397393
    398394                // Nothing to do, move along
    399                 printf(" no landing pad");
     395                LIB_DEBUG_PRINT_SAFE(" no landing pad");
    400396        }
    401397        // No handling found
    402         printf(" table end reached\n");
    403 
    404         // DEBUG
     398        LIB_DEBUG_PRINT_SAFE(" table end reached\n");
     399
    405400        UNWIND:
    406         printf(" unwind\n");
     401        LIB_DEBUG_PRINT_SAFE(" unwind\n");
    407402
    408403        // Keep unwinding the stack
  • src/libcfa/exception.h

    r6ac5223 re50e9ff  
    1010// Created On       : Mon Jun 26 15:11:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug  4 15:20:00 2017
    13 // Update Count     : 5
     12// Last Modified On : Thr Aug 17 15:44:00 2017
     13// Update Count     : 6
    1414//
    1515
     
    5555struct __cfaehm__try_resume_node {
    5656    struct __cfaehm__try_resume_node * next;
    57     int (*handler)(exception * except);
     57    _Bool (*handler)(exception * except);
    5858};
    5959
     
    6161void __cfaehm__try_resume_setup(
    6262    struct __cfaehm__try_resume_node * node,
    63     int (*handler)(exception * except));
     63    _Bool (*handler)(exception * except));
    6464void __cfaehm__try_resume_cleanup(
    6565    struct __cfaehm__try_resume_node * node);
  • src/libcfa/libhdr.h

    r6ac5223 re50e9ff  
    1616#pragma once
    1717
    18 #include "libalign.h"
    19 #include "libdebug.h"
    20 #include "libtools.h"
     18#include "libhdr/libalign.h"
     19#include "libhdr/libdebug.h"
     20#include "libhdr/libtools.h"
    2121
    2222// Local Variables: //
  • src/tests/.expect/32/KRfunctions.txt

    r6ac5223 re50e9ff  
    1515}
    1616struct S {
    17     int __i__i_1;
     17int __i__i_1;
    1818};
    1919static inline void ___constructor__F_P2sS_autogen___1(struct S *___dst__P2sS_1);
     
    7979    __attribute__ ((unused)) int (*___retval_f14__PA0A0i_1)[][((unsigned int )10)];
    8080}
     81int __f15__Fi_iii__1(int __a__i_1, int __b__i_1, int __c__i_1){
     82    __attribute__ ((unused)) int ___retval_f15__i_1;
     83}
    8184const int __fred__FCi___1(){
    8285    __attribute__ ((unused)) const int ___retval_fred__Ci_1;
  • src/tests/.expect/64/KRfunctions.txt

    r6ac5223 re50e9ff  
    7979    __attribute__ ((unused)) int (*___retval_f14__PA0A0i_1)[][((long unsigned int )10)];
    8080}
     81int __f15__Fi_iii__1(int __a__i_1, int __b__i_1, int __c__i_1){
     82    __attribute__ ((unused)) int ___retval_f15__i_1;
     83}
    8184const int __fred__FCi___1(){
    8285    __attribute__ ((unused)) const int ___retval_fred__Ci_1;
  • src/tests/KRfunctions.c

    r6ac5223 re50e9ff  
    1010// Created On       : Thu Feb 16 15:23:17 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 24 22:05:00 2017
    13 // Update Count     : 3
     12// Last Modified On : Sun Aug 20 07:34:17 2017
     13// Update Count     : 7
    1414//
    1515
     
    3737int ((* f13( a, b, c ))[])[10] int a, * b, c[]; {}
    3838int (((* f14( a, b, c ))[])[10]) int a, * b, c[]; {}
     39f15( a, b, c ) {}
    3940
    4041const fred() {
  • src/tests/except-0.c

    r6ac5223 re50e9ff  
    77#include <stdio.h>
    88#include <stdbool.h>
     9
     10#include "except-mac.h"
     11TRIVIAL_EXCEPTION(yin)
     12TRIVIAL_EXCEPTION(yang)
     13TRIVIAL_EXCEPTION(zen)
     14
    915
    1016// Local type to mark exits from scopes. (see ERROR)
     
    2329
    2430
    25 // Local Exception Types and manual vtable types.
    26 //#define TRIVIAL_EXCEPTION(name) //TRIVAL_EXCEPTION(yin)
    27 struct yin;
    28 struct yin_vtable {
    29         struct exception_t_vtable const * parent;
    30         size_t size;
    31     void (*copy)(yin *this, yin * other);
    32     void (*free)(yin *this);
    33     const char (*msg)(yin *this);
    34 };
    35 struct yin {
    36         struct yin_vtable const * parent;
    37 };
    38 void yin_msg(yin) {
    39         return "in";
    40 }
    41 yin_vtable _yin_vtable_instance = {
    42         &_exception_t_vtable_instance, sizeof(yin), ?{}, ^?{}, yin_msg
    43 }
    44 
    45 
    46 void terminate(exception * except_value) {
     31// Mark throws: make sure to only pass in exception types.
     32forall(dtype T)
     33void terminate(T * except_value) {
    4734        signal_exit a = {"terminate function"};
    48         throw except_value;
     35        THROW(except_value);
    4936        printf("terminate returned\n");
    5037}
    5138
    52 void resume(exception * except_value) {
     39forall(dtype T)
     40void resume(T * except_value) {
    5341        signal_exit a = {"resume function"};
    54         throwResume except_value;
     42        THROW_RESUME(except_value);
    5543        printf("resume returned\n");
    5644}
     
    6048        signal_exit a = {"bar function"};
    6149        try {
    62                 terminate(4);
    63         } catch (3) {
    64                 printf("bar caught exception 3.\n");
     50                terminate(&(zen){});
     51        } catch (yin * error) {
     52                printf("bar caught exception yin.\n");
    6553        }
    6654}
     
    7058        try {
    7159                bar();
    72         } catch (4) {
    73                 printf("foo caught exception 4.\n");
    74         } catch (2) {
    75                 printf("foo caught exception 2.\n");
     60        } catch (yang * error) {
     61                printf("foo caught exception yang.\n");
     62        } catch (zen * error) {
     63                printf("foo caught exception zen.\n");
    7664        }
    7765}
     
    8169        signal_exit a = {"beta function"};
    8270        try {
    83                 resume(4);
    84         } catchResume (3) {
    85                 printf("beta caught exception 3\n");
     71                zen x;
     72                resume(&x);
     73        } catchResume (yin * error) {
     74                printf("beta caught exception yin\n");
    8675        }
    8776}
     
    9180        try {
    9281                beta();
    93         } catchResume (2) {
    94                 printf("alpha caught exception 2\n");
    95         } catchResume (4) {
    96                 printf("alpha caught exception 4\n");
     82        } catchResume (yang * error) {
     83                printf("alpha caught exception yang\n");
     84        } catchResume (zen * error) {
     85                printf("alpha caught exception zen\n");
    9786        }
    9887}
     
    117106void fallback() {
    118107        try {
    119                 resume(2);
    120         } catch (2) {
    121                 printf("fallback caught termination 2\n");
     108                zen x;
     109                resume(&x);
     110        } catch (zen * error) {
     111                printf("fallback caught termination zen\n");
    122112        }
    123113}
     
    127117        signal_exit a = {"terminate_swap"};
    128118        try {
    129                 terminate(2);
    130         } catch (2) {
    131                 terminate(3);
     119                yin x;
     120                terminate(&x);
     121        } catch (yin * error) {
     122                yang y;
     123                terminate(&y);
    132124        }
    133125}
     
    137129        try {
    138130                terminate_swap();
    139         } catch (3) {
    140                 printf("terminate_swapped caught exception 3\n");
     131        } catch (yang * error) {
     132                printf("terminate_swapped caught exception yang\n");
    141133        }
    142134}
     
    146138        signal_exit a = {"resume_swap"};
    147139        try {
    148                 resume(2);
    149         } catchResume (2) {
    150                 resume(3);
     140                yin x;
     141                resume(&x);
     142        } catchResume (yin * error) {
     143                yang y;
     144                resume(&y);
    151145        }
    152146}
     
    155149        try {
    156150                resume_swap();
    157         } catchResume (3) {
    158                 printf("resume_swapped caught exception 3\n");
     151        } catchResume (yang * error) {
     152                printf("resume_swapped caught exception yang\n");
    159153        }
    160154}
     
    164158        try {
    165159                try {
    166                         terminate(2);
    167                 } catch (2) {
    168                         printf("reterminate 2 caught and "
    169                                "will rethrow exception 2\n");
     160                        zen x;
     161                        terminate(&x);
     162                } catch (zen * error) {
     163                        printf("reterminate zen caught and "
     164                               "will rethrow exception zen\n");
    170165                        throw;
    171166                }
    172         } catch (2) {
    173                 printf("reterminate 1 caught exception 2\n");
     167        } catch (zen * error) {
     168                printf("reterminate 1 caught exception zen\n");
    174169        }
    175170}
     
    179174        try {
    180175                try {
    181                         resume(2);
    182                 } catchResume (2) {
    183                         printf("reresume 2 caught and rethrows exception 2\n");
     176                        zen x;
     177                        resume(&x);
     178                } catchResume (zen * error) {
     179                        printf("reresume zen caught and rethrows exception zen\n");
    184180                        throwResume;
    185181                }
    186         } catchResume (2) {
    187                 printf("reresume 1 caught exception 2\n");
     182        } catchResume (zen * error) {
     183                printf("reresume 1 caught exception zen\n");
    188184        }
    189185}
     
    193189        // terminate block, call resume
    194190        try {
    195                 resume(3);
    196         } catch (3) {
    197                 printf("fum caught exception 3\n");
     191                zen x;
     192                resume(&x);
     193        } catch (zen * error) {
     194                printf("fum caught exception zen\n");
    198195        }
    199196}
     
    202199        // resume block, call terminate
    203200        try {
    204                 terminate(3);
    205         } catchResume (3) {
    206                 printf("foe caught exception 3\n");
     201                zen y;
     202                terminate(&y);
     203        } catchResume (zen * error) {
     204                printf("foe caught exception zen\n");
    207205        }
    208206}
     
    212210        try {
    213211                foe();
    214         } catch (3) {
    215                 printf("fy caught exception 3\n");
     212        } catch (zen * error) {
     213                printf("fy caught exception zen\n");
    216214                fum();
    217215        }
     
    222220        try {
    223221                fy();
    224         } catchResume (3) {
    225                 printf("fee caught exception 3\n");
     222        } catchResume (zen * error) {
     223                printf("fee caught exception zen\n");
    226224        }
    227225}
     
    242240        reresume(); printf("\n");
    243241        fee(); printf("\n");
     242
    244243        // Uncaught termination test.
    245         terminate(7);
    246 }
     244        printf("Throw uncaught.\n");
     245        yang z;
     246        terminate(&z);
     247}
  • src/tests/except-1.c

    r6ac5223 re50e9ff  
    55#include <stdio.h>
    66
     7#include "except-mac.h"
     8TRIVIAL_EXCEPTION(yin)
     9TRIVIAL_EXCEPTION(yang)
     10
    711int main()
    812{
    913        try {
    10                 throw 3;
     14                yin a;
     15                THROW(&a);
    1116        }
    12         catch( 3 ) {
     17        catch( yin * err ) {
    1318                printf("First Caught\n");
    1419                try {
    15                         throw 4;
     20                        yang b;
     21                        THROW(&b);
    1622                }
    17                 catch( 4 ) {
     23                catch( yang * err ) {
    1824                        printf("Both Caught\n");
    1925                }
     
    2329        try {
    2430                try {
    25                         throw 2;
     31                        yang c;
     32                        THROW(&c);
    2633                }
    27                 catch( 2 ) {
     34                catch( yang * err ) {
    2835                        printf("First Catch and rethrow\n");
    2936                        throw;
    3037                }
    3138        }
    32         catch( 2 ) {
     39        catch( yang * err ) {
    3340                printf("Second Catch\n");
    3441        }
     
    3744        try {
    3845                try {
    39                         throw 5;
     46                        yin d;
     47                        THROW(&d);
    4048                }
    41                 catch( 5 ) {
     49                catch( yin * err ) {
    4250                        printf("Throw before cleanup\n");
    43                         throw 6;
     51                        yang e;
     52                        THROW(&e);
    4453                }
    4554        }
    46         catch( 6 ) {
     55        catch( yang * err ) {
    4756                printf("Catch after cleanup\n");
    4857        }
     
    5160        try {
    5261                try {
    53                         throw 7;
     62                        yin f;
     63                        THROW(&f);
    5464                }
    55                 catch( 7 ) {
     65                catch( yin * err ) {
    5666                        printf("Caught initial throw.\n");
    5767                        try {
    58                                 throw 8;
     68                                yang g;
     69                                THROW(&g);
    5970                        }
    60                         catch( 8 ) {
     71                        catch( yang * err ) {
    6172                                printf("Caught intermediate throw.\n");
    6273                        }
     
    6475                }
    6576        }
    66         catch( 7 ) {
     77        catch( yin * err ) {
    6778                printf("Caught final throw.\n");
    6879        }
  • src/tests/except-2.c

    r6ac5223 re50e9ff  
    22
    33
    4 #include <string.h>
     4#include <stdlib>
     5#include "except-mac.h"
    56
    6 // Local Exception Types and manual vtable types.
    7 #define GLUE2(left, right) left##right
    8 #define GLUE3(left, middle, right) left##middle##right
    9 #define BASE_EXCEPT __cfaehm__base_exception_t
    10 #define TABLE(name) GLUE2(name,_vtable)
    11 #define INSTANCE(name) GLUE3(_,name,_vtable_instance)
    12 #define TRIVIAL_EXCEPTION(name) \
    13 struct name; \
    14 struct TABLE(name) { \
    15         struct TABLE(BASE_EXCEPT) const * parent; \
    16         size_t size; \
    17         void (*copy)(name *this, name * other); \
    18         void (*free)(name *this); \
    19         const char * (*msg)(name *this); \
    20 }; \
    21 extern TABLE(name) INSTANCE(name); \
    22 struct name { \
    23         struct TABLE(name) const * virtual_table; \
    24 }; \
    25 const char * name##_msg(name * this) { \
    26         return #name; \
    27 } \
    28 void name##_copy(name * this, name * other) { \
    29         this->virtual_table = other->virtual_table; \
    30 } \
    31 TABLE(name) INSTANCE(name) @= { \
    32         .parent : &INSTANCE(BASE_EXCEPT), \
    33         .size : sizeof(name), .copy : name##_copy, \
    34         .free : ^?{}, .msg : name##_msg \
    35 }; \
    36 void ?{}(name * this) { \
    37         this->virtual_table = &INSTANCE(name); \
    38 }
    397TRIVIAL_EXCEPTION(yin)
    408TRIVIAL_EXCEPTION(yang)
     
    5018};
    5119extern num_error_vtable INSTANCE(num_error);
     20
    5221struct num_error {
    5322        struct num_error_vtable const * virtual_table;
     
    5524        int num;
    5625};
     26
    5727void num_error_msg(num_error * this) {
    5828        if ( ! this->msg ) {
    59                 const char * base = "Num Error with code: X";
    60                 this->msg = strdup( base );
     29                static const char * base = "Num Error with code: X";
     30                this->msg = malloc(22);
     31                for (int i = 0 ; (this->msg[i] = base[i]) ; ++i);
    6132        }
    6233        this->msg[21] = '0' + this->num;
     
    9061        try {
    9162                yin black;
    92                 throw (BASE_EXCEPT *)&black;
     63                THROW(&black);
    9364        } catch ( yin * error ) {
    9465                printf("throw yin caught.\n");
     
    9768        try {
    9869                yang white;
    99                 throwResume (BASE_EXCEPT *)&white;
     70                THROW_RESUME(&white);
    10071                printf("> throwResume returned.\n");
    10172        } catchResume ( yang * error ) {
     
    10576        try {
    10677                num_error x = { 2 };
    107                 throw (BASE_EXCEPT *)&x;
     78                THROW(&x);
    10879        }
    10980        catch (num_error * error ; 3 == error->virtual_table->code( error ) ) {
Note: See TracChangeset for help on using the changeset viewer.