Changes in src/InitTweak/FixGlobalInit.cc [1cb934d:ea6332d]
- File:
-
- 1 edited
-
src/InitTweak/FixGlobalInit.cc (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/InitTweak/FixGlobalInit.cc
r1cb934d rea6332d 20 20 #include <algorithm> // for replace_if 21 21 22 #include "Common/PassVisitor.h"23 22 #include "Common/SemanticError.h" // for SemanticError 24 23 #include "Common/UniqueName.h" // for UniqueName … … 30 29 #include "SynTree/Expression.h" // for ConstantExpr, Expression (ptr only) 31 30 #include "SynTree/Initializer.h" // for ConstructorInit, Initializer 32 #include "SynTree/Label.h" // for Label 31 #include "SynTree/Label.h" // for Label, noLabels 33 32 #include "SynTree/Statement.h" // for CompoundStmt, Statement (ptr only) 34 33 #include "SynTree/Type.h" // for Type, Type::StorageClasses, Functi... … … 36 35 37 36 namespace InitTweak { 38 class GlobalFixer : public WithShortCircuiting{37 class GlobalFixer : public Visitor { 39 38 public: 40 39 GlobalFixer( const std::string & name, bool inLibrary ); 41 40 42 v oid previsit( ObjectDecl *objDecl );43 v oid previsit( FunctionDecl *functionDecl );44 v oid previsit( StructDecl *aggregateDecl );45 v oid previsit( UnionDecl *aggregateDecl );46 v oid previsit( EnumDecl *aggregateDecl );47 v oid previsit( TraitDecl *aggregateDecl );48 v oid 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 ); 49 48 50 49 UniqueName tempNamer; … … 54 53 55 54 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 ); 59 57 // don't need to include function if it's empty 60 58 if ( fixer.initFunction->get_statements()->get_kids().empty() ) { … … 94 92 dtorParameters.push_back( new ConstantExpr( Constant::from_int( 102 ) ) ); 95 93 } 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 ) ); 97 95 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 ) ); 99 97 destroyFunction->get_attributes().push_back( new Attribute( "destructor", dtorParameters ) ); 100 98 } 101 99 102 void GlobalFixer:: previsit( ObjectDecl *objDecl ) {100 void GlobalFixer::visit( ObjectDecl *objDecl ) { 103 101 std::list< Statement * > & initStatements = initFunction->get_statements()->get_kids(); 104 102 std::list< Statement * > & destroyStatements = destroyFunction->get_statements()->get_kids(); … … 136 134 137 135 // 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 ) {} 144 142 145 143 } // namespace InitTweak
Note:
See TracChangeset
for help on using the changeset viewer.