2024-12-27 10:51:46 +01:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public License
|
|
|
|
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
|
|
|
// obtain one at http://mozilla.org/MPL/2.0/.
|
2024-12-23 13:54:11 +01:00
|
|
|
#include "elna/source/ast.h"
|
2024-12-21 00:08:48 +01:00
|
|
|
|
2024-12-23 13:54:11 +01:00
|
|
|
namespace elna
|
|
|
|
{
|
|
|
|
namespace source
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
2025-01-03 22:18:35 +01:00
|
|
|
void empty_visitor::visit(declaration *)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void empty_visitor::visit(constant_definition *definition)
|
|
|
|
{
|
|
|
|
definition->body().accept(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void empty_visitor::visit(procedure_definition *definition)
|
|
|
|
{
|
2025-01-05 15:21:25 +01:00
|
|
|
for (auto parameter : definition->parameters())
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
parameter->accept(this);
|
|
|
|
}
|
|
|
|
definition->body().accept(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void empty_visitor::visit(call_statement *statement)
|
|
|
|
{
|
|
|
|
for (auto& argument : statement->arguments())
|
|
|
|
{
|
|
|
|
argument->accept(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void empty_visitor::visit(compound_statement *statement)
|
|
|
|
{
|
|
|
|
for (auto& nested_statement : statement->statements())
|
|
|
|
{
|
|
|
|
nested_statement->accept(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void empty_visitor::visit(assign_statement *statement)
|
|
|
|
{
|
|
|
|
statement->rvalue().accept(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void empty_visitor::visit(if_statement *statement)
|
|
|
|
{
|
|
|
|
statement->prerequisite().accept(this);
|
|
|
|
statement->body().accept(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void empty_visitor::visit(while_statement *statement)
|
|
|
|
{
|
|
|
|
statement->prerequisite().accept(this);
|
|
|
|
statement->body().accept(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void empty_visitor::visit(block *block)
|
|
|
|
{
|
|
|
|
for (const auto& constant : block->definitions())
|
|
|
|
{
|
|
|
|
constant->accept(this);
|
|
|
|
}
|
|
|
|
for (const auto& block_declaration : block->declarations())
|
|
|
|
{
|
|
|
|
block_declaration->accept(this);
|
|
|
|
}
|
|
|
|
block->body().accept(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void empty_visitor::visit(program *program)
|
|
|
|
{
|
2024-12-23 13:54:11 +01:00
|
|
|
visit(reinterpret_cast<block *>(program));
|
2024-12-21 00:08:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void empty_visitor::visit(binary_expression *expression)
|
|
|
|
{
|
|
|
|
expression->lhs().accept(this);
|
|
|
|
expression->rhs().accept(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void empty_visitor::visit(unary_expression *expression)
|
|
|
|
{
|
|
|
|
expression->operand().accept(this);
|
|
|
|
}
|
|
|
|
|
2025-01-05 00:06:51 +01:00
|
|
|
void empty_visitor::visit(basic_type_expression *)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
void empty_visitor::visit(array_type_expression *)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-03 22:18:35 +01:00
|
|
|
void empty_visitor::visit(variable_expression *)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-03 22:18:35 +01:00
|
|
|
void empty_visitor::visit(number_literal<std::int32_t> *)
|
2024-12-31 18:10:34 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-03 22:18:35 +01:00
|
|
|
void empty_visitor::visit(number_literal<double> *)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-03 22:18:35 +01:00
|
|
|
void empty_visitor::visit(number_literal<bool> *)
|
2025-01-01 23:02:19 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-03 22:18:35 +01:00
|
|
|
void empty_visitor::visit(char_literal *)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void empty_visitor::visit(string_literal *)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
operand::~operand()
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
integer_operand::integer_operand(const std::int32_t value)
|
|
|
|
: m_value(value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
std::int32_t integer_operand::value() const
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return m_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
variable_operand::variable_operand(const std::string& name)
|
|
|
|
: m_name(name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
const std::string& variable_operand::name() const
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
temporary_variable::temporary_variable(const std::size_t counter)
|
|
|
|
: m_counter(counter)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
std::size_t temporary_variable::counter() const
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return m_counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
label_operand::label_operand(const std::size_t counter)
|
|
|
|
: m_counter(counter)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
std::size_t label_operand::counter() const
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return m_counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
node::node(const struct position position)
|
|
|
|
: source_position(position)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
const struct position& node::position() const
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return this->source_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
statement::statement(const struct position position)
|
|
|
|
: node(position)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
expression::expression(const struct position position)
|
|
|
|
: node(position)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-05 00:06:51 +01:00
|
|
|
type_expression::type_expression(const struct position position)
|
|
|
|
: node(position)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
basic_type_expression *type_expression::is_basic()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
array_type_expression *type_expression::is_array()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2025-01-05 00:06:51 +01:00
|
|
|
basic_type_expression::basic_type_expression(
|
|
|
|
const struct position position, const std::string& name)
|
2025-01-06 15:08:23 +01:00
|
|
|
: type_expression(position), m_name(name)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-05 00:06:51 +01:00
|
|
|
void basic_type_expression::accept(parser_visitor *visitor)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
const std::string& basic_type_expression::base_name()
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
2025-01-06 15:08:23 +01:00
|
|
|
return m_name;
|
2024-12-21 00:08:48 +01:00
|
|
|
}
|
|
|
|
|
2025-01-05 00:06:51 +01:00
|
|
|
basic_type_expression *basic_type_expression::is_basic()
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
2025-01-05 00:06:51 +01:00
|
|
|
return this;
|
2024-12-21 00:08:48 +01:00
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
array_type_expression::array_type_expression(const struct position position, type_expression *base,
|
|
|
|
const std::uint32_t size)
|
|
|
|
: type_expression(position), m_base(base), size(size)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void array_type_expression::accept(parser_visitor *visitor)
|
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_expression& array_type_expression::base()
|
|
|
|
{
|
|
|
|
return *m_base;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& array_type_expression::base_name()
|
|
|
|
{
|
|
|
|
return base().base_name();
|
|
|
|
}
|
|
|
|
|
|
|
|
array_type_expression *array_type_expression::is_array()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_type_expression::~array_type_expression()
|
|
|
|
{
|
|
|
|
delete m_base;
|
|
|
|
}
|
|
|
|
|
2024-12-21 00:08:48 +01:00
|
|
|
declaration::declaration(const struct position position, const std::string& identifier,
|
2025-01-05 15:21:25 +01:00
|
|
|
type_expression *type)
|
|
|
|
: definition(position, identifier), m_type(type)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-05 15:21:25 +01:00
|
|
|
declaration::~declaration()
|
|
|
|
{
|
|
|
|
delete m_type;
|
|
|
|
}
|
|
|
|
|
2024-12-21 00:08:48 +01:00
|
|
|
void declaration::accept(parser_visitor *visitor)
|
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
type_expression& declaration::type()
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return *m_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
definition::definition(const struct position position, const std::string& identifier)
|
|
|
|
: node(position), m_identifier(identifier)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
std::string& definition::identifier()
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return m_identifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
constant_definition::constant_definition(const struct position position, const std::string& identifier,
|
2025-01-05 15:21:25 +01:00
|
|
|
number_literal<std::int32_t> *body)
|
|
|
|
: definition(position, identifier), m_body(body)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void constant_definition::accept(parser_visitor *visitor)
|
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
2024-12-31 18:10:34 +01:00
|
|
|
number_literal<std::int32_t>& constant_definition::body()
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return *m_body;
|
|
|
|
}
|
|
|
|
|
2025-01-05 15:21:25 +01:00
|
|
|
constant_definition::~constant_definition()
|
|
|
|
{
|
|
|
|
delete m_body;
|
|
|
|
}
|
|
|
|
|
2024-12-21 00:08:48 +01:00
|
|
|
procedure_definition::procedure_definition(const struct position position, const std::string& identifier,
|
2025-01-05 15:21:25 +01:00
|
|
|
block *body)
|
|
|
|
: definition(position, identifier), m_body(body)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void procedure_definition::accept(parser_visitor *visitor)
|
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
block& procedure_definition::body()
|
|
|
|
{
|
|
|
|
return *m_body;
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
std::vector<declaration *>& procedure_definition::parameters()
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return m_parameters;
|
|
|
|
}
|
|
|
|
|
2025-01-05 15:21:25 +01:00
|
|
|
procedure_definition::~procedure_definition()
|
|
|
|
{
|
|
|
|
delete m_body;
|
|
|
|
for (auto parameter : m_parameters)
|
|
|
|
{
|
|
|
|
delete parameter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
block::block(const struct position position, std::vector<definition *>&& definitions,
|
|
|
|
std::vector<declaration *>&& declarations,
|
|
|
|
statement *body)
|
2024-12-21 00:08:48 +01:00
|
|
|
: node(position), m_definitions(std::move(definitions)),
|
|
|
|
m_declarations(std::move(declarations)), m_body(std::move(body))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void block::accept(parser_visitor *visitor)
|
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
statement& block::body()
|
|
|
|
{
|
|
|
|
return *m_body;
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
std::vector<definition *>& block::definitions()
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return m_definitions;
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
std::vector<declaration *>& block::declarations()
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return m_declarations;
|
|
|
|
}
|
|
|
|
|
2025-01-05 15:21:25 +01:00
|
|
|
block::~block()
|
|
|
|
{
|
|
|
|
for (auto definition : m_definitions)
|
|
|
|
{
|
|
|
|
delete definition;
|
|
|
|
}
|
|
|
|
for (auto declaration : m_declarations)
|
|
|
|
{
|
|
|
|
delete declaration;
|
|
|
|
}
|
|
|
|
delete m_body;
|
|
|
|
}
|
|
|
|
|
|
|
|
program::program(const struct position position, std::vector<definition *>&& definitions,
|
|
|
|
std::vector<declaration *>&& declarations,
|
|
|
|
statement *body)
|
|
|
|
: block(position, std::move(definitions), std::move(declarations), body)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void program::accept(parser_visitor *visitor)
|
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
2025-01-01 23:02:19 +01:00
|
|
|
char_literal::char_literal(const struct position position, const unsigned char value)
|
|
|
|
: expression(position), m_character(value)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-01 23:02:19 +01:00
|
|
|
void char_literal::accept(parser_visitor *visitor)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
unsigned char char_literal::character() const
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
2025-01-01 23:02:19 +01:00
|
|
|
return m_character;
|
2024-12-21 00:08:48 +01:00
|
|
|
}
|
|
|
|
|
2025-01-03 22:18:35 +01:00
|
|
|
string_literal::string_literal(const struct position position, const std::string& value)
|
|
|
|
: expression(position), m_string(value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void string_literal::accept(parser_visitor *visitor)
|
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
const std::string& string_literal::string() const
|
2025-01-03 22:18:35 +01:00
|
|
|
{
|
|
|
|
return m_string;
|
|
|
|
}
|
|
|
|
|
2024-12-21 00:08:48 +01:00
|
|
|
variable_expression::variable_expression(const struct position position, const std::string& name)
|
|
|
|
: expression(position), m_name(name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void variable_expression::accept(parser_visitor *visitor)
|
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
const std::string& variable_expression::name() const
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
2025-01-05 15:21:25 +01:00
|
|
|
binary_expression::binary_expression(const struct position position, expression *lhs,
|
|
|
|
expression *rhs, const unsigned char operation)
|
2024-12-21 00:08:48 +01:00
|
|
|
: expression(position), m_lhs(std::move(lhs)), m_rhs(std::move(rhs))
|
|
|
|
{
|
|
|
|
switch (operation)
|
|
|
|
{
|
|
|
|
case '+':
|
|
|
|
this->m_operator = binary_operator::sum;
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
this->m_operator = binary_operator::subtraction;
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
this->m_operator = binary_operator::multiplication;
|
|
|
|
break;
|
|
|
|
case '/':
|
|
|
|
this->m_operator = binary_operator::division;
|
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
this->m_operator = binary_operator::equals;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
this->m_operator = binary_operator::not_equals;
|
|
|
|
break;
|
|
|
|
case '<':
|
|
|
|
this->m_operator = binary_operator::less;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
this->m_operator = binary_operator::less_equal;
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
this->m_operator = binary_operator::greater;
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
this->m_operator = binary_operator::greater_equal;
|
|
|
|
break;
|
|
|
|
default:
|
2024-12-23 13:54:11 +01:00
|
|
|
__builtin_unreachable();
|
2024-12-21 00:08:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void binary_expression::accept(parser_visitor *visitor)
|
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
expression& binary_expression::lhs()
|
|
|
|
{
|
|
|
|
return *m_lhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
expression& binary_expression::rhs()
|
|
|
|
{
|
|
|
|
return *m_rhs;
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
binary_operator binary_expression::operation() const
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return m_operator;
|
|
|
|
}
|
|
|
|
|
2025-01-05 15:21:25 +01:00
|
|
|
binary_expression::~binary_expression()
|
|
|
|
{
|
|
|
|
delete m_lhs;
|
|
|
|
delete m_rhs;
|
|
|
|
}
|
|
|
|
|
|
|
|
unary_expression::unary_expression(const struct position position, expression *operand,
|
2024-12-21 00:08:48 +01:00
|
|
|
const unsigned char operation)
|
|
|
|
: expression(position), m_operand(std::move(operand))
|
|
|
|
{
|
|
|
|
switch (operation)
|
|
|
|
{
|
|
|
|
case '@':
|
|
|
|
this->m_operator = unary_operator::reference;
|
|
|
|
break;
|
|
|
|
case '^':
|
|
|
|
this->m_operator = unary_operator::dereference;
|
|
|
|
break;
|
|
|
|
default:
|
2024-12-23 13:54:11 +01:00
|
|
|
__builtin_unreachable();
|
2024-12-21 00:08:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void unary_expression::accept(parser_visitor *visitor)
|
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
expression& unary_expression::operand()
|
|
|
|
{
|
|
|
|
return *m_operand;
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
unary_operator unary_expression::operation() const
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return this->m_operator;
|
|
|
|
}
|
|
|
|
|
2025-01-05 15:21:25 +01:00
|
|
|
unary_expression::~unary_expression()
|
|
|
|
{
|
|
|
|
delete m_operand;
|
|
|
|
}
|
|
|
|
|
2024-12-21 00:08:48 +01:00
|
|
|
call_statement::call_statement(const struct position position, const std::string& name)
|
|
|
|
: statement(position), m_name(name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void call_statement::accept(parser_visitor *visitor)
|
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
std::string& call_statement::name()
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
std::vector<expression *>& call_statement::arguments()
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return m_arguments;
|
|
|
|
}
|
|
|
|
|
2025-01-05 15:21:25 +01:00
|
|
|
call_statement::~call_statement()
|
|
|
|
{
|
|
|
|
for (auto argument : m_arguments)
|
|
|
|
{
|
|
|
|
delete argument;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-21 00:08:48 +01:00
|
|
|
compound_statement::compound_statement(const struct position position)
|
|
|
|
: statement(position)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void compound_statement::accept(parser_visitor *visitor)
|
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
2025-01-05 15:21:25 +01:00
|
|
|
std::vector<statement *>& compound_statement::statements()
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return m_statements;
|
|
|
|
}
|
|
|
|
|
2025-01-05 15:21:25 +01:00
|
|
|
compound_statement::~compound_statement()
|
|
|
|
{
|
|
|
|
for (auto statement : m_statements)
|
|
|
|
{
|
|
|
|
delete statement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-21 00:08:48 +01:00
|
|
|
void assign_statement::accept(parser_visitor *visitor)
|
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
assign_statement::assign_statement(const struct position position, const std::string& lvalue,
|
2025-01-05 15:21:25 +01:00
|
|
|
expression *rvalue)
|
|
|
|
: statement(position), m_lvalue(lvalue), m_rvalue(rvalue)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2025-01-06 15:08:23 +01:00
|
|
|
std::string& assign_statement::lvalue()
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
return m_lvalue;
|
|
|
|
}
|
|
|
|
|
|
|
|
expression& assign_statement::rvalue()
|
|
|
|
{
|
|
|
|
return *m_rvalue;
|
|
|
|
}
|
|
|
|
|
2025-01-05 15:21:25 +01:00
|
|
|
assign_statement::~assign_statement()
|
|
|
|
{
|
|
|
|
delete m_rvalue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if_statement::if_statement(const struct position position, expression *prerequisite,
|
|
|
|
statement *body, statement *alternative)
|
|
|
|
: statement(position), m_prerequisite(prerequisite), m_body(body),
|
|
|
|
m_alternative(alternative)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void if_statement::accept(parser_visitor *visitor)
|
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
expression& if_statement::prerequisite()
|
|
|
|
{
|
|
|
|
return *m_prerequisite;
|
|
|
|
}
|
|
|
|
|
|
|
|
statement& if_statement::body()
|
|
|
|
{
|
|
|
|
return *m_body;
|
|
|
|
}
|
|
|
|
|
2025-01-05 15:21:25 +01:00
|
|
|
statement *if_statement::alternative()
|
2024-12-30 23:12:47 +01:00
|
|
|
{
|
|
|
|
return m_alternative;
|
|
|
|
}
|
|
|
|
|
2025-01-05 15:21:25 +01:00
|
|
|
if_statement::~if_statement()
|
|
|
|
{
|
|
|
|
delete m_prerequisite;
|
|
|
|
delete m_body;
|
|
|
|
|
|
|
|
if (m_alternative != nullptr)
|
|
|
|
{
|
|
|
|
delete m_alternative;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while_statement::while_statement(const struct position position, expression *prerequisite,
|
|
|
|
statement *body)
|
|
|
|
: statement(position), m_prerequisite(prerequisite), m_body(body)
|
2024-12-21 00:08:48 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void while_statement::accept(parser_visitor *visitor)
|
|
|
|
{
|
|
|
|
visitor->visit(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
expression& while_statement::prerequisite()
|
|
|
|
{
|
|
|
|
return *m_prerequisite;
|
|
|
|
}
|
|
|
|
|
|
|
|
statement& while_statement::body()
|
|
|
|
{
|
|
|
|
return *m_body;
|
|
|
|
}
|
2024-12-28 14:33:35 +01:00
|
|
|
|
2025-01-05 15:21:25 +01:00
|
|
|
while_statement::~while_statement()
|
|
|
|
{
|
|
|
|
delete m_prerequisite;
|
|
|
|
delete m_body;
|
|
|
|
}
|
|
|
|
|
2024-12-28 14:33:35 +01:00
|
|
|
const char *print_binary_operator(const binary_operator operation)
|
|
|
|
{
|
|
|
|
switch (operation)
|
|
|
|
{
|
|
|
|
case binary_operator::sum:
|
|
|
|
return "+";
|
|
|
|
case binary_operator::subtraction:
|
|
|
|
return "-";
|
|
|
|
case binary_operator::multiplication:
|
|
|
|
return "*";
|
|
|
|
case binary_operator::division:
|
|
|
|
return "/";
|
|
|
|
case binary_operator::equals:
|
|
|
|
return "=";
|
|
|
|
case binary_operator::not_equals:
|
|
|
|
return "/=";
|
|
|
|
case binary_operator::less:
|
|
|
|
return "<";
|
|
|
|
case binary_operator::less_equal:
|
|
|
|
return "<=";
|
|
|
|
case binary_operator::greater:
|
|
|
|
return ">";
|
|
|
|
case binary_operator::greater_equal:
|
|
|
|
return ">=";
|
|
|
|
}
|
2025-01-03 22:18:35 +01:00
|
|
|
__builtin_unreachable();
|
2024-12-28 14:33:35 +01:00
|
|
|
};
|
2024-12-21 00:08:48 +01:00
|
|
|
}
|
2024-12-23 13:54:11 +01:00
|
|
|
}
|