-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathVisitor.h
More file actions
35 lines (29 loc) · 1.13 KB
/
Visitor.h
File metadata and controls
35 lines (29 loc) · 1.13 KB
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
#pragma once
#include "Syntax.h"
/// Expression visitor base class. The typechecker and code generator are
/// implemented as visitors, which allows all of the logic for a pass to be
/// defined in a single class, rather than being scattered throughout separate
/// methods in the the various syntax classes. A visitor can also retain
/// state in member variables. For example, the typechecker visitor contains
/// a symbol table (\see Scope) that is extended as variable declarations are
/// processed.
class ExpVisitor
{
public:
virtual void* Visit( BoolExp& exp ) = 0;
virtual void* Visit( IntExp& exp ) = 0;
virtual void* Visit( VarExp& exp ) = 0;
virtual void* Visit( CallExp& exp ) = 0;
};
/// Statement visitor base class.
class StmtVisitor
{
public:
virtual void Visit( CallStmt& exp ) = 0;
virtual void Visit( AssignStmt& exp ) = 0;
virtual void Visit( DeclStmt& exp ) = 0;
virtual void Visit( ReturnStmt& exp ) = 0;
virtual void Visit( SeqStmt& exp ) = 0;
virtual void Visit( IfStmt& exp ) = 0;
virtual void Visit( WhileStmt& exp ) = 0;
};