1 | #include <cassert>
|
---|
2 |
|
---|
3 | #include "SynTree.h"
|
---|
4 | #include "SemanticError.h"
|
---|
5 |
|
---|
6 | #ifndef SYNTREE_MUTATOR_H
|
---|
7 | #define SYNTREE_MUTATOR_H
|
---|
8 |
|
---|
9 | class 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( MemberInit *memberInit );
|
---|
75 | virtual Initializer* mutate( ElementInit *elementInit );
|
---|
76 | virtual Initializer* mutate( SingleInit *singleInit );
|
---|
77 | virtual Initializer* mutate( ListInit *listInit );
|
---|
78 |
|
---|
79 | virtual Subrange *mutate( Subrange *subrange );
|
---|
80 |
|
---|
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 );
|
---|
86 | };
|
---|
87 |
|
---|
88 | template< typename TreeType, typename MutatorType >
|
---|
89 | inline TreeType *maybeMutate( TreeType *tree, MutatorType &mutator ) {
|
---|
90 | if ( tree ) {
|
---|
91 | TreeType *newnode = dynamic_cast< TreeType* >( tree->acceptMutator( mutator ) );
|
---|
92 | assert( newnode );
|
---|
93 | return newnode;
|
---|
94 | /// return tree->acceptMutator( mutator );
|
---|
95 | } else {
|
---|
96 | return 0;
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | template< typename Container, typename MutatorType >
|
---|
101 | inline void mutateAll( Container &container, MutatorType &mutator ) {
|
---|
102 | SemanticError errors;
|
---|
103 | for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
|
---|
104 | try {
|
---|
105 | if ( *i ) {
|
---|
106 | /// *i = (*i)->acceptMutator( mutator );
|
---|
107 | *i = dynamic_cast< typename Container::value_type >( (*i)->acceptMutator( mutator ) );
|
---|
108 | assert( *i );
|
---|
109 | }
|
---|
110 | } catch( SemanticError &e ) {
|
---|
111 | errors.append( e );
|
---|
112 | }
|
---|
113 | }
|
---|
114 | if ( !errors.isEmpty() ) {
|
---|
115 | throw errors;
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | #endif // SYNTREE_MUTATOR_H
|
---|
120 |
|
---|
121 | // Local Variables: //
|
---|
122 | // mode: c++ //
|
---|
123 | // End: //
|
---|