#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