source: translator/SynTree/Mutator.h @ 42dcae7

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 42dcae7 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * This file is part of the Cforall project
3 *
4 * $Id: Mutator.h,v 1.19 2005/08/29 20:59:25 rcbilson Exp $
5 *
6 */
7
8#include <cassert>
9
10#include "SynTree.h"
11#include "SemanticError.h"
12
13#ifndef SYNTREE_MUTATOR_H
14#define SYNTREE_MUTATOR_H
15
16
17class Mutator
18{
19protected:
20    Mutator();
21    virtual ~Mutator();
22
23public:
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);
32
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);
49
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);
69
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);
83
84    virtual Initializer* mutate(MemberInit *memberInit);
85    virtual Initializer* mutate(ElementInit *elementInit);
86    virtual Initializer* mutate(SingleInit *singleInit);
87    virtual Initializer* mutate(ListInit *listInit);
88
89    virtual Subrange *mutate(Subrange *subrange);
90
91    virtual Constant *mutate(Constant *constant);
92
93private:
94    virtual Declaration* handleAggregateDecl(AggregateDecl *aggregateDecl);
95    virtual Declaration* handleNamedTypeDecl(NamedTypeDecl *typeDecl);
96    virtual Type* handleReferenceToType(ReferenceToType *aggregateUseType);
97};
98
99template< typename TreeType, typename MutatorType >
100inline TreeType *
101maybeMutate( TreeType *tree, MutatorType &mutator )
102{
103    if( tree ) {
104        TreeType *newnode = dynamic_cast< TreeType* >( tree->acceptMutator( mutator ) );
105        assert( newnode );
106        return newnode;
107///         return tree->acceptMutator( mutator );
108    } else {
109        return 0;
110    }
111}
112
113template< typename Container, typename MutatorType >
114inline void
115mutateAll( Container &container, MutatorType &mutator )
116{
117    SemanticError errors;
118    for( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
119        try {
120            if( *i ) {
121///                 *i = (*i)->acceptMutator( mutator );
122                *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) );
123                assert( *i );
124            }
125        } catch( SemanticError &e ) {
126            errors.append( e );
127        }
128    }
129    if( !errors.isEmpty() ) {
130        throw errors;
131    }
132}
133
134
135
136#endif /* #ifndef SYNTREE_MUTATOR_H */
137
138// Local Variables: //
139// mode: c++ //
140// End:  //
Note: See TracBrowser for help on using the repository browser.