aboutsummaryrefslogtreecommitdiff
path: root/boot/ast.cc
diff options
context:
space:
mode:
Diffstat (limited to 'boot/ast.cc')
-rw-r--r--boot/ast.cc101
1 files changed, 48 insertions, 53 deletions
diff --git a/boot/ast.cc b/boot/ast.cc
index 37e89ac..3454cce 100644
--- a/boot/ast.cc
+++ b/boot/ast.cc
@@ -29,6 +29,11 @@ namespace elna::boot
__builtin_unreachable();
}
+ void empty_visitor::visit(constant_type_expression *)
+ {
+ __builtin_unreachable();
+ }
+
void empty_visitor::visit(type_declaration *)
{
__builtin_unreachable();
@@ -54,11 +59,6 @@ namespace elna::boot
__builtin_unreachable();
}
- void empty_visitor::visit(constant_declaration *)
- {
- __builtin_unreachable();
- }
-
void empty_visitor::visit(procedure_declaration *)
{
__builtin_unreachable();
@@ -210,10 +210,6 @@ namespace elna::boot
}
if (declaration->body.has_value())
{
- for (constant_declaration *const constant : declaration->body.value().constants)
- {
- constant->accept(this);
- }
for (variable_declaration *const variable : declaration->body.value().variables)
{
variable->accept(this);
@@ -336,10 +332,6 @@ namespace elna::boot
{
variable->accept(this);
}
- for (constant_declaration *const constant : unit->constants)
- {
- constant->accept(this);
- }
for (procedure_declaration *const procedure : unit->procedures)
{
procedure->accept(this);
@@ -364,17 +356,17 @@ namespace elna::boot
}
}
- void walking_visitor::visit(constant_declaration *declaration)
+ void walking_visitor::visit(array_type_expression *expression)
{
- declaration->initializer().accept(this);
+ expression->base().accept(this);
}
- void walking_visitor::visit(array_type_expression *expression)
+ void walking_visitor::visit(pointer_type_expression *expression)
{
expression->base().accept(this);
}
- void walking_visitor::visit(pointer_type_expression *expression)
+ void walking_visitor::visit(constant_type_expression *expression)
{
expression->base().accept(this);
}
@@ -557,6 +549,11 @@ namespace elna::boot
return nullptr;
}
+ constant_type_expression *type_expression::is_constant()
+ {
+ return nullptr;
+ }
+
record_type_expression *type_expression::is_record()
{
return nullptr;
@@ -624,6 +621,32 @@ namespace elna::boot
return *m_base;
}
+ constant_type_expression::constant_type_expression(const source_position position,
+ type_expression *base)
+ : node(position), m_base(base)
+ {
+ }
+
+ constant_type_expression::~constant_type_expression()
+ {
+ delete m_base;
+ }
+
+ void constant_type_expression::accept(parser_visitor *visitor)
+ {
+ visitor->visit(this);
+ }
+
+ constant_type_expression *constant_type_expression::is_constant()
+ {
+ return this;
+ }
+
+ type_expression& constant_type_expression::base()
+ {
+ return *m_base;
+ }
+
record_type_expression::record_type_expression(const source_position position,
std::vector<field_declaration>&& fields)
: node(position), fields(std::move(fields))
@@ -753,27 +776,6 @@ namespace elna::boot
{
}
- constant_declaration::constant_declaration(const source_position position, identifier_definition identifier,
- expression *initializer)
- : declaration(position, identifier), m_initializer(initializer)
- {
- }
-
- void constant_declaration::accept(parser_visitor *visitor)
- {
- visitor->visit(this);
- }
-
- expression& constant_declaration::initializer()
- {
- return *m_initializer;
- }
-
- constant_declaration::~constant_declaration()
- {
- delete m_initializer;
- }
-
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))
@@ -863,17 +865,15 @@ namespace elna::boot
return *m_underlying_type;
}
- procedure_body::procedure_body(std::vector<constant_declaration *>&& constants,
- std::vector<variable_declaration *>&& variables, std::vector<statement *>&& entry_point,
- expression *return_expr)
- : constants(std::move(constants)), variables(std::move(variables)),
- entry_point(std::move(entry_point)), return_expression(return_expr)
+ procedure_body::procedure_body(std::vector<variable_declaration *>&& variables,
+ std::vector<statement *>&& entry_point, expression *return_expression)
+ : variables(std::move(variables)),
+ entry_point(std::move(entry_point)), return_expression(return_expression)
{
}
procedure_body::procedure_body(procedure_body&& that)
- : constants(std::move(const_cast<std::vector<constant_declaration *>&>(that.constants))),
- variables(std::move(const_cast<std::vector<variable_declaration *>&>(that.variables))),
+ : variables(std::move(const_cast<std::vector<variable_declaration *>&>(that.variables))),
entry_point(std::move(const_cast<std::vector<statement *>&>(that.entry_point))),
return_expression(that.return_expression)
{
@@ -889,27 +889,22 @@ namespace elna::boot
{
delete variable;
}
- for (constant_declaration *constant : this->constants)
- {
- delete constant;
- }
}
unit::unit(const source_position position)
- : node(position), procedure_body(std::vector<constant_declaration *>{},
- std::vector<variable_declaration *>{}, std::vector<statement *>{}, nullptr)
+ : node(position),
+ procedure_body(std::vector<variable_declaration *>{}, std::vector<statement *>{}, nullptr)
{
}
unit::unit(const source_position position,
std::vector<import_declaration *>&& imports,
- std::vector<constant_declaration *>&& constants,
std::vector<type_declaration *>&& types,
std::vector<variable_declaration *>&& variables,
std::vector<procedure_declaration *>&& procedures,
std::vector<statement *>&& entry_point)
: node(position),
- procedure_body(std::move(constants), std::move(variables), std::move(entry_point)),
+ procedure_body(std::move(variables), std::move(entry_point)),
imports(std::move(imports)), types(std::move(types)), procedures(std::move(procedures))
{
}