aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-07-13 18:14:45 +0200
committerEugen Wissner <belka@caraus.de>2026-07-13 18:14:45 +0200
commit500c0676b3f6cd5a2297987d5b0dc7ccf34a28d9 (patch)
treea394c73de9273489e6045f3d252714b5ac69b17c /include
parent97741a01323021ccec8b0b60c6f8318c88ac373a (diff)
downloadelna-500c0676b3f6cd5a2297987d5b0dc7ccf34a28d9.tar.gz
Make return statement part of the body and not a statement
Diffstat (limited to 'include')
-rw-r--r--include/elna/boot/ast.h62
-rw-r--r--include/elna/boot/semantic.h5
-rw-r--r--include/elna/gcc/elna-generic.h3
3 files changed, 23 insertions, 47 deletions
diff --git a/include/elna/boot/ast.h b/include/elna/boot/ast.h
index d9f3af8..ab79c30 100644
--- a/include/elna/boot/ast.h
+++ b/include/elna/boot/ast.h
@@ -64,7 +64,6 @@ namespace elna::boot
class if_statement;
class import_declaration;
class while_statement;
- class return_statement;
class case_statement;
class traits_expression;
class unit;
@@ -103,7 +102,6 @@ namespace elna::boot
virtual void visit(if_statement *) = 0;
virtual void visit(import_declaration *) = 0;
virtual void visit(while_statement *) = 0;
- virtual void visit(return_statement *) = 0;
virtual void visit(defer_statement *) = 0;
virtual void visit(case_statement *) = 0;
virtual void visit(empty_statement *) = 0;
@@ -148,7 +146,6 @@ namespace elna::boot
[[noreturn]] virtual void visit(if_statement *) override;
[[noreturn]] virtual void visit(import_declaration *) override;
[[noreturn]] virtual void visit(while_statement *) override;
- [[noreturn]] virtual void visit(return_statement *) override;
[[noreturn]] virtual void visit(defer_statement *) override;
[[noreturn]] virtual void visit(empty_statement *) override;
[[noreturn]] virtual void visit(case_statement *) override;
@@ -191,7 +188,6 @@ namespace elna::boot
virtual void visit(if_statement *) override;
virtual void visit(import_declaration *) override;
virtual void visit(while_statement *statement) override;
- virtual void visit(return_statement *statement) override;
virtual void visit(defer_statement *statement) override;
virtual void visit(empty_statement *) override;
virtual void visit(case_statement *statement) override;
@@ -416,26 +412,21 @@ namespace elna::boot
struct procedure_body
{
- procedure_body(std::vector<constant_declaration*>&& constants,
- std::vector<variable_declaration *>&& variables, std::vector<statement *>&& statements);
- procedure_body(std::vector<constant_declaration*>&& constants, std::vector<variable_declaration *>&& variables);
+ const std::vector<constant_declaration *> constants;
+ const std::vector<variable_declaration *> variables;
+ const std::vector<statement *> entry_point;
+ expression *const return_expression{ nullptr };
+
+ procedure_body(std::vector<constant_declaration *>&& constants,
+ std::vector<variable_declaration *>&& variables,
+ std::vector<statement *>&& entry_point,
+ expression *return_expr = nullptr);
procedure_body(const procedure_body&) = delete;
procedure_body(procedure_body&& that);
procedure_body& operator=(const procedure_body&) = delete;
- procedure_body& operator=(procedure_body&& that);
-
- const std::vector<variable_declaration *>& variables();
- const std::vector<constant_declaration *>& constants();
- const std::vector<statement *>& statements();
virtual ~procedure_body();
-
- private:
- std::vector<variable_declaration *> m_variables;
- std::vector<constant_declaration *> m_constants;
- std::vector<statement *> m_statements;
-
};
/**
@@ -526,19 +517,6 @@ namespace elna::boot
virtual ~conditional_statements();
};
- class return_statement : public statement
- {
- public:
- expression *m_return_expression;
-
- return_statement(const struct position position, expression *return_expression);
- void accept(parser_visitor *visitor) override;
-
- expression& return_expression();
-
- virtual ~return_statement() override;
- };
-
struct switch_case
{
std::vector<expression *> labels;
@@ -728,19 +706,23 @@ namespace elna::boot
virtual ~while_statement() override;
};
- class unit : public node
+ class unit : public node, public procedure_body
{
public:
- const std::optional<std::vector<statement *>> entry_point;
-
- 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;
+ const std::vector<import_declaration *> imports;
+ const std::vector<type_declaration *> types;
+ const std::vector<procedure_declaration *> procedures;
unit(const struct position position);
- unit(const struct position position, std::vector<statement *>&& entry_point);
+ unit(const struct 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,
+ expression *const return_expression = nullptr);
+ bool has_body() const;
virtual void accept(parser_visitor *visitor) override;
virtual ~unit() override;
diff --git a/include/elna/boot/semantic.h b/include/elna/boot/semantic.h
index b94d269..1e81ebb 100644
--- a/include/elna/boot/semantic.h
+++ b/include/elna/boot/semantic.h
@@ -18,10 +18,8 @@ along with GCC; see the file COPYING3. If not see
#pragma once
#include <string>
-#include <unordered_map>
#include <memory>
#include <set>
-#include <deque>
#include "elna/boot/ast.h"
#include "elna/boot/result.h"
@@ -147,7 +145,6 @@ namespace elna::boot
*/
class type_analysis_visitor final : public walking_visitor, public error_container
{
- bool returns;
symbol_bag bag;
std::shared_ptr<procedure_info> current_procedure;
@@ -161,7 +158,7 @@ namespace elna::boot
explicit type_analysis_visitor(symbol_bag bag);
void visit(procedure_declaration *declaration) override;
- void visit(return_statement *statement) override;
+ void visit(unit *unit) override;
void visit(assign_statement *statement) override;
void visit(variable_declaration *declaration) override;
void visit(type_declaration *declaration) override;
diff --git a/include/elna/gcc/elna-generic.h b/include/elna/gcc/elna-generic.h
index 28bfe2d..2fe4d48 100644
--- a/include/elna/gcc/elna-generic.h
+++ b/include/elna/gcc/elna-generic.h
@@ -18,8 +18,6 @@ along with GCC; see the file COPYING3. If not see
#pragma once
#include <string>
-#include <forward_list>
-
#include "elna/boot/ast.h"
#include "elna/boot/symbol.h"
#include "elna/boot/semantic.h"
@@ -89,7 +87,6 @@ namespace elna::gcc
void visit(boot::if_statement *statement) override;
void visit(boot::import_declaration *) override;
void visit(boot::while_statement *statement) override;
- void visit(boot::return_statement *statement) override;
void visit(boot::defer_statement *statement) override;
void visit(boot::empty_statement *) override;
void visit(boot::case_statement *statement) override;