-
Notifications
You must be signed in to change notification settings - Fork 1
/
declarations.h
95 lines (80 loc) · 2.06 KB
/
declarations.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
90
91
92
93
94
95
#ifndef _DECLARATIONS_H
#define _DECLARATIONS_H
#include "types.h"
#include "layeredmap.h"
#include "syntaxtree.h"
#include "idmap.h"
#include "translate_utils.h"
#include <map>
#include <list>
namespace Semantic {
enum DeclarationType {
DECL_VARIABLE,
DECL_LOOP_VARIABLE,
DECL_ARGUMENT,
DECL_FUNCTION
};
class Declaration {
public:
DeclarationType kind;
Declaration(DeclarationType _kind) : kind(_kind) {}
};
class Variable: public Declaration {
public:
std::string name;
Type *type;
IR::Code *value;
IR::AbstractVarLocation *implementation;
bool isAccessedByAddress;
Variable(const std::string &_name, Type *_type,
IR::Code *_value, IR::AbstractVarLocation *impl) :
Declaration(DECL_VARIABLE), name(_name), type(_type), value(_value),
implementation(impl), isAccessedByAddress(false) {}
};
class Function;
class FunctionArgument: public Variable {
public:
Function *function;
FunctionArgument(Function *owner, const std::string &_name, Type *_type,
IR::AbstractVarLocation *impl) :
Variable(_name, _type, NULL, impl), function(owner)
{
kind = DECL_ARGUMENT;
}
};
class LoopVariable: public Variable {
public:
LoopVariable(const std::string &_name, Type *_type,
IR::AbstractVarLocation *impl
) : Variable(_name, _type, NULL, impl)
{
kind = DECL_LOOP_VARIABLE;
}
};
class Function: public Declaration {
public:
std::string name;
Type *return_type;
std::list<FunctionArgument> arguments;
Syntax::Tree raw_body;
IR::Code *body;
IR::AbstractFrame *frame;
IR::Label *label;
bool needs_parent_fp;
Function(const std::string &_name, Type *_return_type,
Syntax::Tree _raw, IR::Code *_body,
IR::AbstractFrame *_frame, IR::Label *_label,
bool _needs_parent_fp) :
name(_name), Declaration(DECL_FUNCTION), return_type(_return_type),
raw_body(_raw), body(_body), frame(_frame), label(_label),
needs_parent_fp(_needs_parent_fp)
{}
FunctionArgument *addArgument(const std::string &name, Type *type,
IR::AbstractVarLocation *impl)
{
arguments.push_back(FunctionArgument(this, name, type, impl));
return &(arguments.back());
}
};
}
#endif