source: translator/SynTree/Mutator.h @ 4bf5298

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 4bf5298 was bdd516a, checked in by Peter A. Buhr <pabuhr@…>, 10 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
RevLine 
[51b7345]1#include <cassert>
2
3#include "SynTree.h"
4#include "SemanticError.h"
5
6#ifndef SYNTREE_MUTATOR_H
7#define SYNTREE_MUTATOR_H
8
[d9a0e76]9class Mutator {
10  protected:
[51b7345]11    Mutator();
12    virtual ~Mutator();
[d9a0e76]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 );
[51b7345]84};
85
86template< typename TreeType, typename MutatorType >
[d9a0e76]87inline TreeType *maybeMutate( TreeType *tree, MutatorType &mutator ) {
88    if ( tree ) {
[51b7345]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 >
[d9a0e76]99inline void mutateAll( Container &container, MutatorType &mutator ) {
[51b7345]100    SemanticError errors;
[d9a0e76]101    for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
[51b7345]102        try {
[d9a0e76]103            if ( *i ) {
[51b7345]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    }
[d9a0e76]112    if ( !errors.isEmpty() ) {
[51b7345]113        throw errors;
114    }
115}
116
[d9a0e76]117#endif // SYNTREE_MUTATOR_H
[51b7345]118
119// Local Variables: //
120// mode: c++ //
121// End:  //
Note: See TracBrowser for help on using the repository browser.