Changes in / [e50e9ff:6ac5223]
- Location:
- src
- Files:
-
- 2 deleted
- 27 edited
-
CodeGen/CodeGenerator.cc (modified) (10 diffs)
-
CodeGen/CodeGenerator.h (modified) (4 diffs)
-
CodeGen/Generate.cc (modified) (2 diffs)
-
ControlStruct/ExceptTranslate.cc (modified) (6 diffs)
-
ControlStruct/ForExprMutator.cc (modified) (2 diffs)
-
ControlStruct/ForExprMutator.h (modified) (2 diffs)
-
Parser/StatementNode.cc (modified) (3 diffs)
-
Parser/parser.yy (modified) (11 diffs)
-
SymTab/Indexer.cc (modified) (2 diffs)
-
SymTab/Indexer.h (modified) (2 diffs)
-
SynTree/Initializer.cc (modified) (2 diffs)
-
SynTree/Mutator.cc (modified) (2 diffs)
-
SynTree/Statement.cc (modified) (15 diffs)
-
SynTree/Statement.h (modified) (3 diffs)
-
SynTree/Visitor.cc (modified) (2 diffs)
-
driver/cfa.cc (modified) (2 diffs)
-
libcfa/Makefile.am (modified) (1 diff)
-
libcfa/Makefile.in (modified) (1 diff)
-
libcfa/exception.c (modified) (14 diffs)
-
libcfa/exception.h (modified) (3 diffs)
-
libcfa/libhdr.h (modified) (1 diff)
-
tests/.expect/32/KRfunctions.txt (modified) (2 diffs)
-
tests/.expect/64/KRfunctions.txt (modified) (1 diff)
-
tests/KRfunctions.c (modified) (2 diffs)
-
tests/except-0.c (modified) (18 diffs)
-
tests/except-1.c (modified) (5 diffs)
-
tests/except-2.c (modified) (6 diffs)
-
tests/except-3.c (deleted)
-
tests/except-mac.h (deleted)
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
re50e9ff r6ac5223 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 18 15:34:00 201713 // Update Count : 48 812 // Last Modified On : Tus Jul 25 15:29:00 2017 13 // Update Count : 486 14 14 // 15 15 #include "CodeGenerator.h" … … 79 79 } 80 80 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; 110 100 } 111 101 } … … 204 194 ++indent; 205 195 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) { 206 updateLocation( *i );196 output << lineDirective( *i ) << indent; 207 197 (*i)->accept( *this ); 208 198 output << ";" << endl; … … 227 217 void CodeGenerator::visit( EnumDecl * enumDecl ) { 228 218 extension( enumDecl ); 229 updateLocation( enumDecl );219 output << lineDirective ( enumDecl ); 230 220 output << "enum "; 231 221 genAttributes( enumDecl->get_attributes() ); … … 243 233 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 244 234 assert( obj ); 245 updateLocation( obj ); 246 output << mangleName( obj ); 235 output << lineDirective( obj ) << indent << mangleName( obj ); 247 236 if ( obj->get_init() ) { 248 237 output << " = "; … … 262 251 void CodeGenerator::visit( TypedefDecl * typeDecl ) { 263 252 assertf( ! genC, "Typedefs are removed and substituted in earlier passes." ); 264 updateLocation( typeDecl );253 output << lineDirective( typeDecl ); 265 254 output << "typedef "; 266 255 output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl; … … 763 752 void CodeGenerator::visit( StmtExpr * stmtExpr ) { 764 753 std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids(); 765 updateLocation( stmtExpr ); 766 output << "({" << std::endl; 754 output << lineDirective( stmtExpr) << "({" << std::endl; 767 755 ++indent; 768 756 unsigned int numStmts = stmts.size(); 769 757 unsigned int i = 0; 770 758 for ( Statement * stmt : stmts ) { 771 updateLocation( stmt );759 output << lineDirective( stmt ) << indent; 772 760 output << printLabels( stmt->get_labels() ); 773 761 if ( i+1 == numStmts ) { … … 856 844 857 845 void CodeGenerator::visit( IfStmt * ifStmt ) { 858 updateLocation( ifStmt );846 output << lineDirective( ifStmt ); 859 847 output << "if ( "; 860 848 ifStmt->get_condition()->accept( *this ); … … 870 858 871 859 void CodeGenerator::visit( SwitchStmt * switchStmt ) { 872 updateLocation( switchStmt );860 output << lineDirective( switchStmt ); 873 861 output << "switch ( " ; 874 862 switchStmt->get_condition()->accept( *this ); … … 883 871 884 872 void CodeGenerator::visit( CaseStmt * caseStmt ) { 885 updateLocation( caseStmt ); 873 output << lineDirective( caseStmt ); 874 output << indent; 886 875 if ( caseStmt->isDefault()) { 887 876 output << "default"; -
src/CodeGen/CodeGenerator.h
re50e9ff r6ac5223 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 18 15:40:00 201713 // Update Count : 5 612 // Last Modified On : Tus Jul 25 25:30:00 2017 13 // Update Count : 54 14 14 // 15 15 … … 108 108 }; 109 109 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 110 119 void asmName( DeclarationWithType *decl ); 111 120 112 121 void extension( Expression *expr ); 113 122 void extension( Declaration *decl ); 114 115 void updateLocation( BaseSyntaxNode const * to );116 123 private: 117 124 Indenter indent; … … 122 129 bool genC = false; // true if output has to be C code 123 130 bool lineMarks = false; 124 125 CodeLocation currentLocation;126 void updateLocation( CodeLocation const & to );127 void nextLine();128 131 129 132 void handleStorageClass( DeclarationWithType *decl ); … … 152 155 /// returns C-compatible name of declaration 153 156 std::string genName( DeclarationWithType * decl ); 157 158 std::ostream & operator<<(std::ostream &, 159 CodeGenerator::LineMarker const &); 154 160 } // namespace CodeGen 155 161 -
src/CodeGen/Generate.cc
re50e9ff r6ac5223 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 18 15:39:00 201713 // Update Count : 712 // Last Modified On : Wed May 19 13:05:00 2017 13 // Update Count : 6 14 14 // 15 15 #include "Generate.h" … … 33 33 for ( auto & dcl : translationUnit ) { 34 34 if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) { 35 cgv.updateLocation( dcl);35 os << cgv.lineDirective(dcl); 36 36 dcl->accept(cgv); 37 37 if ( doSemicolon( dcl ) ) { -
src/ControlStruct/ExceptTranslate.cc
re50e9ff r6ac5223 10 10 // Created On : Wed Jun 14 16:49:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : T hr Aug 17 17:19:00 201713 // Update Count : 912 // Last Modified On : Tus Aug 8 16:54:00 2017 13 // Update Count : 7 14 14 // 15 15 … … 166 166 /*bitfieldWidth*/ NULL, 167 167 new BasicType( noQualifiers, BasicType::Bool ), 168 /*init*/ NULL, 169 std::list<Attribute *>{ new Attribute( "unused" ) } 168 /*init*/ NULL 170 169 ); 171 170 ObjectDecl voidptr_obj( … … 184 183 ); 185 184 186 ObjectDecl * unused_index_obj = index_obj.clone();187 unused_index_obj->attributes.push_back( new Attribute( "unused" ) );188 189 185 catch_func_t.get_parameters().push_back( index_obj.clone() ); 190 186 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() ); 192 188 match_func_t.get_parameters().push_back( exception_obj.clone() ); 193 189 handle_func_t.get_returnVals().push_back( bool_obj.clone() ); … … 421 417 } 422 418 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 ) ) ) ); 425 421 426 422 return new FunctionDecl("match", Type::StorageClasses(), … … 453 449 CompoundStmt * body = new CompoundStmt( noLabels ); 454 450 455 FunctionType * func_type = handle_func_t.clone();451 FunctionType * func_type = match_func_t.clone(); 456 452 DeclarationWithType * except_obj = func_type->get_parameters().back(); 457 453 … … 476 472 } 477 473 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 ) ) ) ); 480 476 481 477 return new FunctionDecl("handle", Type::StorageClasses(), -
src/ControlStruct/ForExprMutator.cc
re50e9ff r6ac5223 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Aug 18 10:22:00 201713 // Update Count : 1 211 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Jul 14 12:14:44 2015 13 // Update Count : 10 14 14 // 15 15 … … 21 21 22 22 namespace 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 28 29 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 31 31 CompoundStmt *block = new CompoundStmt( std::list< Label >() ); 32 32 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 34 36 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 *>() ); 37 40 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 );46 41 } 47 42 } // namespace ControlStruct -
src/ControlStruct/ForExprMutator.h
re50e9ff r6ac5223 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 15:32:48 201713 // Update Count : 512 // Last Modified On : Sat Jul 22 09:17:08 2017 13 // Update Count : 4 14 14 // 15 15 16 16 #pragma once 17 17 18 class IfStmt;19 18 class ForStmt; 20 19 class Statement; … … 23 22 class ForExprMutator { 24 23 public: 25 Statement *postmutate( IfStmt * );26 24 Statement *postmutate( ForStmt * ); 27 25 }; -
src/Parser/StatementNode.cc
re50e9ff r6ac5223 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 16:01:31201713 // Update Count : 34 512 // Last Modified On : Wed Aug 16 16:39:43 2017 13 // Update Count : 340 14 14 // 15 15 … … 24 24 #include "SynTree/Expression.h" // for Expression, ConstantExpr 25 25 #include "SynTree/Label.h" // for Label, noLabels 26 #include "SynTree/Declaration.h"27 26 #include "SynTree/Statement.h" // for Statement, BranchStmt, CaseStmt 28 27 #include "parserutility.h" // for notZeroExpr … … 99 98 } // if 100 99 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; 104 109 } 105 110 -
src/Parser/parser.yy
re50e9ff r6ac5223 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 20 09:21:54 201713 // Update Count : 2 57312 // Last Modified On : Wed Aug 16 18:09:14 2017 13 // Update Count : 2485 14 14 // 15 15 … … 131 131 %token ATTRIBUTE EXTENSION // GCC 132 132 %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 // CFA133 %token CHOOSE DISABLE ENABLE FALLTHRU TRY CATCH CATCHRESUME FINALLY THROW THROWRESUME AT WITH // CFA 134 134 %token ASM // C99, extension ISO/IEC 9899:1999 Section J.5.10(1) 135 135 %token ALIGNAS ALIGNOF GENERIC STATICASSERT // C11 … … 796 796 797 797 selection_statement: 798 IF '(' pushif_control_expression ')' statement %prec THEN798 IF '(' if_control_expression ')' statement %prec THEN 799 799 // explicitly deal with the shift/reduce conflict on if/else 800 { $$ = new StatementNode( build_if( $ 4, $6, nullptr ) ); }801 | IF '(' pushif_control_expression ')' statement ELSE statement802 { $$ = 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 804 804 { $$ = new StatementNode( build_switch( $3, $5 ) ); } 805 805 | SWITCH '(' comma_expression ')' '{' push declaration_list_opt switch_clause_list_opt '}' // CFA … … 823 823 824 824 if_control_expression: 825 comma_expression pop825 comma_expression 826 826 { $$ = new IfCtl( nullptr, $1 ); } 827 | c_declaration pop // no semi-colon827 | c_declaration // no semi-coln 828 828 { $$ = new IfCtl( $1, nullptr ); } 829 | cfa_declaration pop// no semi-colon829 | cfa_declaration // no semi-colon 830 830 { $$ = new IfCtl( $1, nullptr ); } 831 | declaration comma_expression // semi-colon separated831 | declaration comma_expression 832 832 { $$ = new IfCtl( $1, $2 ); } 833 833 ; … … 1104 1104 1105 1105 KR_declaration_list_opt: // used to declare parameter types in K&R style functions 1106 // empty1106 pop 1107 1107 { $$ = nullptr; } 1108 1108 | KR_declaration_list … … 1110 1110 1111 1111 KR_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 ';' 1115 1114 { $$ = $1->appendList( $3 ); } 1116 1115 ; … … 1132 1131 1133 1132 declaration: // old & new style declarations 1134 c_declaration pop';'1135 | cfa_declaration pop ';'// CFA1133 c_declaration ';' 1134 | cfa_declaration ';' // CFA 1136 1135 ; 1137 1136 … … 1148 1147 1149 1148 cfa_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 1155 1154 ; 1156 1155 … … 1352 1351 1353 1352 c_declaration: 1354 declaration_specifier declaring_list 1353 declaration_specifier declaring_list pop 1355 1354 { 1356 1355 $$ = distAttr( $1, $2 ); 1357 1356 } 1358 | typedef_declaration 1359 | typedef_expression // GCC, naming expression type1360 | sue_declaration_specifier 1357 | typedef_declaration pop 1358 | typedef_expression pop // GCC, naming expression type 1359 | sue_declaration_specifier pop 1361 1360 ; 1362 1361 … … 2231 2230 $$ = $1->addFunctionBody( $2 ); 2232 2231 } 2233 | KR_function_declarator KR_declaration_list_opt compound_statement2232 | KR_function_declarator push KR_declaration_list_opt compound_statement 2234 2233 { 2235 2234 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2236 2235 typedefTable.leaveScope(); 2237 $$ = $1->addOldDeclList( $ 2 )->addFunctionBody( $3);2236 $$ = $1->addOldDeclList( $3 )->addFunctionBody( $4 ); 2238 2237 } 2239 2238 ; … … 2279 2278 2280 2279 // Old-style K&R function definition, OBSOLESCENT (see 4) 2281 | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement2280 | declaration_specifier KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement 2282 2281 { 2283 2282 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2284 2283 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_statement2284 $$ = $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 2288 2287 { 2289 2288 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2290 2289 typedefTable.leaveScope(); 2291 $$ = $2->addOldDeclList( $ 3 )->addFunctionBody( $5)->addQualifiers( $1 );2290 $$ = $2->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $1 ); 2292 2291 } 2293 2292 2294 2293 // 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_statement2294 | declaration_qualifier_list KR_function_declarator push KR_declaration_list_opt with_clause_opt compound_statement 2296 2295 { 2297 2296 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2298 2297 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_statement2298 $$ = $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 2302 2301 { 2303 2302 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2304 2303 typedefTable.leaveScope(); 2305 $$ = $3->addOldDeclList( $ 4 )->addFunctionBody( $6)->addQualifiers( $2 )->addQualifiers( $1 );2304 $$ = $3->addOldDeclList( $5 )->addFunctionBody( $7 )->addQualifiers( $2 )->addQualifiers( $1 ); 2306 2305 } 2307 2306 ; -
src/SymTab/Indexer.cc
re50e9ff r6ac5223 10 10 // Created On : Sun May 17 21:37:33 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 16:08:40201713 // Update Count : 2012 // Last Modified On : Thu Mar 30 16:38:47 2017 13 // Update Count : 19 14 14 // 15 15 … … 351 351 acceptAll( compoundStmt->get_kids(), *this ); 352 352 leaveScope(); 353 }354 355 void Indexer::visit( IfStmt *ifStmt ) {356 // for statements introduce a level of scope357 enterScope();358 Visitor::visit( ifStmt );359 leaveScope();360 353 } 361 354 -
src/SymTab/Indexer.h
re50e9ff r6ac5223 10 10 // Created On : Sun May 17 21:38:55 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 16:09:12201713 // Update Count : 812 // Last Modified On : Sat Jul 22 09:46:34 2017 13 // Update Count : 7 14 14 // 15 15 … … 45 45 46 46 virtual void visit( CompoundStmt *compoundStmt ); 47 virtual void visit( IfStmt *ifStmt );48 47 virtual void visit( ForStmt *forStmt ); 49 48 virtual void visit( CatchStmt *catchStmt ); -
src/SynTree/Initializer.cc
re50e9ff r6ac5223 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon Aug 21 09:53:15 201713 // Update Count : 3011 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Aug 3 11:33:00 2016 13 // Update Count : 29 14 14 // 15 15 … … 80 80 } 81 81 } 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() ); 83 83 } 84 84 -
src/SynTree/Mutator.cc
re50e9ff r6ac5223 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Aug 17 15:39:37201713 // Update Count : 2 711 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Jul 24 16:32:00 2017 13 // Update Count : 25 14 14 // 15 15 … … 114 114 115 115 Statement *Mutator::mutate( IfStmt *ifStmt ) { 116 mutateAll( ifStmt->get_initialization(), *this );117 116 ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) ); 118 117 ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) ); -
src/SynTree/Statement.cc
re50e9ff r6ac5223 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Aug 17 16:17:20 201713 // Update Count : 6 711 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Aug 14 12:26:00 2017 13 // Update Count : 65 14 14 // 15 15 … … 32 32 using std::endl; 33 33 34 Statement::Statement( std::list<Label> labels ) : labels(labels ) {}34 Statement::Statement( std::list<Label> _labels ) : labels( _labels ) {} 35 35 36 36 void Statement::print( __attribute__((unused)) std::ostream &, __attribute__((unused)) int indent ) const {} … … 38 38 Statement::~Statement() {} 39 39 40 ExprStmt::ExprStmt( std::list<Label> labels, Expression *expr ) : Statement( labels ), expr(expr ) {}40 ExprStmt::ExprStmt( std::list<Label> _labels, Expression *_expr ) : Statement( _labels ), expr( _expr ) {} 41 41 42 42 ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} … … 88 88 const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" }; 89 89 90 BranchStmt::BranchStmt( std::list<Label> labels, Label target, Typetype ) throw ( SemanticError ) :91 Statement( labels ), originalTarget( target ), target( target ), computedTarget( NULL ), type(type ) {90 BranchStmt::BranchStmt( std::list<Label> labels, Label _target, Type _type ) throw ( SemanticError ) : 91 Statement( labels ), originalTarget( _target ), target( _target ), computedTarget( NULL ), type( _type ) { 92 92 //actually this is a syntactic error signaled by the parser 93 93 if ( type == BranchStmt::Goto && target.empty() ) … … 95 95 } 96 96 97 BranchStmt::BranchStmt( std::list<Label> labels, Expression * computedTarget, Typetype ) throw ( SemanticError ) :98 Statement( labels ), computedTarget( computedTarget ), type(type ) {97 BranchStmt::BranchStmt( std::list<Label> labels, Expression *_computedTarget, Type _type ) throw ( SemanticError ) : 98 Statement( labels ), computedTarget( _computedTarget ), type( _type ) { 99 99 if ( type != BranchStmt::Goto || computedTarget == 0 ) 100 100 throw SemanticError("Computed target not valid in branch statement"); … … 105 105 } 106 106 107 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression * expr ) : Statement( labels ), expr(expr ) {}107 ReturnStmt::ReturnStmt( std::list<Label> labels, Expression *_expr ) : Statement( labels ), expr( _expr ) {} 108 108 109 109 ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} … … 122 122 } 123 123 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) {}124 IfStmt::IfStmt( std::list<Label> _labels, Expression *_condition, Statement *_thenPart, Statement *_elsePart ): 125 Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart ) {} 126 126 127 127 IfStmt::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 ) ) {} 131 129 132 130 IfStmt::~IfStmt() { 133 deleteAll( initialization );134 131 delete condition; 135 132 delete thenPart; … … 142 139 condition->print( os, indent + 4 ); 143 140 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 153 141 os << string( indent+2, ' ' ) << "... then: " << endl; 154 142 … … 163 151 } 164 152 165 SwitchStmt::SwitchStmt( std::list<Label> labels, Expression * condition, std::list<Statement *> &statements ):166 Statement( labels ), condition( condition ), statements(statements ) {153 SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_statements ): 154 Statement( _labels ), condition( _condition ), statements( _statements ) { 167 155 } 168 156 … … 191 179 } 192 180 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 ) {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 ) { 195 183 if ( isDefault() && condition != 0 ) 196 184 throw SemanticError("default with conditions"); … … 228 216 } 229 217 230 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition , Statement *body, bool isDoWhile):231 Statement( labels ), condition( condition ), body( body), isDoWhile( isDoWhile) {218 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition_, Statement *body_, bool isDoWhile_ ): 219 Statement( labels ), condition( condition_), body( body_), isDoWhile( isDoWhile_) { 232 220 } 233 221 … … 250 238 } 251 239 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) {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_ ) { 254 242 } 255 243 … … 329 317 } 330 318 331 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt *finallyBlock ) :332 Statement( labels ), block( tryBlock ), handlers( handlers ), finallyBlock(finallyBlock ) {319 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &_handlers, FinallyStmt *_finallyBlock ) : 320 Statement( labels ), block( tryBlock ), handlers( _handlers ), finallyBlock( _finallyBlock ) { 333 321 } 334 322 … … 363 351 } 364 352 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 ) {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 ) { 367 355 } 368 356 … … 401 389 402 390 403 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt * block ) : Statement( labels ), block(block ) {391 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *_block ) : Statement( labels ), block( _block ) { 404 392 assert( labels.empty() ); // finally statement cannot be labeled 405 393 } -
src/SynTree/Statement.h
re50e9ff r6ac5223 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 15:37:53201713 // Update Count : 7 212 // Last Modified On : Wed Aug 16 16:28:55 2017 13 // Update Count : 70 14 14 // 15 15 … … 127 127 class IfStmt : public Statement { 128 128 public: 129 std::list<Statement *> initialization; 129 130 Expression *condition; 130 131 Statement *thenPart; 131 132 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 ); 136 135 IfStmt( const IfStmt &other ); 137 136 virtual ~IfStmt(); 138 137 139 138 std::list<Statement *> &get_initialization() { return initialization; } 139 void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; } 140 140 Expression *get_condition() { return condition; } 141 141 void set_condition( Expression *newValue ) { condition = newValue; } … … 239 239 240 240 std::list<Statement *> &get_initialization() { return initialization; } 241 void set_initialization( std::list<Statement *> newValue ) { initialization = newValue; } 241 242 Expression *get_condition() { return condition; } 242 243 void set_condition( Expression *newValue ) { condition = newValue; } -
src/SynTree/Visitor.cc
re50e9ff r6ac5223 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Thu Aug 17 15:39:38201713 // Update Count : 2 911 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Jul 24 16:30:00 2017 13 // Update Count : 27 14 14 // 15 15 … … 99 99 100 100 void Visitor::visit( IfStmt *ifStmt ) { 101 acceptAll( ifStmt->get_initialization(), *this );102 101 maybeAccept( ifStmt->get_condition(), *this ); 103 102 maybeAccept( ifStmt->get_thenPart(), *this ); -
src/driver/cfa.cc
re50e9ff r6ac5223 9 9 // Author : Peter A. Buhr 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 // Last Modified By : Andrew Beach12 // Last Modified On : Thr Aug 17 15:24:00201713 // Update Count : 15 611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jan 20 14:38:45 2017 13 // Update Count : 155 14 14 // 15 15 … … 281 281 #endif //HAVE_LIBCFA 282 282 283 // Add exception flags (unconditionally)284 args[nargs] = "-fexceptions";285 nargs += 1;286 287 283 // add the correct set of flags based on the type of compile this is 288 284 -
src/libcfa/Makefile.am
re50e9ff r6ac5223 36 36 ${AM_V_GEN}@BACKEND_CC@ @CFA_FLAGS@ -D__CFA_DEBUG__ -O0 -c -o $@ $< 37 37 38 EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function - imacros libcfa-prelude.c @CFA_FLAGS@38 EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function -I${abs_top_srcdir}/src/libcfa/libhdr -imacros libcfa-prelude.c @CFA_FLAGS@ 39 39 40 40 AM_CCASFLAGS = @CFA_FLAGS@ -
src/libcfa/Makefile.in
re50e9ff r6ac5223 416 416 ARFLAGS = cr 417 417 lib_LIBRARIES = $(am__append_1) $(am__append_2) 418 EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function - imacros libcfa-prelude.c @CFA_FLAGS@418 EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function -I${abs_top_srcdir}/src/libcfa/libhdr -imacros libcfa-prelude.c @CFA_FLAGS@ 419 419 AM_CCASFLAGS = @CFA_FLAGS@ 420 420 headers = fstream iostream iterator limits rational stdlib \ -
src/libcfa/exception.c
re50e9ff r6ac5223 10 10 // Created On : Mon Jun 26 15:13:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Aug 17 15:45:00 201713 // Update Count : 712 // Last Modified On : Fri Aug 4 15:20:00 2017 13 // Update Count : 6 14 14 // 15 15 … … 23 23 #include <stdio.h> 24 24 #include <unwind.h> 25 #include <libhdr/libdebug.h>26 25 27 26 // FIX ME: temporary hack to keep ARM build working … … 80 79 void __cfaehm__throw_resume(exception * except) { 81 80 82 LIB_DEBUG_PRINT_SAFE("Throwing resumption exception\n"); 81 // DEBUG 82 printf("Throwing resumption exception\n"); 83 83 84 84 struct __cfaehm__try_resume_node * original_head = shared_stack.current_resume; … … 94 94 } 95 95 96 LIB_DEBUG_PRINT_SAFE("Unhandled exception\n");96 printf("Unhandled exception\n"); 97 97 shared_stack.current_resume = original_head; 98 98 … … 106 106 107 107 void __cfaehm__try_resume_setup(struct __cfaehm__try_resume_node * node, 108 _Bool(*handler)(exception * except)) {108 int (*handler)(exception * except)) { 109 109 node->next = shared_stack.top_resume; 110 110 node->handler = handler; … … 154 154 struct exception_context_t * context = this_exception_context(); 155 155 156 LIB_DEBUG_PRINT_SAFE("Deleting Exception\n"); 156 // DEBUG 157 printf( "Deleting Exception\n"); 157 158 158 159 // Remove the exception from the list. … … 234 235 235 236 void __cfaehm__throw_terminate( exception * val ) { 236 LIB_DEBUG_PRINT_SAFE("Throwing termination exception\n"); 237 // DEBUG 238 printf("Throwing termination exception\n"); 237 239 238 240 __cfaehm__allocate_exception( val ); … … 241 243 242 244 void __cfaehm__rethrow_terminate(void) { 243 LIB_DEBUG_PRINT_SAFE("Rethrowing termination exception\n"); 245 // DEBUG 246 printf("Rethrowing termination exception\n"); 244 247 245 248 __cfaehm__begin_unwind(); … … 254 257 { 255 258 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); 258 262 259 263 // If we've reached the end of the stack then there is nothing much we can do... 260 264 if( actions & _UA_END_OF_STACK ) return _URC_END_OF_STACK; 261 265 266 // DEBUG 262 267 if (actions & _UA_SEARCH_PHASE) { 263 LIB_DEBUG_PRINT_SAFE(" lookup phase"); 264 } 268 printf(" lookup phase"); 269 } 270 // DEBUG 265 271 else if (actions & _UA_CLEANUP_PHASE) { 266 LIB_DEBUG_PRINT_SAFE(" cleanup phase");272 printf(" cleanup phase"); 267 273 } 268 274 // Just in case, probably can't actually happen … … 300 306 // Have we reach the correct frame info yet? 301 307 if( lsd_info.Start + callsite_start + callsite_len < instruction_ptr ) { 302 #ifdef __CFA_DEBUG_PRINT__ 308 //DEBUG BEGIN 303 309 void * ls = (void*)lsd_info.Start; 304 310 void * cs = (void*)callsite_start; … … 307 313 void * ep = (void*)lsd_info.Start + callsite_start + callsite_len; 308 314 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 311 317 continue; 312 318 } … … 356 362 357 363 // 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"); 363 366 return ret; 364 367 } 365 368 366 369 // This is only a cleanup handler, ignore it 367 LIB_DEBUG_PRINT_SAFE(" no action");370 printf(" no action"); 368 371 } 369 372 else if (actions & _UA_CLEANUP_PHASE) { … … 385 388 _Unwind_SetIP( context, ((lsd_info.LPStart) + (callsite_landing_pad)) ); 386 389 387 LIB_DEBUG_PRINT_SAFE(" action\n"); 390 // DEBUG 391 printf(" action\n"); 388 392 389 393 // Return have some action to run … … 393 397 394 398 // Nothing to do, move along 395 LIB_DEBUG_PRINT_SAFE(" no landing pad");399 printf(" no landing pad"); 396 400 } 397 401 // No handling found 398 LIB_DEBUG_PRINT_SAFE(" table end reached\n"); 399 402 printf(" table end reached\n"); 403 404 // DEBUG 400 405 UNWIND: 401 LIB_DEBUG_PRINT_SAFE(" unwind\n");406 printf(" unwind\n"); 402 407 403 408 // Keep unwinding the stack -
src/libcfa/exception.h
re50e9ff r6ac5223 10 10 // Created On : Mon Jun 26 15:11:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Aug 17 15:44:00 201713 // Update Count : 612 // Last Modified On : Fri Aug 4 15:20:00 2017 13 // Update Count : 5 14 14 // 15 15 … … 55 55 struct __cfaehm__try_resume_node { 56 56 struct __cfaehm__try_resume_node * next; 57 _Bool(*handler)(exception * except);57 int (*handler)(exception * except); 58 58 }; 59 59 … … 61 61 void __cfaehm__try_resume_setup( 62 62 struct __cfaehm__try_resume_node * node, 63 _Bool(*handler)(exception * except));63 int (*handler)(exception * except)); 64 64 void __cfaehm__try_resume_cleanup( 65 65 struct __cfaehm__try_resume_node * node); -
src/libcfa/libhdr.h
re50e9ff r6ac5223 16 16 #pragma once 17 17 18 #include "lib hdr/libalign.h"19 #include "lib hdr/libdebug.h"20 #include "lib hdr/libtools.h"18 #include "libalign.h" 19 #include "libdebug.h" 20 #include "libtools.h" 21 21 22 22 // Local Variables: // -
src/tests/.expect/32/KRfunctions.txt
re50e9ff r6ac5223 15 15 } 16 16 struct S { 17 int __i__i_1;17 int __i__i_1; 18 18 }; 19 19 static inline void ___constructor__F_P2sS_autogen___1(struct S *___dst__P2sS_1); … … 79 79 __attribute__ ((unused)) int (*___retval_f14__PA0A0i_1)[][((unsigned int )10)]; 80 80 } 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 }84 81 const int __fred__FCi___1(){ 85 82 __attribute__ ((unused)) const int ___retval_fred__Ci_1; -
src/tests/.expect/64/KRfunctions.txt
re50e9ff r6ac5223 79 79 __attribute__ ((unused)) int (*___retval_f14__PA0A0i_1)[][((long unsigned int )10)]; 80 80 } 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 }84 81 const int __fred__FCi___1(){ 85 82 __attribute__ ((unused)) const int ___retval_fred__Ci_1; -
src/tests/KRfunctions.c
re50e9ff r6ac5223 10 10 // Created On : Thu Feb 16 15:23:17 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 20 07:34:17201713 // Update Count : 712 // Last Modified On : Wed May 24 22:05:00 2017 13 // Update Count : 3 14 14 // 15 15 … … 37 37 int ((* f13( a, b, c ))[])[10] int a, * b, c[]; {} 38 38 int (((* f14( a, b, c ))[])[10]) int a, * b, c[]; {} 39 f15( a, b, c ) {}40 39 41 40 const fred() { -
src/tests/except-0.c
re50e9ff r6ac5223 7 7 #include <stdio.h> 8 8 #include <stdbool.h> 9 10 #include "except-mac.h"11 TRIVIAL_EXCEPTION(yin)12 TRIVIAL_EXCEPTION(yang)13 TRIVIAL_EXCEPTION(zen)14 15 9 16 10 // Local type to mark exits from scopes. (see ERROR) … … 29 23 30 24 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) 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) { 34 47 signal_exit a = {"terminate function"}; 35 THROW(except_value);48 throw except_value; 36 49 printf("terminate returned\n"); 37 50 } 38 51 39 forall(dtype T) 40 void resume(T * except_value) { 52 void resume(exception * except_value) { 41 53 signal_exit a = {"resume function"}; 42 THROW_RESUME(except_value);54 throwResume except_value; 43 55 printf("resume returned\n"); 44 56 } … … 48 60 signal_exit a = {"bar function"}; 49 61 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"); 53 65 } 54 66 } … … 58 70 try { 59 71 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"); 64 76 } 65 77 } … … 69 81 signal_exit a = {"beta function"}; 70 82 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"); 75 86 } 76 87 } … … 80 91 try { 81 92 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"); 86 97 } 87 98 } … … 106 117 void fallback() { 107 118 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"); 112 122 } 113 123 } … … 117 127 signal_exit a = {"terminate_swap"}; 118 128 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); 124 132 } 125 133 } … … 129 137 try { 130 138 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"); 133 141 } 134 142 } … … 138 146 signal_exit a = {"resume_swap"}; 139 147 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); 145 151 } 146 152 } … … 149 155 try { 150 156 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"); 153 159 } 154 160 } … … 158 164 try { 159 165 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"); 165 170 throw; 166 171 } 167 } catch ( zen * error) {168 printf("reterminate 1 caught exception zen\n");172 } catch (2) { 173 printf("reterminate 1 caught exception 2\n"); 169 174 } 170 175 } … … 174 179 try { 175 180 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"); 180 184 throwResume; 181 185 } 182 } catchResume ( zen * error) {183 printf("reresume 1 caught exception zen\n");186 } catchResume (2) { 187 printf("reresume 1 caught exception 2\n"); 184 188 } 185 189 } … … 189 193 // terminate block, call resume 190 194 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"); 195 198 } 196 199 } … … 199 202 // resume block, call terminate 200 203 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"); 205 207 } 206 208 } … … 210 212 try { 211 213 foe(); 212 } catch ( zen * error) {213 printf("fy caught exception zen\n");214 } catch (3) { 215 printf("fy caught exception 3\n"); 214 216 fum(); 215 217 } … … 220 222 try { 221 223 fy(); 222 } catchResume ( zen * error) {223 printf("fee caught exception zen\n");224 } catchResume (3) { 225 printf("fee caught exception 3\n"); 224 226 } 225 227 } … … 240 242 reresume(); printf("\n"); 241 243 fee(); printf("\n"); 242 243 244 // 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 5 5 #include <stdio.h> 6 6 7 #include "except-mac.h"8 TRIVIAL_EXCEPTION(yin)9 TRIVIAL_EXCEPTION(yang)10 11 7 int main() 12 8 { 13 9 try { 14 yin a; 15 THROW(&a); 10 throw 3; 16 11 } 17 catch( yin * err) {12 catch( 3 ) { 18 13 printf("First Caught\n"); 19 14 try { 20 yang b; 21 THROW(&b); 15 throw 4; 22 16 } 23 catch( yang * err) {17 catch( 4 ) { 24 18 printf("Both Caught\n"); 25 19 } … … 29 23 try { 30 24 try { 31 yang c; 32 THROW(&c); 25 throw 2; 33 26 } 34 catch( yang * err) {27 catch( 2 ) { 35 28 printf("First Catch and rethrow\n"); 36 29 throw; 37 30 } 38 31 } 39 catch( yang * err) {32 catch( 2 ) { 40 33 printf("Second Catch\n"); 41 34 } … … 44 37 try { 45 38 try { 46 yin d; 47 THROW(&d); 39 throw 5; 48 40 } 49 catch( yin * err) {41 catch( 5 ) { 50 42 printf("Throw before cleanup\n"); 51 yang e; 52 THROW(&e); 43 throw 6; 53 44 } 54 45 } 55 catch( yang * err) {46 catch( 6 ) { 56 47 printf("Catch after cleanup\n"); 57 48 } … … 60 51 try { 61 52 try { 62 yin f; 63 THROW(&f); 53 throw 7; 64 54 } 65 catch( yin * err) {55 catch( 7 ) { 66 56 printf("Caught initial throw.\n"); 67 57 try { 68 yang g; 69 THROW(&g); 58 throw 8; 70 59 } 71 catch( yang * err) {60 catch( 8 ) { 72 61 printf("Caught intermediate throw.\n"); 73 62 } … … 75 64 } 76 65 } 77 catch( yin * err) {66 catch( 7 ) { 78 67 printf("Caught final throw.\n"); 79 68 } -
src/tests/except-2.c
re50e9ff r6ac5223 2 2 3 3 4 #include <stdlib> 5 #include "except-mac.h" 4 #include <string.h> 6 5 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 } 7 39 TRIVIAL_EXCEPTION(yin) 8 40 TRIVIAL_EXCEPTION(yang) … … 18 50 }; 19 51 extern num_error_vtable INSTANCE(num_error); 20 21 52 struct num_error { 22 53 struct num_error_vtable const * virtual_table; … … 24 55 int num; 25 56 }; 26 27 57 void num_error_msg(num_error * this) { 28 58 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 ); 32 61 } 33 62 this->msg[21] = '0' + this->num; … … 61 90 try { 62 91 yin black; 63 THROW(&black);92 throw (BASE_EXCEPT *)&black; 64 93 } catch ( yin * error ) { 65 94 printf("throw yin caught.\n"); … … 68 97 try { 69 98 yang white; 70 THROW_RESUME(&white);99 throwResume (BASE_EXCEPT *)&white; 71 100 printf("> throwResume returned.\n"); 72 101 } catchResume ( yang * error ) { … … 76 105 try { 77 106 num_error x = { 2 }; 78 THROW(&x);107 throw (BASE_EXCEPT *)&x; 79 108 } 80 109 catch (num_error * error ; 3 == error->virtual_table->code( error ) ) {
Note:
See TracChangeset
for help on using the changeset viewer.