Changeset 1cb934d


Ignore:
Timestamp:
Nov 30, 2017, 5:11:59 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
1fbeebd
Parents:
fd236ed
Message:

Convert FixGlobalInit? to PassVisitor?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixGlobalInit.cc

    rfd236ed r1cb934d  
    2020#include <algorithm>               // for replace_if
    2121
     22#include "Common/PassVisitor.h"
    2223#include "Common/SemanticError.h"  // for SemanticError
    2324#include "Common/UniqueName.h"     // for UniqueName
     
    3536
    3637namespace InitTweak {
    37         class GlobalFixer : public Visitor {
     38        class GlobalFixer : public WithShortCircuiting {
    3839          public:
    3940                GlobalFixer( const std::string & name, bool inLibrary );
    4041
    41                 virtual void visit( ObjectDecl *objDecl );
    42                 virtual void visit( FunctionDecl *functionDecl );
    43                 virtual void visit( StructDecl *aggregateDecl );
    44                 virtual void visit( UnionDecl *aggregateDecl );
    45                 virtual void visit( EnumDecl *aggregateDecl );
    46                 virtual void visit( TraitDecl *aggregateDecl );
    47                 virtual void visit( TypeDecl *typeDecl );
     42                void previsit( ObjectDecl *objDecl );
     43                void previsit( FunctionDecl *functionDecl );
     44                void previsit( StructDecl *aggregateDecl );
     45                void previsit( UnionDecl *aggregateDecl );
     46                void previsit( EnumDecl *aggregateDecl );
     47                void previsit( TraitDecl *aggregateDecl );
     48                void previsit( TypeDecl *typeDecl );
    4849
    4950                UniqueName tempNamer;
     
    5354
    5455        void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name, bool inLibrary ) {
    55                 GlobalFixer fixer( name, inLibrary );
    56                 acceptAll( translationUnit, fixer );
     56                PassVisitor<GlobalFixer> visitor( name, inLibrary );
     57                acceptAll( translationUnit, visitor );
     58                GlobalFixer & fixer = visitor.pass;
    5759                // don't need to include function if it's empty
    5860                if ( fixer.initFunction->get_statements()->get_kids().empty() ) {
     
    98100        }
    99101
    100         void GlobalFixer::visit( ObjectDecl *objDecl ) {
     102        void GlobalFixer::previsit( ObjectDecl *objDecl ) {
    101103                std::list< Statement * > & initStatements = initFunction->get_statements()->get_kids();
    102104                std::list< Statement * > & destroyStatements = destroyFunction->get_statements()->get_kids();
     
    134136
    135137        // only modify global variables
    136         void GlobalFixer::visit( __attribute__((unused)) FunctionDecl *functionDecl ) {}
    137         void GlobalFixer::visit( __attribute__((unused)) StructDecl *aggregateDecl ) {}
    138         void GlobalFixer::visit( __attribute__((unused)) UnionDecl *aggregateDecl ) {}
    139         void GlobalFixer::visit( __attribute__((unused)) EnumDecl *aggregateDecl ) {}
    140         void GlobalFixer::visit( __attribute__((unused)) TraitDecl *aggregateDecl ) {}
    141         void GlobalFixer::visit( __attribute__((unused)) TypeDecl *typeDecl ) {}
     138        void GlobalFixer::previsit( FunctionDecl * ) { visit_children = false; }
     139        void GlobalFixer::previsit( StructDecl * ) { visit_children = false; }
     140        void GlobalFixer::previsit( UnionDecl * ) { visit_children = false; }
     141        void GlobalFixer::previsit( EnumDecl * ) { visit_children = false; }
     142        void GlobalFixer::previsit( TraitDecl * ) { visit_children = false; }
     143        void GlobalFixer::previsit( TypeDecl * ) { visit_children = false; }
    142144
    143145} // namespace InitTweak
Note: See TracChangeset for help on using the changeset viewer.