Changeset d9a0e76 for translator/SynTree/Mutator.h
- Timestamp:
- Dec 16, 2014, 9:41:50 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 17cd4eb
- Parents:
- 3848e0e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/SynTree/Mutator.h
r3848e0e rd9a0e76 1 /*2 * This file is part of the Cforall project3 *4 * $Id: Mutator.h,v 1.19 2005/08/29 20:59:25 rcbilson Exp $5 *6 */7 8 1 #include <cassert> 9 2 … … 14 7 #define SYNTREE_MUTATOR_H 15 8 16 17 class Mutator 18 { 19 protected: 9 class Mutator { 10 protected: 20 11 Mutator(); 21 12 virtual ~Mutator(); 13 public: 14 virtual ObjectDecl* mutate( ObjectDecl *objectDecl ); 15 virtual DeclarationWithType* mutate( FunctionDecl *functionDecl ); 16 virtual Declaration* mutate( StructDecl *aggregateDecl ); 17 virtual Declaration* mutate( UnionDecl *aggregateDecl ); 18 virtual Declaration* mutate( EnumDecl *aggregateDecl ); 19 virtual Declaration* mutate( ContextDecl *aggregateDecl ); 20 virtual TypeDecl* mutate( TypeDecl *typeDecl ); 21 virtual Declaration* mutate( TypedefDecl *typeDecl ); 22 22 23 public: 24 virtual ObjectDecl* mutate(ObjectDecl *objectDecl); 25 virtual DeclarationWithType* mutate(FunctionDecl *functionDecl); 26 virtual Declaration* mutate(StructDecl *aggregateDecl); 27 virtual Declaration* mutate(UnionDecl *aggregateDecl); 28 virtual Declaration* mutate(EnumDecl *aggregateDecl); 29 virtual Declaration* mutate(ContextDecl *aggregateDecl); 30 virtual TypeDecl* mutate(TypeDecl *typeDecl); 31 virtual Declaration* mutate(TypedefDecl *typeDecl); 23 virtual CompoundStmt* mutate( CompoundStmt *compoundStmt ); 24 virtual Statement* mutate( ExprStmt *exprStmt ); 25 virtual Statement* mutate( IfStmt *ifStmt ); 26 virtual Statement* mutate( WhileStmt *whileStmt ); 27 virtual Statement* mutate( ForStmt *forStmt ); 28 virtual Statement* mutate( SwitchStmt *switchStmt ); 29 virtual Statement* mutate( ChooseStmt *chooseStmt ); 30 virtual Statement* mutate( FallthruStmt *fallthruStmt ); 31 virtual Statement* mutate( CaseStmt *caseStmt ); 32 virtual Statement* mutate( BranchStmt *branchStmt ); 33 virtual Statement* mutate( ReturnStmt *returnStmt ); 34 virtual Statement* mutate( TryStmt *returnStmt ); 35 virtual Statement* mutate( CatchStmt *catchStmt ); 36 virtual Statement* mutate( FinallyStmt *catchStmt ); 37 virtual NullStmt* mutate( NullStmt *nullStmt ); 38 virtual Statement* mutate( DeclStmt *declStmt ); 32 39 33 virtual CompoundStmt* mutate(CompoundStmt *compoundStmt); 34 virtual Statement* mutate(ExprStmt *exprStmt); 35 virtual Statement* mutate(IfStmt *ifStmt); 36 virtual Statement* mutate(WhileStmt *whileStmt); 37 virtual Statement* mutate(ForStmt *forStmt); 38 virtual Statement* mutate(SwitchStmt *switchStmt); 39 virtual Statement* mutate(ChooseStmt *chooseStmt); 40 virtual Statement* mutate(FallthruStmt *fallthruStmt); 41 virtual Statement* mutate(CaseStmt *caseStmt); 42 virtual Statement* mutate(BranchStmt *branchStmt); 43 virtual Statement* mutate(ReturnStmt *returnStmt); 44 virtual Statement* mutate(TryStmt *returnStmt); 45 virtual Statement* mutate(CatchStmt *catchStmt); 46 virtual Statement* mutate(FinallyStmt *catchStmt); 47 virtual NullStmt* mutate(NullStmt *nullStmt); 48 virtual Statement* mutate(DeclStmt *declStmt); 40 virtual Expression* mutate( ApplicationExpr *applicationExpr ); 41 virtual Expression* mutate( UntypedExpr *untypedExpr ); 42 virtual Expression* mutate( NameExpr *nameExpr ); 43 virtual Expression* mutate( AddressExpr *castExpr ); 44 virtual Expression* mutate( LabelAddressExpr *labAddressExpr ); 45 virtual Expression* mutate( CastExpr *castExpr ); 46 virtual Expression* mutate( UntypedMemberExpr *memberExpr ); 47 virtual Expression* mutate( MemberExpr *memberExpr ); 48 virtual Expression* mutate( VariableExpr *variableExpr ); 49 virtual Expression* mutate( ConstantExpr *constantExpr ); 50 virtual Expression* mutate( SizeofExpr *sizeofExpr ); 51 virtual Expression* mutate( AttrExpr *attrExpr ); 52 virtual Expression* mutate( LogicalExpr *logicalExpr ); 53 virtual Expression* mutate( ConditionalExpr *conditionalExpr ); 54 virtual Expression* mutate( CommaExpr *commaExpr ); 55 virtual Expression* mutate( TupleExpr *tupleExpr ); 56 virtual Expression* mutate( SolvedTupleExpr *tupleExpr ); 57 virtual Expression* mutate( TypeExpr *typeExpr ); 58 virtual Expression* mutate( UntypedValofExpr *valofExpr ); 49 59 50 virtual Expression* mutate(ApplicationExpr *applicationExpr); 51 virtual Expression* mutate(UntypedExpr *untypedExpr); 52 virtual Expression* mutate(NameExpr *nameExpr); 53 virtual Expression* mutate(AddressExpr *castExpr); 54 virtual Expression* mutate(LabelAddressExpr *labAddressExpr); 55 virtual Expression* mutate(CastExpr *castExpr); 56 virtual Expression* mutate(UntypedMemberExpr *memberExpr); 57 virtual Expression* mutate(MemberExpr *memberExpr); 58 virtual Expression* mutate(VariableExpr *variableExpr); 59 virtual Expression* mutate(ConstantExpr *constantExpr); 60 virtual Expression* mutate(SizeofExpr *sizeofExpr); 61 virtual Expression* mutate(AttrExpr *attrExpr); 62 virtual Expression* mutate(LogicalExpr *logicalExpr); 63 virtual Expression* mutate(ConditionalExpr *conditionalExpr); 64 virtual Expression* mutate(CommaExpr *commaExpr); 65 virtual Expression* mutate(TupleExpr *tupleExpr); 66 virtual Expression* mutate(SolvedTupleExpr *tupleExpr); 67 virtual Expression* mutate(TypeExpr *typeExpr); 68 virtual Expression* mutate(UntypedValofExpr *valofExpr); 60 virtual Type* mutate( VoidType *basicType ); 61 virtual Type* mutate( BasicType *basicType ); 62 virtual Type* mutate( PointerType *pointerType ); 63 virtual Type* mutate( ArrayType *arrayType ); 64 virtual Type* mutate( FunctionType *functionType ); 65 virtual Type* mutate( StructInstType *aggregateUseType ); 66 virtual Type* mutate( UnionInstType *aggregateUseType ); 67 virtual Type* mutate( EnumInstType *aggregateUseType ); 68 virtual Type* mutate( ContextInstType *aggregateUseType ); 69 virtual Type* mutate( TypeInstType *aggregateUseType ); 70 virtual Type* mutate( TupleType *tupleType ); 71 virtual Type* mutate( TypeofType *typeofType ); 72 virtual Type* mutate( AttrType *attrType ); 69 73 70 virtual Type* mutate(VoidType *basicType); 71 virtual Type* mutate(BasicType *basicType); 72 virtual Type* mutate(PointerType *pointerType); 73 virtual Type* mutate(ArrayType *arrayType); 74 virtual Type* mutate(FunctionType *functionType); 75 virtual Type* mutate(StructInstType *aggregateUseType); 76 virtual Type* mutate(UnionInstType *aggregateUseType); 77 virtual Type* mutate(EnumInstType *aggregateUseType); 78 virtual Type* mutate(ContextInstType *aggregateUseType); 79 virtual Type* mutate(TypeInstType *aggregateUseType); 80 virtual Type* mutate(TupleType *tupleType); 81 virtual Type* mutate(TypeofType *typeofType); 82 virtual Type* mutate(AttrType *attrType); 74 virtual Initializer* mutate( MemberInit *memberInit ); 75 virtual Initializer* mutate( ElementInit *elementInit ); 76 virtual Initializer* mutate( SingleInit *singleInit ); 77 virtual Initializer* mutate( ListInit *listInit ); 83 78 84 virtual Initializer* mutate(MemberInit *memberInit); 85 virtual Initializer* mutate(ElementInit *elementInit); 86 virtual Initializer* mutate(SingleInit *singleInit); 87 virtual Initializer* mutate(ListInit *listInit); 79 virtual Subrange *mutate( Subrange *subrange ); 88 80 89 virtual Subrange *mutate(Subrange *subrange); 90 91 virtual Constant *mutate(Constant *constant); 92 93 private: 94 virtual Declaration* handleAggregateDecl(AggregateDecl *aggregateDecl); 95 virtual Declaration* handleNamedTypeDecl(NamedTypeDecl *typeDecl); 96 virtual Type* handleReferenceToType(ReferenceToType *aggregateUseType); 81 virtual Constant *mutate( Constant *constant ); 82 private: 83 virtual Declaration* handleAggregateDecl(AggregateDecl *aggregateDecl ); 84 virtual Declaration* handleNamedTypeDecl(NamedTypeDecl *typeDecl ); 85 virtual Type* handleReferenceToType(ReferenceToType *aggregateUseType ); 97 86 }; 98 87 99 88 template< typename TreeType, typename MutatorType > 100 inline TreeType * 101 maybeMutate( TreeType *tree, MutatorType &mutator ) 102 { 103 if( tree ) { 89 inline TreeType *maybeMutate( TreeType *tree, MutatorType &mutator ) { 90 if ( tree ) { 104 91 TreeType *newnode = dynamic_cast< TreeType* >( tree->acceptMutator( mutator ) ); 105 92 assert( newnode ); … … 112 99 113 100 template< typename Container, typename MutatorType > 114 inline void 115 mutateAll( Container &container, MutatorType &mutator ) 116 { 101 inline void mutateAll( Container &container, MutatorType &mutator ) { 117 102 SemanticError errors; 118 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {103 for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) { 119 104 try { 120 if ( *i ) {105 if ( *i ) { 121 106 /// *i = (*i)->acceptMutator( mutator ); 122 107 *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) ); … … 127 112 } 128 113 } 129 if ( !errors.isEmpty() ) {114 if ( !errors.isEmpty() ) { 130 115 throw errors; 131 116 } 132 117 } 133 118 134 135 136 #endif /* #ifndef SYNTREE_MUTATOR_H */ 119 #endif // SYNTREE_MUTATOR_H 137 120 138 121 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.