aboutsummaryrefslogtreecommitdiff
path: root/boot/ast.cc
diff options
context:
space:
mode:
Diffstat (limited to 'boot/ast.cc')
-rw-r--r--boot/ast.cc142
1 files changed, 87 insertions, 55 deletions
diff --git a/boot/ast.cc b/boot/ast.cc
index 2a22d69..37e89ac 100644
--- a/boot/ast.cc
+++ b/boot/ast.cc
@@ -413,7 +413,7 @@ namespace elna::boot
{
for (const field_initializer& initializer : expression->field_initializers)
{
- initializer.value->accept(this);
+ initializer.value().accept(this);
}
}
@@ -493,8 +493,8 @@ namespace elna::boot
{
}
- node::node(const struct position position)
- : source_position(position)
+ node::node(const source_position position)
+ : m_position(position)
{
}
@@ -502,9 +502,9 @@ namespace elna::boot
{
}
- const struct position& node::position() const
+ const source_position& node::position() const
{
- return this->source_position;
+ return this->m_position;
}
cast_expression *expression::is_cast()
@@ -572,7 +572,7 @@ namespace elna::boot
return nullptr;
}
- array_type_expression::array_type_expression(const struct position position,
+ array_type_expression::array_type_expression(const source_position position,
type_expression *base, const std::uint32_t size)
: node(position), m_base(base), size(size)
{
@@ -598,7 +598,7 @@ namespace elna::boot
return *m_base;
}
- pointer_type_expression::pointer_type_expression(const struct position position,
+ pointer_type_expression::pointer_type_expression(const source_position position,
type_expression *base)
: node(position), m_base(base)
{
@@ -624,15 +624,15 @@ namespace elna::boot
return *m_base;
}
- record_type_expression::record_type_expression(const struct position position,
+ record_type_expression::record_type_expression(const source_position position,
std::vector<field_declaration>&& fields)
: node(position), fields(std::move(fields))
{
}
- record_type_expression::record_type_expression(const struct position position,
- std::vector<field_declaration>&& fields, std::string&& base)
- : node(position), fields(std::move(fields)), base(std::make_optional<std::string>(std::move(base)))
+ record_type_expression::record_type_expression(const source_position position,
+ std::vector<field_declaration>&& fields, identifier&& base)
+ : node(position), fields(std::move(fields)), base(std::make_optional<identifier>(std::move(base)))
{
}
@@ -646,8 +646,48 @@ namespace elna::boot
return this;
}
- record_constructor_expression::record_constructor_expression(const struct position position,
- std::string&& type_name,
+ field_initializer::field_initializer(identifier name, expression *value)
+ : m_name(std::move(name)), m_value(value)
+ {
+ }
+
+ field_initializer::~field_initializer()
+ {
+ delete this->m_value;
+ }
+
+ field_initializer::field_initializer(field_initializer&& other) noexcept
+ : m_name(std::move(other.m_name)), m_value(other.m_value)
+ {
+ other.m_value = nullptr;
+ }
+
+ field_initializer& field_initializer::operator=(field_initializer&& other) noexcept
+ {
+ delete this->m_value;
+ this->m_name = std::move(other.m_name);
+ this->m_value = other.m_value;
+ other.m_value = nullptr;
+ return *this;
+ }
+
+ const std::string& field_initializer::name() const
+ {
+ return this->m_name.name();
+ }
+
+ const identifier& field_initializer::id() const
+ {
+ return this->m_name;
+ }
+
+ expression& field_initializer::value() const
+ {
+ return *this->m_value;
+ }
+
+ record_constructor_expression::record_constructor_expression(const source_position position,
+ identifier&& type_name,
std::vector<field_initializer>&& field_initializers)
: node(position), type_name(std::move(type_name)), field_initializers(std::move(field_initializers))
{
@@ -658,15 +698,7 @@ namespace elna::boot
visitor->visit(this);
}
- record_constructor_expression::~record_constructor_expression()
- {
- for (const field_initializer& initializer : field_initializers)
- {
- delete initializer.value;
- }
- }
-
- array_constructor_expression::array_constructor_expression(const struct position position,
+ array_constructor_expression::array_constructor_expression(const source_position position,
std::uint32_t size, type_expression *element_type,
std::vector<expression *>&& elements)
: node(position), size(size), m_element_type(element_type), elements(std::move(elements))
@@ -687,14 +719,14 @@ namespace elna::boot
}
}
- variable_declaration::variable_declaration(const struct position position,
+ variable_declaration::variable_declaration(const source_position position,
std::vector<identifier_definition>&& identifier, std::shared_ptr<type_expression> variable_type,
expression *initializer)
: node(position), m_variable_type(variable_type), identifiers(std::move(identifier)), initializer(initializer)
{
}
- variable_declaration::variable_declaration(const struct position position,
+ variable_declaration::variable_declaration(const source_position position,
std::vector<identifier_definition>&& identifier, std::shared_ptr<type_expression> variable_type,
std::monostate)
: node(position), m_variable_type(variable_type), identifiers(std::move(identifier)), is_extern(true)
@@ -716,12 +748,12 @@ namespace elna::boot
return *m_variable_type;
}
- declaration::declaration(const struct position position, identifier_definition identifier)
+ declaration::declaration(const source_position position, identifier_definition identifier)
: node(position), identifier(identifier)
{
}
- constant_declaration::constant_declaration(const struct position position, identifier_definition identifier,
+ constant_declaration::constant_declaration(const source_position position, identifier_definition identifier,
expression *initializer)
: declaration(position, identifier), m_initializer(initializer)
{
@@ -742,7 +774,7 @@ namespace elna::boot
delete m_initializer;
}
- procedure_type_expression::procedure_type_expression(const struct position position,
+ procedure_type_expression::procedure_type_expression(const source_position position,
std::vector<field_declaration>&& parameters, return_t return_type)
: node(position), return_type(return_type), parameters(std::move(parameters))
{
@@ -766,9 +798,9 @@ namespace elna::boot
return this;
}
- enumeration_type_expression::enumeration_type_expression(const struct position position,
- std::vector<std::string>&& members)
- : node(position), members(members)
+ enumeration_type_expression::enumeration_type_expression(const source_position position,
+ std::vector<identifier>&& members)
+ : node(position), members(std::move(members))
{
}
@@ -782,14 +814,14 @@ namespace elna::boot
return this;
}
- procedure_declaration::procedure_declaration(const struct position position, identifier_definition identifier,
+ procedure_declaration::procedure_declaration(const source_position position, identifier_definition identifier,
procedure_type_expression *heading, procedure_body&& body)
: declaration(position, identifier), m_heading(heading),
body(std::make_optional<procedure_body>(std::move(body)))
{
}
- procedure_declaration::procedure_declaration(const struct position position, identifier_definition identifier,
+ procedure_declaration::procedure_declaration(const source_position position, identifier_definition identifier,
procedure_type_expression *heading)
: declaration(position, identifier), m_heading(heading)
{
@@ -810,7 +842,7 @@ namespace elna::boot
delete m_heading;
}
- type_declaration::type_declaration(const struct position position, identifier_definition identifier,
+ type_declaration::type_declaration(const source_position position, identifier_definition identifier,
type_expression *underlying_type)
: declaration(position, identifier), m_underlying_type(underlying_type)
{
@@ -863,13 +895,13 @@ namespace elna::boot
}
}
- unit::unit(const struct position position)
+ unit::unit(const source_position position)
: node(position), procedure_body(std::vector<constant_declaration *>{},
std::vector<variable_declaration *>{}, std::vector<statement *>{}, nullptr)
{
}
- unit::unit(const struct position position,
+ unit::unit(const source_position position,
std::vector<import_declaration *>&& imports,
std::vector<constant_declaration *>&& constants,
std::vector<type_declaration *>&& types,
@@ -913,7 +945,7 @@ namespace elna::boot
return this;
}
- defer_statement::defer_statement(const struct position position, std::vector<statement *>&& statements)
+ defer_statement::defer_statement(const source_position position, std::vector<statement *>&& statements)
: node(position), statements(std::move(statements))
{
}
@@ -936,7 +968,7 @@ namespace elna::boot
visitor->visit(this);
}
- empty_statement::empty_statement(const struct position position)
+ empty_statement::empty_statement(const source_position position)
: node(position)
{
}
@@ -971,7 +1003,7 @@ namespace elna::boot
__builtin_unreachable();
}
- named_expression::named_expression(const struct position position, const std::string& name)
+ named_expression::named_expression(const source_position position, const std::string& name)
: node(position), name(name)
{
}
@@ -986,7 +1018,7 @@ namespace elna::boot
return this;
}
- array_access_expression::array_access_expression(const struct position position,
+ array_access_expression::array_access_expression(const source_position position,
expression *base, expression *index)
: node(position), m_base(base), m_index(index)
{
@@ -1018,9 +1050,9 @@ namespace elna::boot
delete m_base;
}
- field_access_expression::field_access_expression(const struct position position,
- expression *base, const std::string& field)
- : node(position), m_base(base), m_field(field)
+ field_access_expression::field_access_expression(const source_position position,
+ expression *base, identifier&& field)
+ : node(position), m_base(base), m_field(std::move(field))
{
}
@@ -1034,7 +1066,7 @@ namespace elna::boot
return *m_base;
}
- std::string& field_access_expression::field()
+ const identifier& field_access_expression::field()
{
return m_field;
}
@@ -1049,7 +1081,7 @@ namespace elna::boot
delete m_base;
}
- dereference_expression::dereference_expression(const struct position position,
+ dereference_expression::dereference_expression(const source_position position,
expression *base)
: node(position), m_base(base)
{
@@ -1075,7 +1107,7 @@ namespace elna::boot
delete m_base;
}
- binary_expression::binary_expression(const struct position position, expression *lhs,
+ binary_expression::binary_expression(const source_position position, expression *lhs,
expression *rhs, const binary_operator operation)
: node(position), m_lhs(lhs), m_rhs(rhs), m_operator(operation)
{
@@ -1112,7 +1144,7 @@ namespace elna::boot
delete m_rhs;
}
- unary_expression::unary_expression(const struct position position, expression *operand,
+ unary_expression::unary_expression(const source_position position, expression *operand,
const unary_operator operation)
: node(position), m_operand(std::move(operand)), m_operator(operation)
{
@@ -1143,7 +1175,7 @@ namespace elna::boot
delete m_operand;
}
- procedure_call::procedure_call(const struct position position, designator_expression *callable,
+ procedure_call::procedure_call(const source_position position, designator_expression *callable,
std::vector<expression *>&& arguments)
: node(position), m_callable(callable), arguments(std::move(arguments))
{
@@ -1173,7 +1205,7 @@ namespace elna::boot
delete m_callable;
}
- cast_expression::cast_expression(const struct position position, type_expression *target, expression *value)
+ cast_expression::cast_expression(const source_position position, type_expression *target, expression *value)
: node(position), m_target(target), m_value(value)
{
}
@@ -1204,9 +1236,9 @@ namespace elna::boot
delete m_value;
}
- traits_expression::traits_expression(const struct position position, const std::string& name,
+ traits_expression::traits_expression(const source_position position, identifier&& name,
std::vector<type_expression *>&& arguments)
- : node(position), arguments(std::move(arguments)), name(name)
+ : node(position), arguments(std::move(arguments)), name(std::move(name))
{
}
@@ -1247,7 +1279,7 @@ namespace elna::boot
}
}
- case_statement::case_statement(const struct position position,
+ case_statement::case_statement(const source_position position,
expression *condition, std::vector<switch_case>&& cases, std::vector<statement *> *alternative)
: node(position), m_condition(condition), cases(std::move(cases)), alternative(alternative)
{
@@ -1263,7 +1295,7 @@ namespace elna::boot
return *m_condition;
}
- assign_statement::assign_statement(const struct position position, designator_expression *lvalue,
+ assign_statement::assign_statement(const source_position position, designator_expression *lvalue,
expression *rvalue)
: node(position), m_lvalue(lvalue), m_rvalue(rvalue)
{
@@ -1309,7 +1341,7 @@ namespace elna::boot
delete m_rvalue;
}
- if_statement::if_statement(const struct position position, conditional_statements *branch,
+ if_statement::if_statement(const source_position position, conditional_statements *branch,
std::vector<conditional_statements *>&& branches,
std::vector<statement *> *alternative)
: node(position), m_branch(branch), branches(std::move(branches)), alternative(alternative)
@@ -1336,7 +1368,7 @@ namespace elna::boot
delete this->alternative;
}
- import_declaration::import_declaration(const struct position position, std::vector<std::string>&& segments)
+ import_declaration::import_declaration(const source_position position, std::vector<std::string>&& segments)
: node(position), segments(std::move(segments))
{
}
@@ -1346,7 +1378,7 @@ namespace elna::boot
visitor->visit(this);
}
- while_statement::while_statement(const struct position position, conditional_statements *branch,
+ while_statement::while_statement(const source_position position, conditional_statements *branch,
std::vector<conditional_statements *>&& branches)
: node(position), m_branch(branch), branches(std::move(branches))
{