From 967be9e750221ab2ab783f95df79bb26d290a45e Mon Sep 17 00:00:00 2001 From: Martial Simon Date: Mon, 15 Sep 2025 01:07:58 +0200 Subject: add: added projects --- tiger-compiler/src/desugar/libdesugar.hxx | 95 +++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 tiger-compiler/src/desugar/libdesugar.hxx (limited to 'tiger-compiler/src/desugar/libdesugar.hxx') 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace desugar +{ + /*----------. + | Helpers. | + `----------*/ + + template 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&); + + /*----------. + | Desugar. | + `----------*/ + + template + 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(desugar.result_get()); + } + + template + 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 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 A* raw_bounds_checks_add(const A& tree) + { + // Add array bounds checking code. + BoundsCheckingVisitor add_bounds_checks; + add_bounds_checks(tree); + return dynamic_cast(add_bounds_checks.result_get()); + } + + template A* bounds_checks_add(const A& tree) + { + // Add bounds checks. + A* transformed = raw_bounds_checks_add(tree); + assertion(transformed); + std::unique_ptr 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 -- cgit v1.2.3