-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASTVisitor.h
90 lines (87 loc) · 4.55 KB
/
ASTVisitor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
#include "AST.h"
/*! \brief Base class for AST visitors.
*
* The AST visitor class abstracts the traversal of an AST. It works
* in concert with the accept methods of ASTNode subtypes. Each of those
* nodes performs a traversal of its children in an order corresponding to
* their appearance in the source program. This class defines default behavior
* for the processing performed when the traversal reaches a node of a given type.
* By default the visit method returns true, indicating that the children of
* the node should also be visited, and the endVisit method does nothing.
*
* Subtypes of ASTVisitor will selectively override these default methods.
* Overriding a visit permits a pre-order processing during traversal and
* overriding endVisit permits a post-order processing.
*
* Subtype of ASTVisitor will also define member data that can be referenced
* by overridden methods to communicate information along the traversal to
* future method invocations.
*/
class ASTVisitor {
public:
virtual bool visit(ASTProgram * element) { return true; }
virtual void endVisit(ASTProgram * element) {}
virtual bool visit(ASTFunction * element) { return true; }
virtual void endVisit(ASTFunction * element) {}
virtual bool visit(ASTNumberExpr * element) { return true; }
virtual void endVisit(ASTNumberExpr * element) {}
virtual bool visit(ASTVariableExpr * element) { return true; }
virtual void endVisit(ASTVariableExpr * element) {}
virtual bool visit(ASTBinaryExpr * element) { return true; }
virtual void endVisit(ASTBinaryExpr * element) {}
virtual bool visit(ASTInputExpr * element) { return true; }
virtual void endVisit(ASTInputExpr * element) {}
virtual bool visit(ASTFunAppExpr * element) { return true; }
virtual void endVisit(ASTFunAppExpr * element) {}
virtual bool visit(ASTAllocExpr * element) { return true; }
virtual void endVisit(ASTAllocExpr * element) {}
virtual bool visit(ASTRefExpr * element) { return true; }
virtual void endVisit(ASTRefExpr * element) {}
virtual bool visit(ASTDeRefExpr * element) { return true; }
virtual void endVisit(ASTDeRefExpr * element) {}
virtual bool visit(ASTNullExpr * element) { return true; }
virtual void endVisit(ASTNullExpr * element) {}
virtual bool visit(ASTFieldExpr * element) { return true; }
virtual void endVisit(ASTFieldExpr * element) {}
virtual bool visit(ASTRecordExpr * element) { return true; }
virtual void endVisit(ASTRecordExpr * element) {}
virtual bool visit(ASTAccessExpr * element) { return true; }
virtual void endVisit(ASTAccessExpr * element) {}
virtual bool visit(ASTDeclNode * element) { return true; }
virtual void endVisit(ASTDeclNode * element) {}
virtual bool visit(ASTDeclStmt * element) { return true; }
virtual void endVisit(ASTDeclStmt * element) {}
virtual bool visit(ASTAssignStmt * element) { return true; }
virtual void endVisit(ASTAssignStmt * element) {}
virtual bool visit(ASTWhileStmt * element) { return true; }
virtual void endVisit(ASTWhileStmt * element) {}
virtual bool visit(ASTIfStmt * element) { return true; }
virtual void endVisit(ASTIfStmt * element) {}
virtual bool visit(ASTOutputStmt * element) { return true; }
virtual void endVisit(ASTOutputStmt * element) {}
virtual bool visit(ASTReturnStmt * element) { return true; }
virtual void endVisit(ASTReturnStmt * element) {}
virtual bool visit(ASTErrorStmt * element) { return true; }
virtual void endVisit(ASTErrorStmt * element) {}
virtual bool visit(ASTBlockStmt * element) { return true; }
virtual void endVisit(ASTBlockStmt * element) {}
virtual bool visit(ASTUnaryExpr * element) { return true; }
virtual void endVisit(ASTUnaryExpr * element) {}
virtual bool visit(ASTTernaryExpr * element) { return true; }
virtual void endVisit(ASTTernaryExpr * element) {}
virtual bool visit(ASTIncDecStmt * element) { return true; }
virtual void endVisit(ASTIncDecStmt * element) {}
virtual bool visit(ASTForStmt * element) { return true; }
virtual void endVisit(ASTForStmt * element) {}
virtual bool visit(ASTForEachStmt * element) { return true; }
virtual void endVisit(ASTForEachStmt * element) {}
virtual bool visit(ASTMainArray * element) { return true; }
virtual void endVisit(ASTMainArray * element) {}
virtual bool visit(ASTAlternateArray * element) { return true; }
virtual void endVisit(ASTAlternateArray * element) {}
virtual bool visit(ASTBoolExpr * element) { return true; }
virtual void endVisit(ASTBoolExpr * element) {}
virtual bool visit(ASTArrIndex * element) { return true; }
virtual void endVisit(ASTArrIndex * element) {}
};