Changeset b4bfa0a for src/GenPoly
- Timestamp:
- Sep 25, 2017, 5:04:00 PM (7 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:
- ac74057
- Parents:
- 696bf6e
- git-author:
- Rob Schluntz <rschlunt@…> (09/25/17 16:04:02)
- git-committer:
- Rob Schluntz <rschlunt@…> (09/25/17 17:04:00)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r696bf6e rb4bfa0a 32 32 #include "Common/UniqueName.h" // for UniqueName 33 33 #include "Common/utility.h" // for toString 34 #include "DeclMutator.h" // for DeclMutator35 34 #include "FindFunction.h" // for findFunction, findAndReplace... 36 35 #include "GenPoly/ErasableScopedMap.h" // for ErasableScopedMap<>::const_i... … … 63 62 64 63 /// Adds layout-generation functions to polymorphic types 65 class LayoutFunctionBuilder final : public DeclMutator{66 unsigned int functionNesting ; // current level of nested functions64 class LayoutFunctionBuilder final : public WithDeclsToAdd, public WithVisitorRef<LayoutFunctionBuilder>, public WithShortCircuiting { 65 unsigned int functionNesting = 0; // current level of nested functions 67 66 public: 68 LayoutFunctionBuilder() : functionNesting( 0 ) {} 69 70 using DeclMutator::mutate; 71 virtual DeclarationWithType *mutate( FunctionDecl *functionDecl ) override; 72 virtual Declaration *mutate( StructDecl *structDecl ) override; 73 virtual Declaration *mutate( UnionDecl *unionDecl ) override; 67 void previsit( FunctionDecl *functionDecl ); 68 void previsit( StructDecl *structDecl ); 69 void previsit( UnionDecl *unionDecl ); 74 70 }; 75 71 … … 247 243 248 244 void box( std::list< Declaration *>& translationUnit ) { 249 LayoutFunctionBuilderlayoutBuilder;245 PassVisitor<LayoutFunctionBuilder> layoutBuilder; 250 246 Pass1 pass1; 251 247 Pass2 pass2; … … 253 249 Pass3 pass3; 254 250 255 layoutBuilder.mutateDeclarationList( translationUnit);251 acceptAll( translationUnit, layoutBuilder ); 256 252 mutateTranslationUnit/*All*/( translationUnit, pass1 ); 257 253 mutateTranslationUnit/*All*/( translationUnit, pass2 ); … … 262 258 ////////////////////////////////// LayoutFunctionBuilder //////////////////////////////////////////// 263 259 264 DeclarationWithType *LayoutFunctionBuilder::mutate( FunctionDecl *functionDecl ) { 265 functionDecl->set_functionType( maybeMutate( functionDecl->get_functionType(), *this ) ); 260 void LayoutFunctionBuilder::previsit( FunctionDecl *functionDecl ) { 261 visit_children = false; 262 maybeAccept( functionDecl->get_functionType(), *visitor ); 266 263 ++functionNesting; 267 functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ));264 maybeAccept( functionDecl->get_statements(), *visitor ); 268 265 --functionNesting; 269 return functionDecl;270 266 } 271 267 … … 356 352 } 357 353 358 Declaration *LayoutFunctionBuilder::mutate( StructDecl *structDecl ) {354 void LayoutFunctionBuilder::previsit( StructDecl *structDecl ) { 359 355 // do not generate layout function for "empty" tag structs 360 if ( structDecl->get_members().empty() ) return structDecl; 356 visit_children = false; 357 if ( structDecl->get_members().empty() ) return; 361 358 362 359 // get parameters that can change layout, exiting early if none 363 360 std::list< TypeDecl* > otypeParams = takeOtypeOnly( structDecl->get_parameters() ); 364 if ( otypeParams.empty() ) return structDecl;361 if ( otypeParams.empty() ) return; 365 362 366 363 // build layout function signature … … 413 410 addStmt( layoutDecl->get_statements(), makeAlignTo( derefVar( sizeParam ), derefVar( alignParam ) ) ); 414 411 415 addDeclarationAfter( layoutDecl ); 416 return structDecl; 412 declsToAddAfter.push_back( layoutDecl ); 417 413 } 418 414 419 Declaration *LayoutFunctionBuilder::mutate( UnionDecl *unionDecl ) {415 void LayoutFunctionBuilder::previsit( UnionDecl *unionDecl ) { 420 416 // do not generate layout function for "empty" tag unions 421 if ( unionDecl->get_members().empty() ) return unionDecl; 417 visit_children = false; 418 if ( unionDecl->get_members().empty() ) return; 422 419 423 420 // get parameters that can change layout, exiting early if none 424 421 std::list< TypeDecl* > otypeParams = takeOtypeOnly( unionDecl->get_parameters() ); 425 if ( otypeParams.empty() ) return unionDecl;422 if ( otypeParams.empty() ) return; 426 423 427 424 // build layout function signature … … 456 453 addStmt( layoutDecl->get_statements(), makeAlignTo( derefVar( sizeParam ), derefVar( alignParam ) ) ); 457 454 458 addDeclarationAfter( layoutDecl ); 459 return unionDecl; 455 declsToAddAfter.push_back( layoutDecl ); 460 456 } 461 457
Note: See TracChangeset
for help on using the changeset viewer.