blob: 3858fc6b43692ed11c99575c21f7aa49b743488f (
plain)
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
|
#ifndef PCC_DECLNODE_HH
#define PCC_DECLNODE_HH
#include <list>
#include "BaseNode.hh"
#include "LiteralNode.hh"
namespace pcc {
class DeclNode : public BaseNode {
public:
DeclNode(Context* context, VariableList* scope);
// the scope of variable is an inherited attribute, but we don't have a good
// way to set inherited attribute during the construction of AST, so we call
// this in parent's constructor.
void SetScope(VariableList* scope);
virtual Value CodeGen() = 0;
protected:
VariableList* scope_;
};
class VarDeclNode : public DeclNode {
public:
VarDeclNode(Context* context, VariableList* scope,
std::list<Declaration>&& decls);
virtual Value CodeGen() override;
protected:
std::list<Declaration> decls_;
};
// name and type
using Constant = std::pair<std::string, std::shared_ptr<ExprNode>>;
class ConstDeclNode : public DeclNode {
public:
ConstDeclNode(Context* context, VariableList* scope,
std::list<Constant>&& decls);
virtual Value CodeGen() override;
protected:
std::list<Constant> decls_;
};
class TypeDeclNode : public DeclNode {
public:
TypeDeclNode(Context* context, VariableList* scope,
std::list<Declaration>&& decls);
virtual Value CodeGen() override;
protected:
std::list<Declaration> decls_;
};
} // namespace pcc
#endif // !PCC_DECLNODE_HH
|