Gyoji Compiler
Loading...
Searching...
No Matches
function-resolver.hpp
1#pragma once
2
3#include <gyoji-mir.hpp>
4#include <gyoji-frontend.hpp>
5#include <gyoji-frontend/function-scope.hpp>
6
7
24 class TypeResolver;
25
38 public:
40 Gyoji::context::CompilerContext & _compiler_context,
41 const Gyoji::frontend::tree::FileStatementFunctionDefinition & _function_definition,
42 Gyoji::mir::MIR & _mir,
43 TypeResolver & _type_resolver
44 );
46
59 bool resolve();
60
61 private:
62 // Private members
63 Gyoji::context::CompilerContext & compiler_context;
64 const Gyoji::frontend::tree::FileStatementFunctionDefinition & function_definition;
65 Gyoji::mir::MIR & mir;
66 TypeResolver & type_resolver;
67 ScopeTracker scope_tracker;
68 Gyoji::mir::Type *class_type;
69 const Gyoji::mir::TypeMethod *method;
70
71 bool is_method() const;
72
74 size_t current_block;
75
76 // Private Methods
77
78 // Returns the current point in the current block
79 // where the 'unwindings' a 'goto' statement
80 // will be placed.
81 FunctionPoint get_current_point() const;
82
83 bool numeric_widen(
84 const Gyoji::context::SourceReference & _src_ref,
85 size_t & _widen_var,
86 const Gyoji::mir::Type *widen_to
87 );
88
89
90 bool create_constant_integer(
91 const Gyoji::frontend::integers::ParseLiteralIntResult & parse_result,
92 size_t & returned_tmpvar,
93 const Gyoji::context::SourceReference & _src_ref
94 );
95
96 bool create_constant_integer_one(
97 const Gyoji::mir::Type *type,
98 size_t & returned_tmpvar,
99 const Gyoji::context::SourceReference & _src_ref
100 );
101
102 bool create_incdec_operation(
103 const Gyoji::context::SourceReference & src_ref,
104 size_t & returned_tmpvar,
105 const size_t & operand_tmpvar,
106 bool is_increment,
107 bool is_postfix
108 );
109
110 bool local_declare_or_error(
111 const Gyoji::mir::Type *mir_type,
112 const std::string & name,
113 const Gyoji::context::SourceReference & source_ref
114 );
115
116 // Widen the shorter
117 // of the two operands to be the
118 // larger one.
119 bool numeric_widen_binary_operation(
120 const Gyoji::context::SourceReference & _src_ref,
121 size_t & a_tmpvar,
122 size_t & b_tmpvar,
123 const Gyoji::mir::Type *atype,
124 const Gyoji::mir::Type *btype,
125 const Gyoji::mir::Type **widened
126 );
127
128 bool handle_binary_operation_arithmetic(
129 const Gyoji::context::SourceReference & _src_ref,
131 size_t & returned_tmpvar,
132 size_t a_tmpvar,
133 size_t b_tmpvar
134 );
135
136 bool handle_binary_operation_logical(
137 const Gyoji::context::SourceReference & _src_ref,
139 size_t & returned_tmpvar,
140 size_t a_tmpvar,
141 size_t b_tmpvar
142 );
143
144 bool handle_binary_operation_bitwise(
145 const Gyoji::context::SourceReference & _src_ref,
147 size_t & returned_tmpvar,
148 size_t a_tmpvar,
149 size_t b_tmpvar
150 );
151
152 bool handle_binary_operation_shift(
153 const Gyoji::context::SourceReference & _src_ref,
155 size_t & returned_tmpvar,
156 size_t a_tmpvar,
157 size_t b_tmpvar
158 );
159
160 bool handle_binary_operation_compare(
161 const Gyoji::context::SourceReference & _src_ref,
163 size_t & returned_tmpvar,
164 size_t a_tmpvar,
165 size_t b_tmpvar
166 );
167
168 bool handle_binary_operation_assignment(
169 const Gyoji::context::SourceReference & _src_ref,
171 size_t & returned_tmpvar,
172 size_t a_tmpvar,
173 size_t b_tmpvar
174 );
175
176 bool extract_from_expression_primary_identifier(
177 size_t & returned_tmpvar,
178 const Gyoji::frontend::tree::ExpressionPrimaryIdentifier & expression);
179
180 bool extract_from_expression_primary_nested(
181 size_t & returned_tmpvar,
182 const Gyoji::frontend::tree::ExpressionPrimaryNested & expression);
183
184 bool extract_from_expression_primary_literal_char(
185 size_t & returned_tmpvar,
186 const Gyoji::frontend::tree::ExpressionPrimaryLiteralChar & expression);
187
188 bool extract_from_expression_primary_literal_string(
189 size_t & returned_tmpvar,
190 const Gyoji::frontend::tree::ExpressionPrimaryLiteralString & expression);
191
192 bool extract_from_expression_primary_literal_int(
193 size_t & returned_tmpvar,
194 const Gyoji::frontend::tree::ExpressionPrimaryLiteralInt & expression);
195
196 bool extract_from_expression_primary_literal_float(
197 size_t & returned_tmpvar,
198 const Gyoji::frontend::tree::ExpressionPrimaryLiteralFloat & expression);
199
200 bool extract_from_expression_postfix_array_index(
201 size_t & returned_tmpvar,
202 const Gyoji::frontend::tree::ExpressionPostfixArrayIndex & expression);
203
204 bool extract_from_expression_postfix_function_call(
205 size_t & returned_tmpvar,
206 const Gyoji::frontend::tree::ExpressionPostfixFunctionCall & expression);
207
208 bool extract_from_expression_postfix_dot(
209 size_t & returned_tmpvar,
210 const Gyoji::frontend::tree::ExpressionPostfixDot & expression);
211
212 bool extract_from_expression_postfix_arrow(
213 size_t & returned_tmpvar,
214 const Gyoji::frontend::tree::ExpressionPostfixArrow & expression);
215
216 bool extract_from_expression_postfix_incdec(
217 size_t & returned_tmpvar,
218 const Gyoji::frontend::tree::ExpressionPostfixIncDec & expression);
219
220 bool extract_from_expression_unary_prefix(
221 size_t & returned_tmpvar,
222 const Gyoji::frontend::tree::ExpressionUnaryPrefix & expression);
223
224 bool extract_from_expression_unary_sizeof_type(
225 size_t & returned_tmpvar,
226 const Gyoji::frontend::tree::ExpressionUnarySizeofType & expression);
227
228 bool extract_from_expression_binary(
229 size_t & returned_tmpvar,
230 const Gyoji::frontend::tree::ExpressionBinary & expression);
231
232 bool extract_from_expression_trinary(
233 size_t & returned_tmpvar,
234 const Gyoji::frontend::tree::ExpressionTrinary & expression);
235
236 bool extract_from_expression_cast(
237 size_t & returned_tmpvar,
238 const Gyoji::frontend::tree::ExpressionCast & expression);
239
240 bool extract_from_expression(
241 size_t & returned_tmpvar,
242 const Gyoji::frontend::tree::Expression & expression
243 );
244
245 bool extract_from_statement_variable_declaration(
247 );
248
249 bool extract_from_statement_ifelse(
251 );
252
253 bool extract_from_statement_while(
255 );
256
257 bool extract_from_statement_for(
258 const Gyoji::frontend::tree::StatementFor & statement
259 );
260
261 bool extract_from_statement_label(
262 const Gyoji::frontend::tree::StatementLabel & statement
263 );
264
265 bool extract_from_statement_break(
266 const Gyoji::frontend::tree::StatementBreak & statement
267 );
268
269 bool extract_from_statement_continue(
270 const Gyoji::frontend::tree::StatementContinue & statement
271 );
272
273 bool extract_from_statement_goto(
274 const Gyoji::frontend::tree::StatementGoto & statement
275 );
276
277 bool extract_from_statement_return(
278 const Gyoji::frontend::tree::StatementReturn & statement
279 );
280
281 void
282 leave_scope(
283 const Gyoji::context::SourceReference & src_ref,
284 std::vector<std::string> & unwind);
285
286 bool extract_from_statement_list(
287 const Gyoji::frontend::tree::StatementList & statement_list
288 );
289
290 };
291
307 public:
318 Gyoji::context::CompilerContext & _compiler_context,
319 const Gyoji::frontend::ParseResult & _parse_result,
320 Gyoji::mir::MIR & _mir,
321 TypeResolver & _type_resolver
322 );
323
331
337 bool resolve();
338 private:
339 Gyoji::context::CompilerContext & compiler_context;
340 const Gyoji::frontend::ParseResult & parse_result;
341 Gyoji::mir::MIR & mir;
342 TypeResolver & type_resolver;
343
344 bool extract_from_class_definition(const Gyoji::frontend::tree::ClassDefinition & definition);
345 bool extract_from_namespace(
346 const Gyoji::frontend::tree::FileStatementNamespace & namespace_declaration
347 );
348 bool extract_functions(const std::vector<Gyoji::owned<Gyoji::frontend::tree::FileStatement>> & statements);
349
350 };
351
352};
353
Compiler Context.
Definition gyoji-context.hpp:30
References a location in the source-file.
Definition source-reference.hpp:16
Definition parse-result.hpp:53
Lowering for a function.
Definition function-resolver.hpp:37
bool resolve()
Resolve a single function definition.
Definition function-resolver.cpp:151
Location inside a specific basic block.
Definition function-scope.hpp:23
Resolves all functions found in the MIR.
Definition function-resolver.hpp:306
~FunctionResolver()
Move along, nothing to see here.
Definition function-resolver.cpp:24
bool resolve()
Definition function-resolver.cpp:27
Tracks variables declared in each scope along with abels and goto statements in a highly simplified i...
Definition function-scope.hpp:290
The TypeResolver is the lowering process for types. This function reads the result of a parse and pro...
Definition type-resolver.hpp:21
This represents an if condition in one of several forms.
Definition tree.hpp:1192
Represents the declaration of a variable inside the scope of a function or block.
Definition tree.hpp:1018
Represents a 'while' statement in a function or scope.
Definition tree.hpp:1295
The middle-tier intermediate representation (MIR) of a translation unit.
Definition gyoji-mir.hpp:57
OperationType
Operations of the MIR virtual-machine.
Definition operations.hpp:72
Method of a class.
Definition types.hpp:255
This represents a type as declared in a translation unit.
Definition types.hpp:299
Converts the strongly-typed syntax tree into the MIR representation.
Definition function-resolver.hpp:23