aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/elna/boot/ast.h33
-rw-r--r--include/elna/boot/materialization.h4
-rw-r--r--include/elna/boot/name_analysis.h6
-rw-r--r--include/elna/boot/type_check.h4
-rw-r--r--include/elna/boot/validation.h3
5 files changed, 32 insertions, 18 deletions
diff --git a/include/elna/boot/ast.h b/include/elna/boot/ast.h
index 6a3b9c9..82dde80 100644
--- a/include/elna/boot/ast.h
+++ b/include/elna/boot/ast.h
@@ -21,6 +21,8 @@ along with GCC; see the file COPYING3. If not see
#include <string>
#include <vector>
#include <optional>
+#include <concepts>
+#include <ranges>
#include "elna/boot/symbol.h"
#include "elna/boot/result.h"
@@ -321,12 +323,6 @@ namespace elna::boot
void visit(literal<std::uint32_t> *) override;
void visit(literal<std::nullptr_t> *) override;
void visit(literal<std::string> *) override;
-
- protected:
- /// Passes needing the entry point's scope override this.
- virtual void visit_entry_point(unit *unit);
- /// Passes needing the scope of a block override this.
- virtual void traverse_block(block& body);
};
/**
@@ -700,7 +696,30 @@ namespace elna::boot
procedure_body& operator=(procedure_body&& that) noexcept;
};
- void traverse_body(parser_visitor *visitor, const procedure_body& body);
+ /**
+ * Vistis all nodes in a container.
+ *
+ * \tparam R Container or range type.
+ * \param visitor Visitor.
+ * \param nodes Visited container.
+ */
+ template<std::ranges::input_range R>
+ requires std::derived_from<std::remove_pointer_t<std::ranges::range_value_t<R>>, node>
+ void visit_all(parser_visitor *visitor, R&& nodes)
+ {
+ for (auto *const node : nodes)
+ {
+ node->accept(visitor);
+ }
+ }
+
+ /**
+ * Visits the declarations and the statements of a block.
+ *
+ * \param visitor Visitor.
+ * \param nodes Visited block.
+ */
+ void traverse_block(parser_visitor *visitor, const block& body);
/**
* Procedure definition.
diff --git a/include/elna/boot/materialization.h b/include/elna/boot/materialization.h
index 63d6155..b239836 100644
--- a/include/elna/boot/materialization.h
+++ b/include/elna/boot/materialization.h
@@ -49,6 +49,7 @@ namespace elna::boot
public:
explicit materialization_visitor(const target_info& target);
+ void visit(unit *unit) override;
void visit(procedure_declaration *declaration) override;
void visit(variable_declaration *declaration) override;
@@ -56,8 +57,5 @@ namespace elna::boot
void visit(literal<integer_literal> *literal) override;
void visit(literal<float_literal> *literal) override;
-
- protected:
- void visit_entry_point(unit *unit) override;
};
}
diff --git a/include/elna/boot/name_analysis.h b/include/elna/boot/name_analysis.h
index 004aeae..c726a4f 100644
--- a/include/elna/boot/name_analysis.h
+++ b/include/elna/boot/name_analysis.h
@@ -298,11 +298,7 @@ namespace elna::boot
std::optional<type> lookup_pointer_like_field(const std::string& field_name,
const type& element_type);
type lookup_field(const type& composite_type, const std::string& field_name);
- /*
- * Visits the declarations and the statements of a block in the scope
- * the caller has opened for it.
- */
- void traverse_block(block& body);
+
/*
* Opens the scope of a block, remembers it on the block for the later
* passes and visits the block in it.
diff --git a/include/elna/boot/type_check.h b/include/elna/boot/type_check.h
index 620af74..5e4f792 100644
--- a/include/elna/boot/type_check.h
+++ b/include/elna/boot/type_check.h
@@ -305,12 +305,12 @@ namespace elna::boot
type promote_variadic_argument(const expression& argument);
protected:
- void visit_entry_point(unit *unit) override;
- void traverse_block(block& body) override;
+ void traverse_block(block& body);
public:
explicit type_analysis_visitor(symbol_bag bag, const target_info& target);
+ void visit(unit *unit) override;
void visit(procedure_declaration *declaration) override;
void visit(assign_statement *statement) override;
void visit(variable_declaration *declaration) override;
diff --git a/include/elna/boot/validation.h b/include/elna/boot/validation.h
index d3a22d1..2af68e0 100644
--- a/include/elna/boot/validation.h
+++ b/include/elna/boot/validation.h
@@ -48,7 +48,8 @@ namespace elna::boot
symbol_bag& bag;
evaluator constant_evaluator;
- void visit_statements(const std::vector<statement *>& statements);
+ void visit_statements(const std::vector<statement *>& statements,
+ const std::shared_ptr<symbol_table>& scope);
/// Visits the statements of a block in its own scope.
void visit_block(const block& body);