forked from codekitchen/cirth
/
ir.h
210 lines (177 loc) · 5.78 KB
/
ir.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#ifndef __IR_H__
#define __IR_H__
#include "common.h"
#include "ast.h"
namespace cirth {
namespace ir {
struct Expression {
virtual ~Expression() {}
virtual std::string format() const = 0;
protected: Expression() {} };
struct Value {
virtual ~Value() {}
virtual std::string format() const = 0;
protected: Value() {} };
struct Name {
Name(const std::string& name_, bool user_provided_, bool scoped_)
: name(name_), user_provided(user_provided_), scoped(scoped_) {}
Name(const cirth::ast::Variable& var)
: name(var.name), user_provided(var.user_provided), scoped(var.scoped) {}
std::string format() const;
std::string name;
bool user_provided;
bool scoped;
};
struct Definition : public Expression {
Definition(const Name& assignee_, PTR<Value> value_)
: assignee(assignee_), value(value_) {}
Name assignee;
PTR<Value> value;
std::string format() const;
};
struct VariableMutation : public Expression {
VariableMutation(const Name& assignee_, PTR<Value> value_)
: assignee(assignee_), value(value_) {}
Name assignee;
PTR<Value> value;
std::string format() const;
};
struct ObjectMutation : public Expression {
ObjectMutation(PTR<Value> object_, const Name& field_, PTR<Value> value_)
: object(object_), field(field_), value(value_) {}
PTR<Value> object;
Name field;
PTR<Value> value;
std::string format() const;
};
struct Field : public Value {
Field(const PTR<Value>& object_, const Name& field_)
: object(object_), field(field_) {}
std::string format() const;
PTR<Value> object;
Name field;
};
struct Variable : public Value {
Variable(const Name& variable_) : variable(variable_) {}
Name variable;
std::string format() const;
};
struct Integer : public Value {
Integer(const long long& value_) : value(value_) {}
long long value;
std::string format() const;
};
struct CharString : public Value {
CharString(const std::string& value_) : value(value_) {}
std::string value;
std::string format() const;
};
struct ByteString : public Value {
ByteString(const std::string& value_) : value(value_) {}
std::string value;
std::string format() const;
};
struct Float : public Value {
Float(const double& value_) : value(value_) {}
double value;
std::string format() const;
};
struct PositionalOutArgument {
PositionalOutArgument(const PTR<Value>& variable_) : variable(variable_) {}
PTR<Value> variable;
std::string format() const;
};
struct OptionalOutArgument {
OptionalOutArgument(const Name& key_, const PTR<Value>& variable_)
: key(key_), variable(variable_) {}
Name key;
PTR<Value> variable;
std::string format() const;
};
struct ArbitraryOutArgument {
ArbitraryOutArgument(const PTR<Value>& variable_) : variable(variable_) {}
PTR<Value> variable;
std::string format() const;
};
struct KeywordOutArgument {
KeywordOutArgument(const PTR<Value>& variable_) : variable(variable_) {}
PTR<Value> variable;
std::string format() const;
};
struct Call {
PTR<Value> callable;
std::vector<PositionalOutArgument> left_positional_args;
boost::optional<ArbitraryOutArgument> left_arbitrary_arg;
std::vector<PositionalOutArgument> right_positional_args;
std::vector<OptionalOutArgument> right_optional_args;
boost::optional<ArbitraryOutArgument> right_arbitrary_arg;
boost::optional<KeywordOutArgument> right_keyword_arg;
std::vector<OptionalOutArgument> scoped_optional_args;
boost::optional<KeywordOutArgument> scoped_keyword_arg;
std::string format() const;
};
struct ReturnValue : public Expression {
ReturnValue(const Name& assignee_, PTR<Call> term_)
: assignee(assignee_), term(term_) {}
Name assignee;
PTR<Call> term;
std::string format() const;
};
struct DictDefinition {
DictDefinition(const PTR<Value>& key_, const PTR<Value>& value_)
: key(key_), value(value_) {}
PTR<Value> key;
PTR<Value> value;
std::string format() const;
};
struct Dictionary : public Value {
std::vector<DictDefinition> definitions;
std::string format() const;
};
struct Array : public Value {
std::vector<PTR<Value> > values;
std::string format() const;
};
struct PositionalInArgument {
PositionalInArgument(const Name& variable_) : variable(variable_) {}
Name variable;
std::string format() const;
};
struct OptionalInArgument {
OptionalInArgument(const Name& variable_, const PTR<Value>& defaultval_)
: variable(variable_), defaultval(defaultval_) {}
Name variable;
PTR<Value> defaultval;
std::string format() const;
};
struct ArbitraryInArgument {
ArbitraryInArgument(const Name& variable_) : variable(variable_) {}
Name variable;
std::string format() const;
};
struct KeywordInArgument {
KeywordInArgument(const Name& variable_) : variable(variable_) {}
Name variable;
std::string format() const;
};
struct Callable : public Value {
std::vector<PTR<Expression> > expressions;
PTR<Value> lastval;
};
struct Function : public Callable {
std::vector<PositionalInArgument> left_positional_args;
boost::optional<ArbitraryInArgument> left_arbitrary_arg;
std::vector<PositionalInArgument> right_positional_args;
std::vector<OptionalInArgument> right_optional_args;
boost::optional<ArbitraryInArgument> right_arbitrary_arg;
boost::optional<KeywordInArgument> right_keyword_arg;
std::string format() const;
};
struct Scope : public Callable {
std::string format() const;
};
void convert(const std::vector<PTR<cirth::ast::Expression> >& exps,
std::vector<PTR<cirth::ir::Expression> >& out,
PTR<cirth::ir::Value>& lastval);
}}
#endif