summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/desugar/libdesugar.hxx
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /tiger-compiler/src/desugar/libdesugar.hxx
add: added projectsHEADmain
Diffstat (limited to 'tiger-compiler/src/desugar/libdesugar.hxx')
-rw-r--r--tiger-compiler/src/desugar/libdesugar.hxx95
1 files changed, 95 insertions, 0 deletions
diff --git a/tiger-compiler/src/desugar/libdesugar.hxx b/tiger-compiler/src/desugar/libdesugar.hxx
new file mode 100644
index 0000000..191bd8d
--- /dev/null
+++ b/tiger-compiler/src/desugar/libdesugar.hxx
@@ -0,0 +1,95 @@
+#pragma once
+
+/**
+ ** \file desugar/libdesugar.hxx
+ ** \brief Functions exported by the desugar module.
+ */
+
+#include <memory>
+
+#include <ast/chunk-list.hh>
+#include <ast/exp.hh>
+#include <bind/libbind.hh>
+#include <desugar/bounds-checking-visitor.hh>
+#include <desugar/desugar-visitor.hh>
+#include <desugar/libdesugar.hh>
+#include <escapes/libescapes.hh>
+#include <overload/liboverload.hh>
+#include <type/libtype.hh>
+
+namespace desugar
+{
+ /*----------.
+ | Helpers. |
+ `----------*/
+
+ template <typename A> void bind_and_types_check(A& tree)
+ {
+ misc::error e;
+ // FIXME DONE: Some code was deleted here.
+ e << bind::bind(&tree);
+ e.ice_on_error_here();
+ e << type::types_check(tree);
+ e.ice_on_error_here();
+ }
+
+ // Explicit instantiation.
+ template void bind_and_types_check<ast::ChunkList>(ast::ChunkList&);
+
+ /*----------.
+ | Desugar. |
+ `----------*/
+
+ template <typename A>
+ A* raw_desugar(const A& tree, bool desugar_for_p, bool desugar_string_cmp_p)
+ {
+ // Desugar.
+ DesugarVisitor desugar(desugar_for_p, desugar_string_cmp_p);
+ desugar(tree);
+ return dynamic_cast<A*>(desugar.result_get());
+ }
+
+ template <typename A>
+ A* desugar(const A& tree, bool desugar_for_p, bool desugar_string_cmp_p)
+ {
+ // Desugar.
+ A* desugared = raw_desugar(tree, desugar_for_p, desugar_string_cmp_p);
+ assertion(desugared);
+ std::unique_ptr<A> desugared_ptr(desugared);
+ // Recompute the bindings and the types.
+ bind_and_types_check(*desugared_ptr);
+ return desugared_ptr.release();
+ }
+
+ /// Explicit instantiations.
+ template ast::ChunkList* raw_desugar(const ast::ChunkList&, bool, bool);
+ template ast::ChunkList* desugar(const ast::ChunkList&, bool, bool);
+
+ /*-----------------------.
+ | Array bounds checking. |
+ `-----------------------*/
+
+ template <typename A> A* raw_bounds_checks_add(const A& tree)
+ {
+ // Add array bounds checking code.
+ BoundsCheckingVisitor add_bounds_checks;
+ add_bounds_checks(tree);
+ return dynamic_cast<A*>(add_bounds_checks.result_get());
+ }
+
+ template <typename A> A* bounds_checks_add(const A& tree)
+ {
+ // Add bounds checks.
+ A* transformed = raw_bounds_checks_add(tree);
+ assertion(transformed);
+ std::unique_ptr<A> transformed_ptr(transformed);
+ // Recompute the bindings and the types.
+ bind_and_types_check(*transformed_ptr);
+ return transformed_ptr.release();
+ }
+
+ /// Explicit instantiations.
+ template ast::ChunkList* raw_bounds_checks_add(const ast::ChunkList&);
+ template ast::ChunkList* bounds_checks_add(const ast::ChunkList&);
+
+} // namespace desugar