Changes in / [e50e9ff:6ac5223]


Ignore:
Location:
src
Files:
2 deleted
27 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    re50e9ff r6ac5223  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug 18 15:34:00 2017
    13 // Update Count     : 488
     12// Last Modified On : Tus Jul 25 15:29:00 2017
     13// Update Count     : 486
    1414//
    1515#include "CodeGenerator.h"
     
    7979        }
    8080
    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;
     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;
    110100                }
    111101        }
     
    204194                        ++indent;
    205195                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) {
    206                                 updateLocation( *i );
     196                                output << lineDirective( *i ) << indent;
    207197                                (*i)->accept( *this );
    208198                                output << ";" << endl;
     
    227217        void CodeGenerator::visit( EnumDecl * enumDecl ) {
    228218                extension( enumDecl );
    229                 updateLocation( enumDecl );
     219                output << lineDirective ( enumDecl );
    230220                output << "enum ";
    231221                genAttributes( enumDecl->get_attributes() );
     
    243233                                ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
    244234                                assert( obj );
    245                                 updateLocation( obj );
    246                                 output << mangleName( obj );
     235                                output << lineDirective( obj ) << indent << mangleName( obj );
    247236                                if ( obj->get_init() ) {
    248237                                        output << " = ";
     
    262251        void CodeGenerator::visit( TypedefDecl * typeDecl ) {
    263252                assertf( ! genC, "Typedefs are removed and substituted in earlier passes." );
    264                 updateLocation( typeDecl );
     253                output << lineDirective( typeDecl );
    265254                output << "typedef ";
    266255                output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl;
     
    763752        void CodeGenerator::visit( StmtExpr * stmtExpr ) {
    764753                std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids();
    765                 updateLocation( stmtExpr );
    766                 output << "({" << std::endl;
     754                output << lineDirective( stmtExpr) << "({" << std::endl;
    767755                ++indent;
    768756                unsigned int numStmts = stmts.size();
    769757                unsigned int i = 0;
    770758                for ( Statement * stmt : stmts ) {
    771                         updateLocation( stmt );
     759                        output << lineDirective( stmt ) << indent;
    772760            output << printLabels( stmt->get_labels() );
    773761                        if ( i+1 == numStmts ) {
     
    856844
    857845        void CodeGenerator::visit( IfStmt * ifStmt ) {
    858                 updateLocation( ifStmt );
     846                output << lineDirective( ifStmt );
    859847                output << "if ( ";
    860848                ifStmt->get_condition()->accept( *this );
     
    870858
    871859        void CodeGenerator::visit( SwitchStmt * switchStmt ) {
    872                 updateLocation( switchStmt );
     860                output << lineDirective( switchStmt );
    873861                output << "switch ( " ;
    874862                switchStmt->get_condition()->accept( *this );
     
    883871
    884872        void CodeGenerator::visit( CaseStmt * caseStmt ) {
    885                 updateLocation( caseStmt );
     873                output << lineDirective( caseStmt );
     874                output << indent;
    886875                if ( caseStmt->isDefault()) {
    887876                        output << "default";
  • src/CodeGen/CodeGenerator.h

    re50e9ff r6ac5223  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug 18 15:40:00 2017
    13 // Update Count     : 56
     12// Last Modified On : Tus Jul 25 25:30:00 2017
     13// Update Count     : 54
    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
    110119                void asmName( DeclarationWithType *decl );
    111120
    112121                void extension( Expression *expr );
    113122                void extension( Declaration *decl );
    114 
    115                 void updateLocation( BaseSyntaxNode const * to );
    116123          private:
    117124                Indenter indent;
     
    122129                bool genC = false;    // true if output has to be C code
    123130                bool lineMarks = false;
    124 
    125                 CodeLocation currentLocation;
    126                 void updateLocation( CodeLocation const & to );
    127                 void nextLine();
    128131
    129132                void handleStorageClass( DeclarationWithType *decl );
     
    152155        /// returns C-compatible name of declaration
    153156        std::string genName( DeclarationWithType * decl );
     157
     158        std::ostream & operator<<(std::ostream &,
     159                CodeGenerator::LineMarker const &);
    154160} // namespace CodeGen
    155161
  • src/CodeGen/Generate.cc

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

    re50e9ff r6ac5223  
    1010// Created On       : Wed Jun 14 16:49:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug 17 17:19:00 2017
    13 // Update Count     : 9
     12// Last Modified On : Tus Aug  8 16:54:00 2017
     13// Update Count     : 7
    1414//
    1515
     
    166166                        /*bitfieldWidth*/ NULL,
    167167                        new BasicType( noQualifiers, BasicType::Bool ),
    168                         /*init*/ NULL,
    169                         std::list<Attribute *>{ new Attribute( "unused" ) }
     168                        /*init*/ NULL
    170169                        );
    171170                ObjectDecl voidptr_obj(
     
    184183                        );
    185184
    186                 ObjectDecl * unused_index_obj = index_obj.clone();
    187                 unused_index_obj->attributes.push_back( new Attribute( "unused" ) );
    188 
    189185                catch_func_t.get_parameters().push_back( index_obj.clone() );
    190186                catch_func_t.get_parameters().push_back( exception_obj.clone() );
    191                 match_func_t.get_returnVals().push_back( unused_index_obj );
     187                match_func_t.get_returnVals().push_back( index_obj.clone() );
    192188                match_func_t.get_parameters().push_back( exception_obj.clone() );
    193189                handle_func_t.get_returnVals().push_back( bool_obj.clone() );
     
    421417                }
    422418
    423                 body->push_back( new ReturnStmt( noLabels,
    424                         new ConstantExpr( Constant::from_int( 0 ) ) ) );
     419                body->push_back( new ReturnStmt( noLabels, new ConstantExpr(
     420                        Constant::from_int( 0 ) ) ) );
    425421
    426422                return new FunctionDecl("match", Type::StorageClasses(),
     
    453449                CompoundStmt * body = new CompoundStmt( noLabels );
    454450
    455                 FunctionType * func_type = handle_func_t.clone();
     451                FunctionType * func_type = match_func_t.clone();
    456452                DeclarationWithType * except_obj = func_type->get_parameters().back();
    457453
     
    476472                }
    477473
    478                 body->push_back( new ReturnStmt( noLabels,
    479                         new ConstantExpr( Constant::from_bool( false ) ) ) );
     474                body->push_back( new ReturnStmt( noLabels, new ConstantExpr(
     475                        Constant::from_bool( false ) ) ) );
    480476
    481477                return new FunctionDecl("handle", Type::StorageClasses(),
  • src/ControlStruct/ForExprMutator.cc

    re50e9ff r6ac5223  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug 18 10:22:00 2017
    13 // Update Count     : 12
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Jul 14 12:14:44 2015
     13// Update Count     : 10
    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                 }
     23        Statement *ForExprMutator::postmutate( ForStmt *forStmt ) {
     24                // 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
    2829
    29                 // Create compound statement, move initializers outside,
    30                 // the resut of the original stays as is.
     30                // create compound statement, move initializers outside, leave _for_ as-is
    3131                CompoundStmt *block = new CompoundStmt( std::list< Label >() );
    3232                std::list<Statement *> &stmts = block->get_kids();
    33                 stmts.splice( stmts.end(), init );
     33                for ( std::list<Statement *>::iterator it = init.begin(); it != init.end(); ++it ) {
     34                        stmts.push_back( *it );
     35                }       // for
    3436
    35                 // Add for to the new block.
    36                 stmts.push_back( originalStmt );
     37                // add for to the new block
     38                stmts.push_back( forStmt );
     39                forStmt->set_initialization( std::list<Statement *>() );
    3740                return block;
    38         }
    39 
    40         Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) {
    41                 return hoist( ifStmt, ifStmt->initialization );
    42         }
    43         Statement *ForExprMutator::postmutate( ForStmt *forStmt ) {
    44                 // hoist any initializer declarations to make them C89 (rather than C99)
    45                 return hoist( forStmt, forStmt->initialization );
    4641        }
    4742} // namespace ControlStruct
  • src/ControlStruct/ForExprMutator.h

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

    re50e9ff r6ac5223  
    1010// Created On       : Sat May 16 14:59:41 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 16:01:31 2017
    13 // Update Count     : 345
     12// Last Modified On : Wed Aug 16 16:39:43 2017
     13// Update Count     : 340
    1414//
    1515
     
    2424#include "SynTree/Expression.h"    // for Expression, ConstantExpr
    2525#include "SynTree/Label.h"         // for Label, noLabels
    26 #include "SynTree/Declaration.h"
    2726#include "SynTree/Statement.h"     // for Statement, BranchStmt, CaseStmt
    2827#include "parserutility.h"         // for notZeroExpr
     
    9998        } // if
    10099
    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 );
     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;
    104109}
    105110
  • src/Parser/parser.yy

    re50e9ff r6ac5223  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug 20 09:21:54 2017
    13 // Update Count     : 2573
     12// Last Modified On : Wed Aug 16 18:09:14 2017
     13// Update Count     : 2485
    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 '(' push if_control_expression ')' statement                         %prec THEN
     798        IF '(' if_control_expression ')' statement                              %prec THEN
    799799                // explicitly deal with the shift/reduce conflict on if/else
    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
     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
    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 pop
     825        comma_expression
    826826                { $$ = new IfCtl( nullptr, $1 ); }
    827         | c_declaration pop                                                                     // no semi-colon
     827        | c_declaration                                                                         // no semi-coln
    828828                { $$ = new IfCtl( $1, nullptr ); }
    829         | cfa_declaration pop                                                           // no semi-colon
     829        | cfa_declaration                                                                       // no semi-colon
    830830                { $$ = new IfCtl( $1, nullptr ); }
    831         | declaration comma_expression                                          // semi-colon separated
     831        | declaration comma_expression
    832832                { $$ = new IfCtl( $1, $2 ); }
    833833        ;
     
    11041104
    11051105KR_declaration_list_opt:                                                                // used to declare parameter types in K&R style functions
    1106         // empty
     1106        pop
    11071107                { $$ = nullptr; }
    11081108        | KR_declaration_list
     
    11101110
    11111111KR_declaration_list:
    1112         push c_declaration pop ';'
    1113                 { $$ = $2; }
    1114         | KR_declaration_list push c_declaration pop ';'
     1112        c_declaration ';'
     1113        | KR_declaration_list push c_declaration ';'
    11151114                { $$ = $1->appendList( $3 ); }
    11161115        ;
     
    11321131
    11331132declaration:                                                                                    // old & new style declarations
    1134         c_declaration pop ';'
    1135         | cfa_declaration pop ';'                                                       // CFA
     1133        c_declaration ';'
     1134        | cfa_declaration ';'                                                           // CFA
    11361135        ;
    11371136
     
    11481147
    11491148cfa_declaration:                                                                                // CFA
    1150         cfa_variable_declaration
    1151         | cfa_typedef_declaration
    1152         | cfa_function_declaration
    1153         | type_declaring_list
    1154         | trait_specifier
     1149        cfa_variable_declaration pop
     1150        | cfa_typedef_declaration pop
     1151        | cfa_function_declaration pop
     1152        | type_declaring_list pop
     1153        | trait_specifier pop
    11551154        ;
    11561155
     
    13521351
    13531352c_declaration:
    1354         declaration_specifier declaring_list
     1353        declaration_specifier declaring_list pop
    13551354                {
    13561355                        $$ = distAttr( $1, $2 );
    13571356                }
    1358         | typedef_declaration
    1359         | typedef_expression                                                            // GCC, naming expression type
    1360         | sue_declaration_specifier
     1357        | typedef_declaration pop
     1358        | typedef_expression pop                                                        // GCC, naming expression type
     1359        | sue_declaration_specifier pop
    13611360        ;
    13621361
     
    22312230                        $$ = $1->addFunctionBody( $2 );
    22322231                }
    2233         | KR_function_declarator KR_declaration_list_opt compound_statement
     2232        | KR_function_declarator push KR_declaration_list_opt compound_statement
    22342233                {
    22352234                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22362235                        typedefTable.leaveScope();
    2237                         $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 );
     2236                        $$ = $1->addOldDeclList( $3 )->addFunctionBody( $4 );
    22382237                }
    22392238        ;
     
    22792278
    22802279                // Old-style K&R function definition, OBSOLESCENT (see 4)
    2281         | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2280        | declaration_specifier KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
    22822281                {
    22832282                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22842283                        typedefTable.leaveScope();
    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
     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
    22882287                {
    22892288                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22902289                        typedefTable.leaveScope();
    2291                         $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 );
     2290                        $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $1 );
    22922291                }
    22932292
    22942293                // Old-style K&R function definition with "implicit int" type_specifier, OBSOLESCENT (see 4)
    2295         | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement
     2294        | declaration_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement
    22962295                {
    22972296                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    22982297                        typedefTable.leaveScope();
    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
     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
    23022301                {
    23032302                        typedefTable.addToEnclosingScope( TypedefTable::ID );
    23042303                        typedefTable.leaveScope();
    2305                         $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 );
     2304                        $$ = $3->addOldDeclList( $5 )->addFunctionBody( $7 )->addQualifiers( $2 )->addQualifiers( $1 );
    23062305                }
    23072306        ;
  • src/SymTab/Indexer.cc

    re50e9ff r6ac5223  
    1010// Created On       : Sun May 17 21:37:33 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 16:08:40 2017
    13 // Update Count     : 20
     12// Last Modified On : Thu Mar 30 16:38:47 2017
     13// Update Count     : 19
    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();
    360353        }
    361354
  • src/SymTab/Indexer.h

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

    re50e9ff r6ac5223  
    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 : Mon Aug 21 09:53:15 2017
    13 // Update Count     : 30
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thr Aug  3 11:33:00 2016
     13// Update Count     : 29
    1414//
    1515
     
    8080                        }
    8181                }
    82                 assertf( initializers.size() == designations.size(), "Created ListInit with mismatching initializers (%zd) and designations (%zd)", initializers.size(), designations.size() );
     82                assertf( initializers.size() == designations.size(), "Created ListInit with mismatching initializers (%lu) and designations (%lu)", initializers.size(), designations.size() );
    8383}
    8484
  • src/SynTree/Mutator.cc

    re50e9ff r6ac5223  
    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 Aug 17 15:39:37 2017
    13 // Update Count     : 27
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Jul 24 16:32:00 2017
     13// Update Count     : 25
    1414//
    1515
     
    114114
    115115Statement *Mutator::mutate( IfStmt *ifStmt ) {
    116         mutateAll( ifStmt->get_initialization(), *this );
    117116        ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) );
    118117        ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) );
  • src/SynTree/Statement.cc

    re50e9ff r6ac5223  
    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 Aug 17 16:17:20 2017
    13 // Update Count     : 67
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Aug 14 12:26:00 2017
     13// Update Count     : 65
    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, std::list<Statement *> initialization ):
    125         Statement( labels ), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {}
     124IfStmt::IfStmt( std::list<Label> _labels, Expression *_condition, Statement *_thenPart, Statement *_elsePart ):
     125        Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart ) {}
    126126
    127127IfStmt::IfStmt( const IfStmt & other ) :
    128         Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {
    129         cloneAll( other.initialization, initialization );
    130 }
     128        Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {}
    131129
    132130IfStmt::~IfStmt() {
    133         deleteAll( initialization );
    134131        delete condition;
    135132        delete thenPart;
     
    142139        condition->print( os, indent + 4 );
    143140
    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 
    153141        os << string( indent+2, ' ' ) << "... then: " << endl;
    154142
     
    163151}
    164152
    165 SwitchStmt::SwitchStmt( std::list<Label> labels, Expression * condition, std::list<Statement *> &statements ):
    166         Statement( labels ), condition( condition ), statements( statements ) {
     153SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_statements ):
     154        Statement( _labels ), condition( _condition ), statements( _statements ) {
    167155}
    168156
     
    191179}
    192180
    193 CaseStmt::CaseStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements, bool deflt ) throw ( SemanticError ) :
    194         Statement( labels ), condition( condition ), stmts( statements ), _isDefault( deflt ) {
     181CaseStmt::CaseStmt( std::list<Label> _labels, Expression *_condition, std::list<Statement *> &_statements, bool deflt ) throw ( SemanticError ) :
     182        Statement( _labels ), condition( _condition ), stmts( _statements ), _isDefault( deflt ) {
    195183        if ( isDefault() && condition != 0 )
    196184                throw SemanticError("default with conditions");
     
    228216}
    229217
    230 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition, Statement *body, bool isDoWhile ):
    231         Statement( labels ), condition( condition), body( body), isDoWhile( isDoWhile) {
     218WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ):
     219        Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) {
    232220}
    233221
     
    250238}
    251239
    252 ForStmt::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 ) {
     240ForStmt::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_ ) {
    254242}
    255243
     
    329317}
    330318
    331 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) :
    332         Statement( labels ), block( tryBlock ),  handlers( handlers ), finallyBlock( finallyBlock ) {
     319TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &_handlers, FinallyStmt *_finallyBlock ) :
     320        Statement( labels ), block( tryBlock ),  handlers( _handlers ), finallyBlock( _finallyBlock ) {
    333321}
    334322
     
    363351}
    364352
    365 CatchStmt::CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, Expression *cond, Statement *body ) :
    366         Statement( labels ), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) {
     353CatchStmt::CatchStmt( std::list<Label> labels, Kind _kind, Declaration *_decl, Expression *_cond, Statement *_body ) :
     354        Statement( labels ), kind ( _kind ), decl ( _decl ), cond ( _cond ), body( _body ) {
    367355}
    368356
     
    401389
    402390
    403 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *block ) : Statement( labels ), block( block ) {
     391FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : Statement( labels ), block( _block ) {
    404392        assert( labels.empty() ); // finally statement cannot be labeled
    405393}
  • src/SynTree/Statement.h

    re50e9ff r6ac5223  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 17 15:37:53 2017
    13 // Update Count     : 72
     12// Last Modified On : Wed Aug 16 16:28:55 2017
     13// Update Count     : 70
    1414//
    1515
     
    127127class IfStmt : public Statement {
    128128  public:
     129        std::list<Statement *> initialization;
    129130        Expression *condition;
    130131        Statement *thenPart;
    131132        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 *>() );
     133
     134        IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart );
    136135        IfStmt( const IfStmt &other );
    137136        virtual ~IfStmt();
    138137
    139138        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; }
    241242        Expression *get_condition() { return condition; }
    242243        void set_condition( Expression *newValue ) { condition = newValue; }
  • src/SynTree/Visitor.cc

    re50e9ff r6ac5223  
    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 Aug 17 15:39:38 2017
    13 // Update Count     : 29
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Jul 24 16:30:00 2017
     13// Update Count     : 27
    1414//
    1515
     
    9999
    100100void Visitor::visit( IfStmt *ifStmt ) {
    101         acceptAll( ifStmt->get_initialization(), *this );
    102101        maybeAccept( ifStmt->get_condition(), *this );
    103102        maybeAccept( ifStmt->get_thenPart(), *this );
  • src/driver/cfa.cc

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

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

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

    re50e9ff r6ac5223  
    1010// Created On       : Mon Jun 26 15:13:00 2017
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug 17 15:45:00 2017
    13 // Update Count     : 7
     12// Last Modified On : Fri Aug  4 15:20:00 2017
     13// Update Count     : 6
    1414//
    1515
     
    2323#include <stdio.h>
    2424#include <unwind.h>
    25 #include <libhdr/libdebug.h>
    2625
    2726// FIX ME: temporary hack to keep ARM build working
     
    8079void __cfaehm__throw_resume(exception * except) {
    8180
    82         LIB_DEBUG_PRINT_SAFE("Throwing resumption exception\n");
     81        // DEBUG
     82        printf("Throwing resumption exception\n");
    8383
    8484        struct __cfaehm__try_resume_node * original_head = shared_stack.current_resume;
     
    9494        }
    9595
    96         LIB_DEBUG_PRINT_SAFE("Unhandled exception\n");
     96        printf("Unhandled exception\n");
    9797        shared_stack.current_resume = original_head;
    9898
     
    106106
    107107void __cfaehm__try_resume_setup(struct __cfaehm__try_resume_node * node,
    108                         _Bool (*handler)(exception * except)) {
     108                        int (*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         LIB_DEBUG_PRINT_SAFE("Deleting Exception\n");
     156        // DEBUG
     157        printf( "Deleting Exception\n");
    157158
    158159        // Remove the exception from the list.
     
    234235
    235236void __cfaehm__throw_terminate( exception * val ) {
    236         LIB_DEBUG_PRINT_SAFE("Throwing termination exception\n");
     237        // DEBUG
     238        printf("Throwing termination exception\n");
    237239
    238240        __cfaehm__allocate_exception( val );
     
    241243
    242244void __cfaehm__rethrow_terminate(void) {
    243         LIB_DEBUG_PRINT_SAFE("Rethrowing termination exception\n");
     245        // DEBUG
     246        printf("Rethrowing termination exception\n");
    244247
    245248        __cfaehm__begin_unwind();
     
    254257{
    255258
    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);
     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);
    258262
    259263        // If we've reached the end of the stack then there is nothing much we can do...
    260264        if( actions & _UA_END_OF_STACK ) return _URC_END_OF_STACK;
    261265
     266        // DEBUG
    262267        if (actions & _UA_SEARCH_PHASE) {
    263                 LIB_DEBUG_PRINT_SAFE(" lookup phase");
    264         }
     268                printf(" lookup phase");
     269        }
     270        // DEBUG
    265271        else if (actions & _UA_CLEANUP_PHASE) {
    266                 LIB_DEBUG_PRINT_SAFE(" cleanup phase");
     272                printf(" cleanup phase");
    267273        }
    268274        // Just in case, probably can't actually happen
     
    300306                // Have we reach the correct frame info yet?
    301307                if( lsd_info.Start + callsite_start + callsite_len < instruction_ptr ) {
    302 #ifdef __CFA_DEBUG_PRINT__
     308                        //DEBUG BEGIN
    303309                        void * ls = (void*)lsd_info.Start;
    304310                        void * cs = (void*)callsite_start;
     
    307313                        void * ep = (void*)lsd_info.Start + callsite_start + callsite_len;
    308314                        void * ip = (void*)instruction_ptr;
    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__
     315                        printf("\nfound %p - %p (%p, %p, %p), looking for %p\n", bp, ep, ls, cs, cl, ip);
     316                        //DEBUG END
    311317                        continue;
    312318                }
     
    356362
    357363                                        // Based on the return value, check if we matched the exception
    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                                         }
     364                                        if( ret == _URC_HANDLER_FOUND) printf(" handler found\n");
     365                                        else printf(" no handler\n");
    363366                                        return ret;
    364367                                }
    365368
    366369                                // This is only a cleanup handler, ignore it
    367                                 LIB_DEBUG_PRINT_SAFE(" no action");
     370                                printf(" no action");
    368371                        }
    369372                        else if (actions & _UA_CLEANUP_PHASE) {
     
    385388                                _Unwind_SetIP( context, ((lsd_info.LPStart) + (callsite_landing_pad)) );
    386389
    387                                 LIB_DEBUG_PRINT_SAFE(" action\n");
     390                                // DEBUG
     391                                printf(" action\n");
    388392
    389393                                // Return have some action to run
     
    393397
    394398                // Nothing to do, move along
    395                 LIB_DEBUG_PRINT_SAFE(" no landing pad");
     399                printf(" no landing pad");
    396400        }
    397401        // No handling found
    398         LIB_DEBUG_PRINT_SAFE(" table end reached\n");
    399 
     402        printf(" table end reached\n");
     403
     404        // DEBUG
    400405        UNWIND:
    401         LIB_DEBUG_PRINT_SAFE(" unwind\n");
     406        printf(" unwind\n");
    402407
    403408        // Keep unwinding the stack
  • src/libcfa/exception.h

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

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

    re50e9ff r6ac5223  
    1515}
    1616struct S {
    17 int __i__i_1;
     17    int __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}
    81 int __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 }
    8481const int __fred__FCi___1(){
    8582    __attribute__ ((unused)) const int ___retval_fred__Ci_1;
  • src/tests/.expect/64/KRfunctions.txt

    re50e9ff r6ac5223  
    7979    __attribute__ ((unused)) int (*___retval_f14__PA0A0i_1)[][((long unsigned int )10)];
    8080}
    81 int __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 }
    8481const int __fred__FCi___1(){
    8582    __attribute__ ((unused)) const int ___retval_fred__Ci_1;
  • src/tests/KRfunctions.c

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

    re50e9ff r6ac5223  
    77#include <stdio.h>
    88#include <stdbool.h>
    9 
    10 #include "except-mac.h"
    11 TRIVIAL_EXCEPTION(yin)
    12 TRIVIAL_EXCEPTION(yang)
    13 TRIVIAL_EXCEPTION(zen)
    14 
    159
    1610// Local type to mark exits from scopes. (see ERROR)
     
    2923
    3024
    31 // Mark throws: make sure to only pass in exception types.
    32 forall(dtype T)
    33 void terminate(T * except_value) {
     25// Local Exception Types and manual vtable types.
     26//#define TRIVIAL_EXCEPTION(name) //TRIVAL_EXCEPTION(yin)
     27struct yin;
     28struct 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};
     35struct yin {
     36        struct yin_vtable const * parent;
     37};
     38void yin_msg(yin) {
     39        return "in";
     40}
     41yin_vtable _yin_vtable_instance = {
     42        &_exception_t_vtable_instance, sizeof(yin), ?{}, ^?{}, yin_msg
     43}
     44
     45
     46void terminate(exception * except_value) {
    3447        signal_exit a = {"terminate function"};
    35         THROW(except_value);
     48        throw except_value;
    3649        printf("terminate returned\n");
    3750}
    3851
    39 forall(dtype T)
    40 void resume(T * except_value) {
     52void resume(exception * except_value) {
    4153        signal_exit a = {"resume function"};
    42         THROW_RESUME(except_value);
     54        throwResume except_value;
    4355        printf("resume returned\n");
    4456}
     
    4860        signal_exit a = {"bar function"};
    4961        try {
    50                 terminate(&(zen){});
    51         } catch (yin * error) {
    52                 printf("bar caught exception yin.\n");
     62                terminate(4);
     63        } catch (3) {
     64                printf("bar caught exception 3.\n");
    5365        }
    5466}
     
    5870        try {
    5971                bar();
    60         } catch (yang * error) {
    61                 printf("foo caught exception yang.\n");
    62         } catch (zen * error) {
    63                 printf("foo caught exception zen.\n");
     72        } catch (4) {
     73                printf("foo caught exception 4.\n");
     74        } catch (2) {
     75                printf("foo caught exception 2.\n");
    6476        }
    6577}
     
    6981        signal_exit a = {"beta function"};
    7082        try {
    71                 zen x;
    72                 resume(&x);
    73         } catchResume (yin * error) {
    74                 printf("beta caught exception yin\n");
     83                resume(4);
     84        } catchResume (3) {
     85                printf("beta caught exception 3\n");
    7586        }
    7687}
     
    8091        try {
    8192                beta();
    82         } catchResume (yang * error) {
    83                 printf("alpha caught exception yang\n");
    84         } catchResume (zen * error) {
    85                 printf("alpha caught exception zen\n");
     93        } catchResume (2) {
     94                printf("alpha caught exception 2\n");
     95        } catchResume (4) {
     96                printf("alpha caught exception 4\n");
    8697        }
    8798}
     
    106117void fallback() {
    107118        try {
    108                 zen x;
    109                 resume(&x);
    110         } catch (zen * error) {
    111                 printf("fallback caught termination zen\n");
     119                resume(2);
     120        } catch (2) {
     121                printf("fallback caught termination 2\n");
    112122        }
    113123}
     
    117127        signal_exit a = {"terminate_swap"};
    118128        try {
    119                 yin x;
    120                 terminate(&x);
    121         } catch (yin * error) {
    122                 yang y;
    123                 terminate(&y);
     129                terminate(2);
     130        } catch (2) {
     131                terminate(3);
    124132        }
    125133}
     
    129137        try {
    130138                terminate_swap();
    131         } catch (yang * error) {
    132                 printf("terminate_swapped caught exception yang\n");
     139        } catch (3) {
     140                printf("terminate_swapped caught exception 3\n");
    133141        }
    134142}
     
    138146        signal_exit a = {"resume_swap"};
    139147        try {
    140                 yin x;
    141                 resume(&x);
    142         } catchResume (yin * error) {
    143                 yang y;
    144                 resume(&y);
     148                resume(2);
     149        } catchResume (2) {
     150                resume(3);
    145151        }
    146152}
     
    149155        try {
    150156                resume_swap();
    151         } catchResume (yang * error) {
    152                 printf("resume_swapped caught exception yang\n");
     157        } catchResume (3) {
     158                printf("resume_swapped caught exception 3\n");
    153159        }
    154160}
     
    158164        try {
    159165                try {
    160                         zen x;
    161                         terminate(&x);
    162                 } catch (zen * error) {
    163                         printf("reterminate zen caught and "
    164                                "will rethrow exception zen\n");
     166                        terminate(2);
     167                } catch (2) {
     168                        printf("reterminate 2 caught and "
     169                               "will rethrow exception 2\n");
    165170                        throw;
    166171                }
    167         } catch (zen * error) {
    168                 printf("reterminate 1 caught exception zen\n");
     172        } catch (2) {
     173                printf("reterminate 1 caught exception 2\n");
    169174        }
    170175}
     
    174179        try {
    175180                try {
    176                         zen x;
    177                         resume(&x);
    178                 } catchResume (zen * error) {
    179                         printf("reresume zen caught and rethrows exception zen\n");
     181                        resume(2);
     182                } catchResume (2) {
     183                        printf("reresume 2 caught and rethrows exception 2\n");
    180184                        throwResume;
    181185                }
    182         } catchResume (zen * error) {
    183                 printf("reresume 1 caught exception zen\n");
     186        } catchResume (2) {
     187                printf("reresume 1 caught exception 2\n");
    184188        }
    185189}
     
    189193        // terminate block, call resume
    190194        try {
    191                 zen x;
    192                 resume(&x);
    193         } catch (zen * error) {
    194                 printf("fum caught exception zen\n");
     195                resume(3);
     196        } catch (3) {
     197                printf("fum caught exception 3\n");
    195198        }
    196199}
     
    199202        // resume block, call terminate
    200203        try {
    201                 zen y;
    202                 terminate(&y);
    203         } catchResume (zen * error) {
    204                 printf("foe caught exception zen\n");
     204                terminate(3);
     205        } catchResume (3) {
     206                printf("foe caught exception 3\n");
    205207        }
    206208}
     
    210212        try {
    211213                foe();
    212         } catch (zen * error) {
    213                 printf("fy caught exception zen\n");
     214        } catch (3) {
     215                printf("fy caught exception 3\n");
    214216                fum();
    215217        }
     
    220222        try {
    221223                fy();
    222         } catchResume (zen * error) {
    223                 printf("fee caught exception zen\n");
     224        } catchResume (3) {
     225                printf("fee caught exception 3\n");
    224226        }
    225227}
     
    240242        reresume(); printf("\n");
    241243        fee(); printf("\n");
    242 
    243244        // Uncaught termination test.
    244         printf("Throw uncaught.\n");
    245         yang z;
    246         terminate(&z);
    247 }
     245        terminate(7);
     246}
  • src/tests/except-1.c

    re50e9ff r6ac5223  
    55#include <stdio.h>
    66
    7 #include "except-mac.h"
    8 TRIVIAL_EXCEPTION(yin)
    9 TRIVIAL_EXCEPTION(yang)
    10 
    117int main()
    128{
    139        try {
    14                 yin a;
    15                 THROW(&a);
     10                throw 3;
    1611        }
    17         catch( yin * err ) {
     12        catch( 3 ) {
    1813                printf("First Caught\n");
    1914                try {
    20                         yang b;
    21                         THROW(&b);
     15                        throw 4;
    2216                }
    23                 catch( yang * err ) {
     17                catch( 4 ) {
    2418                        printf("Both Caught\n");
    2519                }
     
    2923        try {
    3024                try {
    31                         yang c;
    32                         THROW(&c);
     25                        throw 2;
    3326                }
    34                 catch( yang * err ) {
     27                catch( 2 ) {
    3528                        printf("First Catch and rethrow\n");
    3629                        throw;
    3730                }
    3831        }
    39         catch( yang * err ) {
     32        catch( 2 ) {
    4033                printf("Second Catch\n");
    4134        }
     
    4437        try {
    4538                try {
    46                         yin d;
    47                         THROW(&d);
     39                        throw 5;
    4840                }
    49                 catch( yin * err ) {
     41                catch( 5 ) {
    5042                        printf("Throw before cleanup\n");
    51                         yang e;
    52                         THROW(&e);
     43                        throw 6;
    5344                }
    5445        }
    55         catch( yang * err ) {
     46        catch( 6 ) {
    5647                printf("Catch after cleanup\n");
    5748        }
     
    6051        try {
    6152                try {
    62                         yin f;
    63                         THROW(&f);
     53                        throw 7;
    6454                }
    65                 catch( yin * err ) {
     55                catch( 7 ) {
    6656                        printf("Caught initial throw.\n");
    6757                        try {
    68                                 yang g;
    69                                 THROW(&g);
     58                                throw 8;
    7059                        }
    71                         catch( yang * err ) {
     60                        catch( 8 ) {
    7261                                printf("Caught intermediate throw.\n");
    7362                        }
     
    7564                }
    7665        }
    77         catch( yin * err ) {
     66        catch( 7 ) {
    7867                printf("Caught final throw.\n");
    7968        }
  • src/tests/except-2.c

    re50e9ff r6ac5223  
    22
    33
    4 #include <stdlib>
    5 #include "except-mac.h"
     4#include <string.h>
    65
     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) \
     13struct name; \
     14struct 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}; \
     21extern TABLE(name) INSTANCE(name); \
     22struct name { \
     23        struct TABLE(name) const * virtual_table; \
     24}; \
     25const char * name##_msg(name * this) { \
     26        return #name; \
     27} \
     28void name##_copy(name * this, name * other) { \
     29        this->virtual_table = other->virtual_table; \
     30} \
     31TABLE(name) INSTANCE(name) @= { \
     32        .parent : &INSTANCE(BASE_EXCEPT), \
     33        .size : sizeof(name), .copy : name##_copy, \
     34        .free : ^?{}, .msg : name##_msg \
     35}; \
     36void ?{}(name * this) { \
     37        this->virtual_table = &INSTANCE(name); \
     38}
    739TRIVIAL_EXCEPTION(yin)
    840TRIVIAL_EXCEPTION(yang)
     
    1850};
    1951extern num_error_vtable INSTANCE(num_error);
    20 
    2152struct num_error {
    2253        struct num_error_vtable const * virtual_table;
     
    2455        int num;
    2556};
    26 
    2757void num_error_msg(num_error * this) {
    2858        if ( ! this->msg ) {
    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);
     59                const char * base = "Num Error with code: X";
     60                this->msg = strdup( base );
    3261        }
    3362        this->msg[21] = '0' + this->num;
     
    6190        try {
    6291                yin black;
    63                 THROW(&black);
     92                throw (BASE_EXCEPT *)&black;
    6493        } catch ( yin * error ) {
    6594                printf("throw yin caught.\n");
     
    6897        try {
    6998                yang white;
    70                 THROW_RESUME(&white);
     99                throwResume (BASE_EXCEPT *)&white;
    71100                printf("> throwResume returned.\n");
    72101        } catchResume ( yang * error ) {
     
    76105        try {
    77106                num_error x = { 2 };
    78                 THROW(&x);
     107                throw (BASE_EXCEPT *)&x;
    79108        }
    80109        catch (num_error * error ; 3 == error->virtual_table->code( error ) ) {
Note: See TracChangeset for help on using the changeset viewer.