Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/InitTweak/FixGlobalInit.cc

    r1cb934d rea6332d  
    2020#include <algorithm>               // for replace_if
    2121
    22 #include "Common/PassVisitor.h"
    2322#include "Common/SemanticError.h"  // for SemanticError
    2423#include "Common/UniqueName.h"     // for UniqueName
     
    3029#include "SynTree/Expression.h"    // for ConstantExpr, Expression (ptr only)
    3130#include "SynTree/Initializer.h"   // for ConstructorInit, Initializer
    32 #include "SynTree/Label.h"         // for Label
     31#include "SynTree/Label.h"         // for Label, noLabels
    3332#include "SynTree/Statement.h"     // for CompoundStmt, Statement (ptr only)
    3433#include "SynTree/Type.h"          // for Type, Type::StorageClasses, Functi...
     
    3635
    3736namespace InitTweak {
    38         class GlobalFixer : public WithShortCircuiting {
     37        class GlobalFixer : public Visitor {
    3938          public:
    4039                GlobalFixer( const std::string & name, bool inLibrary );
    4140
    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 );
     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 );
    4948
    5049                UniqueName tempNamer;
     
    5453
    5554        void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name, bool inLibrary ) {
    56                 PassVisitor<GlobalFixer> visitor( name, inLibrary );
    57                 acceptAll( translationUnit, visitor );
    58                 GlobalFixer & fixer = visitor.pass;
     55                GlobalFixer fixer( name, inLibrary );
     56                acceptAll( translationUnit, fixer );
    5957                // don't need to include function if it's empty
    6058                if ( fixer.initFunction->get_statements()->get_kids().empty() ) {
     
    9492                        dtorParameters.push_back( new ConstantExpr( Constant::from_int( 102 ) ) );
    9593                }
    96                 initFunction = new FunctionDecl( "_init_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() );
     94                initFunction = new FunctionDecl( "_init_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ) );
    9795                initFunction->get_attributes().push_back( new Attribute( "constructor", ctorParameters ) );
    98                 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt() );
     96                destroyFunction = new FunctionDecl( "_destroy_" + fixedName, Type::StorageClasses( Type::Static ), LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ) );
    9997                destroyFunction->get_attributes().push_back( new Attribute( "destructor", dtorParameters ) );
    10098        }
    10199
    102         void GlobalFixer::previsit( ObjectDecl *objDecl ) {
     100        void GlobalFixer::visit( ObjectDecl *objDecl ) {
    103101                std::list< Statement * > & initStatements = initFunction->get_statements()->get_kids();
    104102                std::list< Statement * > & destroyStatements = destroyFunction->get_statements()->get_kids();
     
    136134
    137135        // only modify global variables
    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; }
     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 ) {}
    144142
    145143} // namespace InitTweak
Note: See TracChangeset for help on using the changeset viewer.