source: translator/SynTree/Mutator.h @ c11e31c

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 c11e31c was bdd516a, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

fixed sizeof type variable, find lowest cost alternative for sizeof expression, removed unused classes, added compiler flag, remove temporary file for -CFA, formatting

  • Property mode set to 100644
File size: 4.7 KB
Line 
1#include <cassert>
2
3#include "SynTree.h"
4#include "SemanticError.h"
5
6#ifndef SYNTREE_MUTATOR_H
7#define SYNTREE_MUTATOR_H
8
9class Mutator {
10  protected:
11    Mutator();
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
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 );
39
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 );
59
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 );
73
74    virtual Initializer* mutate( SingleInit *singleInit );
75    virtual Initializer* mutate( ListInit *listInit );
76
77    virtual Subrange *mutate( Subrange *subrange );
78
79    virtual Constant *mutate( Constant *constant );
80  private:
81    virtual Declaration* handleAggregateDecl(AggregateDecl *aggregateDecl );
82    virtual Declaration* handleNamedTypeDecl(NamedTypeDecl *typeDecl );
83    virtual Type* handleReferenceToType(ReferenceToType *aggregateUseType );
84};
85
86template< typename TreeType, typename MutatorType >
87inline TreeType *maybeMutate( TreeType *tree, MutatorType &mutator ) {
88    if ( tree ) {
89        TreeType *newnode = dynamic_cast< TreeType* >( tree->acceptMutator( mutator ) );
90        assert( newnode );
91        return newnode;
92///         return tree->acceptMutator( mutator );
93    } else {
94        return 0;
95    }
96}
97
98template< typename Container, typename MutatorType >
99inline void mutateAll( Container &container, MutatorType &mutator ) {
100    SemanticError errors;
101    for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
102        try {
103            if ( *i ) {
104///                 *i = (*i)->acceptMutator( mutator );
105                *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) );
106                assert( *i );
107            }
108        } catch( SemanticError &e ) {
109            errors.append( e );
110        }
111    }
112    if ( !errors.isEmpty() ) {
113        throw errors;
114    }
115}
116
117#endif // SYNTREE_MUTATOR_H
118
119// Local Variables: //
120// mode: c++ //
121// End:  //
Note: See TracBrowser for help on using the repository browser.