aboutsummaryrefslogtreecommitdiff
path: root/boot
diff options
context:
space:
mode:
Diffstat (limited to 'boot')
-rw-r--r--boot/ast.cc11
-rw-r--r--boot/parser.yy12
-rw-r--r--boot/semantic.cc22
3 files changed, 9 insertions, 36 deletions
diff --git a/boot/ast.cc b/boot/ast.cc
index 14bad30..2a22d69 100644
--- a/boot/ast.cc
+++ b/boot/ast.cc
@@ -348,10 +348,6 @@ namespace elna::boot
{
entry_statement->accept(this);
}
- if (unit->return_expression != nullptr)
- {
- unit->return_expression->accept(this);
- }
}
void walking_visitor::visit(type_declaration *declaration)
@@ -879,10 +875,9 @@ namespace elna::boot
std::vector<type_declaration *>&& types,
std::vector<variable_declaration *>&& variables,
std::vector<procedure_declaration *>&& procedures,
- std::vector<statement *>&& entry_point,
- expression *const return_expression)
+ std::vector<statement *>&& entry_point)
: node(position),
- procedure_body(std::move(constants), std::move(variables), std::move(entry_point), return_expression),
+ procedure_body(std::move(constants), std::move(variables), std::move(entry_point)),
imports(std::move(imports)), types(std::move(types)), procedures(std::move(procedures))
{
}
@@ -894,7 +889,7 @@ namespace elna::boot
bool unit::has_body() const
{
- return !this->entry_point.empty() || this->return_expression != nullptr;
+ return !this->entry_point.empty();
}
unit::~unit()
diff --git a/boot/parser.yy b/boot/parser.yy
index ef887ab..9f610ee 100644
--- a/boot/parser.yy
+++ b/boot/parser.yy
@@ -136,7 +136,7 @@ along with GCC; see the file COPYING3. If not see
%type <elna::boot::type_expression *> type_expression;
%type <std::vector<elna::boot::type_expression *>> type_expressions;
%type <elna::boot::traits_expression *> traits_expression;
-%type <elna::boot::expression *> expression operand simple_expression return_statement;
+%type <elna::boot::expression *> expression operand simple_expression procedure_return;
%type <elna::boot::unary_expression *> unary_expression;
%type <elna::boot::binary_expression *> binary_expression;
%type <std::vector<elna::boot::expression *>> expressions actual_parameter_list;
@@ -164,13 +164,13 @@ along with GCC; see the file COPYING3. If not see
%type <std::vector<elna::boot::import_declaration *>> import_declarations import_part;
%%
program:
- import_part constant_part type_part variable_part procedure_part statement_part return_statement "end" "."
+ import_part constant_part type_part variable_part procedure_part statement_part "end" "."
{
- boot::unit *tree = new boot::unit(boot::make_position(@$), $1, $2, $3, $4, $5, $6, $7);
+ boot::unit *tree = new boot::unit(boot::make_position(@$), $1, $2, $3, $4, $5, $6);
driver.tree.reset(tree);
}
procedure_body:
- constant_part variable_part statement_part return_statement "end"
+ constant_part variable_part statement_part procedure_return
{ $$ = std::make_unique<boot::procedure_body>($1, $2, $3, $4); }
statement_part:
@@ -233,9 +233,9 @@ elsif_then_statements:
$$.emplace($$.begin(), branch);
}
| /* no branches */ {}
-return_statement:
+procedure_return:
"return" expression { $$ = $2; }
- | /* no return statement */ { $$ = nullptr; }
+ | "return" { $$ = nullptr; }
literal:
INTEGER { $$ = new boot::literal<std::int32_t>(boot::make_position(@$), $1); }
| WORD { $$ = new boot::literal<std::uint32_t>(boot::make_position(@$), $1); }
diff --git a/boot/semantic.cc b/boot/semantic.cc
index d7a23be..dd9022b 100644
--- a/boot/semantic.cc
+++ b/boot/semantic.cc
@@ -177,24 +177,6 @@ namespace elna::boot
void type_analysis_visitor::visit(unit *unit)
{
walking_visitor::visit(unit);
-
- if (unit->has_body())
- {
- if (unit->return_expression != nullptr)
- {
- type return_type = this->bag.lookup("Int")->is_type()->symbol;
-
- if (!is_assignable_from(return_type, unit->return_expression->type_decoration))
- {
- add_error<type_expectation_error>(type_expectation_error::kind::result,
- unit->return_expression->position());
- }
- }
- else
- {
- add_error<return_error>("module", unit->position());
- }
- }
}
void type_analysis_visitor::visit(assign_statement *statement)
@@ -773,10 +755,6 @@ namespace elna::boot
{
statement->accept(this);
}
- if (unit->return_expression != nullptr)
- {
- unit->return_expression->accept(this);
- }
this->bag.leave();
}
}