Changeset b4bfa0a


Ignore:
Timestamp:
Sep 25, 2017, 5:04:00 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
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)
Message:

Convert LayoutFunctionBuilder? to PassVisitor?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r696bf6e rb4bfa0a  
    3232#include "Common/UniqueName.h"           // for UniqueName
    3333#include "Common/utility.h"              // for toString
    34 #include "DeclMutator.h"                 // for DeclMutator
    3534#include "FindFunction.h"                // for findFunction, findAndReplace...
    3635#include "GenPoly/ErasableScopedMap.h"   // for ErasableScopedMap<>::const_i...
     
    6362
    6463                /// Adds layout-generation functions to polymorphic types
    65                 class LayoutFunctionBuilder final : public DeclMutator {
    66                         unsigned int functionNesting;  // current level of nested functions
     64                class LayoutFunctionBuilder final : public WithDeclsToAdd, public WithVisitorRef<LayoutFunctionBuilder>, public WithShortCircuiting {
     65                        unsigned int functionNesting = 0;  // current level of nested functions
    6766                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 );
    7470                };
    7571
     
    247243
    248244        void box( std::list< Declaration *>& translationUnit ) {
    249                 LayoutFunctionBuilder layoutBuilder;
     245                PassVisitor<LayoutFunctionBuilder> layoutBuilder;
    250246                Pass1 pass1;
    251247                Pass2 pass2;
     
    253249                Pass3 pass3;
    254250
    255                 layoutBuilder.mutateDeclarationList( translationUnit );
     251                acceptAll( translationUnit, layoutBuilder );
    256252                mutateTranslationUnit/*All*/( translationUnit, pass1 );
    257253                mutateTranslationUnit/*All*/( translationUnit, pass2 );
     
    262258        ////////////////////////////////// LayoutFunctionBuilder ////////////////////////////////////////////
    263259
    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 );
    266263                ++functionNesting;
    267                 functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );
     264                maybeAccept( functionDecl->get_statements(), *visitor );
    268265                --functionNesting;
    269                 return functionDecl;
    270266        }
    271267
     
    356352        }
    357353
    358         Declaration *LayoutFunctionBuilder::mutate( StructDecl *structDecl ) {
     354        void LayoutFunctionBuilder::previsit( StructDecl *structDecl ) {
    359355                // 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;
    361358
    362359                // get parameters that can change layout, exiting early if none
    363360                std::list< TypeDecl* > otypeParams = takeOtypeOnly( structDecl->get_parameters() );
    364                 if ( otypeParams.empty() ) return structDecl;
     361                if ( otypeParams.empty() ) return;
    365362
    366363                // build layout function signature
     
    413410                addStmt( layoutDecl->get_statements(), makeAlignTo( derefVar( sizeParam ), derefVar( alignParam ) ) );
    414411
    415                 addDeclarationAfter( layoutDecl );
    416                 return structDecl;
     412                declsToAddAfter.push_back( layoutDecl );
    417413        }
    418414
    419         Declaration *LayoutFunctionBuilder::mutate( UnionDecl *unionDecl ) {
     415        void LayoutFunctionBuilder::previsit( UnionDecl *unionDecl ) {
    420416                // 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;
    422419
    423420                // get parameters that can change layout, exiting early if none
    424421                std::list< TypeDecl* > otypeParams = takeOtypeOnly( unionDecl->get_parameters() );
    425                 if ( otypeParams.empty() ) return unionDecl;
     422                if ( otypeParams.empty() ) return;
    426423
    427424                // build layout function signature
     
    456453                addStmt( layoutDecl->get_statements(), makeAlignTo( derefVar( sizeParam ), derefVar( alignParam ) ) );
    457454
    458                 addDeclarationAfter( layoutDecl );
    459                 return unionDecl;
     455                declsToAddAfter.push_back( layoutDecl );
    460456        }
    461457
Note: See TracChangeset for help on using the changeset viewer.