Changeset e50e9ff
- Timestamp:
- Aug 22, 2017, 11:42:06 AM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 90c4df0
- Parents:
- 6ac5223 (diff), b3d413b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src
- Files:
-
- 2 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r6ac5223 re50e9ff 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Jul 25 15:29:00 201713 // Update Count : 48 612 // Last Modified On : Fri Aug 18 15:34:00 2017 13 // Update Count : 488 14 14 // 15 15 #include "CodeGenerator.h" … … 79 79 } 80 80 81 CodeGenerator::LineMarker::LineMarker( 82 CodeLocation const & loc, bool toPrint) : 83 loc(loc), toPrint(toPrint) 84 {} 85 86 CodeGenerator::LineMarker CodeGenerator::lineDirective( 87 BaseSyntaxNode const * node) { 88 return LineMarker(node->location, lineMarks); 89 } 90 91 std::ostream & operator<<(std::ostream & out, 92 CodeGenerator::LineMarker const & marker) { 93 if (marker.toPrint && marker.loc.isSet()) { 94 return out << "\n# " << marker.loc.linenumber << " \"" 95 << marker.loc.filename << "\"\n"; 96 } else if (marker.toPrint) { 97 return out << "\n/* Missing CodeLocation */\n"; 98 } else { 99 return out; 81 /* Using updateLocation at the beginning of a node and nextLine 82 * within a node should become the method of formating. 83 */ 84 void CodeGenerator::updateLocation( CodeLocation const & to ) { 85 if ( !lineMarks ) { 86 return; 87 } else if ( currentLocation.followedBy( to, 0 ) ) { 88 return; 89 } else if ( currentLocation.followedBy( to, 1 ) ) { 90 output << "\n" << indent; 91 currentLocation.linenumber += 1; 92 } else if ( currentLocation.followedBy( to, 2 ) ) { 93 output << "\n\n" << indent; 94 currentLocation.linenumber += 2; 95 } else { 96 output << "\n# " << to.linenumber << " \"" << to.filename 97 << "\"\n" << indent; 98 currentLocation = to; 99 } 100 output << std::flush; 101 } 102 103 void CodeGenerator::updateLocation( BaseSyntaxNode const * to ) { 104 updateLocation( to->location ); 105 } 106 107 void CodeGenerator::nextLine() { 108 if ( !lineMarks ) { 109 output << "\n" << indent << std::flush; 100 110 } 101 111 } … … 194 204 ++indent; 195 205 for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end(); i++ ) { 196 output << lineDirective( *i ) << indent;206 updateLocation( *i ); 197 207 (*i)->accept( *this ); 198 208 output << ";" << endl; … … 217 227 void CodeGenerator::visit( EnumDecl * enumDecl ) { 218 228 extension( enumDecl ); 219 output << lineDirective( enumDecl );229 updateLocation( enumDecl ); 220 230 output << "enum "; 221 231 genAttributes( enumDecl->get_attributes() ); … … 233 243 ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i ); 234 244 assert( obj ); 235 output << lineDirective( obj ) << indent << mangleName( obj ); 245 updateLocation( obj ); 246 output << mangleName( obj ); 236 247 if ( obj->get_init() ) { 237 248 output << " = "; … … 251 262 void CodeGenerator::visit( TypedefDecl * typeDecl ) { 252 263 assertf( ! genC, "Typedefs are removed and substituted in earlier passes." ); 253 output << lineDirective( typeDecl );264 updateLocation( typeDecl ); 254 265 output << "typedef "; 255 266 output << genType( typeDecl->get_base(), typeDecl->get_name(), pretty, genC ) << endl; … … 752 763 void CodeGenerator::visit( StmtExpr * stmtExpr ) { 753 764 std::list< Statement * > & stmts = stmtExpr->get_statements()->get_kids(); 754 output << lineDirective( stmtExpr) << "({" << std::endl; 765 updateLocation( stmtExpr ); 766 output << "({" << std::endl; 755 767 ++indent; 756 768 unsigned int numStmts = stmts.size(); 757 769 unsigned int i = 0; 758 770 for ( Statement * stmt : stmts ) { 759 output << lineDirective( stmt ) << indent;771 updateLocation( stmt ); 760 772 output << printLabels( stmt->get_labels() ); 761 773 if ( i+1 == numStmts ) { … … 844 856 845 857 void CodeGenerator::visit( IfStmt * ifStmt ) { 846 output << lineDirective( ifStmt );858 updateLocation( ifStmt ); 847 859 output << "if ( "; 848 860 ifStmt->get_condition()->accept( *this ); … … 858 870 859 871 void CodeGenerator::visit( SwitchStmt * switchStmt ) { 860 output << lineDirective( switchStmt );872 updateLocation( switchStmt ); 861 873 output << "switch ( " ; 862 874 switchStmt->get_condition()->accept( *this ); … … 871 883 872 884 void CodeGenerator::visit( CaseStmt * caseStmt ) { 873 output << lineDirective( caseStmt ); 874 output << indent; 885 updateLocation( caseStmt ); 875 886 if ( caseStmt->isDefault()) { 876 887 output << "default"; -
src/CodeGen/CodeGenerator.h
r6ac5223 re50e9ff 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Jul 25 25:30:00 201713 // Update Count : 5 412 // Last Modified On : Fri Aug 18 15:40:00 2017 13 // Update Count : 56 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 119 110 void asmName( DeclarationWithType *decl ); 120 111 121 112 void extension( Expression *expr ); 122 113 void extension( Declaration *decl ); 114 115 void updateLocation( BaseSyntaxNode const * to ); 123 116 private: 124 117 Indenter indent; … … 129 122 bool genC = false; // true if output has to be C code 130 123 bool lineMarks = false; 124 125 CodeLocation currentLocation; 126 void updateLocation( CodeLocation const & to ); 127 void nextLine(); 131 128 132 129 void handleStorageClass( DeclarationWithType *decl ); … … 155 152 /// returns C-compatible name of declaration 156 153 std::string genName( DeclarationWithType * decl ); 157 158 std::ostream & operator<<(std::ostream &,159 CodeGenerator::LineMarker const &);160 154 } // namespace CodeGen 161 155 -
src/CodeGen/Generate.cc
r6ac5223 re50e9ff 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 19 13:05:00 201713 // Update Count : 612 // Last Modified On : Fri Aug 18 15:39:00 2017 13 // Update Count : 7 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 os << cgv.lineDirective(dcl);35 cgv.updateLocation( dcl ); 36 36 dcl->accept(cgv); 37 37 if ( doSemicolon( dcl ) ) { -
src/ControlStruct/ExceptTranslate.cc
r6ac5223 re50e9ff 10 10 // Created On : Wed Jun 14 16:49:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : T us Aug 8 16:54:00 201713 // Update Count : 712 // Last Modified On : Thr Aug 17 17:19:00 2017 13 // Update Count : 9 14 14 // 15 15 … … 166 166 /*bitfieldWidth*/ NULL, 167 167 new BasicType( noQualifiers, BasicType::Bool ), 168 /*init*/ NULL 168 /*init*/ NULL, 169 std::list<Attribute *>{ new Attribute( "unused" ) } 169 170 ); 170 171 ObjectDecl voidptr_obj( … … 183 184 ); 184 185 186 ObjectDecl * unused_index_obj = index_obj.clone(); 187 unused_index_obj->attributes.push_back( new Attribute( "unused" ) ); 188 185 189 catch_func_t.get_parameters().push_back( index_obj.clone() ); 186 190 catch_func_t.get_parameters().push_back( exception_obj.clone() ); 187 match_func_t.get_returnVals().push_back( index_obj.clone());191 match_func_t.get_returnVals().push_back( unused_index_obj ); 188 192 match_func_t.get_parameters().push_back( exception_obj.clone() ); 189 193 handle_func_t.get_returnVals().push_back( bool_obj.clone() ); … … 417 421 } 418 422 419 body->push_back( new ReturnStmt( noLabels, new ConstantExpr(420 Constant::from_int( 0 ) ) ) );423 body->push_back( new ReturnStmt( noLabels, 424 new ConstantExpr( Constant::from_int( 0 ) ) ) ); 421 425 422 426 return new FunctionDecl("match", Type::StorageClasses(), … … 449 453 CompoundStmt * body = new CompoundStmt( noLabels ); 450 454 451 FunctionType * func_type = match_func_t.clone();455 FunctionType * func_type = handle_func_t.clone(); 452 456 DeclarationWithType * except_obj = func_type->get_parameters().back(); 453 457 … … 472 476 } 473 477 474 body->push_back( new ReturnStmt( noLabels, new ConstantExpr(475 Constant::from_bool( false ) ) ) );478 body->push_back( new ReturnStmt( noLabels, 479 new ConstantExpr( Constant::from_bool( false ) ) ) ); 476 480 477 481 return new FunctionDecl("handle", Type::StorageClasses(), -
src/ControlStruct/ForExprMutator.cc
r6ac5223 re50e9ff 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Tue Jul 14 12:14:44 201513 // Update Count : 1 011 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 18 10:22:00 2017 13 // Update Count : 12 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 } 28 29 // Create compound statement, move initializers outside, 30 // the resut of the original stays as is. 31 CompoundStmt *block = new CompoundStmt( std::list< Label >() ); 32 std::list<Statement *> &stmts = block->get_kids(); 33 stmts.splice( stmts.end(), init ); 34 35 // Add for to the new block. 36 stmts.push_back( originalStmt ); 37 return block; 38 } 39 40 Statement *ForExprMutator::postmutate( IfStmt *ifStmt ) { 41 return hoist( ifStmt, ifStmt->initialization ); 42 } 23 43 Statement *ForExprMutator::postmutate( ForStmt *forStmt ) { 24 44 // hoist any initializer declarations to make them C89 (rather than C99) 25 std::list<Statement *> &init = forStmt->get_initialization(); 26 if ( init.size() == 0 ) { 27 return forStmt; 28 } // if 29 30 // create compound statement, move initializers outside, leave _for_ as-is 31 CompoundStmt *block = new CompoundStmt( std::list< Label >() ); 32 std::list<Statement *> &stmts = block->get_kids(); 33 for ( std::list<Statement *>::iterator it = init.begin(); it != init.end(); ++it ) { 34 stmts.push_back( *it ); 35 } // for 36 37 // add for to the new block 38 stmts.push_back( forStmt ); 39 forStmt->set_initialization( std::list<Statement *>() ); 40 return block; 45 return hoist( forStmt, forStmt->initialization ); 41 46 } 42 47 } // namespace ControlStruct -
src/ControlStruct/ForExprMutator.h
r6ac5223 re50e9ff 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:17:08 201713 // Update Count : 412 // Last Modified On : Thu Aug 17 15:32:48 2017 13 // Update Count : 5 14 14 // 15 15 16 16 #pragma once 17 17 18 class IfStmt; 18 19 class ForStmt; 19 20 class Statement; … … 22 23 class ForExprMutator { 23 24 public: 25 Statement *postmutate( IfStmt * ); 24 26 Statement *postmutate( ForStmt * ); 25 27 }; -
src/Parser/StatementNode.cc
r6ac5223 re50e9ff 10 10 // Created On : Sat May 16 14:59:41 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 16 16:39:43201713 // Update Count : 34 012 // Last Modified On : Thu Aug 17 16:01:31 2017 13 // Update Count : 345 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" 26 27 #include "SynTree/Statement.h" // for Statement, BranchStmt, CaseStmt 27 28 #include "parserutility.h" // for notZeroExpr … … 98 99 } // if 99 100 100 return new IfStmt( noLabels, notZeroExpr( 101 /*ctl->condition 102 ?*/ maybeMoveBuild< Expression >(ctl->condition) 103 /*: new VariableExpr( init.end() )*/ ) 104 , thenb, elseb ); 105 // ret->initialization = init; 106 // delete ctl; 107 // assert( ret ); 108 // return ret; 101 Expression * cond = ctl->condition ? maybeMoveBuild< Expression >(ctl->condition) : new VariableExpr( dynamic_cast<DeclarationWithType *>( dynamic_cast<DeclStmt *>( init.back() )->decl ) ); 102 delete ctl; 103 return new IfStmt( noLabels, notZeroExpr( cond ), thenb, elseb, init ); 109 104 } 110 105 -
src/Parser/parser.yy
r6ac5223 re50e9ff 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 16 18:09:14 201713 // Update Count : 2 48512 // Last Modified On : Sun Aug 20 09:21:54 2017 13 // Update Count : 2573 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 133 %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 '(' if_control_expression ')' statement %prec THEN798 IF '(' push if_control_expression ')' statement %prec THEN 799 799 // explicitly deal with the shift/reduce conflict on if/else 800 { $$ = new StatementNode( build_if( $ 3, $5, nullptr ) ); }801 | IF '(' if_control_expression ')' statement ELSE statement802 { $$ = new StatementNode( build_if( $ 3, $5, $7) ); }803 | SWITCH '(' comma_expression ')' case_clause // CFA800 { $$ = 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 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 825 comma_expression pop 826 826 { $$ = new IfCtl( nullptr, $1 ); } 827 | c_declaration // no semi-coln827 | c_declaration pop // no semi-colon 828 828 { $$ = new IfCtl( $1, nullptr ); } 829 | cfa_declaration 829 | cfa_declaration pop // no semi-colon 830 830 { $$ = new IfCtl( $1, nullptr ); } 831 | declaration comma_expression 831 | declaration comma_expression // semi-colon separated 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 pop1106 // empty 1107 1107 { $$ = nullptr; } 1108 1108 | KR_declaration_list … … 1110 1110 1111 1111 KR_declaration_list: 1112 c_declaration ';' 1113 | KR_declaration_list push c_declaration ';' 1112 push c_declaration pop ';' 1113 { $$ = $2; } 1114 | KR_declaration_list push c_declaration pop ';' 1114 1115 { $$ = $1->appendList( $3 ); } 1115 1116 ; … … 1131 1132 1132 1133 declaration: // old & new style declarations 1133 c_declaration ';'1134 | cfa_declaration ';'// CFA1134 c_declaration pop ';' 1135 | cfa_declaration pop ';' // CFA 1135 1136 ; 1136 1137 … … 1147 1148 1148 1149 cfa_declaration: // CFA 1149 cfa_variable_declaration pop1150 | cfa_typedef_declaration pop1151 | cfa_function_declaration pop1152 | type_declaring_list pop1153 | trait_specifier pop1150 cfa_variable_declaration 1151 | cfa_typedef_declaration 1152 | cfa_function_declaration 1153 | type_declaring_list 1154 | trait_specifier 1154 1155 ; 1155 1156 … … 1351 1352 1352 1353 c_declaration: 1353 declaration_specifier declaring_list pop1354 declaration_specifier declaring_list 1354 1355 { 1355 1356 $$ = distAttr( $1, $2 ); 1356 1357 } 1357 | typedef_declaration pop1358 | typedef_expression pop// GCC, naming expression type1359 | sue_declaration_specifier pop1358 | typedef_declaration 1359 | typedef_expression // GCC, naming expression type 1360 | sue_declaration_specifier 1360 1361 ; 1361 1362 … … 2230 2231 $$ = $1->addFunctionBody( $2 ); 2231 2232 } 2232 | KR_function_declarator pushKR_declaration_list_opt compound_statement2233 | KR_function_declarator KR_declaration_list_opt compound_statement 2233 2234 { 2234 2235 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2235 2236 typedefTable.leaveScope(); 2236 $$ = $1->addOldDeclList( $ 3 )->addFunctionBody( $4);2237 $$ = $1->addOldDeclList( $2 )->addFunctionBody( $3 ); 2237 2238 } 2238 2239 ; … … 2278 2279 2279 2280 // Old-style K&R function definition, OBSOLESCENT (see 4) 2280 | declaration_specifier KR_function_declarator pushKR_declaration_list_opt with_clause_opt compound_statement2281 | declaration_specifier KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2281 2282 { 2282 2283 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2283 2284 typedefTable.leaveScope(); 2284 $$ = $2->addOldDeclList( $ 4 )->addFunctionBody( $6)->addType( $1 );2285 } 2286 | type_qualifier_list KR_function_declarator pushKR_declaration_list_opt with_clause_opt compound_statement2285 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addType( $1 ); 2286 } 2287 | type_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2287 2288 { 2288 2289 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2289 2290 typedefTable.leaveScope(); 2290 $$ = $2->addOldDeclList( $ 4 )->addFunctionBody( $6)->addQualifiers( $1 );2291 $$ = $2->addOldDeclList( $3 )->addFunctionBody( $5 )->addQualifiers( $1 ); 2291 2292 } 2292 2293 2293 2294 // Old-style K&R function definition with "implicit int" type_specifier, OBSOLESCENT (see 4) 2294 | declaration_qualifier_list KR_function_declarator pushKR_declaration_list_opt with_clause_opt compound_statement2295 | declaration_qualifier_list KR_function_declarator KR_declaration_list_opt with_clause_opt compound_statement 2295 2296 { 2296 2297 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2297 2298 typedefTable.leaveScope(); 2298 $$ = $2->addOldDeclList( $ 4 )->addFunctionBody( $6)->addQualifiers( $1 );2299 } 2300 | declaration_qualifier_list type_qualifier_list KR_function_declarator pushKR_declaration_list_opt with_clause_opt compound_statement2299 $$ = $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 2301 2302 { 2302 2303 typedefTable.addToEnclosingScope( TypedefTable::ID ); 2303 2304 typedefTable.leaveScope(); 2304 $$ = $3->addOldDeclList( $ 5 )->addFunctionBody( $7)->addQualifiers( $2 )->addQualifiers( $1 );2305 $$ = $3->addOldDeclList( $4 )->addFunctionBody( $6 )->addQualifiers( $2 )->addQualifiers( $1 ); 2305 2306 } 2306 2307 ; -
src/SymTab/Indexer.cc
r6ac5223 re50e9ff 10 10 // Created On : Sun May 17 21:37:33 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 30 16:38:47201713 // Update Count : 1912 // Last Modified On : Thu Aug 17 16:08:40 2017 13 // Update Count : 20 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 scope 357 enterScope(); 358 Visitor::visit( ifStmt ); 359 leaveScope(); 353 360 } 354 361 -
src/SymTab/Indexer.h
r6ac5223 re50e9ff 10 10 // Created On : Sun May 17 21:38:55 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:46:34201713 // Update Count : 712 // Last Modified On : Thu Aug 17 16:09:12 2017 13 // Update Count : 8 14 14 // 15 15 … … 45 45 46 46 virtual void visit( CompoundStmt *compoundStmt ); 47 virtual void visit( IfStmt *ifStmt ); 47 48 virtual void visit( ForStmt *forStmt ); 48 49 virtual void visit( CatchStmt *catchStmt ); -
src/SynTree/Initializer.cc
r6ac5223 re50e9ff 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Thr Aug 3 11:33:00 201613 // Update Count : 2911 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Aug 21 09:53:15 2017 13 // Update Count : 30 14 14 // 15 15 … … 80 80 } 81 81 } 82 assertf( initializers.size() == designations.size(), "Created ListInit with mismatching initializers (% lu) and designations (%lu)", initializers.size(), designations.size() );82 assertf( initializers.size() == designations.size(), "Created ListInit with mismatching initializers (%zd) and designations (%zd)", initializers.size(), designations.size() ); 83 83 } 84 84 -
src/SynTree/Mutator.cc
r6ac5223 re50e9ff 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Jul 24 16:32:00201713 // Update Count : 2 511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 15:39:37 2017 13 // Update Count : 27 14 14 // 15 15 … … 114 114 115 115 Statement *Mutator::mutate( IfStmt *ifStmt ) { 116 mutateAll( ifStmt->get_initialization(), *this ); 116 117 ifStmt->set_condition( maybeMutate( ifStmt->get_condition(), *this ) ); 117 118 ifStmt->set_thenPart( maybeMutate( ifStmt->get_thenPart(), *this ) ); -
src/SynTree/Statement.cc
r6ac5223 re50e9ff 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Aug 14 12:26:00 201713 // Update Count : 6 511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 16:17:20 2017 13 // Update Count : 67 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, Type _type ) 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, Type _type ) 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):125 Statement( _labels ), condition( _condition ), thenPart( _thenPart ), elsePart( _elsePart) {}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 ) {} 126 126 127 127 IfStmt::IfStmt( const IfStmt & other ) : 128 Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) {} 128 Statement( other ), condition( maybeClone( other.condition ) ), thenPart( maybeClone( other.thenPart ) ), elsePart( maybeClone( other.elsePart ) ) { 129 cloneAll( other.initialization, initialization ); 130 } 129 131 130 132 IfStmt::~IfStmt() { 133 deleteAll( initialization ); 131 134 delete condition; 132 135 delete thenPart; … … 139 142 condition->print( os, indent + 4 ); 140 143 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 141 153 os << string( indent+2, ' ' ) << "... then: " << endl; 142 154 … … 151 163 } 152 164 153 SwitchStmt::SwitchStmt( std::list<Label> _labels, Expression * _condition, std::list<Statement *> &_statements ):154 Statement( _labels ), condition( _condition ), statements( _statements ) {165 SwitchStmt::SwitchStmt( std::list<Label> labels, Expression * condition, std::list<Statement *> &statements ): 166 Statement( labels ), condition( condition ), statements( statements ) { 155 167 } 156 168 … … 179 191 } 180 192 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 ) {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 ) { 183 195 if ( isDefault() && condition != 0 ) 184 196 throw SemanticError("default with conditions"); … … 216 228 } 217 229 218 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition _, Statement *body_, bool isDoWhile_):219 Statement( labels ), condition( condition _), body( body_), isDoWhile( isDoWhile_) {230 WhileStmt::WhileStmt( std::list<Label> labels, Expression *condition, Statement *body, bool isDoWhile ): 231 Statement( labels ), condition( condition), body( body), isDoWhile( isDoWhile) { 220 232 } 221 233 … … 238 250 } 239 251 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_) {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 ) { 242 254 } 243 255 … … 317 329 } 318 330 319 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> & _handlers, FinallyStmt *_finallyBlock ) :320 Statement( labels ), block( tryBlock ), handlers( _handlers ), finallyBlock( _finallyBlock ) {331 TryStmt::TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) : 332 Statement( labels ), block( tryBlock ), handlers( handlers ), finallyBlock( finallyBlock ) { 321 333 } 322 334 … … 351 363 } 352 364 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 ) {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 ) { 355 367 } 356 368 … … 389 401 390 402 391 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt * _block ) : Statement( labels ), block( _block ) {403 FinallyStmt::FinallyStmt( std::list<Label> labels, CompoundStmt *block ) : Statement( labels ), block( block ) { 392 404 assert( labels.empty() ); // finally statement cannot be labeled 393 405 } -
src/SynTree/Statement.h
r6ac5223 re50e9ff 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Aug 16 16:28:55201713 // Update Count : 7 012 // Last Modified On : Thu Aug 17 15:37:53 2017 13 // Update Count : 72 14 14 // 15 15 … … 127 127 class IfStmt : public Statement { 128 128 public: 129 std::list<Statement *> initialization;130 129 Expression *condition; 131 130 Statement *thenPart; 132 131 Statement *elsePart; 133 134 IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart ); 132 std::list<Statement *> initialization; 133 134 IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart, 135 std::list<Statement *> initialization = std::list<Statement *>() ); 135 136 IfStmt( const IfStmt &other ); 136 137 virtual ~IfStmt(); 137 138 138 139 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; }242 241 Expression *get_condition() { return condition; } 243 242 void set_condition( Expression *newValue ) { condition = newValue; } -
src/SynTree/Visitor.cc
r6ac5223 re50e9ff 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Mon Jul 24 16:30:00201713 // Update Count : 2 711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Aug 17 15:39:38 2017 13 // Update Count : 29 14 14 // 15 15 … … 99 99 100 100 void Visitor::visit( IfStmt *ifStmt ) { 101 acceptAll( ifStmt->get_initialization(), *this ); 101 102 maybeAccept( ifStmt->get_condition(), *this ); 102 103 maybeAccept( ifStmt->get_thenPart(), *this ); -
src/driver/cfa.cc
r6ac5223 re50e9ff 9 9 // Author : Peter A. Buhr 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Jan 20 14:38:45201713 // Update Count : 15 511 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Aug 17 15:24:00 2017 13 // Update Count : 156 14 14 // 15 15 … … 281 281 #endif //HAVE_LIBCFA 282 282 283 // Add exception flags (unconditionally) 284 args[nargs] = "-fexceptions"; 285 nargs += 1; 286 283 287 // add the correct set of flags based on the type of compile this is 284 288 -
src/libcfa/Makefile.am
r6ac5223 re50e9ff 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 - I${abs_top_srcdir}/src/libcfa/libhdr -imacros libcfa-prelude.c @CFA_FLAGS@38 EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function -imacros libcfa-prelude.c @CFA_FLAGS@ 39 39 40 40 AM_CCASFLAGS = @CFA_FLAGS@ -
src/libcfa/Makefile.in
r6ac5223 re50e9ff 416 416 ARFLAGS = cr 417 417 lib_LIBRARIES = $(am__append_1) $(am__append_2) 418 EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function - I${abs_top_srcdir}/src/libcfa/libhdr -imacros libcfa-prelude.c @CFA_FLAGS@418 EXTRA_FLAGS = -g -Wall -Werror -Wno-unused-function -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
r6ac5223 re50e9ff 10 10 // Created On : Mon Jun 26 15:13:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 4 15:20:00 201713 // Update Count : 612 // Last Modified On : Thr Aug 17 15:45:00 2017 13 // Update Count : 7 14 14 // 15 15 … … 23 23 #include <stdio.h> 24 24 #include <unwind.h> 25 #include <libhdr/libdebug.h> 25 26 26 27 // FIX ME: temporary hack to keep ARM build working … … 79 80 void __cfaehm__throw_resume(exception * except) { 80 81 81 // DEBUG 82 printf("Throwing resumption exception\n"); 82 LIB_DEBUG_PRINT_SAFE("Throwing resumption exception\n"); 83 83 84 84 struct __cfaehm__try_resume_node * original_head = shared_stack.current_resume; … … 94 94 } 95 95 96 printf("Unhandled exception\n");96 LIB_DEBUG_PRINT_SAFE("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 int(*handler)(exception * except)) {108 _Bool (*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 // DEBUG 157 printf( "Deleting Exception\n"); 156 LIB_DEBUG_PRINT_SAFE("Deleting Exception\n"); 158 157 159 158 // Remove the exception from the list. … … 235 234 236 235 void __cfaehm__throw_terminate( exception * val ) { 237 // DEBUG 238 printf("Throwing termination exception\n"); 236 LIB_DEBUG_PRINT_SAFE("Throwing termination exception\n"); 239 237 240 238 __cfaehm__allocate_exception( val ); … … 243 241 244 242 void __cfaehm__rethrow_terminate(void) { 245 // DEBUG 246 printf("Rethrowing termination exception\n"); 243 LIB_DEBUG_PRINT_SAFE("Rethrowing termination exception\n"); 247 244 248 245 __cfaehm__begin_unwind(); … … 257 254 { 258 255 259 // DEBUG 260 //printf("CFA: 0x%lx\n", _Unwind_GetCFA(context)); 261 printf("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context); 256 //LIB_DEBUG_PRINT_SAFE("CFA: 0x%lx\n", _Unwind_GetCFA(context)); 257 LIB_DEBUG_PRINT_SAFE("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context); 262 258 263 259 // If we've reached the end of the stack then there is nothing much we can do... 264 260 if( actions & _UA_END_OF_STACK ) return _URC_END_OF_STACK; 265 261 266 // DEBUG267 262 if (actions & _UA_SEARCH_PHASE) { 268 printf(" lookup phase"); 269 } 270 // DEBUG 263 LIB_DEBUG_PRINT_SAFE(" lookup phase"); 264 } 271 265 else if (actions & _UA_CLEANUP_PHASE) { 272 printf(" cleanup phase");266 LIB_DEBUG_PRINT_SAFE(" cleanup phase"); 273 267 } 274 268 // Just in case, probably can't actually happen … … 306 300 // Have we reach the correct frame info yet? 307 301 if( lsd_info.Start + callsite_start + callsite_len < instruction_ptr ) { 308 //DEBUG BEGIN 302 #ifdef __CFA_DEBUG_PRINT__ 309 303 void * ls = (void*)lsd_info.Start; 310 304 void * cs = (void*)callsite_start; … … 313 307 void * ep = (void*)lsd_info.Start + callsite_start + callsite_len; 314 308 void * ip = (void*)instruction_ptr; 315 printf("\nfound %p - %p (%p, %p, %p), looking for %p\n", bp, ep, ls, cs, cl, ip);316 //DEBUG END 309 LIB_DEBUG_PRINT_SAFE("\nfound %p - %p (%p, %p, %p), looking for %p\n", bp, ep, ls, cs, cl, ip); 310 #endif // __CFA_DEBUG_PRINT__ 317 311 continue; 318 312 } … … 362 356 363 357 // Based on the return value, check if we matched the exception 364 if( ret == _URC_HANDLER_FOUND) printf(" handler found\n"); 365 else printf(" no handler\n"); 358 if( ret == _URC_HANDLER_FOUND) { 359 LIB_DEBUG_PRINT_SAFE(" handler found\n"); 360 } else { 361 LIB_DEBUG_PRINT_SAFE(" no handler\n"); 362 } 366 363 return ret; 367 364 } 368 365 369 366 // This is only a cleanup handler, ignore it 370 printf(" no action");367 LIB_DEBUG_PRINT_SAFE(" no action"); 371 368 } 372 369 else if (actions & _UA_CLEANUP_PHASE) { … … 388 385 _Unwind_SetIP( context, ((lsd_info.LPStart) + (callsite_landing_pad)) ); 389 386 390 // DEBUG 391 printf(" action\n"); 387 LIB_DEBUG_PRINT_SAFE(" action\n"); 392 388 393 389 // Return have some action to run … … 397 393 398 394 // Nothing to do, move along 399 printf(" no landing pad");395 LIB_DEBUG_PRINT_SAFE(" no landing pad"); 400 396 } 401 397 // No handling found 402 printf(" table end reached\n"); 403 404 // DEBUG 398 LIB_DEBUG_PRINT_SAFE(" table end reached\n"); 399 405 400 UNWIND: 406 printf(" unwind\n");401 LIB_DEBUG_PRINT_SAFE(" unwind\n"); 407 402 408 403 // Keep unwinding the stack -
src/libcfa/exception.h
r6ac5223 re50e9ff 10 10 // Created On : Mon Jun 26 15:11:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 4 15:20:00 201713 // Update Count : 512 // Last Modified On : Thr Aug 17 15:44:00 2017 13 // Update Count : 6 14 14 // 15 15 … … 55 55 struct __cfaehm__try_resume_node { 56 56 struct __cfaehm__try_resume_node * next; 57 int(*handler)(exception * except);57 _Bool (*handler)(exception * except); 58 58 }; 59 59 … … 61 61 void __cfaehm__try_resume_setup( 62 62 struct __cfaehm__try_resume_node * node, 63 int(*handler)(exception * except));63 _Bool (*handler)(exception * except)); 64 64 void __cfaehm__try_resume_cleanup( 65 65 struct __cfaehm__try_resume_node * node); -
src/libcfa/libhdr.h
r6ac5223 re50e9ff 16 16 #pragma once 17 17 18 #include "lib align.h"19 #include "lib debug.h"20 #include "lib tools.h"18 #include "libhdr/libalign.h" 19 #include "libhdr/libdebug.h" 20 #include "libhdr/libtools.h" 21 21 22 22 // Local Variables: // -
src/tests/.expect/32/KRfunctions.txt
r6ac5223 re50e9ff 15 15 } 16 16 struct S { 17 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 } 81 84 const int __fred__FCi___1(){ 82 85 __attribute__ ((unused)) const int ___retval_fred__Ci_1; -
src/tests/.expect/64/KRfunctions.txt
r6ac5223 re50e9ff 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 } 81 84 const int __fred__FCi___1(){ 82 85 __attribute__ ((unused)) const int ___retval_fred__Ci_1; -
src/tests/KRfunctions.c
r6ac5223 re50e9ff 10 10 // Created On : Thu Feb 16 15:23:17 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 24 22:05:00201713 // Update Count : 312 // Last Modified On : Sun Aug 20 07:34:17 2017 13 // Update Count : 7 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 ) {} 39 40 40 41 const fred() { -
src/tests/except-0.c
r6ac5223 re50e9ff 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 9 15 10 16 // Local type to mark exits from scopes. (see ERROR) … … 23 29 24 30 25 // Local Exception Types and manual vtable types. 26 //#define TRIVIAL_EXCEPTION(name) //TRIVAL_EXCEPTION(yin) 27 struct yin; 28 struct yin_vtable { 29 struct exception_t_vtable const * parent; 30 size_t size; 31 void (*copy)(yin *this, yin * other); 32 void (*free)(yin *this); 33 const char (*msg)(yin *this); 34 }; 35 struct yin { 36 struct yin_vtable const * parent; 37 }; 38 void yin_msg(yin) { 39 return "in"; 40 } 41 yin_vtable _yin_vtable_instance = { 42 &_exception_t_vtable_instance, sizeof(yin), ?{}, ^?{}, yin_msg 43 } 44 45 46 void terminate(exception * except_value) { 31 // Mark throws: make sure to only pass in exception types. 32 forall(dtype T) 33 void terminate(T * except_value) { 47 34 signal_exit a = {"terminate function"}; 48 throw except_value;35 THROW(except_value); 49 36 printf("terminate returned\n"); 50 37 } 51 38 52 void resume(exception * except_value) { 39 forall(dtype T) 40 void resume(T * except_value) { 53 41 signal_exit a = {"resume function"}; 54 throwResume except_value;42 THROW_RESUME(except_value); 55 43 printf("resume returned\n"); 56 44 } … … 60 48 signal_exit a = {"bar function"}; 61 49 try { 62 terminate( 4);63 } catch ( 3) {64 printf("bar caught exception 3.\n");50 terminate(&(zen){}); 51 } catch (yin * error) { 52 printf("bar caught exception yin.\n"); 65 53 } 66 54 } … … 70 58 try { 71 59 bar(); 72 } catch ( 4) {73 printf("foo caught exception 4.\n");74 } catch ( 2) {75 printf("foo caught exception 2.\n");60 } catch (yang * error) { 61 printf("foo caught exception yang.\n"); 62 } catch (zen * error) { 63 printf("foo caught exception zen.\n"); 76 64 } 77 65 } … … 81 69 signal_exit a = {"beta function"}; 82 70 try { 83 resume(4); 84 } catchResume (3) { 85 printf("beta caught exception 3\n"); 71 zen x; 72 resume(&x); 73 } catchResume (yin * error) { 74 printf("beta caught exception yin\n"); 86 75 } 87 76 } … … 91 80 try { 92 81 beta(); 93 } catchResume ( 2) {94 printf("alpha caught exception 2\n");95 } catchResume ( 4) {96 printf("alpha caught exception 4\n");82 } catchResume (yang * error) { 83 printf("alpha caught exception yang\n"); 84 } catchResume (zen * error) { 85 printf("alpha caught exception zen\n"); 97 86 } 98 87 } … … 117 106 void fallback() { 118 107 try { 119 resume(2); 120 } catch (2) { 121 printf("fallback caught termination 2\n"); 108 zen x; 109 resume(&x); 110 } catch (zen * error) { 111 printf("fallback caught termination zen\n"); 122 112 } 123 113 } … … 127 117 signal_exit a = {"terminate_swap"}; 128 118 try { 129 terminate(2); 130 } catch (2) { 131 terminate(3); 119 yin x; 120 terminate(&x); 121 } catch (yin * error) { 122 yang y; 123 terminate(&y); 132 124 } 133 125 } … … 137 129 try { 138 130 terminate_swap(); 139 } catch ( 3) {140 printf("terminate_swapped caught exception 3\n");131 } catch (yang * error) { 132 printf("terminate_swapped caught exception yang\n"); 141 133 } 142 134 } … … 146 138 signal_exit a = {"resume_swap"}; 147 139 try { 148 resume(2); 149 } catchResume (2) { 150 resume(3); 140 yin x; 141 resume(&x); 142 } catchResume (yin * error) { 143 yang y; 144 resume(&y); 151 145 } 152 146 } … … 155 149 try { 156 150 resume_swap(); 157 } catchResume ( 3) {158 printf("resume_swapped caught exception 3\n");151 } catchResume (yang * error) { 152 printf("resume_swapped caught exception yang\n"); 159 153 } 160 154 } … … 164 158 try { 165 159 try { 166 terminate(2); 167 } catch (2) { 168 printf("reterminate 2 caught and " 169 "will rethrow exception 2\n"); 160 zen x; 161 terminate(&x); 162 } catch (zen * error) { 163 printf("reterminate zen caught and " 164 "will rethrow exception zen\n"); 170 165 throw; 171 166 } 172 } catch ( 2) {173 printf("reterminate 1 caught exception 2\n");167 } catch (zen * error) { 168 printf("reterminate 1 caught exception zen\n"); 174 169 } 175 170 } … … 179 174 try { 180 175 try { 181 resume(2); 182 } catchResume (2) { 183 printf("reresume 2 caught and rethrows exception 2\n"); 176 zen x; 177 resume(&x); 178 } catchResume (zen * error) { 179 printf("reresume zen caught and rethrows exception zen\n"); 184 180 throwResume; 185 181 } 186 } catchResume ( 2) {187 printf("reresume 1 caught exception 2\n");182 } catchResume (zen * error) { 183 printf("reresume 1 caught exception zen\n"); 188 184 } 189 185 } … … 193 189 // terminate block, call resume 194 190 try { 195 resume(3); 196 } catch (3) { 197 printf("fum caught exception 3\n"); 191 zen x; 192 resume(&x); 193 } catch (zen * error) { 194 printf("fum caught exception zen\n"); 198 195 } 199 196 } … … 202 199 // resume block, call terminate 203 200 try { 204 terminate(3); 205 } catchResume (3) { 206 printf("foe caught exception 3\n"); 201 zen y; 202 terminate(&y); 203 } catchResume (zen * error) { 204 printf("foe caught exception zen\n"); 207 205 } 208 206 } … … 212 210 try { 213 211 foe(); 214 } catch ( 3) {215 printf("fy caught exception 3\n");212 } catch (zen * error) { 213 printf("fy caught exception zen\n"); 216 214 fum(); 217 215 } … … 222 220 try { 223 221 fy(); 224 } catchResume ( 3) {225 printf("fee caught exception 3\n");222 } catchResume (zen * error) { 223 printf("fee caught exception zen\n"); 226 224 } 227 225 } … … 242 240 reresume(); printf("\n"); 243 241 fee(); printf("\n"); 242 244 243 // Uncaught termination test. 245 terminate(7); 246 } 244 printf("Throw uncaught.\n"); 245 yang z; 246 terminate(&z); 247 } -
src/tests/except-1.c
r6ac5223 re50e9ff 5 5 #include <stdio.h> 6 6 7 #include "except-mac.h" 8 TRIVIAL_EXCEPTION(yin) 9 TRIVIAL_EXCEPTION(yang) 10 7 11 int main() 8 12 { 9 13 try { 10 throw 3; 14 yin a; 15 THROW(&a); 11 16 } 12 catch( 3) {17 catch( yin * err ) { 13 18 printf("First Caught\n"); 14 19 try { 15 throw 4; 20 yang b; 21 THROW(&b); 16 22 } 17 catch( 4) {23 catch( yang * err ) { 18 24 printf("Both Caught\n"); 19 25 } … … 23 29 try { 24 30 try { 25 throw 2; 31 yang c; 32 THROW(&c); 26 33 } 27 catch( 2) {34 catch( yang * err ) { 28 35 printf("First Catch and rethrow\n"); 29 36 throw; 30 37 } 31 38 } 32 catch( 2) {39 catch( yang * err ) { 33 40 printf("Second Catch\n"); 34 41 } … … 37 44 try { 38 45 try { 39 throw 5; 46 yin d; 47 THROW(&d); 40 48 } 41 catch( 5) {49 catch( yin * err ) { 42 50 printf("Throw before cleanup\n"); 43 throw 6; 51 yang e; 52 THROW(&e); 44 53 } 45 54 } 46 catch( 6) {55 catch( yang * err ) { 47 56 printf("Catch after cleanup\n"); 48 57 } … … 51 60 try { 52 61 try { 53 throw 7; 62 yin f; 63 THROW(&f); 54 64 } 55 catch( 7) {65 catch( yin * err ) { 56 66 printf("Caught initial throw.\n"); 57 67 try { 58 throw 8; 68 yang g; 69 THROW(&g); 59 70 } 60 catch( 8) {71 catch( yang * err ) { 61 72 printf("Caught intermediate throw.\n"); 62 73 } … … 64 75 } 65 76 } 66 catch( 7) {77 catch( yin * err ) { 67 78 printf("Caught final throw.\n"); 68 79 } -
src/tests/except-2.c
r6ac5223 re50e9ff 2 2 3 3 4 #include <string.h> 4 #include <stdlib> 5 #include "except-mac.h" 5 6 6 // Local Exception Types and manual vtable types.7 #define GLUE2(left, right) left##right8 #define GLUE3(left, middle, right) left##middle##right9 #define BASE_EXCEPT __cfaehm__base_exception_t10 #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 }39 7 TRIVIAL_EXCEPTION(yin) 40 8 TRIVIAL_EXCEPTION(yang) … … 50 18 }; 51 19 extern num_error_vtable INSTANCE(num_error); 20 52 21 struct num_error { 53 22 struct num_error_vtable const * virtual_table; … … 55 24 int num; 56 25 }; 26 57 27 void num_error_msg(num_error * this) { 58 28 if ( ! this->msg ) { 59 const char * base = "Num Error with code: X"; 60 this->msg = strdup( base ); 29 static const char * base = "Num Error with code: X"; 30 this->msg = malloc(22); 31 for (int i = 0 ; (this->msg[i] = base[i]) ; ++i); 61 32 } 62 33 this->msg[21] = '0' + this->num; … … 90 61 try { 91 62 yin black; 92 throw (BASE_EXCEPT *)&black;63 THROW(&black); 93 64 } catch ( yin * error ) { 94 65 printf("throw yin caught.\n"); … … 97 68 try { 98 69 yang white; 99 throwResume (BASE_EXCEPT *)&white;70 THROW_RESUME(&white); 100 71 printf("> throwResume returned.\n"); 101 72 } catchResume ( yang * error ) { … … 105 76 try { 106 77 num_error x = { 2 }; 107 throw (BASE_EXCEPT *)&x;78 THROW(&x); 108 79 } 109 80 catch (num_error * error ; 3 == error->virtual_table->code( error ) ) {
Note: See TracChangeset
for help on using the changeset viewer.