-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast.h
77 lines (61 loc) · 1.22 KB
/
ast.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
#pragma once
#include "symboltable.h"
// forward declarations
//////////////////// general
class ast
{
protected:
string indent(int lvl);
string debugoptype(int optype);
public:
ast()
{ }
virtual void debug(int ind)
{ }
virtual void semanticCheck()
{ }
virtual void createTypes()
{ }
virtual registerid generateCode(operation* &p)
{ return 0; }
virtual ~ast()
{ }
};
template <class T>
class astnodelist
{
private:
typename std::vector<T> contents;
typename std::vector<T>::iterator it;
public:
void add(T newx)
{ contents.push_back(newx); }
void begin()
{ it = contents.begin(); }
bool atEnd()
{ return it == contents.end(); }
T getCurrent()
{ return (*it); }
void gotoNext()
{ it++; }
void debug(int ind);
virtual ~astnodelist();
};
template <class T>
void astnodelist<T>::debug(int ind)
{
typename std::vector<T>::iterator i;
for (i = contents.begin() ; i != contents.end() ; i++) {
ast* p = *i;
p->debug(ind);
}
}
template <class T>
astnodelist<T>::~astnodelist()
{
typename std::vector<T>::iterator i;
for (i = contents.begin() ; i != contents.end() ; i++) {
ast* p = *i;
delete p; // virtual destructor will ensure the correct stuff gets done
}
}