- Timestamp:
- Aug 10, 2017, 3:39:11 PM (8 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:
- 38d70ab
- Parents:
- 275f4b4 (diff), e1780a2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src
- Files:
-
- 4 added
- 46 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/ControlStruct/ExceptTranslate.cc
r275f4b4 rcd7ef0b 10 10 // Created On : Wed Jun 14 16:49:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Jul 18 10:09:00 201713 // Update Count : 412 // Last Modified On : Tus Aug 8 16:54:00 2017 13 // Update Count : 7 14 14 // 15 15 … … 21 21 #include "SynTree/Type.h" 22 22 #include "SynTree/Attribute.h" 23 #include "SynTree/VarExprReplacer.h" 23 24 24 25 namespace ControlStruct { 25 26 26 // This (large) section could probably be moved out of the class 27 // and be static helpers instead. 28 29 // Type(Qualifiers &, false, std::list<Attribute *> &) 30 31 // void (*function)(); 32 static FunctionType try_func_t(Type::Qualifiers(), false); 33 // void (*function)(int, exception); 34 static FunctionType catch_func_t(Type::Qualifiers(), false); 35 // int (*function)(exception); 36 static FunctionType match_func_t(Type::Qualifiers(), false); 37 // bool (*function)(exception); 38 static FunctionType handle_func_t(Type::Qualifiers(), false); 39 // void (*function)(__attribute__((unused)) void *); 40 static FunctionType finally_func_t(Type::Qualifiers(), false); 41 42 static void init_func_types() { 43 static bool init_complete = false; 44 if (init_complete) { 45 return; 46 } 27 // Buricratic Helpers (Not having to do with the paritular operation.) 28 29 typedef std::list<CatchStmt*> CatchList; 30 31 void split( CatchList& allHandlers, CatchList& terHandlers, 32 CatchList& resHandlers ) { 33 while ( !allHandlers.empty() ) { 34 CatchStmt * stmt = allHandlers.front(); 35 allHandlers.pop_front(); 36 if (CatchStmt::Terminate == stmt->get_kind()) { 37 terHandlers.push_back(stmt); 38 } else { 39 resHandlers.push_back(stmt); 40 } 41 } 42 } 43 44 void appendDeclStmt( CompoundStmt * block, Declaration * item ) { 45 block->push_back(new DeclStmt(noLabels, item)); 46 } 47 48 Expression * nameOf( DeclarationWithType * decl ) { 49 return new VariableExpr( decl ); 50 } 51 52 class ExceptionMutatorCore : public WithGuards { 53 enum Context { NoHandler, TerHandler, ResHandler }; 54 55 // Also need to handle goto, break & continue. 56 // They need to be cut off in a ResHandler, until we enter another 57 // loop, switch or the goto stays within the function. 58 59 Context cur_context; 60 61 // The current (innermost) termination handler exception declaration. 62 ObjectDecl * handler_except_decl; 63 64 // The built in types used in translation. 65 StructDecl * except_decl; 66 StructDecl * node_decl; 67 StructDecl * hook_decl; 68 69 // The many helper functions for code/syntree generation. 70 Statement * create_given_throw( 71 const char * throwFunc, ThrowStmt * throwStmt ); 72 Statement * create_terminate_throw( ThrowStmt * throwStmt ); 73 Statement * create_terminate_rethrow( ThrowStmt * throwStmt ); 74 Statement * create_resume_throw( ThrowStmt * throwStmt ); 75 Statement * create_resume_rethrow( ThrowStmt * throwStmt ); 76 CompoundStmt * take_try_block( TryStmt * tryStmt ); 77 FunctionDecl * create_try_wrapper( CompoundStmt * body ); 78 FunctionDecl * create_terminate_catch( CatchList &handlers ); 79 CompoundStmt * create_single_matcher( 80 DeclarationWithType * except_obj, CatchStmt * modded_handler ); 81 FunctionDecl * create_terminate_match( CatchList &handlers ); 82 CompoundStmt * create_terminate_caller( FunctionDecl * try_wrapper, 83 FunctionDecl * terminate_catch, FunctionDecl * terminate_match ); 84 FunctionDecl * create_resume_handler( CatchList &handlers ); 85 CompoundStmt * create_resume_wrapper( 86 Statement * wraps, FunctionDecl * resume_handler ); 87 FunctionDecl * create_finally_wrapper( TryStmt * tryStmt ); 88 ObjectDecl * create_finally_hook( FunctionDecl * finally_wrapper ); 89 90 // Types used in translation, make sure to use clone. 91 // void (*function)(); 92 FunctionType try_func_t; 93 // void (*function)(int, exception); 94 FunctionType catch_func_t; 95 // int (*function)(exception); 96 FunctionType match_func_t; 97 // bool (*function)(exception); 98 FunctionType handle_func_t; 99 // void (*function)(__attribute__((unused)) void *); 100 FunctionType finally_func_t; 101 102 StructInstType * create_except_type() { 103 assert( except_decl ); 104 return new StructInstType( noQualifiers, except_decl ); 105 } 106 void init_func_types(); 107 108 public: 109 ExceptionMutatorCore() : 110 cur_context( NoHandler ), 111 handler_except_decl( nullptr ), 112 except_decl( nullptr ), node_decl( nullptr ), hook_decl( nullptr ), 113 try_func_t( noQualifiers, false ), 114 catch_func_t( noQualifiers, false ), 115 match_func_t( noQualifiers, false ), 116 handle_func_t( noQualifiers, false ), 117 finally_func_t( noQualifiers, false ) 118 {} 119 120 void premutate( CatchStmt *catchStmt ); 121 void premutate( StructDecl *structDecl ); 122 Statement * postmutate( ThrowStmt *throwStmt ); 123 Statement * postmutate( TryStmt *tryStmt ); 124 }; 125 126 void ExceptionMutatorCore::init_func_types() { 127 assert( except_decl ); 128 47 129 ObjectDecl index_obj( 48 130 "__handler_index", … … 60 142 new PointerType( 61 143 noQualifiers, 62 new BasicType( noQualifiers, BasicType::SignedInt)144 new StructInstType( noQualifiers, except_decl ) 63 145 ), 64 146 /*init*/ NULL … … 69 151 LinkageSpec::Cforall, 70 152 /*bitfieldWidth*/ NULL, 71 new BasicType( noQualifiers, BasicType::Bool),153 new BasicType( noQualifiers, BasicType::Bool ), 72 154 /*init*/ NULL 73 155 ); … … 82 164 noQualifiers 83 165 ), 84 std::list<Attribute *>{ new Attribute("unused")}166 std::list<Attribute *>{ new Attribute( "unused" ) } 85 167 ), 86 168 NULL … … 94 176 handle_func_t.get_parameters().push_back( exception_obj.clone() ); 95 177 finally_func_t.get_parameters().push_back( voidptr_obj.clone() ); 96 97 init_complete = true;98 }99 100 // Buricratic Helpers (Not having to do with the paritular operation.)101 102 typedef std::list<CatchStmt*> CatchList;103 104 void split( CatchList& allHandlers, CatchList& terHandlers,105 CatchList& resHandlers ) {106 while ( !allHandlers.empty() ) {107 CatchStmt * stmt = allHandlers.front();108 allHandlers.pop_front();109 if (CatchStmt::Terminate == stmt->get_kind()) {110 terHandlers.push_back(stmt);111 } else {112 resHandlers.push_back(stmt);113 }114 }115 }116 117 template<typename T>118 void free_all( std::list<T *> &list ) {119 typename std::list<T *>::iterator it;120 for ( it = list.begin() ; it != list.end() ; ++it ) {121 delete *it;122 }123 list.clear();124 }125 126 void appendDeclStmt( CompoundStmt * block, Declaration * item ) {127 block->push_back(new DeclStmt(noLabels, item));128 }129 130 Expression * nameOf( DeclarationWithType * decl ) {131 return new VariableExpr( decl );132 178 } 133 179 134 180 // ThrowStmt Mutation Helpers 135 181 136 Statement * create_given_throw(182 Statement * ExceptionMutatorCore::create_given_throw( 137 183 const char * throwFunc, ThrowStmt * throwStmt ) { 138 // { int NAME = EXPR; throwFunc( &NAME ); } 139 CompoundStmt * result = new CompoundStmt( noLabels ); 140 ObjectDecl * local = new ObjectDecl( 141 "__local_exception_copy", 142 Type::StorageClasses(), 143 LinkageSpec::Cforall, 144 NULL, 145 new BasicType( noQualifiers, BasicType::SignedInt ), 146 new SingleInit( throwStmt->get_expr() ) 147 ); 148 appendDeclStmt( result, local ); 184 // `throwFunc`( `throwStmt->get_name` ); 149 185 UntypedExpr * call = new UntypedExpr( new NameExpr( throwFunc ) ); 150 call->get_args().push_back( new AddressExpr( nameOf( local ) ) ); 151 result->push_back( new ExprStmt( throwStmt->get_labels(), call ) ); 186 call->get_args().push_back( throwStmt->get_expr() ); 152 187 throwStmt->set_expr( nullptr ); 153 188 delete throwStmt; 154 return result; 155 } 156 157 Statement * create_terminate_throw( ThrowStmt *throwStmt ) { 158 // { int NAME = EXPR; __throw_terminate( &NAME ); } 189 return new ExprStmt( noLabels, call ); 190 } 191 192 Statement * ExceptionMutatorCore::create_terminate_throw( 193 ThrowStmt *throwStmt ) { 194 // __throw_terminate( `throwStmt->get_name()` ); } 159 195 return create_given_throw( "__cfaehm__throw_terminate", throwStmt ); 160 196 } 161 Statement * create_terminate_rethrow( ThrowStmt *throwStmt ) { 162 // __rethrow_terminate(); 197 198 Statement * ExceptionMutatorCore::create_terminate_rethrow( 199 ThrowStmt *throwStmt ) { 200 // { `handler_except_decl` = NULL; __rethrow_terminate(); } 163 201 assert( nullptr == throwStmt->get_expr() ); 164 Statement * result = new ExprStmt( 165 throwStmt->get_labels(), 202 assert( handler_except_decl ); 203 204 CompoundStmt * result = new CompoundStmt( throwStmt->get_labels() ); 205 result->push_back( new ExprStmt( noLabels, UntypedExpr::createAssign( 206 nameOf( handler_except_decl ), 207 new ConstantExpr( Constant::null( 208 new PointerType( 209 noQualifiers, 210 handler_except_decl->get_type()->clone() 211 ) 212 ) ) 213 ) ) ); 214 result->push_back( new ExprStmt( 215 noLabels, 166 216 new UntypedExpr( new NameExpr( "__cfaehm__rethrow_terminate" ) ) 167 ) ;217 ) ); 168 218 delete throwStmt; 169 219 return result; 170 220 } 171 Statement * create_resume_throw( ThrowStmt *throwStmt ) { 172 // __throw_resume( EXPR ); 221 222 Statement * ExceptionMutatorCore::create_resume_throw( 223 ThrowStmt *throwStmt ) { 224 // __throw_resume( `throwStmt->get_name` ); 173 225 return create_given_throw( "__cfaehm__throw_resume", throwStmt ); 174 226 } 175 Statement * create_resume_rethrow( ThrowStmt *throwStmt ) { 227 228 Statement * ExceptionMutatorCore::create_resume_rethrow( 229 ThrowStmt *throwStmt ) { 176 230 // return false; 177 231 Statement * result = new ReturnStmt( … … 185 239 // TryStmt Mutation Helpers 186 240 187 CompoundStmt * take_try_block( TryStmt *tryStmt ) {241 CompoundStmt * ExceptionMutatorCore::take_try_block( TryStmt *tryStmt ) { 188 242 CompoundStmt * block = tryStmt->get_block(); 189 243 tryStmt->set_block( nullptr ); 190 244 return block; 191 245 } 192 FunctionDecl * create_try_wrapper( CompoundStmt *body ) { 246 247 FunctionDecl * ExceptionMutatorCore::create_try_wrapper( 248 CompoundStmt *body ) { 193 249 194 250 return new FunctionDecl( "try", Type::StorageClasses(), … … 196 252 } 197 253 198 FunctionDecl * create_terminate_catch( CatchList &handlers ) { 254 FunctionDecl * ExceptionMutatorCore::create_terminate_catch( 255 CatchList &handlers ) { 199 256 std::list<CaseStmt *> handler_wrappers; 200 257 201 258 FunctionType *func_type = catch_func_t.clone(); 202 259 DeclarationWithType * index_obj = func_type->get_parameters().front(); 203 //DeclarationWithType * except_obj = func_type->get_parameters().back();260 DeclarationWithType * except_obj = func_type->get_parameters().back(); 204 261 205 262 // Index 1..{number of handlers} … … 210 267 CatchStmt * handler = *it; 211 268 212 // INTEGERconstant Version213 269 // case `index`: 214 270 // { 215 // `handler.body` 271 // `handler.decl` = { (virtual `decl.type`)`except` }; 272 // `handler.body`; 216 273 // } 217 274 // return; 218 std::list<Statement *> caseBody; 219 caseBody.push_back( handler->get_body() ); 275 CompoundStmt * block = new CompoundStmt( noLabels ); 276 277 // Just copy the exception value. (Post Validation) 278 ObjectDecl * handler_decl = 279 static_cast<ObjectDecl *>( handler->get_decl() ); 280 ObjectDecl * local_except = handler_decl->clone(); 281 local_except->set_init( 282 new ListInit({ new SingleInit( 283 new VirtualCastExpr( nameOf( except_obj ), 284 local_except->get_type() 285 ) 286 ) }) 287 ); 288 block->push_back( new DeclStmt( noLabels, local_except ) ); 289 290 // Add the cleanup attribute. 291 local_except->get_attributes().push_back( new Attribute( 292 "cleanup", 293 { new NameExpr( "__cfaehm__cleanup_terminate" ) } 294 ) ); 295 296 // Update variables in the body to point to this local copy. 297 { 298 VarExprReplacer::DeclMap mapping; 299 mapping[ handler_decl ] = local_except; 300 VarExprReplacer mapper( mapping ); 301 handler->get_body()->accept( mapper ); 302 } 303 304 block->push_back( handler->get_body() ); 220 305 handler->set_body( nullptr ); 221 caseBody.push_back( new ReturnStmt( noLabels, nullptr ) ); 222 306 307 std::list<Statement *> caseBody 308 { block, new ReturnStmt( noLabels, nullptr ) }; 223 309 handler_wrappers.push_back( new CaseStmt( 224 310 noLabels, … … 249 335 // Create a single check from a moddified handler. 250 336 // except_obj is referenced, modded_handler will be freed. 251 CompoundStmt * create_single_matcher(337 CompoundStmt * ExceptionMutatorCore::create_single_matcher( 252 338 DeclarationWithType * except_obj, CatchStmt * modded_handler ) { 339 // { 340 // `modded_handler.decl` 341 // if ( `decl.name = (virtual `decl.type`)`except` 342 // [&& `modded_handler.cond`] ) { 343 // `modded_handler.body` 344 // } 345 // } 346 253 347 CompoundStmt * block = new CompoundStmt( noLabels ); 254 348 255 // INTEGERconstant Version 256 assert( nullptr == modded_handler->get_decl() ); 257 ConstantExpr * number = 258 dynamic_cast<ConstantExpr*>( modded_handler->get_cond() ); 259 assert( number ); 260 modded_handler->set_cond( nullptr ); 261 262 Expression * cond; 263 { 264 std::list<Expression *> args; 265 args.push_back( number ); 266 267 std::list<Expression *> rhs_args; 268 rhs_args.push_back( nameOf( except_obj ) ); 269 Expression * rhs = new UntypedExpr( 270 new NameExpr( "*?" ), rhs_args ); 271 args.push_back( rhs ); 272 273 cond = new UntypedExpr( new NameExpr( "?==?" /*???*/), args ); 274 } 275 349 // Local Declaration 350 ObjectDecl * local_except = 351 dynamic_cast<ObjectDecl *>( modded_handler->get_decl() ); 352 assert( local_except ); 353 block->push_back( new DeclStmt( noLabels, local_except ) ); 354 355 // Check for type match. 356 Expression * cond = UntypedExpr::createAssign( nameOf( local_except ), 357 new VirtualCastExpr( nameOf( except_obj ), 358 local_except->get_type()->clone() ) ); 359 360 // Add the check on the conditional if it is provided. 276 361 if ( modded_handler->get_cond() ) { 277 362 cond = new LogicalExpr( cond, modded_handler->get_cond() ); 278 363 } 364 // Construct the match condition. 279 365 block->push_back( new IfStmt( noLabels, 280 366 cond, modded_handler->get_body(), nullptr ) ); … … 287 373 } 288 374 289 FunctionDecl * create_terminate_match( CatchList &handlers ) { 375 FunctionDecl * ExceptionMutatorCore::create_terminate_match( 376 CatchList &handlers ) { 377 // int match(exception * except) { 378 // HANDLER WRAPPERS { return `index`; } 379 // } 380 290 381 CompoundStmt * body = new CompoundStmt( noLabels ); 291 382 … … 319 410 } 320 411 321 CompoundStmt * create_terminate_caller(412 CompoundStmt * ExceptionMutatorCore::create_terminate_caller( 322 413 FunctionDecl * try_wrapper, 323 414 FunctionDecl * terminate_catch, 324 FunctionDecl * terminate_match) { 415 FunctionDecl * terminate_match ) { 416 // { __cfaehm__try_terminate(`try`, `catch`, `match`); } 325 417 326 418 UntypedExpr * caller = new UntypedExpr( new NameExpr( … … 336 428 } 337 429 338 FunctionDecl * create_resume_handler( CatchList &handlers ) { 430 FunctionDecl * ExceptionMutatorCore::create_resume_handler( 431 CatchList &handlers ) { 432 // bool handle(exception * except) { 433 // HANDLER WRAPPERS { `hander->body`; return true; } 434 // } 339 435 CompoundStmt * body = new CompoundStmt( noLabels ); 340 436 … … 369 465 } 370 466 371 CompoundStmt * create_resume_wrapper( 372 StructDecl * node_decl, 467 CompoundStmt * ExceptionMutatorCore::create_resume_wrapper( 373 468 Statement * wraps, 374 469 FunctionDecl * resume_handler ) { … … 414 509 } 415 510 416 FunctionDecl * create_finally_wrapper( TryStmt * tryStmt ) { 511 FunctionDecl * ExceptionMutatorCore::create_finally_wrapper( 512 TryStmt * tryStmt ) { 513 // void finally() { <finally code> } 417 514 FinallyStmt * finally = tryStmt->get_finally(); 418 515 CompoundStmt * body = finally->get_block(); … … 425 522 } 426 523 427 ObjectDecl * create_finally_hook(428 StructDecl * hook_decl,FunctionDecl * finally_wrapper ) {524 ObjectDecl * ExceptionMutatorCore::create_finally_hook( 525 FunctionDecl * finally_wrapper ) { 429 526 // struct __cfaehm__cleanup_hook __finally_hook 430 527 // __attribute__((cleanup( finally_wrapper ))); … … 452 549 } 453 550 454 455 class ExceptionMutatorCore : public WithGuards { 456 enum Context { NoHandler, TerHandler, ResHandler }; 457 458 // Also need to handle goto, break & continue. 459 // They need to be cut off in a ResHandler, until we enter another 460 // loop, switch or the goto stays within the function. 461 462 Context cur_context; 463 464 // We might not need this, but a unique base for each try block's 465 // generated functions might be nice. 466 //std::string curFunctionName; 467 //unsigned int try_count = 0; 468 469 StructDecl *node_decl; 470 StructDecl *hook_decl; 471 472 public: 473 ExceptionMutatorCore() : 474 cur_context(NoHandler), 475 node_decl(nullptr), hook_decl(nullptr) 476 {} 477 478 void premutate( CatchStmt *catchStmt ); 479 void premutate( StructDecl *structDecl ); 480 Statement * postmutate( ThrowStmt *throwStmt ); 481 Statement * postmutate( TryStmt *tryStmt ); 482 }; 551 // Visiting/Mutating Functions 552 void ExceptionMutatorCore::premutate( CatchStmt *catchStmt ) { 553 // Validate the Statement's form. 554 ObjectDecl * decl = 555 dynamic_cast<ObjectDecl *>( catchStmt->get_decl() ); 556 if ( decl && true /* check decl->get_type() */ ) { 557 // Pass. 558 } else if ( CatchStmt::Terminate == catchStmt->get_kind() ) { 559 throw SemanticError("catch must have exception type"); 560 } else { 561 throw SemanticError("catchResume must have exception type"); 562 } 563 564 // Track the handler context. 565 GuardValue( cur_context ); 566 if ( CatchStmt::Terminate == catchStmt->get_kind() ) { 567 cur_context = TerHandler; 568 569 GuardValue( handler_except_decl ); 570 handler_except_decl = decl; 571 } else { 572 cur_context = ResHandler; 573 } 574 } 575 576 void ExceptionMutatorCore::premutate( StructDecl *structDecl ) { 577 if ( !structDecl->has_body() ) { 578 // Skip children? 579 return; 580 } else if ( structDecl->get_name() == "__cfaehm__base_exception_t" ) { 581 assert( nullptr == except_decl ); 582 except_decl = structDecl; 583 init_func_types(); 584 } else if ( structDecl->get_name() == "__cfaehm__try_resume_node" ) { 585 assert( nullptr == node_decl ); 586 node_decl = structDecl; 587 } else if ( structDecl->get_name() == "__cfaehm__cleanup_hook" ) { 588 assert( nullptr == hook_decl ); 589 hook_decl = structDecl; 590 } 591 // Later we might get the exception type as well. 592 } 483 593 484 594 Statement * ExceptionMutatorCore::postmutate( ThrowStmt *throwStmt ) { 595 assert( except_decl ); 596 485 597 // Ignoring throwStmt->get_target() for now. 486 598 if ( ThrowStmt::Terminate == throwStmt->get_kind() ) { … … 510 622 511 623 Statement * ExceptionMutatorCore::postmutate( TryStmt *tryStmt ) { 624 assert( except_decl ); 512 625 assert( node_decl ); 513 626 assert( hook_decl ); … … 524 637 appendDeclStmt( block, finally_block ); 525 638 // Create and add the finally cleanup hook. 526 appendDeclStmt( block, 527 create_finally_hook( hook_decl, finally_block ) ); 639 appendDeclStmt( block, create_finally_hook( finally_block ) ); 528 640 } 529 641 … … 539 651 appendDeclStmt( block, resume_handler ); 540 652 // Prepare hooks 541 inner = create_resume_wrapper( node_decl,inner, resume_handler );653 inner = create_resume_wrapper( inner, resume_handler ); 542 654 } 543 655 … … 560 672 block->push_back( inner ); 561 673 562 //free_all( termination_handlers );563 //free_all( resumption_handlers );564 565 674 return block; 566 675 } 567 676 568 void ExceptionMutatorCore::premutate( CatchStmt *catchStmt ) {569 GuardValue( cur_context );570 if ( CatchStmt::Terminate == catchStmt->get_kind() ) {571 cur_context = TerHandler;572 } else {573 cur_context = ResHandler;574 }575 }576 577 void ExceptionMutatorCore::premutate( StructDecl *structDecl ) {578 if ( !structDecl->has_body() ) {579 // Skip children?580 return;581 } else if ( structDecl->get_name() == "__cfaehm__try_resume_node" ) {582 assert( nullptr == node_decl );583 node_decl = structDecl;584 } else if ( structDecl->get_name() == "__cfaehm__cleanup_hook" ) {585 assert( nullptr == hook_decl );586 hook_decl = structDecl;587 }588 // Later we might get the exception type as well.589 }590 591 677 void translateEHM( std::list< Declaration *> & translationUnit ) { 592 init_func_types();593 594 678 PassVisitor<ExceptionMutatorCore> translator; 595 679 mutateAll( translationUnit, translator ); -
src/GenPoly/Box.cc
r275f4b4 rcd7ef0b 27 27 #include "Box.h" 28 28 #include "DeclMutator.h" 29 #include "Lvalue.h" 30 #include "FindFunction.h" 29 31 #include "PolyMutator.h" 30 #include "FindFunction.h"31 32 #include "ScopedSet.h" 32 33 #include "ScrubTyVars.h" … … 755 756 756 757 void Pass1::boxParam( Type *param, Expression *&arg, const TyVarMap &exprTyVars ) { 757 assert ( arg->has_result() );758 assertf( arg->has_result(), "arg does not have result: %s", toString( arg ).c_str() ); 758 759 if ( isPolyType( param, exprTyVars ) ) { 759 if ( isPolyType( arg->get_result() ) ) { 760 Type * newType = arg->get_result()->clone(); 761 if ( env ) env->apply( newType ); 762 std::auto_ptr<Type> manager( newType ); 763 if ( isPolyType( newType ) ) { 760 764 // if the argument's type is polymorphic, we don't need to box again! 761 765 return; 762 766 } else if ( arg->get_result()->get_lvalue() ) { 763 // VariableExpr and MemberExpr are lvalues; need to check this isn't coming from the second arg of a comma expression though (not an lvalue) 764 // xxx - need to test that this code is still reachable 765 if ( CommaExpr *commaArg = dynamic_cast< CommaExpr* >( arg ) ) { 766 commaArg->set_arg2( new AddressExpr( commaArg->get_arg2() ) ); 767 } else { 768 arg = new AddressExpr( arg ); 769 } 767 // argument expression may be CFA lvalue, but not C lvalue -- apply generalizedLvalue transformations. 768 arg = generalizedLvalue( new AddressExpr( arg ) ); 770 769 if ( ! ResolvExpr::typesCompatible( param, arg->get_result(), SymTab::Indexer() ) ) { 771 770 // silence warnings by casting boxed parameters when the actual type does not match up with the formal type. … … 1879 1878 return structDecl; 1880 1879 } 1881 1880 1882 1881 Declaration *Pass3::mutate( UnionDecl *unionDecl ) { 1883 1882 stripGenericMembers( unionDecl ); -
src/GenPoly/Lvalue.cc
r275f4b4 rcd7ef0b 27 27 #include "SynTree/Mutator.h" 28 28 #include "SymTab/Indexer.h" 29 29 30 #include "ResolvExpr/Resolver.h" 31 #include "ResolvExpr/TypeEnvironment.h" 30 32 #include "ResolvExpr/typeops.h" 33 #include "ResolvExpr/Unify.h" 31 34 32 35 #include "Common/UniqueName.h" … … 60 63 typedef Mutator Parent; 61 64 65 virtual Expression * mutate( MemberExpr * memExpr ); 62 66 virtual Expression * mutate( AddressExpr * addressExpr ); 67 68 template<typename Func> 69 Expression * applyTransformation( Expression * expr, Expression * arg, Func mkExpr ); 63 70 }; 64 71 } // namespace … … 71 78 acceptAll( translationUnit, p2 ); 72 79 mutateAll( translationUnit, genLval ); 80 } 81 82 Expression * generalizedLvalue( Expression * expr ) { 83 GeneralizedLvalue genLval; 84 return expr->acceptMutator( genLval ); 73 85 } 74 86 … … 163 175 } 164 176 165 Expression * GeneralizedLvalue::mutate( AddressExpr * addrExpr ) {166 addrExpr = safe_dynamic_cast< AddressExpr * >( Parent::mutate( addrExpr ) );167 if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( a ddrExpr->get_arg()) ) {177 template<typename Func> 178 Expression * GeneralizedLvalue::applyTransformation( Expression * expr, Expression * arg, Func mkExpr ) { 179 if ( CommaExpr * commaExpr = dynamic_cast< CommaExpr * >( arg ) ) { 168 180 Expression * arg1 = commaExpr->get_arg1()->clone(); 169 181 Expression * arg2 = commaExpr->get_arg2()->clone(); 170 delete addrExpr; 171 return new CommaExpr( arg1, new AddressExpr( arg2 ) ); 172 } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( addrExpr->get_arg() ) ) { 182 Expression * ret = new CommaExpr( arg1, mkExpr( arg2 ) ); 183 ret->set_env( expr->get_env() ); 184 expr->set_env( nullptr ); 185 delete expr; 186 return ret->acceptMutator( *this ); 187 } else if ( ConditionalExpr * condExpr = dynamic_cast< ConditionalExpr * >( arg ) ) { 173 188 Expression * arg1 = condExpr->get_arg1()->clone(); 174 189 Expression * arg2 = condExpr->get_arg2()->clone(); 175 190 Expression * arg3 = condExpr->get_arg3()->clone(); 176 delete addrExpr; 177 return new ConditionalExpr( arg1, new AddressExpr( arg2 ), new AddressExpr( arg3 ) ); 191 ConditionalExpr * ret = new ConditionalExpr( arg1, mkExpr( arg2 ), mkExpr( arg3 ) ); 192 ret->set_env( expr->get_env() ); 193 expr->set_env( nullptr ); 194 delete expr; 195 196 // conditional expr type may not be either of the argument types, need to unify 197 using namespace ResolvExpr; 198 Type* commonType = nullptr; 199 TypeEnvironment newEnv; 200 AssertionSet needAssertions, haveAssertions; 201 OpenVarSet openVars; 202 unify( ret->get_arg2()->get_result(), ret->get_arg3()->get_result(), newEnv, needAssertions, haveAssertions, openVars, SymTab::Indexer(), commonType ); 203 ret->set_result( commonType ? commonType : ret->get_arg2()->get_result()->clone() ); 204 return ret->acceptMutator( *this ); 178 205 } 179 return addrExpr; 206 return expr; 207 } 208 209 Expression * GeneralizedLvalue::mutate( MemberExpr * memExpr ) { 210 Parent::mutate( memExpr ); 211 return applyTransformation( memExpr, memExpr->get_aggregate(), [=]( Expression * aggr ) { return new MemberExpr( memExpr->get_member(), aggr ); } ); 212 } 213 214 Expression * GeneralizedLvalue::mutate( AddressExpr * addrExpr ) { 215 addrExpr = safe_dynamic_cast< AddressExpr * >( Parent::mutate( addrExpr ) ); 216 return applyTransformation( addrExpr, addrExpr->get_arg(), []( Expression * arg ) { return new AddressExpr( arg ); } ); 180 217 } 181 218 } // namespace -
src/GenPoly/Lvalue.h
r275f4b4 rcd7ef0b 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Lvalue.h -- 7 // Lvalue.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 23 23 /// replaces return type of `lvalue T` with `T*`, along with appropriate address-of and dereference operators 24 24 void convertLvalue( std::list< Declaration* >& translationUnit ); 25 26 /// applies transformations that allow GCC to accept more complicated lvalue expressions, e.g. &(a, b) 27 Expression * generalizedLvalue( Expression * expr ); 25 28 } // namespace GenPoly 26 29 -
src/Makefile.am
r275f4b4 rcd7ef0b 43 43 cfa_cpplib_PROGRAMS = driver/cfa-cpp 44 44 driver_cfa_cpp_SOURCES = ${SRC} 45 driver_cfa_cpp_LDADD = ${LEXLIB}-ldl # yywrap45 driver_cfa_cpp_LDADD = -ldl # yywrap 46 46 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -Wextra -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14 47 47 driver_cfa_cpp_LDFLAGS = -Xlinker -export-dynamic -
src/Makefile.in
r275f4b4 rcd7ef0b 262 262 am_driver_cfa_cpp_OBJECTS = $(am__objects_1) 263 263 driver_cfa_cpp_OBJECTS = $(am_driver_cfa_cpp_OBJECTS) 264 am__DEPENDENCIES_1 = 265 driver_cfa_cpp_DEPENDENCIES = $(am__DEPENDENCIES_1) 264 driver_cfa_cpp_DEPENDENCIES = 266 265 driver_cfa_cpp_LINK = $(CXXLD) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) \ 267 266 $(driver_cfa_cpp_LDFLAGS) $(LDFLAGS) -o $@ … … 548 547 cfa_cpplibdir = ${CFA_LIBDIR} 549 548 driver_cfa_cpp_SOURCES = ${SRC} 550 driver_cfa_cpp_LDADD = ${LEXLIB}-ldl # yywrap549 driver_cfa_cpp_LDADD = -ldl # yywrap 551 550 driver_cfa_cpp_CXXFLAGS = -Wno-deprecated -Wall -Wextra -DDEBUG_ALL -I${abs_top_srcdir}/src/include -DYY_NO_INPUT -O2 -g -std=c++14 552 551 driver_cfa_cpp_LDFLAGS = -Xlinker -export-dynamic -
src/Parser/ExpressionNode.cc
r275f4b4 rcd7ef0b 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Jul 25 10:11:00 2017 13 // Update Count : 551 14 // 15 16 #include <cassert> 17 #include <cctype> 18 #include <climits> 19 #include <cstdio> 20 #include <algorithm> 12 // Last Modified On : Wed Aug 2 11:12:00 2017 13 // Update Count : 568 14 // 15 16 #include <climits> // access INT_MAX, UINT_MAX, LONG_MAX, ULONG_MAX, LLONG_MAX 21 17 #include <sstream> 22 18 … … 26 22 #include "SynTree/Expression.h" 27 23 #include "SynTree/Declaration.h" 28 #include "Common/UnimplementedError.h"29 24 #include "parserutility.h" 30 #include "Common/utility.h"31 25 32 26 using namespace std; … … 46 40 // type. 47 41 48 Type::Qualifiers noQualifiers;// no qualifiers on constants42 extern const Type::Qualifiers noQualifiers; // no qualifiers on constants 49 43 50 44 static inline bool checkU( char c ) { return c == 'u' || c == 'U'; } … … 55 49 static inline bool checkX( char c ) { return c == 'x' || c == 'X'; } 56 50 57 Expression * build_constantInteger( const std::string & str ) {51 Expression * build_constantInteger( const std::string & str ) { 58 52 static const BasicType::Kind kind[2][3] = { 59 53 { BasicType::SignedInt, BasicType::LongSignedInt, BasicType::LongLongSignedInt }, … … 62 56 bool dec = true, Unsigned = false; // decimal, unsigned constant 63 57 int size; // 0 => int, 1 => long, 2 => long long 64 unsigned long long int v; 58 unsigned long long int v; // converted integral value 65 59 size_t last = str.length() - 1; // last character of constant 66 60 Expression * ret; 61 62 // special constants 63 if ( str == "0" ) { 64 ret = new ConstantExpr( Constant( (Type *)new ZeroType( noQualifiers ), str, (unsigned long long int)0 ) ); 65 goto CLEANUP; 66 } // if 67 if ( str == "1" ) { 68 ret = new ConstantExpr( Constant( (Type *)new OneType( noQualifiers ), str, (unsigned long long int)1 ) ); 69 goto CLEANUP; 70 } // if 71 67 72 if ( str[0] == '0' ) { // octal/hex constant ? 68 73 dec = false; … … 118 123 } // if 119 124 120 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) ); 125 ret = new ConstantExpr( Constant( new BasicType( noQualifiers, kind[Unsigned][size] ), str, v ) ); 126 CLEANUP: 121 127 delete &str; // created by lex 122 128 return ret; 123 129 } // build_constantInteger 124 130 125 Expression * build_constantFloat( const std::string & str ) {131 Expression * build_constantFloat( const std::string & str ) { 126 132 static const BasicType::Kind kind[2][3] = { 127 133 { BasicType::Float, BasicType::Double, BasicType::LongDouble }, … … 158 164 } // build_constantFloat 159 165 160 Expression * build_constantChar( const std::string & str ) {166 Expression * build_constantChar( const std::string & str ) { 161 167 Expression * ret = new ConstantExpr( Constant( new BasicType( noQualifiers, BasicType::Char ), str, (unsigned long long int)(unsigned char)str[1] ) ); 162 168 delete &str; // created by lex … … 164 170 } // build_constantChar 165 171 166 ConstantExpr * build_constantStr( const std::string & str ) {172 ConstantExpr * build_constantStr( const std::string & str ) { 167 173 // string should probably be a primitive type 168 ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ),169 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), 174 ArrayType * at = new ArrayType( noQualifiers, new BasicType( Type::Qualifiers( Type::Const ), BasicType::Char ), 175 new ConstantExpr( Constant::from_ulong( str.size() + 1 - 2 ) ), // +1 for '\0' and -2 for '"' 170 176 false, false ); 171 // constant 0 is ignored for pure string value 172 ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); 177 ConstantExpr * ret = new ConstantExpr( Constant( at, str, (unsigned long long int)0 ) ); // constant 0 is ignored for pure string value 173 178 delete &str; // created by lex 174 179 return ret; 175 180 } // build_constantStr 176 177 Expression *build_constantZeroOne( const std::string & str ) {178 Expression * ret = new ConstantExpr( Constant( str == "0" ? (Type *)new ZeroType( noQualifiers ) : (Type*)new OneType( noQualifiers ), str,179 str == "0" ? (unsigned long long int)0 : (unsigned long long int)1 ) );180 delete &str; // created by lex181 return ret;182 } // build_constantChar183 181 184 182 Expression * build_field_name_FLOATINGconstant( const std::string & str ) { … … 209 207 } // build_field_name_fraction_constants 210 208 211 212 213 209 Expression * build_field_name_REALFRACTIONconstant( const std::string & str ) { 214 210 if ( str.find_first_not_of( "0123456789", 1 ) != string::npos ) throw SemanticError( "invalid tuple index " + str ); … … 225 221 } // build_field_name_REALDECIMALconstant 226 222 227 NameExpr * build_varref( const string * name ) {228 NameExpr * expr = new NameExpr( *name, nullptr );223 NameExpr * build_varref( const string * name ) { 224 NameExpr * expr = new NameExpr( *name, nullptr ); 229 225 delete name; 230 226 return expr; 231 } 232 233 // Must harmonize with OperKinds. 234 static const char * OperName[] = {227 } // build_varref 228 229 230 static const char * OperName[] = { // must harmonize with OperKinds 235 231 // diadic 236 232 "SizeOf", "AlignOf", "OffsetOf", "?+?", "?-?", "?\\?", "?*?", "?/?", "?%?", "||", "&&", … … 240 236 // monadic 241 237 "+?", "-?", "AddressOf", "*?", "!?", "~?", "++?", "?++", "--?", "?--", "&&" 242 }; 243 244 Expression * build_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) {245 Type * targetType = maybeMoveBuildType( decl_node );238 }; // OperName 239 240 Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) { 241 Type * targetType = maybeMoveBuildType( decl_node ); 246 242 if ( dynamic_cast< VoidType * >( targetType ) ) { 247 243 delete targetType; … … 250 246 return new CastExpr( maybeMoveBuild< Expression >(expr_node), targetType ); 251 247 } // if 252 } 253 254 255 Expression *build_virtual_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) { 256 Type *targetType = maybeMoveBuildType( decl_node ); 257 Expression *castArg = maybeMoveBuild< Expression >( expr_node ); 248 } // build_cast 249 250 Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ) { 251 Type * targetType = maybeMoveBuildType( decl_node ); 252 Expression * castArg = maybeMoveBuild< Expression >( expr_node ); 258 253 return new VirtualCastExpr( castArg, targetType ); 259 } 260 261 Expression * build_fieldSel( ExpressionNode *expr_node, Expression *member ) {262 UntypedMemberExpr * ret = new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) );263 return ret; 264 } 265 266 Expression * build_pfieldSel( ExpressionNode *expr_node, Expression *member ) {267 UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) );254 } // build_virtual_cast 255 256 Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ) { 257 UntypedMemberExpr * ret = new UntypedMemberExpr( member, maybeMoveBuild< Expression >(expr_node) ); 258 return ret; 259 } // build_fieldSel 260 261 Expression * build_pfieldSel( ExpressionNode * expr_node, Expression * member ) { 262 UntypedExpr * deref = new UntypedExpr( new NameExpr( "*?" ) ); 268 263 deref->location = expr_node->location; 269 264 deref->get_args().push_back( maybeMoveBuild< Expression >(expr_node) ); 270 UntypedMemberExpr * ret = new UntypedMemberExpr( member, deref );271 return ret; 272 } 273 274 Expression * build_addressOf( ExpressionNode *expr_node ) {265 UntypedMemberExpr * ret = new UntypedMemberExpr( member, deref ); 266 return ret; 267 } // build_pfieldSel 268 269 Expression * build_addressOf( ExpressionNode * expr_node ) { 275 270 return new AddressExpr( maybeMoveBuild< Expression >(expr_node) ); 276 } 277 Expression *build_sizeOfexpr( ExpressionNode *expr_node ) { 271 } // build_addressOf 272 273 Expression * build_sizeOfexpr( ExpressionNode * expr_node ) { 278 274 return new SizeofExpr( maybeMoveBuild< Expression >(expr_node) ); 279 } 280 Expression *build_sizeOftype( DeclarationNode *decl_node ) { 275 } // build_sizeOfexpr 276 277 Expression * build_sizeOftype( DeclarationNode * decl_node ) { 281 278 return new SizeofExpr( maybeMoveBuildType( decl_node ) ); 282 } 283 Expression *build_alignOfexpr( ExpressionNode *expr_node ) { 279 } // build_sizeOftype 280 281 Expression * build_alignOfexpr( ExpressionNode * expr_node ) { 284 282 return new AlignofExpr( maybeMoveBuild< Expression >(expr_node) ); 285 } 286 Expression *build_alignOftype( DeclarationNode *decl_node ) { 283 } // build_alignOfexpr 284 285 Expression * build_alignOftype( DeclarationNode * decl_node ) { 287 286 return new AlignofExpr( maybeMoveBuildType( decl_node) ); 288 } 289 Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member ) { 287 } // build_alignOftype 288 289 Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member ) { 290 290 Expression * ret = new UntypedOffsetofExpr( maybeMoveBuildType( decl_node ), member->get_name() ); 291 291 delete member; 292 292 return ret; 293 } 294 295 Expression * build_and_or( ExpressionNode *expr_node1, ExpressionNode *expr_node2, bool kind ) {293 } // build_offsetOf 294 295 Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode * expr_node2, bool kind ) { 296 296 return new LogicalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), notZeroExpr( maybeMoveBuild< Expression >(expr_node2) ), kind ); 297 } 298 299 Expression * build_unary_val( OperKinds op, ExpressionNode *expr_node ) {297 } // build_and_or 298 299 Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node ) { 300 300 std::list< Expression * > args; 301 301 args.push_back( maybeMoveBuild< Expression >(expr_node) ); 302 302 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 303 } 304 Expression *build_unary_ptr( OperKinds op, ExpressionNode *expr_node ) { 303 } // build_unary_val 304 305 Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node ) { 305 306 std::list< Expression * > args; 306 307 args.push_back( new AddressExpr( maybeMoveBuild< Expression >(expr_node) ) ); 307 308 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 308 } 309 Expression *build_binary_val( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 309 } // build_unary_ptr 310 311 Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) { 310 312 std::list< Expression * > args; 311 313 args.push_back( maybeMoveBuild< Expression >(expr_node1) ); 312 314 args.push_back( maybeMoveBuild< Expression >(expr_node2) ); 313 315 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 314 } 315 Expression *build_binary_ptr( OperKinds op, ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) { 316 } // build_binary_val 317 318 Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) { 316 319 std::list< Expression * > args; 317 320 args.push_back( new AddressExpr( maybeMoveBuild< Expression >(expr_node1) ) ); 318 321 args.push_back( maybeMoveBuild< Expression >(expr_node2) ); 319 322 return new UntypedExpr( new NameExpr( OperName[ (int)op ] ), args ); 320 } 321 322 Expression * build_cond( ExpressionNode *expr_node1, ExpressionNode *expr_node2, ExpressionNode *expr_node3 ) {323 } // build_binary_ptr 324 325 Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 ) { 323 326 return new ConditionalExpr( notZeroExpr( maybeMoveBuild< Expression >(expr_node1) ), maybeMoveBuild< Expression >(expr_node2), maybeMoveBuild< Expression >(expr_node3) ); 324 } 325 326 Expression * build_comma( ExpressionNode *expr_node1, ExpressionNode *expr_node2 ) {327 } // build_cond 328 329 Expression * build_comma( ExpressionNode * expr_node1, ExpressionNode * expr_node2 ) { 327 330 return new CommaExpr( maybeMoveBuild< Expression >(expr_node1), maybeMoveBuild< Expression >(expr_node2) ); 328 } 329 330 Expression * build_attrexpr( NameExpr *var, ExpressionNode * expr_node ) {331 } // build_comma 332 333 Expression * build_attrexpr( NameExpr * var, ExpressionNode * expr_node ) { 331 334 return new AttrExpr( var, maybeMoveBuild< Expression >(expr_node) ); 332 } 333 Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ) { 335 } // build_attrexpr 336 337 Expression * build_attrtype( NameExpr * var, DeclarationNode * decl_node ) { 334 338 return new AttrExpr( var, maybeMoveBuildType( decl_node ) ); 335 } 336 337 Expression * build_tuple( ExpressionNode * expr_node ) {339 } // build_attrtype 340 341 Expression * build_tuple( ExpressionNode * expr_node ) { 338 342 std::list< Expression * > exprs; 339 343 buildMoveList( expr_node, exprs ); 340 344 return new UntypedTupleExpr( exprs );; 341 } 342 343 Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ) {345 } // build_tuple 346 347 Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node ) { 344 348 std::list< Expression * > args; 345 349 buildMoveList( expr_node, args ); 346 350 return new UntypedExpr( maybeMoveBuild< Expression >(function), args, nullptr ); 347 } 348 349 Expression * build_range( ExpressionNode * low, ExpressionNode *high ) {351 } // build_func 352 353 Expression * build_range( ExpressionNode * low, ExpressionNode * high ) { 350 354 return new RangeExpr( maybeMoveBuild< Expression >( low ), maybeMoveBuild< Expression >( high ) ); 351 } 352 353 Expression * build_asmexpr( ExpressionNode *inout, ConstantExpr *constraint, ExpressionNode *operand ) {355 } // build_range 356 357 Expression * build_asmexpr( ExpressionNode * inout, ConstantExpr * constraint, ExpressionNode * operand ) { 354 358 return new AsmExpr( maybeMoveBuild< Expression >( inout ), constraint, maybeMoveBuild< Expression >(operand) ); 355 } 356 357 Expression * build_valexpr( StatementNode *s ) {359 } // build_asmexpr 360 361 Expression * build_valexpr( StatementNode * s ) { 358 362 return new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(s) ) ); 359 } 360 Expression *build_typevalue( DeclarationNode *decl ) { 363 } // build_valexpr 364 365 Expression * build_typevalue( DeclarationNode * decl ) { 361 366 return new TypeExpr( maybeMoveBuildType( decl ) ); 362 } 363 364 Expression * build_compoundLiteral( DeclarationNode *decl_node, InitializerNode *kids ) {367 } // build_typevalue 368 369 Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids ) { 365 370 Declaration * newDecl = maybeBuild< Declaration >(decl_node); // compound literal type 366 371 if ( DeclarationWithType * newDeclWithType = dynamic_cast< DeclarationWithType * >( newDecl ) ) { // non-sue compound-literal type … … 388 393 assert( false ); 389 394 } // if 390 } 395 } // build_compoundLiteral 391 396 392 397 // Local Variables: // -
src/Parser/InitializerNode.cc
r275f4b4 rcd7ef0b 10 10 // Created On : Sat May 16 13:20:24 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Oct 1 23:09:51 201613 // Update Count : 2 112 // Last Modified On : Fri Jul 28 23:27:20 2017 13 // Update Count : 26 14 14 // 15 15 … … 22 22 #include "SynTree/Initializer.h" 23 23 24 InitializerNode::InitializerNode( ExpressionNode * _expr, bool aggrp, ExpressionNode *des )25 : expr( _expr ), aggregate( aggrp ), designator( des ), kids( 0), maybeConstructed( true ) {24 InitializerNode::InitializerNode( ExpressionNode * _expr, bool aggrp, ExpressionNode * des ) 25 : expr( _expr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) { 26 26 if ( aggrp ) 27 27 kids = dynamic_cast< InitializerNode * >( get_next() ); 28 28 29 if ( kids != 0)30 set_last( 0);31 } 29 if ( kids ) 30 set_last( nullptr ); 31 } // InitializerNode::InitializerNode 32 32 33 InitializerNode::InitializerNode( InitializerNode * init, bool aggrp, ExpressionNode *des )34 : expr( 0 ), aggregate( aggrp ), designator( des ), kids( 0), maybeConstructed( true ) {35 if ( init != 0)33 InitializerNode::InitializerNode( InitializerNode * init, bool aggrp, ExpressionNode * des ) 34 : expr( nullptr ), aggregate( aggrp ), designator( des ), kids( nullptr ), maybeConstructed( true ) { 35 if ( init ) 36 36 set_last( init ); 37 37 … … 39 39 kids = dynamic_cast< InitializerNode * >( get_next() ); 40 40 41 if ( kids != 0)42 set_next( 0);43 } 41 if ( kids ) 42 set_next( nullptr ); 43 } // InitializerNode::InitializerNode 44 44 45 45 InitializerNode::~InitializerNode() { … … 47 47 delete designator; 48 48 delete kids; 49 } 49 } // InitializerNode::~InitializerNode 50 50 51 51 void InitializerNode::print( std::ostream &os, int indent ) const { 52 52 os << std::string( indent, ' ' ) << "Initializer expression" << std::endl; 53 } 53 } // InitializerNode::print 54 54 55 55 void InitializerNode::printOneLine( std::ostream &os ) const { 56 56 if ( ! aggregate ) { 57 if ( designator != 0) {57 if ( designator ) { 58 58 os << "designated by: ("; 59 59 ExpressionNode *curdes = designator; 60 while ( curdes != 0) {60 while ( curdes != nullptr) { 61 61 curdes->printOneLine(os); 62 62 curdes = (ExpressionNode *)(curdes->get_next()); … … 65 65 os << ")"; 66 66 } // if 67 if ( expr ) expr->printOneLine( os);67 if ( expr ) expr->printOneLine( os ); 68 68 } else { // It's an aggregate 69 69 os << "[--"; 70 if ( next_init() != 0)71 next_init()->printOneLine( os);70 if ( next_init() != nullptr ) 71 next_init()->printOneLine( os ); 72 72 if (aggregate) os << "--]"; 73 73 } // if … … 76 76 if ( (moreInit = dynamic_cast< InitializerNode * >( get_next() ) ) ) { 77 77 moreInit->printOneLine( os ); 78 } 79 } 78 } // if 79 } // InitializerNode::printOneLine 80 80 81 Initializer * InitializerNode::build() const {81 Initializer * InitializerNode::build() const { 82 82 if ( aggregate ) { 83 83 // steal designators from children … … 93 93 return new ListInit( initlist, designlist, maybeConstructed ); 94 94 } else { 95 if ( get_expression() != 0) {95 if ( get_expression() ) { 96 96 return new SingleInit( maybeBuild< Expression >( get_expression() ), maybeConstructed ); 97 } 97 } // if 98 98 } // if 99 return 0;100 } 99 return nullptr; 100 } // InitializerNode::build 101 101 102 102 // Local Variables: // -
src/Parser/ParseNode.h
r275f4b4 rcd7ef0b 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:28:16 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : T us Jul 25 10:09:00201713 // Update Count : 78 711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 27 12:08:08 2017 13 // Update Count : 788 14 14 // 15 15 … … 159 159 Expression * build_constantFloat( const std::string &str ); 160 160 Expression * build_constantChar( const std::string &str ); 161 Expression * build_constantZeroOne( const std::string &str );162 161 ConstantExpr * build_constantStr( const std::string &str ); 163 162 Expression * build_field_name_FLOATINGconstant( const std::string & str ); -
src/Parser/TypeData.cc
r275f4b4 rcd7ef0b 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Jul 18 10:10:00 201713 // Update Count : 56 612 // Last Modified On : Wed Aug 9 13:50:00 2017 13 // Update Count : 567 14 14 // 15 15 … … 748 748 } // buildAggInst 749 749 750 NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, Type::StorageClasses scs ) {750 NamedTypeDecl * buildSymbolic( const TypeData * td, const string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage ) { 751 751 assert( td->kind == TypeData::Symbolic ); 752 752 NamedTypeDecl * ret; 753 753 assert( td->base ); 754 754 if ( td->symbolic.isTypedef ) { 755 ret = new TypedefDecl( name, scs, typebuild( td->base ) );755 ret = new TypedefDecl( name, scs, typebuild( td->base ), linkage ); 756 756 } else { 757 757 ret = new TypeDecl( name, scs, typebuild( td->base ), TypeDecl::Any ); … … 817 817 return buildEnum( td, attributes ); 818 818 } else if ( td->kind == TypeData::Symbolic ) { 819 return buildSymbolic( td, name, scs );819 return buildSymbolic( td, name, scs, linkage ); 820 820 } else { 821 821 return (new ObjectDecl( name, scs, linkage, bitfieldWidth, typebuild( td ), init, attributes ))->set_asmName( asmName ); -
src/Parser/lex.ll
r275f4b4 rcd7ef0b 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : Mon Jul 24 08:27:23201713 * Update Count : 5 4512 * Last Modified On : Thu Jul 27 21:46:06 2017 13 * Update Count : 550 14 14 */ 15 15 16 16 %option yylineno 17 %option noyywrap 17 18 %option nounput 18 19 … … 288 289 289 290 /* numeric constants */ 290 "0" { NUMERIC_RETURN(ZERO); } // CFA291 "1" { NUMERIC_RETURN(ONE); } // CFA292 291 {decimal_constant} { NUMERIC_RETURN(INTEGERconstant); } 293 292 {octal_constant} { NUMERIC_RETURN(INTEGERconstant); } … … 420 419 421 420 /* unknown characters */ 422 . { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); }421 . { printf("unknown character(s):\"%s\" on line %d\n", yytext, yylineno); } 423 422 424 423 %% -
src/Parser/parser.yy
r275f4b4 rcd7ef0b 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Jul 25 10:07:00 201713 // Update Count : 24 6412 // Last Modified On : Wed Aug 4 13:33:00 2017 13 // Update Count : 2475 14 14 // 15 15 … … 142 142 // converted into the tuple index (.)(1). e.g., 3.x 143 143 %token<tok> REALDECIMALconstant REALFRACTIONconstant FLOATINGconstant 144 %token<tok> ZERO ONE // CFA145 144 146 145 // multi-character operators … … 159 158 %token ATassign // @= 160 159 161 %type<tok> identifier no_attr_identifier zero_one160 %type<tok> identifier no_attr_identifier 162 161 %type<tok> identifier_or_type_name no_attr_identifier_or_type_name attr_name 163 162 %type<constant> string_literal … … 183 182 %type<en> asm_clobbers_list_opt 184 183 %type<flag> asm_volatile_opt 184 %type<en> handler_predicate_opt 185 185 186 186 // statements … … 360 360 ; 361 361 362 zero_one: // CFA363 ZERO364 | ONE365 ;366 367 362 string_literal: 368 363 string_literal_list { $$ = build_constantStr( *$1 ); } … … 384 379 IDENTIFIER // typedef name cannot be used as a variable name 385 380 { $$ = new ExpressionNode( build_varref( $1 ) ); } 386 | zero_one387 { $$ = new ExpressionNode( build_constantZeroOne( *$1 ) ); }388 381 | tuple 389 382 | '(' comma_expression ')' … … 485 478 $$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) ); 486 479 } 487 | zero_one fraction_constants488 {489 $$ = new ExpressionNode( build_field_name_fraction_constants( build_constantZeroOne( *$1 ), $2 ) );490 }491 480 ; 492 481 … … 539 528 | ALIGNOF unary_expression // GCC, variable alignment 540 529 { $$ = new ExpressionNode( build_alignOfexpr( $2 ) ); } 541 | ALIGNOF '(' type_no_function ')' // GCC, type alignment530 | ALIGNOF '(' type_no_function ')' // GCC, type alignment 542 531 { $$ = new ExpressionNode( build_alignOftype( $3 ) ); } 543 532 | OFFSETOF '(' type_no_function ',' no_attr_identifier ')' … … 980 969 981 970 handler_clause: 982 // TEMPORARY, TEST EXCEPTIONS 983 handler_key '(' push push INTEGERconstant pop ')' compound_statement pop 984 { $$ = new StatementNode( build_catch( $1, nullptr, new ExpressionNode( build_constantInteger( *$5 ) ), $8 ) ); } 985 | handler_clause handler_key '(' push push INTEGERconstant pop ')' compound_statement pop 986 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, nullptr, new ExpressionNode( build_constantInteger( *$6 ) ), $9 ) ) ); } 987 988 | handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop 989 { $$ = new StatementNode( build_catch( $1, $5, nullptr, $9 ) ); } 971 handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop 972 { $$ = new StatementNode( build_catch( $1, $5, $7, $9 ) ); } 990 973 | handler_clause handler_key '(' push push exception_declaration pop handler_predicate_opt ')' compound_statement pop 991 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, nullptr, $10 ) ) ); }974 { $$ = (StatementNode *)$1->set_last( new StatementNode( build_catch( $2, $6, $8, $10 ) ) ); } 992 975 ; 993 976 994 977 handler_predicate_opt: 995 978 //empty 979 { $$ = nullptr; } 996 980 | ';' conditional_expression 981 { $$ = $2; } 997 982 ; 998 983 … … 1686 1671 | aggregate_key attribute_list_opt typegen_name // CFA 1687 1672 { $$ = $3->addQualifiers( $2 ); } 1688 1689 // Temp, testing TreeStruct1690 | STRUCT TRY attribute_list_opt no_attr_identifier_or_type_name1691 {1692 typedefTable.makeTypedef( *$4 ); // create typedef1693 if ( forall ) typedefTable.changeKind( *$4, TypedefTable::TG ); // $1694 forall = false; // reset1695 }1696 '{' field_declaration_list '}'1697 {1698 $$ = DeclarationNode::newTreeStruct( DeclarationNode::Struct,1699 $4, nullptr, nullptr, $7, true )->addQualifiers( $3 );1700 }1701 | STRUCT TRY attribute_list_opt no_attr_identifier_or_type_name TYPEDEFname1702 {1703 typedefTable.makeTypedef( *$4 ); // create typedef1704 if ( forall ) typedefTable.changeKind( *$4, TypedefTable::TG ); // $1705 forall = false; // reset1706 }1707 '{' field_declaration_list '}'1708 {1709 $$ = DeclarationNode::newTreeStruct( DeclarationNode::Struct,1710 $4, $5, nullptr, $8, true )->addQualifiers( $3 );1711 }1712 1673 ; 1713 1674 … … 1969 1930 | '=' initializer 1970 1931 { $$ = $2; } 1932 | '=' VOID 1933 { $$ = nullptr; } 1971 1934 | ATassign initializer 1972 1935 { $$ = $2->set_maybeConstructed( false ); } -
src/ResolvExpr/CurrentObject.cc
r275f4b4 rcd7ef0b 36 36 return constExpr->get_constant()->get_ival(); 37 37 } else { 38 assertf( false, "Non-integer constant expression in getConstValue ", toString( constExpr ).c_str() ); // xxx - might be semantic error38 assertf( false, "Non-integer constant expression in getConstValue %s", toString( constExpr ).c_str() ); // xxx - might be semantic error 39 39 } 40 40 } else if ( dynamic_cast< OneType * >( constExpr->get_result() ) ) { … … 176 176 setPosition( castExpr->get_arg() ); 177 177 } else if ( VariableExpr * varExpr = dynamic_cast< VariableExpr * >( expr ) ) { 178 assertf( dynamic_cast<EnumInstType *> ( varExpr->get_result() ), "ArrayIterator given variable that isn't an enum constant ", toString( expr ).c_str() );178 assertf( dynamic_cast<EnumInstType *> ( varExpr->get_result() ), "ArrayIterator given variable that isn't an enum constant : %s", toString( expr ).c_str() ); 179 179 index = 0; // xxx - get actual value of enum constant 180 180 } else if ( dynamic_cast< SizeofExpr * >( expr ) || dynamic_cast< AlignofExpr * >( expr ) ) { … … 518 518 curTypes = newTypes; 519 519 newTypes.clear(); 520 assertf( desigAlts.size() == curTypes.size(), "Designator alternatives (% d) and current types (%d) out of sync", desigAlts.size(), curTypes.size() );520 assertf( desigAlts.size() == curTypes.size(), "Designator alternatives (%zu) and current types (%zu) out of sync", desigAlts.size(), curTypes.size() ); 521 521 } // for 522 522 if ( desigAlts.size() > 1 ) { -
src/ResolvExpr/Resolver.cc
r275f4b4 rcd7ef0b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:17:01 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : T hu Mar 23 17:23:14201713 // Update Count : 21 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Aug 8 16:06:00 2017 13 // Update Count : 212 14 14 // 15 15 … … 71 71 virtual void visit( ReturnStmt *returnStmt ) override; 72 72 virtual void visit( ThrowStmt *throwStmt ) override; 73 virtual void visit( CatchStmt *catchStmt ) override; 73 74 74 75 virtual void visit( SingleInit *singleInit ) override; … … 368 369 369 370 void Resolver::visit( ThrowStmt *throwStmt ) { 371 // TODO: Replace *exception type with &exception type. 370 372 if ( throwStmt->get_expr() ) { 371 Expression * wrapped = new CastExpr( throwStmt->get_expr(), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 373 StructDecl * exception_decl = 374 lookupStruct( "__cfaehm__base_exception_t" ); 375 assert( exception_decl ); 376 Expression * wrapped = new CastExpr( 377 throwStmt->get_expr(), 378 new PointerType( 379 noQualifiers, 380 new StructInstType( 381 noQualifiers, 382 exception_decl 383 ) 384 ) 385 ); 372 386 Expression * newExpr = findSingleExpression( wrapped, *this ); 373 387 throwStmt->set_expr( newExpr ); 388 } 389 } 390 391 void Resolver::visit( CatchStmt *catchStmt ) { 392 if ( catchStmt->get_cond() ) { 393 Expression * wrapped = new CastExpr( 394 catchStmt->get_cond(), 395 new BasicType( noQualifiers, BasicType::Bool ) 396 ); 397 catchStmt->set_cond( findSingleExpression( wrapped, *this ) ); 374 398 } 375 399 } -
src/SymTab/Validate.cc
r275f4b4 rcd7ef0b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:50:04 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : T hu Mar 30 16:50:13201713 // Update Count : 35 711 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Aug 8 13:27:00 2017 13 // Update Count : 358 14 14 // 15 15 … … 686 686 Type *designatorType = tyDecl->get_base()->stripDeclarator(); 687 687 if ( StructInstType *aggDecl = dynamic_cast< StructInstType * >( designatorType ) ) { 688 return new StructDecl( aggDecl->get_name() );688 return new StructDecl( aggDecl->get_name(), DeclarationNode::Struct, noAttributes, tyDecl->get_linkage() ); 689 689 } else if ( UnionInstType *aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) { 690 return new UnionDecl( aggDecl->get_name() );690 return new UnionDecl( aggDecl->get_name(), noAttributes, tyDecl->get_linkage() ); 691 691 } else if ( EnumInstType *enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) { 692 return new EnumDecl( enumDecl->get_name() );692 return new EnumDecl( enumDecl->get_name(), noAttributes, tyDecl->get_linkage() ); 693 693 } else { 694 694 return ret->clone(); … … 783 783 type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() ); 784 784 } // if 785 TypedefDeclPtr tyDecl( new TypedefDecl( aggDecl->get_name(), Type::StorageClasses(), type ) );785 TypedefDeclPtr tyDecl( new TypedefDecl( aggDecl->get_name(), Type::StorageClasses(), type, aggDecl->get_linkage() ) ); 786 786 typedefNames[ aggDecl->get_name() ] = std::make_pair( std::move( tyDecl ), scopeLevel ); 787 787 } // if … … 903 903 FunctionType * ftype = functionDecl->get_functionType(); 904 904 std::list< DeclarationWithType * > & retVals = ftype->get_returnVals(); 905 assertf( retVals.size() == 0 || retVals.size() == 1, "Function %s has too many return values: % d", functionDecl->get_name().c_str(), retVals.size() );905 assertf( retVals.size() == 0 || retVals.size() == 1, "Function %s has too many return values: %zu", functionDecl->get_name().c_str(), retVals.size() ); 906 906 if ( retVals.size() == 1 ) { 907 907 // ensure all function return values have a name - use the name of the function to disambiguate (this also provides a nice bit of help for debugging). -
src/SynTree/AggregateDecl.cc
r275f4b4 rcd7ef0b 10 10 // Created On : Sun May 17 23:56:39 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tus Jun 27 15:30:00 201713 // Update Count : 2 112 // Last Modified On : Fri Aug 4 14:22:00 2017 13 // Update Count : 22 14 14 // 15 15 … … 40 40 using std::endl; 41 41 42 os << typeString() << " " << get_name(); 43 os << string( indent+2, ' ' ) << "with body " << has_body() << endl; 42 os << typeString() << " " << get_name() << ":"; 43 if ( get_linkage() != LinkageSpec::Cforall ) { 44 os << " " << LinkageSpec::linkageName( get_linkage() ); 45 } // if 46 os << " with body " << has_body() << endl; 44 47 45 48 if ( ! parameters.empty() ) { -
src/SynTree/Declaration.cc
r275f4b4 rcd7ef0b 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 Mar 16 07:49:18201713 // Update Count : 2 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Aug 9 14:38:00 2017 13 // Update Count : 25 14 14 // 15 15 … … 28 28 29 29 Declaration::Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage ) 30 : name( name ), storageClasses( scs ), linkage( linkage), uniqueId( 0 ) {30 : name( name ), linkage( linkage ), storageClasses( scs ), uniqueId( 0 ) { 31 31 } 32 32 33 33 Declaration::Declaration( const Declaration &other ) 34 : BaseSyntaxNode( other ), name( other.name ), storageClasses( other.storageClasses ), linkage( other.linkage), uniqueId( other.uniqueId ) {34 : BaseSyntaxNode( other ), name( other.name ), linkage( other.linkage ), extension( other.extension ), storageClasses( other.storageClasses ), uniqueId( other.uniqueId ) { 35 35 } 36 36 -
src/SynTree/Declaration.h
r275f4b4 rcd7ef0b 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 : Sat Jul 22 09:52:59201713 // Update Count : 12 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Aug 9 14:45:00 2017 13 // Update Count : 126 14 14 // 15 15 … … 27 27 class Declaration : public BaseSyntaxNode { 28 28 public: 29 std::string name; 30 LinkageSpec::Spec linkage; 31 bool extension = false; 32 29 33 Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage ); 30 34 Declaration( const Declaration &other ); … … 53 57 static void dumpIds( std::ostream &os ); 54 58 static Declaration *declFromId( UniqueId id ); 55 private: 56 std::string name; 59 60 private: 57 61 Type::StorageClasses storageClasses; 58 LinkageSpec::Spec linkage;59 62 UniqueId uniqueId; 60 bool extension = false;61 63 }; 62 64 63 65 class DeclarationWithType : public Declaration { 64 66 public: 65 DeclarationWithType( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs );66 DeclarationWithType( const DeclarationWithType &other );67 virtual ~DeclarationWithType();68 69 std::string get_mangleName() const { return mangleName; }70 DeclarationWithType * set_mangleName( std::string newValue ) { mangleName = newValue; return this; }71 72 std::string get_scopedMangleName() const { return mangleName + "_" + std::to_string(scopeLevel); }73 74 int get_scopeLevel() const { return scopeLevel; }75 DeclarationWithType * set_scopeLevel( int newValue ) { scopeLevel = newValue; return this; }76 77 ConstantExpr *get_asmName() const { return asmName; }78 DeclarationWithType * set_asmName( ConstantExpr *newValue ) { asmName = newValue; return this; }79 80 std::list< Attribute * >& get_attributes() { return attributes; }81 const std::list< Attribute * >& get_attributes() const { return attributes; }82 83 Type::FuncSpecifiers get_funcSpec() const { return fs; }84 //void set_functionSpecifiers( Type::FuncSpecifiers newValue ) { fs = newValue; }85 86 virtual DeclarationWithType *clone() const = 0;87 virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0;88 89 virtual Type *get_type() const = 0;90 virtual void set_type(Type *) = 0;91 private:92 67 // this represents the type with all types and typedefs expanded it is generated by SymTab::Validate::Pass2 93 68 std::string mangleName; … … 97 72 ConstantExpr *asmName; 98 73 std::list< Attribute * > attributes; 74 75 DeclarationWithType( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs ); 76 DeclarationWithType( const DeclarationWithType &other ); 77 virtual ~DeclarationWithType(); 78 79 std::string get_mangleName() const { return mangleName; } 80 DeclarationWithType * set_mangleName( std::string newValue ) { mangleName = newValue; return this; } 81 82 std::string get_scopedMangleName() const { return mangleName + "_" + std::to_string(scopeLevel); } 83 84 int get_scopeLevel() const { return scopeLevel; } 85 DeclarationWithType * set_scopeLevel( int newValue ) { scopeLevel = newValue; return this; } 86 87 ConstantExpr *get_asmName() const { return asmName; } 88 DeclarationWithType * set_asmName( ConstantExpr *newValue ) { asmName = newValue; return this; } 89 90 std::list< Attribute * >& get_attributes() { return attributes; } 91 const std::list< Attribute * >& get_attributes() const { return attributes; } 92 93 Type::FuncSpecifiers get_funcSpec() const { return fs; } 94 //void set_functionSpecifiers( Type::FuncSpecifiers newValue ) { fs = newValue; } 95 96 virtual DeclarationWithType *clone() const = 0; 97 virtual DeclarationWithType *acceptMutator( Mutator &m ) = 0; 98 99 virtual Type *get_type() const = 0; 100 virtual void set_type(Type *) = 0; 101 102 private: 99 103 Type::FuncSpecifiers fs; 100 104 }; … … 103 107 typedef DeclarationWithType Parent; 104 108 public: 109 Type *type; 110 Initializer *init; 111 Expression *bitfieldWidth; 112 105 113 ObjectDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Expression *bitfieldWidth, Type *type, Initializer *init, 106 114 const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() ); … … 122 130 virtual void print( std::ostream &os, int indent = 0 ) const; 123 131 virtual void printShort( std::ostream &os, int indent = 0 ) const; 124 private:125 Type *type;126 Initializer *init;127 Expression *bitfieldWidth;128 132 }; 129 133 … … 131 135 typedef DeclarationWithType Parent; 132 136 public: 137 FunctionType *type; 138 CompoundStmt *statements; 139 133 140 FunctionDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements, 134 141 const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() ); … … 149 156 virtual void print( std::ostream &os, int indent = 0 ) const; 150 157 virtual void printShort( std::ostream &os, int indent = 0 ) const; 151 private:152 FunctionType *type;153 CompoundStmt *statements;154 158 }; 155 159 … … 157 161 typedef Declaration Parent; 158 162 public: 163 Type *base; 164 std::list< TypeDecl* > parameters; 165 std::list< DeclarationWithType* > assertions; 166 159 167 NamedTypeDecl( const std::string &name, Type::StorageClasses scs, Type *type ); 160 168 NamedTypeDecl( const NamedTypeDecl &other ); … … 171 179 virtual void print( std::ostream &os, int indent = 0 ) const; 172 180 virtual void printShort( std::ostream &os, int indent = 0 ) const; 173 protected:174 private:175 Type *base;176 std::list< TypeDecl* > parameters;177 std::list< DeclarationWithType* > assertions;178 181 }; 179 182 … … 182 185 public: 183 186 enum Kind { Any, Dtype, Ftype, Ttype }; 187 188 Type * init; 189 bool sized; 190 184 191 /// Data extracted from a type decl 185 192 struct Data { … … 216 223 private: 217 224 Kind kind; 218 Type * init;219 bool sized;220 225 }; 221 226 … … 223 228 typedef NamedTypeDecl Parent; 224 229 public: 225 TypedefDecl( const std::string &name, Type::StorageClasses scs, Type *type ) : Parent( name, scs, type ) {}230 TypedefDecl( const std::string &name, Type::StorageClasses scs, Type *type, LinkageSpec::Spec spec = LinkageSpec::Cforall ) : Parent( name, scs, type ) { set_linkage( spec ); } 226 231 TypedefDecl( const TypedefDecl &other ) : Parent( other ) {} 227 232 … … 237 242 typedef Declaration Parent; 238 243 public: 239 AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );240 AggregateDecl( const AggregateDecl &other );241 virtual ~AggregateDecl();242 243 std::list<Declaration*>& get_members() { return members; }244 std::list<TypeDecl*>& get_parameters() { return parameters; }245 246 std::list< Attribute * >& get_attributes() { return attributes; }247 const std::list< Attribute * >& get_attributes() const { return attributes; }248 249 bool has_body() const { return body; }250 AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }251 252 virtual void print( std::ostream &os, int indent = 0 ) const;253 virtual void printShort( std::ostream &os, int indent = 0 ) const;254 protected:255 virtual std::string typeString() const = 0;256 257 private:258 244 std::list<Declaration*> members; 259 245 std::list<TypeDecl*> parameters; 260 246 bool body; 261 247 std::list< Attribute * > attributes; 248 249 AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ); 250 AggregateDecl( const AggregateDecl &other ); 251 virtual ~AggregateDecl(); 252 253 std::list<Declaration*>& get_members() { return members; } 254 std::list<TypeDecl*>& get_parameters() { return parameters; } 255 256 std::list< Attribute * >& get_attributes() { return attributes; } 257 const std::list< Attribute * >& get_attributes() const { return attributes; } 258 259 bool has_body() const { return body; } 260 AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; } 261 262 virtual void print( std::ostream &os, int indent = 0 ) const; 263 virtual void printShort( std::ostream &os, int indent = 0 ) const; 264 protected: 265 virtual std::string typeString() const = 0; 262 266 }; 263 267 … … 333 337 class AsmDecl : public Declaration { 334 338 public: 339 AsmStmt *stmt; 340 335 341 AsmDecl( AsmStmt *stmt ); 336 342 AsmDecl( const AsmDecl &other ); … … 345 351 virtual void print( std::ostream &os, int indent = 0 ) const; 346 352 virtual void printShort( std::ostream &os, int indent = 0 ) const; 347 private:348 AsmStmt *stmt;349 353 }; 350 354 -
src/SynTree/Expression.h
r275f4b4 rcd7ef0b 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Jul 24 16:27:00 201713 // Update Count : 4 312 // Last Modified On : Fri Aug 8 11:54:00 2017 13 // Update Count : 44 14 14 // 15 15 … … 29 29 class Expression : public BaseSyntaxNode{ 30 30 public: 31 Type * result; 32 TypeSubstitution * env; 33 Expression * argName; // if expression is used as an argument, it can be "designated" by this name 34 bool extension = false; 35 31 36 Expression( Expression * _aname = nullptr ); 32 37 Expression( const Expression & other ); … … 49 54 virtual Expression * acceptMutator( Mutator & m ) = 0; 50 55 virtual void print( std::ostream & os, int indent = 0 ) const; 51 protected:52 Type * result;53 TypeSubstitution * env;54 Expression * argName; // if expression is used as an argument, it can be "designated" by this name55 bool extension = false;56 56 }; 57 57 … … 79 79 class ApplicationExpr : public Expression { 80 80 public: 81 Expression * function; 82 81 83 ApplicationExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >() ); 82 84 ApplicationExpr( const ApplicationExpr & other ); … … 92 94 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 93 95 virtual void print( std::ostream & os, int indent = 0 ) const; 96 94 97 private: 95 Expression * function;96 98 std::list<Expression *> args; 97 99 InferredParams inferParams; … … 103 105 class UntypedExpr : public Expression { 104 106 public: 107 Expression * function; 108 std::list<Expression*> args; 109 105 110 UntypedExpr( Expression * function, const std::list<Expression *> & args = std::list< Expression * >(), Expression *_aname = nullptr ); 106 111 UntypedExpr( const UntypedExpr & other ); … … 123 128 virtual void print( std::ostream & os, int indent = 0 ) const; 124 129 virtual void printArgs(std::ostream & os, int indent = 0) const; 125 private:126 Expression * function;127 std::list<Expression*> args;128 130 }; 129 131 … … 131 133 class NameExpr : public Expression { 132 134 public: 135 std::string name; 136 133 137 NameExpr( std::string name, Expression *_aname = nullptr ); 134 138 NameExpr( const NameExpr & other ); … … 142 146 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 143 147 virtual void print( std::ostream & os, int indent = 0 ) const; 144 private:145 std::string name;146 148 }; 147 149 … … 152 154 class AddressExpr : public Expression { 153 155 public: 156 Expression * arg; 157 154 158 AddressExpr( Expression * arg, Expression *_aname = nullptr ); 155 159 AddressExpr( const AddressExpr & other ); … … 163 167 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 164 168 virtual void print( std::ostream & os, int indent = 0 ) const; 165 private:166 Expression * arg;167 169 }; 168 170 … … 170 172 class LabelAddressExpr : public Expression { 171 173 public: 174 Expression * arg; 175 172 176 LabelAddressExpr( Expression * arg ); 173 177 LabelAddressExpr( const LabelAddressExpr & other ); … … 181 185 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 182 186 virtual void print( std::ostream & os, int indent = 0 ) const; 183 private:184 Expression * arg;185 187 }; 186 188 … … 188 190 class CastExpr : public Expression { 189 191 public: 192 Expression * arg; 193 190 194 CastExpr( Expression * arg, Expression *_aname = nullptr ); 191 195 CastExpr( Expression * arg, Type * toType, Expression *_aname = nullptr ); … … 200 204 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 201 205 virtual void print( std::ostream & os, int indent = 0 ) const; 202 private:203 Expression * arg;204 206 }; 205 207 … … 207 209 class VirtualCastExpr : public Expression { 208 210 public: 211 Expression * arg; 212 209 213 VirtualCastExpr( Expression * arg, Type * toType ); 210 214 VirtualCastExpr( const VirtualCastExpr & other ); … … 218 222 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 219 223 virtual void print( std::ostream & os, int indent = 0 ) const; 220 private:221 Expression * arg;222 224 }; 223 225 … … 225 227 class UntypedMemberExpr : public Expression { 226 228 public: 229 Expression * member; 230 Expression * aggregate; 231 227 232 UntypedMemberExpr( Expression * member, Expression * aggregate, Expression *_aname = nullptr ); 228 233 UntypedMemberExpr( const UntypedMemberExpr & other ); … … 238 243 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 239 244 virtual void print( std::ostream & os, int indent = 0 ) const; 240 private:241 Expression * member;242 Expression * aggregate;243 245 }; 244 246 … … 247 249 class MemberExpr : public Expression { 248 250 public: 251 DeclarationWithType * member; 252 Expression * aggregate; 253 249 254 MemberExpr( DeclarationWithType * member, Expression * aggregate, Expression *_aname = nullptr ); 250 255 MemberExpr( const MemberExpr & other ); … … 260 265 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 261 266 virtual void print( std::ostream & os, int indent = 0 ) const; 262 private:263 DeclarationWithType * member;264 Expression * aggregate;265 267 }; 266 268 … … 269 271 class VariableExpr : public Expression { 270 272 public: 273 DeclarationWithType * var; 274 271 275 VariableExpr( DeclarationWithType * var, Expression *_aname = nullptr ); 272 276 VariableExpr( const VariableExpr & other ); … … 280 284 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 281 285 virtual void print( std::ostream & os, int indent = 0 ) const; 282 private:283 DeclarationWithType * var;284 286 }; 285 287 … … 287 289 class ConstantExpr : public Expression { 288 290 public: 291 Constant constant; 292 289 293 ConstantExpr( Constant constant, Expression *_aname = nullptr ); 290 294 ConstantExpr( const ConstantExpr & other ); … … 298 302 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 299 303 virtual void print( std::ostream & os, int indent = 0 ) const; 300 private:301 Constant constant;302 304 }; 303 305 … … 305 307 class SizeofExpr : public Expression { 306 308 public: 309 Expression * expr; 310 Type * type; 311 bool isType; 312 307 313 SizeofExpr( Expression * expr, Expression *_aname = nullptr ); 308 314 SizeofExpr( const SizeofExpr & other ); … … 321 327 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 322 328 virtual void print( std::ostream & os, int indent = 0 ) const; 323 private: 329 }; 330 331 /// AlignofExpr represents an alignof expression 332 class AlignofExpr : public Expression { 333 public: 324 334 Expression * expr; 325 335 Type * type; 326 336 bool isType; 327 }; 328 329 /// AlignofExpr represents an alignof expression 330 class AlignofExpr : public Expression { 331 public: 337 332 338 AlignofExpr( Expression * expr, Expression *_aname = nullptr ); 333 339 AlignofExpr( const AlignofExpr & other ); … … 346 352 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 347 353 virtual void print( std::ostream & os, int indent = 0 ) const; 348 private:349 Expression * expr;350 Type * type;351 bool isType;352 354 }; 353 355 … … 355 357 class UntypedOffsetofExpr : public Expression { 356 358 public: 359 Type * type; 360 std::string member; 361 357 362 UntypedOffsetofExpr( Type * type, const std::string & member, Expression *_aname = nullptr ); 358 363 UntypedOffsetofExpr( const UntypedOffsetofExpr & other ); … … 368 373 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 369 374 virtual void print( std::ostream & os, int indent = 0 ) const; 370 private:371 Type * type;372 std::string member;373 375 }; 374 376 … … 376 378 class OffsetofExpr : public Expression { 377 379 public: 380 Type * type; 381 DeclarationWithType * member; 382 378 383 OffsetofExpr( Type * type, DeclarationWithType * member, Expression *_aname = nullptr ); 379 384 OffsetofExpr( const OffsetofExpr & other ); … … 389 394 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 390 395 virtual void print( std::ostream & os, int indent = 0 ) const; 391 private:392 Type * type;393 DeclarationWithType * member;394 396 }; 395 397 … … 397 399 class OffsetPackExpr : public Expression { 398 400 public: 401 StructInstType * type; 402 399 403 OffsetPackExpr( StructInstType * type_, Expression * aname_ = 0 ); 400 404 OffsetPackExpr( const OffsetPackExpr & other ); … … 407 411 virtual void accept( Visitor & v ) { v.visit( this ); } 408 412 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 409 410 virtual void print( std::ostream & os, int indent = 0 ) const; 411 412 private: 413 StructInstType * type; 413 virtual void print( std::ostream & os, int indent = 0 ) const; 414 414 }; 415 415 … … 417 417 class AttrExpr : public Expression { 418 418 public: 419 Expression * attr; 420 Expression * expr; 421 Type * type; 422 bool isType; 423 419 424 AttrExpr(Expression * attr, Expression * expr, Expression *_aname = nullptr ); 420 425 AttrExpr( const AttrExpr & other ); … … 435 440 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 436 441 virtual void print( std::ostream & os, int indent = 0 ) const; 437 private:438 Expression * attr;439 Expression * expr;440 Type * type;441 bool isType;442 442 }; 443 443 … … 445 445 class LogicalExpr : public Expression { 446 446 public: 447 Expression * arg1; 448 Expression * arg2; 449 447 450 LogicalExpr( Expression * arg1, Expression * arg2, bool andp = true, Expression *_aname = nullptr ); 448 451 LogicalExpr( const LogicalExpr & other ); … … 459 462 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 460 463 virtual void print( std::ostream & os, int indent = 0 ) const; 464 461 465 private: 466 bool isAnd; 467 }; 468 469 /// ConditionalExpr represents the three-argument conditional ( p ? a : b ) 470 class ConditionalExpr : public Expression { 471 public: 462 472 Expression * arg1; 463 473 Expression * arg2; 464 bool isAnd; 465 }; 466 467 /// ConditionalExpr represents the three-argument conditional ( p ? a : b ) 468 class ConditionalExpr : public Expression { 469 public: 474 Expression * arg3; 475 470 476 ConditionalExpr( Expression * arg1, Expression * arg2, Expression * arg3, Expression *_aname = nullptr ); 471 477 ConditionalExpr( const ConditionalExpr & other ); … … 483 489 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 484 490 virtual void print( std::ostream & os, int indent = 0 ) const; 485 private: 491 }; 492 493 /// CommaExpr represents the sequence operator ( a, b ) 494 class CommaExpr : public Expression { 495 public: 486 496 Expression * arg1; 487 497 Expression * arg2; 488 Expression * arg3; 489 }; 490 491 /// CommaExpr represents the sequence operator ( a, b ) 492 class CommaExpr : public Expression { 493 public: 498 494 499 CommaExpr( Expression * arg1, Expression * arg2, Expression *_aname = nullptr ); 495 500 CommaExpr( const CommaExpr & other ); … … 505 510 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 506 511 virtual void print( std::ostream & os, int indent = 0 ) const; 507 private:508 Expression * arg1;509 Expression * arg2;510 512 }; 511 513 … … 513 515 class TypeExpr : public Expression { 514 516 public: 517 Type * type; 518 515 519 TypeExpr( Type * type ); 516 520 TypeExpr( const TypeExpr & other ); … … 524 528 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 525 529 virtual void print( std::ostream & os, int indent = 0 ) const; 526 private:527 Type * type;528 530 }; 529 531 … … 531 533 class AsmExpr : public Expression { 532 534 public: 535 Expression * inout; 536 ConstantExpr * constraint; 537 Expression * operand; 538 533 539 AsmExpr( Expression * inout, ConstantExpr * constraint, Expression * operand ) : inout( inout ), constraint( constraint ), operand( operand ) {} 534 540 AsmExpr( const AsmExpr & other ); … … 548 554 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 549 555 virtual void print( std::ostream & os, int indent = 0 ) const; 550 private: 556 551 557 // https://gcc.gnu.org/onlinedocs/gcc-4.7.1/gcc/Machine-Constraints.html#Machine-Constraints 552 Expression * inout;553 ConstantExpr * constraint;554 Expression * operand;555 558 }; 556 559 … … 559 562 class ImplicitCopyCtorExpr : public Expression { 560 563 public: 561 ImplicitCopyCtorExpr( ApplicationExpr * callExpr );562 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other );563 virtual ~ImplicitCopyCtorExpr();564 565 ApplicationExpr * get_callExpr() const { return callExpr; }566 void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; }567 568 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; }569 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; }570 std::list< Expression * > & get_dtors() { return dtors; }571 572 virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); }573 virtual void accept( Visitor & v ) { v.visit( this ); }574 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); }575 virtual void print( std::ostream & os, int indent = 0 ) const;576 private:577 564 ApplicationExpr * callExpr; 578 565 std::list< ObjectDecl * > tempDecls; 579 566 std::list< ObjectDecl * > returnDecls; 580 567 std::list< Expression * > dtors; 568 569 ImplicitCopyCtorExpr( ApplicationExpr * callExpr ); 570 ImplicitCopyCtorExpr( const ImplicitCopyCtorExpr & other ); 571 virtual ~ImplicitCopyCtorExpr(); 572 573 ApplicationExpr * get_callExpr() const { return callExpr; } 574 void set_callExpr( ApplicationExpr * newValue ) { callExpr = newValue; } 575 576 std::list< ObjectDecl * > & get_tempDecls() { return tempDecls; } 577 std::list< ObjectDecl * > & get_returnDecls() { return returnDecls; } 578 std::list< Expression * > & get_dtors() { return dtors; } 579 580 virtual ImplicitCopyCtorExpr * clone() const { return new ImplicitCopyCtorExpr( * this ); } 581 virtual void accept( Visitor & v ) { v.visit( this ); } 582 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 583 virtual void print( std::ostream & os, int indent = 0 ) const; 581 584 }; 582 585 … … 584 587 class ConstructorExpr : public Expression { 585 588 public: 589 Expression * callExpr; 590 586 591 ConstructorExpr( Expression * callExpr ); 587 592 ConstructorExpr( const ConstructorExpr & other ); … … 595 600 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 596 601 virtual void print( std::ostream & os, int indent = 0 ) const; 597 private:598 Expression * callExpr;599 602 }; 600 603 … … 602 605 class CompoundLiteralExpr : public Expression { 603 606 public: 607 Initializer * initializer; 608 604 609 CompoundLiteralExpr( Type * type, Initializer * initializer ); 605 610 CompoundLiteralExpr( const CompoundLiteralExpr & other ); … … 613 618 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 614 619 virtual void print( std::ostream & os, int indent = 0 ) const; 615 private:616 Initializer * initializer;617 620 }; 618 621 … … 620 623 class RangeExpr : public Expression { 621 624 public: 625 Expression * low, * high; 626 622 627 RangeExpr( Expression * low, Expression * high ); 623 628 RangeExpr( const RangeExpr & other ); … … 632 637 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 633 638 virtual void print( std::ostream & os, int indent = 0 ) const; 634 private:635 Expression * low, * high;636 639 }; 637 640 … … 639 642 class UntypedTupleExpr : public Expression { 640 643 public: 644 std::list<Expression*> exprs; 645 641 646 UntypedTupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr ); 642 647 UntypedTupleExpr( const UntypedTupleExpr & other ); … … 649 654 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 650 655 virtual void print( std::ostream & os, int indent = 0 ) const; 651 private:652 std::list<Expression*> exprs;653 656 }; 654 657 … … 656 659 class TupleExpr : public Expression { 657 660 public: 661 std::list<Expression*> exprs; 662 658 663 TupleExpr( const std::list< Expression * > & exprs, Expression *_aname = nullptr ); 659 664 TupleExpr( const TupleExpr & other ); … … 666 671 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 667 672 virtual void print( std::ostream & os, int indent = 0 ) const; 668 private:669 std::list<Expression*> exprs;670 673 }; 671 674 … … 673 676 class TupleIndexExpr : public Expression { 674 677 public: 678 Expression * tuple; 679 unsigned int index; 680 675 681 TupleIndexExpr( Expression * tuple, unsigned int index ); 676 682 TupleIndexExpr( const TupleIndexExpr & other ); … … 686 692 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 687 693 virtual void print( std::ostream & os, int indent = 0 ) const; 688 private:689 Expression * tuple;690 unsigned int index;691 694 }; 692 695 … … 694 697 class TupleAssignExpr : public Expression { 695 698 public: 699 StmtExpr * stmtExpr = nullptr; 700 696 701 TupleAssignExpr( const std::list< Expression * > & assigns, const std::list< ObjectDecl * > & tempDecls, Expression * _aname = nullptr ); 697 702 TupleAssignExpr( const TupleAssignExpr & other ); … … 705 710 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 706 711 virtual void print( std::ostream & os, int indent = 0 ) const; 707 private:708 StmtExpr * stmtExpr = nullptr;709 712 }; 710 713 … … 712 715 class StmtExpr : public Expression { 713 716 public: 717 CompoundStmt * statements; 718 std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression 719 std::list< Expression * > dtors; // destructor(s) for return variable(s) 720 714 721 StmtExpr( CompoundStmt * statements ); 715 722 StmtExpr( const StmtExpr & other ); … … 726 733 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 727 734 virtual void print( std::ostream & os, int indent = 0 ) const; 728 private:729 CompoundStmt * statements;730 std::list< ObjectDecl * > returnDecls; // return variable(s) for stmt expression731 std::list< Expression * > dtors; // destructor(s) for return variable(s)732 735 }; 733 736 734 737 class UniqueExpr : public Expression { 735 738 public: 739 Expression * expr; 740 ObjectDecl * object; 741 VariableExpr * var; 742 736 743 UniqueExpr( Expression * expr, long long idVal = -1 ); 737 744 UniqueExpr( const UniqueExpr & other ); … … 753 760 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 754 761 virtual void print( std::ostream & os, int indent = 0 ) const; 762 755 763 private: 756 Expression * expr;757 ObjectDecl * object;758 VariableExpr * var;759 764 int id; 760 765 static long long count; … … 773 778 class UntypedInitExpr : public Expression { 774 779 public: 780 Expression * expr; 781 std::list<InitAlternative> initAlts; 782 775 783 UntypedInitExpr( Expression * expr, const std::list<InitAlternative> & initAlts ); 776 784 UntypedInitExpr( const UntypedInitExpr & other ); … … 786 794 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 787 795 virtual void print( std::ostream & os, int indent = 0 ) const; 788 private:789 Expression * expr;790 std::list<InitAlternative> initAlts;791 796 }; 792 797 793 798 class InitExpr : public Expression { 794 799 public: 800 Expression * expr; 801 Designation * designation; 802 795 803 InitExpr( Expression * expr, Designation * designation ); 796 804 InitExpr( const InitExpr & other ); … … 807 815 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 808 816 virtual void print( std::ostream & os, int indent = 0 ) const; 809 private:810 Expression * expr;811 Designation * designation;812 817 }; 813 818 -
src/SynTree/Initializer.cc
r275f4b4 rcd7ef0b 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Fri May 13 13:23:03201613 // Update Count : 2 811 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Aug 3 11:33:00 2016 13 // Update Count : 29 14 14 // 15 15 … … 74 74 } 75 75 } 76 assertf( initializers.size() == designations.size(), "Created ListInit with mismatching initializers (% d) and designations (%d)", initializers.size(), designations.size() );76 assertf( initializers.size() == designations.size(), "Created ListInit with mismatching initializers (%lu) and designations (%lu)", initializers.size(), designations.size() ); 77 77 } 78 78 -
src/SynTree/Initializer.h
r275f4b4 rcd7ef0b 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 : Sat Jul 22 09:52:02201713 // Update Count : 2 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Aug 9 10:19:00 2017 13 // Update Count : 22 14 14 // 15 15 … … 27 27 class Designation : public BaseSyntaxNode { 28 28 public: 29 std::list< Expression * > designators; 30 29 31 Designation( const std::list< Expression * > & designators ); 30 32 Designation( const Designation & other ); … … 37 39 virtual Designation * acceptMutator( Mutator &m ) { return m.mutate( this ); } 38 40 virtual void print( std::ostream &os, int indent = 0 ) const; 39 private:40 std::list< Expression * > designators;41 41 }; 42 42 … … 63 63 class SingleInit : public Initializer { 64 64 public: 65 //Constant *value; 66 Expression *value; // has to be a compile-time constant 67 65 68 SingleInit( Expression *value, bool maybeConstructed = false ); 66 69 SingleInit( const SingleInit &other ); … … 74 77 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } 75 78 virtual void print( std::ostream &os, int indent = 0 ) const; 76 private:77 //Constant *value;78 Expression *value; // has to be a compile-time constant79 79 }; 80 80 … … 83 83 class ListInit : public Initializer { 84 84 public: 85 std::list<Initializer *> initializers; // order *is* important 86 std::list<Designation *> designations; // order/length is consistent with initializers 87 85 88 ListInit( const std::list<Initializer*> &initializers, 86 89 const std::list<Designation *> &designators = {}, bool maybeConstructed = false ); … … 102 105 virtual Initializer *acceptMutator( Mutator &m ) { return m.mutate( this ); } 103 106 virtual void print( std::ostream &os, int indent = 0 ) const; 104 private:105 std::list<Initializer *> initializers; // order *is* important106 std::list<Designation *> designations; // order/length is consistent with initializers107 107 }; 108 108 … … 113 113 class ConstructorInit : public Initializer { 114 114 public: 115 Statement * ctor; 116 Statement * dtor; 117 115 118 ConstructorInit( Statement * ctor, Statement * dtor, Initializer * init ); 116 119 ConstructorInit( const ConstructorInit &other ); … … 130 133 131 134 private: 132 Statement * ctor;133 Statement * dtor;134 135 // C-style initializer made up of SingleInit and ListInit nodes to use as a fallback 135 136 // if an appropriate constructor definition is not found by the resolver -
src/SynTree/NamedTypeDecl.cc
r275f4b4 rcd7ef0b 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 Mar 16 07:49:44201713 // Update Count : 1 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Aug 9 13:28:00 2017 13 // Update Count : 14 14 14 // 15 15 … … 38 38 if ( get_name() != "" ) { 39 39 os << get_name() << ": "; 40 } // if 41 if ( get_linkage() != LinkageSpec::Cforall ) { 42 os << LinkageSpec::linkageName( get_linkage() ) << " "; 40 43 } // if 41 44 get_storageClasses().print( os ); -
src/SynTree/Statement.h
r275f4b4 rcd7ef0b 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 : Sat Jul 22 09:54:32201713 // Update Count : 6 811 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr Aug 3 14:08:00 2017 13 // Update Count : 69 14 14 // 15 15 … … 26 26 class Statement : public BaseSyntaxNode { 27 27 public: 28 std::list<Label> labels; 29 28 30 Statement( std::list<Label> labels ); 29 31 virtual ~Statement(); … … 36 38 virtual Statement *acceptMutator( Mutator &m ) = 0; 37 39 virtual void print( std::ostream &os, int indent = 0 ) const; 38 protected:39 std::list<Label> labels;40 40 }; 41 41 42 42 class CompoundStmt : public Statement { 43 43 public: 44 std::list<Statement*> kids; 45 44 46 CompoundStmt( std::list<Label> labels ); 45 47 CompoundStmt( const CompoundStmt &other ); … … 54 56 virtual CompoundStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } 55 57 virtual void print( std::ostream &os, int indent = 0 ) const; 56 private:57 std::list<Statement*> kids;58 58 }; 59 59 … … 67 67 virtual NullStmt *acceptMutator( Mutator &m ) { return m.mutate( this ); } 68 68 virtual void print( std::ostream &os, int indent = 0 ) const; 69 70 private:71 69 }; 72 70 73 71 class ExprStmt : public Statement { 74 72 public: 73 Expression *expr; 74 75 75 ExprStmt( std::list<Label> labels, Expression *expr ); 76 76 ExprStmt( const ExprStmt &other ); … … 84 84 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 85 85 virtual void print( std::ostream &os, int indent = 0 ) const; 86 private:87 Expression *expr;88 86 }; 89 87 90 88 class AsmStmt : public Statement { 91 89 public: 90 bool voltile; 91 ConstantExpr *instruction; 92 std::list<Expression *> output, input; 93 std::list<ConstantExpr *> clobber; 94 std::list<Label> gotolabels; 95 92 96 AsmStmt( std::list<Label> labels, bool voltile, ConstantExpr *instruction, std::list<Expression *> input, std::list<Expression *> output, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ); 93 97 AsmStmt( const AsmStmt &other ); … … 111 115 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 112 116 virtual void print( std::ostream &os, int indent = 0 ) const; 113 private:114 bool voltile;115 ConstantExpr *instruction;116 std::list<Expression *> output, input;117 std::list<ConstantExpr *> clobber;118 std::list<Label> gotolabels;119 117 }; 120 118 121 119 class IfStmt : public Statement { 122 120 public: 121 Expression *condition; 122 Statement *thenPart; 123 Statement *elsePart; 124 123 125 IfStmt( std::list<Label> labels, Expression *condition, Statement *thenPart, Statement *elsePart ); 124 126 IfStmt( const IfStmt &other ); … … 136 138 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 137 139 virtual void print( std::ostream &os, int indent = 0 ) const; 138 private:139 Expression *condition;140 Statement *thenPart;141 Statement *elsePart;142 140 }; 143 141 144 142 class SwitchStmt : public Statement { 145 143 public: 144 Expression * condition; 145 146 146 SwitchStmt( std::list<Label> labels, Expression *condition, std::list<Statement *> &statements ); 147 147 SwitchStmt( const SwitchStmt &other ); … … 159 159 virtual void print( std::ostream &os, int indent = 0 ) const; 160 160 private: 161 std::list<Statement *> statements; 162 }; 163 164 class CaseStmt : public Statement { 165 public: 161 166 Expression * condition; 162 std::list<Statement *> statements; 163 }; 164 165 class CaseStmt : public Statement { 166 public: 167 std::list<Statement *> stmts; 168 167 169 CaseStmt( std::list<Label> labels, Expression *conditions, std::list<Statement *> &stmts, bool isdef = false ) throw(SemanticError); 168 170 CaseStmt( const CaseStmt &other ); … … 186 188 virtual void print( std::ostream &os, int indent = 0 ) const; 187 189 private: 188 Expression * condition;189 std::list<Statement *> stmts;190 190 bool _isDefault; 191 191 }; … … 193 193 class WhileStmt : public Statement { 194 194 public: 195 Expression *condition; 196 Statement *body; 197 bool isDoWhile; 198 195 199 WhileStmt( std::list<Label> labels, Expression *condition, 196 200 Statement *body, bool isDoWhile = false ); … … 209 213 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 210 214 virtual void print( std::ostream &os, int indent = 0 ) const; 211 private: 215 }; 216 217 class ForStmt : public Statement { 218 public: 219 std::list<Statement *> initialization; 212 220 Expression *condition; 221 Expression *increment; 213 222 Statement *body; 214 bool isDoWhile; 215 }; 216 217 class ForStmt : public Statement { 218 public: 223 219 224 ForStmt( std::list<Label> labels, std::list<Statement *> initialization, 220 225 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 ); … … 235 240 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 236 241 virtual void print( std::ostream &os, int indent = 0 ) const; 237 private:238 std::list<Statement *> initialization;239 Expression *condition;240 Expression *increment;241 Statement *body;242 242 }; 243 243 … … 245 245 public: 246 246 enum Type { Goto = 0, Break, Continue }; 247 248 // originalTarget kept for error messages. 249 const Label originalTarget; 250 Label target; 251 Expression *computedTarget; 252 Type type; 247 253 248 254 BranchStmt( std::list<Label> labels, Label target, Type ) throw (SemanticError); … … 265 271 private: 266 272 static const char *brType[]; 267 Label originalTarget; // can give better error messages if we remember the label name that the user entered268 Label target;269 Expression *computedTarget;270 Type type;271 273 }; 272 274 273 275 class ReturnStmt : public Statement { 274 276 public: 277 Expression *expr; 278 275 279 ReturnStmt( std::list<Label> labels, Expression *expr ); 276 280 ReturnStmt( const ReturnStmt &other ); … … 284 288 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 285 289 virtual void print( std::ostream &os, int indent = 0 ) const; 286 private:287 Expression *expr;288 290 }; 289 291 … … 291 293 public: 292 294 enum Kind { Terminate, Resume }; 295 296 const Kind kind; 297 Expression * expr; 298 Expression * target; 293 299 294 300 ThrowStmt( std::list<Label> labels, Kind kind, Expression * expr, Expression * target = nullptr ); … … 306 312 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 307 313 virtual void print( std::ostream &os, int indent = 0 ) const; 308 private:309 Kind kind;310 Expression * expr;311 Expression * target;312 314 }; 313 315 314 316 class TryStmt : public Statement { 315 317 public: 318 CompoundStmt *block; 319 std::list<CatchStmt *> handlers; 320 FinallyStmt *finallyBlock; 321 316 322 TryStmt( std::list<Label> labels, CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 ); 317 323 TryStmt( const TryStmt &other ); … … 329 335 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 330 336 virtual void print( std::ostream &os, int indent = 0 ) const; 331 332 private:333 CompoundStmt *block;334 std::list<CatchStmt *> handlers;335 FinallyStmt *finallyBlock;336 337 }; 337 338 … … 339 340 public: 340 341 enum Kind { Terminate, Resume }; 342 343 const Kind kind; 344 Declaration *decl; 345 Expression *cond; 346 Statement *body; 341 347 342 348 CatchStmt( std::list<Label> labels, Kind kind, Declaration *decl, … … 357 363 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 358 364 virtual void print( std::ostream &os, int indent = 0 ) const; 359 360 private:361 Kind kind;362 Declaration *decl;363 Expression *cond;364 Statement *body;365 365 }; 366 366 367 367 class FinallyStmt : public Statement { 368 368 public: 369 CompoundStmt *block; 370 369 371 FinallyStmt( std::list<Label> labels, CompoundStmt *block ); 370 372 FinallyStmt( const FinallyStmt &other ); … … 378 380 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 379 381 virtual void print( std::ostream &os, int indent = 0 ) const; 380 private:381 CompoundStmt *block;382 382 }; 383 383 … … 386 386 class DeclStmt : public Statement { 387 387 public: 388 Declaration *decl; 389 388 390 DeclStmt( std::list<Label> labels, Declaration *decl ); 389 391 DeclStmt( const DeclStmt &other ); … … 397 399 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 398 400 virtual void print( std::ostream &os, int indent = 0 ) const; 399 private:400 Declaration *decl;401 401 }; 402 402 … … 407 407 class ImplicitCtorDtorStmt : public Statement { 408 408 public: 409 // Non-owned pointer to the constructor/destructor statement 410 Statement * callStmt; 411 409 412 ImplicitCtorDtorStmt( Statement * callStmt ); 410 413 ImplicitCtorDtorStmt( const ImplicitCtorDtorStmt & other ); … … 418 421 virtual Statement *acceptMutator( Mutator &m ) { return m.mutate( this ); } 419 422 virtual void print( std::ostream &os, int indent = 0 ) const; 420 421 private:422 // Non-owned pointer to the constructor/destructor statement423 Statement * callStmt;424 423 }; 425 424 -
src/SynTree/Type.cc
r275f4b4 rcd7ef0b 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 : Fri Mar 17 08:42:47201713 // Update Count : 2 811 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Aug 2 11:11:00 2017 13 // Update Count : 29 14 14 // 15 15 … … 88 88 } 89 89 90 // Empty Variable declarations: 91 const Type::FuncSpecifiers noFuncSpecifiers; 92 const Type::StorageClasses noStorageClasses; 93 const Type::Qualifiers noQualifiers; 94 90 95 std::ostream & operator<<( std::ostream & out, const Type * type ) { 91 96 if ( type ) { -
src/SynTree/Type.h
r275f4b4 rcd7ef0b 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 : Sat Jul 22 09:53:29201713 // Update Count : 15 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Aug 9 14:25:00 2017 13 // Update Count : 152 14 14 // 15 15 … … 127 127 }; // Qualifiers 128 128 129 typedef std::list<TypeDecl *> ForallList; 130 131 Qualifiers tq; 132 ForallList forall; 133 std::list< Attribute * > attributes; 134 129 135 Type( const Qualifiers & tq, const std::list< Attribute * > & attributes ); 130 136 Type( const Type & other ); … … 145 151 void set_atomic( bool newValue ) { tq.is_atomic = newValue; } 146 152 147 typedef std::list<TypeDecl *> ForallList;148 153 ForallList& get_forall() { return forall; } 149 154 … … 165 170 virtual Type *acceptMutator( Mutator & m ) = 0; 166 171 virtual void print( std::ostream & os, int indent = 0 ) const; 167 private: 168 Qualifiers tq; 169 ForallList forall; 170 std::list< Attribute * > attributes; 171 }; 172 173 extern Type::Qualifiers noQualifiers; // no qualifiers on constants 172 }; 173 174 extern const Type::FuncSpecifiers noFuncSpecifiers; 175 extern const Type::StorageClasses noStorageClasses; 176 extern const Type::Qualifiers noQualifiers; // no qualifiers on constants 174 177 175 178 class VoidType : public Type { … … 211 214 LongDoubleImaginary, 212 215 NUMBER_OF_BASIC_TYPES 213 } ;216 } kind; 214 217 215 218 static const char *typeNames[]; // string names for basic types, MUST MATCH with Kind … … 226 229 227 230 bool isInteger() const; 228 private:229 Kind kind;230 231 }; 231 232 232 233 class PointerType : public Type { 233 234 public: 235 Type *base; 236 237 // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] ) 238 Expression *dimension; 239 bool isVarLen; 240 bool isStatic; 241 234 242 PointerType( const Type::Qualifiers & tq, Type *base, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 235 243 PointerType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); … … 252 260 virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } 253 261 virtual void print( std::ostream & os, int indent = 0 ) const; 254 private: 262 }; 263 264 class ArrayType : public Type { 265 public: 255 266 Type *base; 256 257 // In C99, pointer types can be qualified in many ways e.g., int f( int a[ static 3 ] )258 267 Expression *dimension; 259 268 bool isVarLen; 260 269 bool isStatic; 261 }; 262 263 class ArrayType : public Type { 264 public: 270 265 271 ArrayType( const Type::Qualifiers & tq, Type *base, Expression *dimension, bool isVarLen, bool isStatic, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 266 272 ArrayType( const ArrayType& ); … … 282 288 virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } 283 289 virtual void print( std::ostream & os, int indent = 0 ) const; 284 private:285 Type *base;286 Expression *dimension;287 bool isVarLen;288 bool isStatic;289 290 }; 290 291 291 292 class FunctionType : public Type { 292 293 public: 294 std::list<DeclarationWithType*> returnVals; 295 std::list<DeclarationWithType*> parameters; 296 297 // Does the function accept a variable number of arguments following the arguments specified in the parameters list. 298 // This could be because of 299 // - an ellipsis in a prototype declaration 300 // - an unprototyped declaration 301 bool isVarArgs; 302 293 303 FunctionType( const Type::Qualifiers & tq, bool isVarArgs, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 294 304 FunctionType( const FunctionType& ); … … 305 315 virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } 306 316 virtual void print( std::ostream & os, int indent = 0 ) const; 307 private:308 std::list<DeclarationWithType*> returnVals;309 std::list<DeclarationWithType*> parameters;310 311 // Does the function accept a variable number of arguments following the arguments specified in the parameters list.312 // This could be because of313 // - an ellipsis in a prototype declaration314 // - an unprototyped declaration315 bool isVarArgs;316 317 }; 317 318 318 319 class ReferenceToType : public Type { 319 320 public: 321 std::list< Expression* > parameters; 322 std::string name; 323 bool hoistType; 324 320 325 ReferenceToType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes ); 321 326 ReferenceToType( const ReferenceToType & other ); … … 336 341 protected: 337 342 virtual std::string typeString() const = 0; 338 std::list< Expression* > parameters;339 std::string name;340 private:341 bool hoistType;342 343 }; 343 344 … … 345 346 typedef ReferenceToType Parent; 346 347 public: 348 // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree, 349 // where the structure used in this type is actually defined 350 StructDecl *baseStruct; 351 347 352 StructInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ), baseStruct( 0 ) {} 348 353 StructInstType( const Type::Qualifiers & tq, StructDecl * baseStruct, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); … … 368 373 private: 369 374 virtual std::string typeString() const; 370 371 // this decl is not "owned" by the struct inst; it is merely a pointer to elsewhere in the tree,372 // where the structure used in this type is actually defined373 StructDecl *baseStruct;374 375 }; 375 376 … … 377 378 typedef ReferenceToType Parent; 378 379 public: 380 // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree, 381 // where the union used in this type is actually defined 382 UnionDecl *baseUnion; 383 379 384 UnionInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ), baseUnion( 0 ) {} 380 385 UnionInstType( const Type::Qualifiers & tq, UnionDecl * baseUnion, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); … … 400 405 private: 401 406 virtual std::string typeString() const; 402 407 }; 408 409 class EnumInstType : public ReferenceToType { 410 typedef ReferenceToType Parent; 411 public: 403 412 // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree, 404 413 // where the union used in this type is actually defined 405 UnionDecl *baseUnion; 406 }; 407 408 class EnumInstType : public ReferenceToType { 409 typedef ReferenceToType Parent; 410 public: 414 EnumDecl *baseEnum = nullptr; 415 411 416 EnumInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {} 412 417 EnumInstType( const Type::Qualifiers & tq, EnumDecl * baseEnum, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); … … 423 428 private: 424 429 virtual std::string typeString() const; 425 426 // this decl is not "owned" by the union inst; it is merely a pointer to elsewhere in the tree,427 // where the union used in this type is actually defined428 EnumDecl *baseEnum = nullptr;429 430 }; 430 431 … … 432 433 typedef ReferenceToType Parent; 433 434 public: 435 // this member is filled in by the validate pass, which instantiates the members of the correponding 436 // aggregate with the actual type parameters specified for this use of the context 437 std::list< Declaration* > members; 438 434 439 TraitInstType( const Type::Qualifiers & tq, const std::string & name, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : Parent( tq, name, attributes ) {} 435 440 TraitInstType( const TraitInstType & other ); … … 445 450 private: 446 451 virtual std::string typeString() const; 447 448 // this member is filled in by the validate pass, which instantiates the members of the correponding449 // aggregate with the actual type parameters specified for this use of the context450 std::list< Declaration* > members;451 452 }; 452 453 … … 454 455 typedef ReferenceToType Parent; 455 456 public: 457 // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree, 458 // where the type used here is actually defined 459 TypeDecl *baseType; 460 bool isFtype; 461 456 462 TypeInstType( const Type::Qualifiers & tq, const std::string & name, TypeDecl *baseType, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 457 463 TypeInstType( const Type::Qualifiers & tq, const std::string & name, bool isFtype, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); … … 472 478 private: 473 479 virtual std::string typeString() const; 474 // this decl is not "owned" by the type inst; it is merely a pointer to elsewhere in the tree,475 // where the type used here is actually defined476 TypeDecl *baseType;477 bool isFtype;478 480 }; 479 481 480 482 class TupleType : public Type { 481 483 public: 484 std::list<Type *> types; 485 std::list<Declaration *> members; 486 482 487 TupleType( const Type::Qualifiers & tq, const std::list< Type * > & types, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 483 488 TupleType( const TupleType& ); … … 508 513 virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } 509 514 virtual void print( std::ostream & os, int indent = 0 ) const; 510 private:511 std::list<Type *> types;512 std::list<Declaration *> members;513 515 }; 514 516 515 517 class TypeofType : public Type { 516 518 public: 519 Expression *expr; 520 517 521 TypeofType( const Type::Qualifiers & tq, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 518 522 TypeofType( const TypeofType& ); … … 528 532 virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } 529 533 virtual void print( std::ostream & os, int indent = 0 ) const; 530 private: 534 }; 535 536 class AttrType : public Type { 537 public: 538 std::string name; 531 539 Expression *expr; 532 }; 533 534 class AttrType : public Type { 535 public: 540 Type *type; 541 bool isType; 542 536 543 AttrType( const Type::Qualifiers & tq, const std::string & name, Expression *expr, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); 537 544 AttrType( const Type::Qualifiers & tq, const std::string & name, Type *type, const std::list< Attribute * > & attributes = std::list< Attribute * >() ); … … 554 561 virtual Type *acceptMutator( Mutator & m ) { return m.mutate( this ); } 555 562 virtual void print( std::ostream & os, int indent = 0 ) const; 556 private:557 std::string name;558 Expression *expr;559 Type *type;560 bool isType;561 563 }; 562 564 -
src/SynTree/TypeDecl.cc
r275f4b4 rcd7ef0b 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 Mar 16 07:49:58201713 // Update Count : 511 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Aug 9 14:35:00 2017 13 // Update Count : 6 14 14 // 15 15 … … 18 18 #include "Common/utility.h" 19 19 20 TypeDecl::TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, Type * init ) : Parent( name, scs, type ), kind( kind ), init( init ), sized( kind == Any || kind == Ttype) {20 TypeDecl::TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, Type * init ) : Parent( name, scs, type ), init( init ), sized( kind == Any || kind == Ttype ), kind( kind ) { 21 21 } 22 22 23 TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), kind( other.kind ), init( maybeClone( other.init ) ), sized( other.sized ) {23 TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), init( maybeClone( other.init ) ), sized( other.sized ), kind( other.kind ) { 24 24 } 25 25 -
src/SynTree/TypeExpr.cc
r275f4b4 rcd7ef0b 21 21 } 22 22 23 TypeExpr::TypeExpr( const TypeExpr &other ) : type( maybeClone( other.type ) ) {23 TypeExpr::TypeExpr( const TypeExpr &other ) : Expression( other ), type( maybeClone( other.type ) ) { 24 24 } 25 25 -
src/Tuples/TupleExpansion.cc
r275f4b4 rcd7ef0b 66 66 }; 67 67 68 class TupleTypeReplacer : public GenPoly::DeclMutator { 69 public: 70 typedef GenPoly::DeclMutator Parent; 71 using Parent::mutate; 72 73 virtual Type * mutate( TupleType * tupleType ) override; 74 75 virtual CompoundStmt * mutate( CompoundStmt * stmt ) override { 76 typeMap.beginScope(); 77 stmt = Parent::mutate( stmt ); 78 typeMap.endScope(); 79 return stmt; 68 struct TupleTypeReplacer : public WithDeclsToAdd, public WithGuards, public WithTypeSubstitution { 69 Type * postmutate( TupleType * tupleType ); 70 71 void premutate( CompoundStmt * ) { 72 GuardScope( typeMap ); 80 73 } 81 74 private: … … 111 104 mutateAll( translationUnit, assnExpander ); 112 105 113 TupleTypeReplacerreplacer;114 replacer.mutateDeclarationList( translationUnit);106 PassVisitor<TupleTypeReplacer> replacer; 107 mutateAll( translationUnit, replacer ); 115 108 116 109 PassVisitor<TupleIndexExpander> idxExpander; … … 218 211 } 219 212 220 Type * TupleTypeReplacer::mutate( TupleType * tupleType ) { 221 tupleType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) ); 213 Type * TupleTypeReplacer::postmutate( TupleType * tupleType ) { 222 214 unsigned tupleSize = tupleType->size(); 223 215 if ( ! typeMap.count( tupleSize ) ) { … … 226 218 decl->set_body( true ); 227 219 for ( size_t i = 0; i < tupleSize; ++i ) { 228 TypeDecl * tyParam = new TypeDecl( toString( "tuple_param_", i ), Type::StorageClasses(), nullptr, TypeDecl::Any );220 TypeDecl * tyParam = new TypeDecl( toString( "tuple_param_", tupleSize, "_", i ), Type::StorageClasses(), nullptr, TypeDecl::Any ); 229 221 decl->get_members().push_back( new ObjectDecl( toString("field_", i ), Type::StorageClasses(), LinkageSpec::C, nullptr, new TypeInstType( Type::Qualifiers(), tyParam->get_name(), tyParam ), nullptr ) ); 230 222 decl->get_parameters().push_back( tyParam ); … … 235 227 } 236 228 typeMap[tupleSize] = decl; 237 addDeclaration( decl );229 declsToAddBefore.push_back( decl ); 238 230 } 239 231 Type::Qualifiers qualifiers = tupleType->get_qualifiers(); … … 241 233 StructDecl * decl = typeMap[tupleSize]; 242 234 StructInstType * newType = new StructInstType( qualifiers, decl ); 243 for ( Type * t : *tupleType ) { 235 for ( auto p : group_iterate( tupleType->get_types(), decl->get_parameters() ) ) { 236 Type * t = std::get<0>(p); 237 TypeDecl * td = std::get<1>(p); 244 238 newType->get_parameters().push_back( new TypeExpr( t->clone() ) ); 239 if ( env ) { 240 // add bindings to the type environment. 241 // xxx - This may not be sufficient, it may be necessary to rename type variables on StructInstType? 242 env->add( td->get_name(), t->clone() ); 243 } 245 244 } 246 245 delete tupleType; -
src/Virtual/ExpandCasts.cc
r275f4b4 rcd7ef0b 10 10 // Created On : Mon Jul 24 13:59:00 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jul 26 14:16:00 201713 // Update Count : 012 // Last Modified On : Tus Aug 2 14:59:00 2017 13 // Update Count : 1 14 14 // 15 15 … … 78 78 79 79 void VirtualCastCore::premutate( FunctionDecl * functionDecl ) { 80 if ( (! vcast_decl) && functionDecl->get_statements() &&80 if ( (! vcast_decl) && 81 81 functionDecl->get_name() == "__cfa__virtual_cast" ) { 82 82 vcast_decl = functionDecl; … … 101 101 assertf( castExpr->get_result(), "Virtual Cast target not found before expansion." ); 102 102 103 //assert( vcast_decl );103 assert( vcast_decl ); 104 104 assert( pvt_decl ); 105 105 106 106 // May only cast to a pointer or reference type. 107 107 // A earlier validation should give a syntax error, this is 108 // just to make sure errors don't creep in. 108 // just to make sure errors don't creep during translation. 109 // Move to helper with more detailed error messages. 109 110 PointerType * target_type = 110 111 dynamic_cast<PointerType *>( castExpr->get_result() ); 111 112 assert( target_type ); 112 113 113 114 StructInstType * target_struct = 114 115 dynamic_cast<StructInstType *>( target_type->get_base() ); 116 assert( target_struct ); 117 115 118 StructDecl * target_decl = target_struct->get_baseStruct(); 116 119 … … 124 127 125 128 Expression * result = new CastExpr( 126 //new ApplicationExpr( new VariableExpr( vcast_decl ), { 129 //new ApplicationExpr( 130 //new AddressExpr( new VariableExpr( vcast_decl ) ), 131 //new CastExpr( new VariableExpr( vcast_decl ), 132 // new PointerType( noQualifiers, 133 // vcast_decl->get_type()->clone() 134 // ) 135 // ), 127 136 new UntypedExpr( new NameExpr( "__cfa__virtual_cast" ), { 128 new CastExpr(129 new AddressExpr( new VariableExpr( table ) ),130 pointer_to_pvt(1)131 ),132 new CastExpr(133 castExpr->get_arg(),134 pointer_to_pvt(2)135 ) }136 ),137 castExpr->get_result() 137 new CastExpr( 138 new AddressExpr( new VariableExpr( table ) ), 139 pointer_to_pvt(1) 140 ), 141 new CastExpr( 142 castExpr->get_arg(), 143 pointer_to_pvt(2) 144 ) 145 } ), 146 castExpr->get_result()->clone() 138 147 ); 139 148 -
src/driver/cfa.cc
r275f4b4 rcd7ef0b 10 10 // Created On : Tue Aug 20 13:44:49 2002 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 20 15:54:45 201713 // Update Count : 15 612 // Last Modified On : Fri Jan 20 14:38:45 2017 13 // Update Count : 155 14 14 // 15 15 … … 76 76 bool cpp_flag = false; // -E or -M flag, preprocessor only 77 77 bool std_flag = false; // -std= flag 78 bool noincstd_flag = false; // -no-include-stdhdr= flag 78 79 bool debugging __attribute(( unused )) = false; // -g flag 79 80 … … 133 134 } else if ( arg == "-nohelp" ) { 134 135 help = false; // strip the nohelp flag 136 } else if ( arg == "-no-include-stdhdr" ) { 137 noincstd_flag = true; // strip the no-include-stdhdr flag 135 138 } else if ( arg == "-compiler" ) { 136 139 // use the user specified compiler … … 231 234 args[nargs] = "-I" CFA_INCDIR; 232 235 nargs += 1; 233 args[nargs] = "-I" CFA_INCDIR "/stdhdr"; 234 nargs += 1; 236 if ( ! noincstd_flag ) { // do not use during build 237 args[nargs] = "-I" CFA_INCDIR "/stdhdr"; 238 nargs += 1; 239 } // if 235 240 args[nargs] = "-I" CFA_INCDIR "/concurrency"; 236 241 nargs += 1; -
src/include/cassert
r275f4b4 rcd7ef0b 10 10 // Created On : Thu Aug 18 13:19:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Aug 18 13:25:55 201613 // Update Count : 412 // Last Modified On : Tue Aug 1 11:56:01 2017 13 // Update Count : 16 14 14 // 15 15 … … 18 18 // IWYU pragma: private, include <cassert> 19 19 20 #include_next < assert.h>20 #include_next <cassert> 21 21 22 #define __STRINGIFY__(str) #str 23 #define __VSTRINGIFY__(str) __STRINGIFY__(str) 24 #define assertf(expr, fmt, ...) ((expr) ? static_cast<void>(0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ )) 22 #ifdef NDEBUG 25 23 26 void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) __attribute__((noreturn)); 24 #define assertf(expr, fmt, ...) (__ASSERT_VOID_ASSERT (0)) 25 26 #else 27 28 #define assertf(expr, fmt, ...) ((expr) \ 29 ? (__ASSERT_VOID_CAST (0)) \ 30 : __assert_fail_f( #expr, __FILE__, __LINE__, \ 31 __ASSERT_FUNCTION, fmt, ## __VA_ARGS__ )) 32 33 void __assert_fail_f( const char *assertion, const char *file, 34 unsigned int line, const char *function, 35 const char *fmt, ... 36 ) __attribute__((noreturn, format(printf, 5, 6))); 37 38 #endif 27 39 28 40 template<typename T, typename U> 29 static inline T safe_dynamic_cast( const U& src) {41 static inline T safe_dynamic_cast( const U & src ) { 30 42 T ret = dynamic_cast<T>(src); 31 43 assert(ret); -
src/libcfa/Makefile.am
r275f4b4 rcd7ef0b 39 39 40 40 AM_CCASFLAGS = @CFA_FLAGS@ 41 CFLAGS = -quiet -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS} 41 42 #CFLAGS for most libcfa src 43 #use -no-include-stdhdr to prevent rebuild cycles 44 #The built sources must not depend on the installed headers 45 CFLAGS = -quiet -no-include-stdhdr -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS} 42 46 CC = ${abs_top_srcdir}/src/driver/cfa 43 47 -
src/libcfa/Makefile.in
r275f4b4 rcd7ef0b 308 308 CFA_NAME = @CFA_NAME@ 309 309 CFA_PREFIX = @CFA_PREFIX@ 310 CFLAGS = -quiet -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS} 310 311 #CFLAGS for most libcfa src 312 #use -no-include-stdhdr to prevent rebuild cycles 313 #The built sources must not depend on the installed headers 314 CFLAGS = -quiet -no-include-stdhdr -I${abs_top_srcdir}/src/libcfa/stdhdr -XCFA -t -B${abs_top_srcdir}/src/driver ${EXTRA_FLAGS} 311 315 CPP = @CPP@ 312 316 CPPFLAGS = @CPPFLAGS@ -
src/libcfa/concurrency/monitor.c
r275f4b4 rcd7ef0b 10 10 // Created On : Thd Feb 23 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 22:37:11201713 // Update Count : 112 // Last Modified On : Mon Jul 31 14:59:05 2017 13 // Update Count : 3 14 14 // 15 15 … … 484 484 if( !this->monitors ) { 485 485 // LIB_DEBUG_PRINT_SAFE("Branding\n"); 486 assertf( thrd->current_monitors != NULL, "No current monitor to brand condition ", thrd->current_monitors );486 assertf( thrd->current_monitors != NULL, "No current monitor to brand condition %p", thrd->current_monitors ); 487 487 this->monitor_count = thrd->current_monitor_count; 488 488 -
src/libcfa/exception.c
r275f4b4 rcd7ef0b 9 9 // Author : Andrew Beach 10 10 // Created On : Mon Jun 26 15:13:00 2017 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Jul 26 10:37:51201713 // Update Count : 211 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 4 15:20:00 2017 13 // Update Count : 6 14 14 // 15 16 #include <stddef.h> // for size_t 15 17 16 18 #include "exception.h" … … 32 34 #include "lsda.h" 33 35 36 37 // Base exception vtable is abstract, you should not have base exceptions. 38 struct __cfaehm__base_exception_t_vtable 39 ___cfaehm__base_exception_t_vtable_instance = { 40 .parent = NULL, 41 .size = 0, 42 .copy = NULL, 43 .free = NULL, 44 .msg = NULL 45 }; 46 47 34 48 // Temperary global exception context. Does not work with concurency. 35 struct shared_stack_t {49 struct exception_context_t { 36 50 struct __cfaehm__try_resume_node * top_resume; 37 51 struct __cfaehm__try_resume_node * current_resume; 38 52 39 exception current_exception;53 exception * current_exception; 40 54 int current_handler_index; 41 55 } shared_stack = {NULL, NULL, 0, 0}; 42 56 57 // Get the current exception context. 58 // There can be a single global until multithreading occurs, then each stack 59 // needs its own. It will have to be updated to handle that. 60 struct exception_context_t * this_exception_context() { 61 return &shared_stack; 62 } 63 //#define SAVE_EXCEPTION_CONTEXT(to_name) 64 //struct exception_context_t * to_name = this_exception_context(); 65 //exception * this_exception() { 66 // return this_exception_context()->current_exception; 67 //} 43 68 44 69 … … 55 80 56 81 // DEBUG 57 printf("Throwing resumption exception %d\n", *except);82 printf("Throwing resumption exception\n"); 58 83 59 84 struct __cfaehm__try_resume_node * original_head = shared_stack.current_resume; … … 69 94 } 70 95 71 printf("Unhandled exception %d\n", *except);96 printf("Unhandled exception\n"); 72 97 shared_stack.current_resume = original_head; 73 98 … … 94 119 // TERMINATION =============================================================== 95 120 96 // Requires -fexceptions to work. 97 98 // Global which defines the current exception. Currently an int just to make matching easier. 99 //int this_exception; (became shared_stack.current_exception) 121 // MEMORY MANAGEMENT (still for integers) 122 // May have to move to cfa for constructors and destructors (references). 123 124 struct __cfaehm__node { 125 struct __cfaehm__node * next; 126 }; 127 128 #define NODE_TO_EXCEPT(node) ((exception *)(1 + (node))) 129 #define EXCEPT_TO_NODE(except) ((struct __cfaehm__node *)(except) - 1) 130 131 // Creates a copy of the indicated exception and sets current_exception to it. 132 static void __cfaehm__allocate_exception( exception * except ) { 133 struct exception_context_t * context = this_exception_context(); 134 135 // Allocate memory for the exception. 136 struct __cfaehm__node * store = malloc( 137 sizeof( struct __cfaehm__node ) + except->virtual_table->size ); 138 139 if ( ! store ) { 140 // Failure: cannot allocate exception. Terminate thread. 141 abort(); // <- Although I think it might be the process. 142 } 143 144 // Add the node to the list: 145 store->next = EXCEPT_TO_NODE(context->current_exception); 146 context->current_exception = NODE_TO_EXCEPT(store); 147 148 // Copy the exception to storage. 149 except->virtual_table->copy( context->current_exception, except ); 150 } 151 152 // Delete the provided exception, unsetting current_exception if relivant. 153 static void __cfaehm__delete_exception( exception * except ) { 154 struct exception_context_t * context = this_exception_context(); 155 156 // DEBUG 157 printf( "Deleting Exception\n"); 158 159 // Remove the exception from the list. 160 struct __cfaehm__node * to_free = EXCEPT_TO_NODE(except); 161 struct __cfaehm__node * node; 162 163 if ( context->current_exception == except ) { 164 node = to_free->next; 165 context->current_exception = (node) ? NODE_TO_EXCEPT(node) : 0; 166 } else { 167 node = EXCEPT_TO_NODE(context->current_exception); 168 // It may always be in the first or second position. 169 while( to_free != node->next ) { 170 node = node->next; 171 } 172 node->next = to_free->next; 173 } 174 175 // Free the old exception node. 176 except->virtual_table->free( except ); 177 free( to_free ); 178 } 179 180 // If this isn't a rethrow (*except==0), delete the provided exception. 181 void __cfaehm__cleanup_terminate( void * except ) { 182 if ( *(void**)except ) __cfaehm__delete_exception( *(exception**)except ); 183 } 184 100 185 101 186 // We need a piece of storage to raise the exception … … 117 202 } 118 203 119 void __cfaehm__throw_terminate( exception * val ) { 120 // Store the current exception 121 shared_stack.current_exception = *val; 122 123 // DEBUG 124 printf("Throwing termination exception %d\n", *val); 204 // The exception that is being thrown must already be stored. 205 __attribute__((noreturn)) void __cfaehm__begin_unwind(void) { 206 if ( ! this_exception_context()->current_exception ) { 207 printf("UNWIND ERROR missing exception in begin unwind\n"); 208 abort(); 209 } 210 125 211 126 212 // Call stdlibc to raise the exception … … 148 234 } 149 235 150 // Nesting this the other way would probably be faster. 236 void __cfaehm__throw_terminate( exception * val ) { 237 // DEBUG 238 printf("Throwing termination exception\n"); 239 240 __cfaehm__allocate_exception( val ); 241 __cfaehm__begin_unwind(); 242 } 243 151 244 void __cfaehm__rethrow_terminate(void) { 152 245 // DEBUG 153 246 printf("Rethrowing termination exception\n"); 154 247 155 __cfaehm__ throw_terminate(&shared_stack.current_exception);248 __cfaehm__begin_unwind(); 156 249 } 157 250 … … 263 356 _Unwind_Reason_Code (*matcher)(exception *) = 264 357 MATCHER_FROM_CONTEXT(context); 265 int index = matcher( &shared_stack.current_exception);358 int index = matcher(shared_stack.current_exception); 266 359 _Unwind_Reason_Code ret = (0 == index) 267 360 ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND; … … 359 452 // Exception handler 360 453 catch_block( shared_stack.current_handler_index, 361 &shared_stack.current_exception );454 shared_stack.current_exception ); 362 455 } 363 456 -
src/libcfa/exception.h
r275f4b4 rcd7ef0b 9 9 // Author : Andrew Beach 10 10 // Created On : Mon Jun 26 15:11:00 2017 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sat Jul 22 09:57:02201713 // Update Count : 311 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 4 15:20:00 2017 13 // Update Count : 5 14 14 // 15 15 16 16 #pragma once 17 17 18 // Later to be a special structure type.19 typedef int exception;20 18 21 19 #ifdef __CFORALL__ 22 20 extern "C" { 23 21 #endif 22 23 struct __cfaehm__base_exception_t; 24 typedef struct __cfaehm__base_exception_t exception; 25 struct __cfaehm__base_exception_t_vtable { 26 const struct __cfaehm__base_exception_t_vtable * parent; 27 size_t size; 28 void (*copy)(struct __cfaehm__base_exception_t *this, 29 struct __cfaehm__base_exception_t * other); 30 void (*free)(struct __cfaehm__base_exception_t *this); 31 const char (*msg)(struct __cfaehm__base_exception_t *this); 32 }; 33 struct __cfaehm__base_exception_t { 34 struct __cfaehm__base_exception_t_vtable const * virtual_table; 35 }; 36 extern struct __cfaehm__base_exception_t_vtable 37 ___cfaehm__base_exception_t_vtable_instance; 38 24 39 25 40 // Used in throw statement translation. … … 34 49 int (*match_block)(exception * except)); 35 50 51 // Clean-up the exception in catch blocks. 52 void __cfaehm__cleanup_terminate(void * except); 53 36 54 // Data structure creates a list of resume handlers. 37 55 struct __cfaehm__try_resume_node { … … 40 58 }; 41 59 60 // These act as constructor and destructor for the resume node. 42 61 void __cfaehm__try_resume_setup( 43 62 struct __cfaehm__try_resume_node * node, … … 47 66 48 67 // Check for a standard way to call fake deconstructors. 49 struct __cfaehm__cleanup_hook { 50 }; 68 struct __cfaehm__cleanup_hook {}; 51 69 52 70 #ifdef __CFORALL__ -
src/libcfa/iostream
r275f4b4 rcd7ef0b 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 7 08:35:59201713 // Update Count : 1 1812 // Last Modified On : Wed Aug 9 16:42:47 2017 13 // Update Count : 131 14 14 // 15 15 … … 46 46 }; // ostream 47 47 48 trait writeable( otype T ) { 49 forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T ); 48 // trait writeable( otype T ) { 49 // forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, T ); 50 // }; // writeable 51 52 trait writeable( otype T, dtype ostype | ostream( ostype ) ) { 53 ostype * ?|?( ostype *, T ); 50 54 }; // writeable 51 55 … … 77 81 78 82 // tuples 79 forall( dtype ostype, otype T, ttype Params | ostream( ostype ) | writeable( T ) | { ostype * ?|?( ostype *, Params ); } ) ostype * ?|?( ostype * os, T arg, Params rest ); 83 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype * ?|?( ostype *, Params ); } ) 84 ostype * ?|?( ostype * os, T arg, Params rest ); 80 85 81 86 // manipulators … … 90 95 91 96 // writes the range [begin, end) to the given stream 92 forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )93 void write( iterator_type begin, iterator_type end, os _type *os );97 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) 98 void write( iterator_type begin, iterator_type end, ostype * os ); 94 99 95 forall( otype elt_type | writeable( elt_type ), otype iterator_type | iterator( iterator_type, elt_type ), dtype os_type | ostream( os_type ) )96 void write_reverse( iterator_type begin, iterator_type end, os _type *os );100 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) 101 void write_reverse( iterator_type begin, iterator_type end, ostype * os ); 97 102 98 103 //--------------------------------------- -
src/libcfa/iostream.c
r275f4b4 rcd7ef0b 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jul 16 21:12:03201713 // Update Count : 39812 // Last Modified On : Wed Aug 9 16:46:51 2017 13 // Update Count : 401 14 14 // 15 15 … … 193 193 194 194 // tuples 195 forall( dtype ostype, otype T, ttype Params | ostream( ostype ) | writeable( T) | { ostype * ?|?( ostype *, Params ); } )195 forall( dtype ostype, otype T, ttype Params | writeable( T, ostype ) | { ostype * ?|?( ostype *, Params ); } ) 196 196 ostype * ?|?( ostype * os, T arg, Params rest ) { 197 197 os | arg; // print first argument … … 256 256 //--------------------------------------- 257 257 258 forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )259 void write( iterator type begin, iteratortype end, ostype * os ) {260 void print( elt type i ) { os | i; }258 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) 259 void write( iterator_type begin, iterator_type end, ostype * os ) { 260 void print( elt_type i ) { os | i; } 261 261 for_each( begin, end, print ); 262 262 } // ?|? 263 263 264 forall( otype elttype | writeable( elttype ), otype iteratortype | iterator( iteratortype, elttype ), dtype ostype | ostream( ostype ) )265 void write_reverse( iterator type begin, iteratortype end, ostype * os ) {266 void print( elt type i ) { os | i; }264 forall( dtype ostype, otype elt_type | writeable( elt_type, ostype ), otype iterator_type | iterator( iterator_type, elt_type ) ) 265 void write_reverse( iterator_type begin, iterator_type end, ostype * os ) { 266 void print( elt_type i ) { os | i; } 267 267 for_each_reverse( begin, end, print ); 268 268 } // ?|? -
src/libcfa/math
r275f4b4 rcd7ef0b 10 10 // Created On : Mon Apr 18 23:37:04 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 17:03:13201713 // Update Count : 10 112 // Last Modified On : Mon Aug 7 07:51:15 2017 13 // Update Count : 108 14 14 // 15 15 … … 18 18 #include <math.h> 19 19 #include <complex.h> 20 21 //---------------------- General ---------------------- 20 22 21 23 static inline float ?%?( float x, float y ) { return fmodf( x, y ); } … … 37 39 static inline [ int, long double ] remquo( long double x, long double y ) { int quo; x = remquol( x, y, &quo ); return [ quo, x ]; } 38 40 39 // alternative name for remquo 40 static inline float div( float x, float y, int * quo ) { return remquof( x, y, quo ); } 41 static inline double div( double x, double y, int * quo ) { return remquo( x, y, quo ); } 42 static inline long double div( long double x, long double y, int * quo ) { return remquol( x, y, quo ); } 43 static inline [ int, float ] div( float x, float y ) { int quo; x = remquof( x, y, &quo ); return [ quo, x ]; } 44 static inline [ int, double ] div( double x, double y ) { int quo; x = remquo( x, y, &quo ); return [ quo, x ]; } 45 static inline [ int, long double ] div( long double x, long double y ) { int quo; x = remquol( x, y, &quo ); return [ quo, x ]; } 41 static inline [ float, float ] div( float x, float y ) { y = modff( x / y, &x ); return [ x, y ]; } 42 static inline [ double, double ] div( double x, double y ) { y = modf( x / y, &x ); return [ x, y ]; } 43 static inline [ long double, long double ] div( long double x, long double y ) { y = modfl( x / y, &x ); return [ x, y ]; } 46 44 47 45 static inline float fma( float x, float y, float z ) { return fmaf( x, y, z ); } -
src/libcfa/stdhdr/assert.h
r275f4b4 rcd7ef0b 10 10 // Created On : Mon Jul 4 23:25:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 20 21:06:48201713 // Update Count : 1 112 // Last Modified On : Mon Jul 31 23:09:32 2017 13 // Update Count : 13 14 14 // 15 15 … … 25 25 #define __STRINGIFY__(str) #str 26 26 #define __VSTRINGIFY__(str) __STRINGIFY__(str) 27 #define assertf(expr, fmt, ...) ((expr) ? ((void)0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ )) 28 void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) __attribute__((noreturn)); 27 #define assertf( expr, fmt, ... ) ((expr) ? ((void)0) : __assert_fail_f(__VSTRINGIFY__(expr), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, ## __VA_ARGS__ )) 28 29 void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ) __attribute__((noreturn, format( printf, 5, 6) )); 29 30 #endif 30 31 -
src/libcfa/stdlib
r275f4b4 rcd7ef0b 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 20 14:32:37 201713 // Update Count : 22 012 // Last Modified On : Mon Aug 7 11:19:07 2017 13 // Update Count : 223 14 14 // 15 15 … … 183 183 //--------------------------------------- 184 184 185 [ int, int ] div( int num, int denom ); 186 [ long int, long int ] div( long int num, long int denom ); 187 [ long long int, long long int ] div( long long int num, long long int denom ); 185 188 forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } ) 186 [ T, T ] div( T t1, T t2);189 [ T, T ] div( T num, T demon ); 187 190 188 191 //--------------------------------------- -
src/libcfa/stdlib.c
r275f4b4 rcd7ef0b 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Jul 20 16:01:40201713 // Update Count : 2 8212 // Last Modified On : Tue Aug 8 17:31:13 2017 13 // Update Count : 291 14 14 // 15 15 … … 255 255 //--------------------------------------- 256 256 257 [ int, int ] div( int num, int denom ) { div_t qr = div( num, denom ); return [ qr.quot, qr.rem ]; } 258 [ long int, long int ] div( long int num, long int denom ) { ldiv_t qr = ldiv( num, denom ); return [ qr.quot, qr.rem ]; } 259 [ long long int, long long int ] div( long long int num, long long int denom ) { lldiv_t qr = lldiv( num, denom ); return [ qr.quot, qr.rem ]; } 257 260 forall( otype T | { T ?/?( T, T ); T ?%?( T, T ); } ) 258 [ T, T ] div( T t1, T t2 ) { return [ t1 / t2, t1 % t2]; }261 [ T, T ] div( T num, T denom ) { return [ num / denom, num % denom ]; } 259 262 260 263 //--------------------------------------- -
src/tests/.expect/32/math.txt
r275f4b4 rcd7ef0b 2 2 remainder:-1 -1 -1 3 3 remquo:7 0.0999999 7 0.1 7 0.0999999999999999999 4 div:7 0.0999999 7 0.1 7 0.09999999999999999994 div:7, 0.2 7, 0.2 7, 0.2 5 5 fma:-2 -2 -2 6 6 fdim:2 2 2 … … 55 55 frexp:0.5 3 0.5 3 0.5 3 56 56 ldexp:8 8 8 57 modf:2 0.3 2 0.3 2 0.3 nextafter:2 2 2 57 modf:2 0.3 2 0.3 2 0.3 58 modf:2, 0.3 2, 0.3 2, 0.3 59 nextafter:2 2 2 58 60 nexttoward:2 2 2 59 61 scalbn:16 16 16 -
src/tests/.expect/64/math.txt
r275f4b4 rcd7ef0b 2 2 remainder:-1 -1 -1 3 3 remquo:7 0.0999999 7 0.1 7 0.0999999999999999999 4 div:7 0.0999999 7 0.1 7 0.09999999999999999994 div:7, 0.2 7, 0.2 7, 0.2 5 5 fma:-2 -2 -2 6 6 fdim:2 2 2 … … 55 55 frexp:0.5 3 0.5 3 0.5 3 56 56 ldexp:8 8 8 57 modf:2 0.3 2 0.3 2 0.3 nextafter:2 2 2 57 modf:2 0.3 2 0.3 2 0.3 58 modf:2, 0.3 2, 0.3 2, 0.3 59 nextafter:2 2 2 58 60 nexttoward:2 2 2 59 61 scalbn:16 16 16 -
src/tests/designations.c
r275f4b4 rcd7ef0b 9 9 // Author : Rob Schluntz 10 10 // Created On : Thu Jun 29 15:26:36 2017 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Thu Ju n 29 15:27:05 201713 // Update Count : 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 27 11:46:35 2017 13 // Update Count : 3 14 14 // 15 15 … … 89 89 }; 90 90 91 struct Fred { 92 double i[3]; 93 int j; 94 struct Mary { 95 struct Jane { 96 double j; 97 } j; 98 double i; 99 } m; 100 }; 101 struct Fred s1 @= { .m.j : 3 }; 102 struct Fred s2 @= { .i : { [2] : 2 } }; 103 91 104 int main() { 92 105 // simple designation case - starting from beginning of structure, leaves ptr default-initialized (zero) … … 199 212 }; 200 213 #endif 201 214 // array designation 215 int i[2] = { [1] : 3 }; 202 216 // allowed to have 'too many' initialized lists - essentially they are ignored. 203 217 int i1 = { 3 }; … … 240 254 const char * str0 = "hello"; 241 255 char str1[] = "hello"; 256 const char c1[] = "abc"; 257 const char c2[] = { 'a', 'b', 'c' }; 258 const char c3[][2] = { { 'a', 'b' }, { 'c', 'd'}, { 'c', 'd'} }; 242 259 } 243 260 -
src/tests/except-0.c
r275f4b4 rcd7ef0b 6 6 #include <stdbool.h> 7 7 8 // Local type to mark exits from scopes. (see ERROR) 8 9 struct signal_exit { 9 10 const char * area; … … 19 20 } 20 21 21 void terminate(int except_value) { 22 23 // Local Exception Types and manual vtable types. 24 //#define TRIVIAL_EXCEPTION(name) //TRIVAL_EXCEPTION(yin) 25 struct yin; 26 struct yin_vtable { 27 struct exception_t_vtable const * parent; 28 size_t size; 29 void (*copy)(yin *this, yin * other); 30 void (*free)(yin *this); 31 const char (*msg)(yin *this); 32 }; 33 struct yin { 34 struct yin_vtable const * parent; 35 }; 36 void yin_msg(yin) { 37 return "in"; 38 } 39 yin_vtable _yin_vtable_instance = { 40 &_exception_t_vtable_instance, sizeof(yin), ?{}, ^?{}, yin_msg 41 } 42 43 44 void terminate(exception * except_value) { 22 45 signal_exit a = {"terminate function"}; 23 46 throw except_value; … … 25 48 } 26 49 27 void resume( intexcept_value) {50 void resume(exception * except_value) { 28 51 signal_exit a = {"resume function"}; 29 52 throwResume except_value; -
src/tests/math.c
r275f4b4 rcd7ef0b 10 10 // Created On : Fri Apr 22 14:59:21 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 10:32:04201713 // Update Count : 7 312 // Last Modified On : Wed Aug 9 07:20:49 2017 13 // Update Count : 77 14 14 // 15 15 … … 31 31 l = remquo( 3.6L, 0.5L, " ); 32 32 sout | quot | l | endl; 33 f = div( 3.6F, 0.5F, " ); 34 sout | "div:" | quot | f; 35 d = div( 3.6D, 0.5F, " ); 36 sout | quot | d; 37 l = div( 3.6L, 0.5L, " ); 38 sout | quot | l | endl; 33 sout | "div:" | div( 3.6F, 0.5F ) | div( 3.6D, 0.5D ) | div( 3.6L, 0.5L ) | endl; 39 34 sout | "fma:" | fma( 3.0F, -1.0F, 1.0F ) | fma( 3.0D, -1.0D, 1.0D ) | fma( 3.0L, -1.0L, , 1.0L ) | endl; 40 35 sout | "fdim:" | fdim( 1.0F, -1.0F ) | fdim( 1.0D, -1.0D ) | fdim( 1.0L, -1.0L ) | endl; … … 137 132 sout | di | d; 138 133 l = modf( 2.3L, &ldi ); 139 sout | ldi | l; 134 sout | ldi | l | endl; 135 sout | "modf:" | modf( 2.3F ) | modf( 2.3D ) | modf( 2.3L ) | endl; 140 136 sout | "nextafter:" | nextafter( 2.0F, 3.0F ) | nextafter( 2.0D, 3.0D ) | nextafter( 2.0L, 3.0L ) | endl; 141 137 sout | "nexttoward:" | nexttoward( 2.0F, 3.0F ) | nexttoward( 2.0D, 3.0D ) | nexttoward( 2.0L, 3.0L ) | endl;
Note:
See TracChangeset
for help on using the changeset viewer.