summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/desugar/bounds-checking-visitor.hh
diff options
context:
space:
mode:
Diffstat (limited to 'tiger-compiler/src/desugar/bounds-checking-visitor.hh')
-rw-r--r--tiger-compiler/src/desugar/bounds-checking-visitor.hh46
1 files changed, 46 insertions, 0 deletions
diff --git a/tiger-compiler/src/desugar/bounds-checking-visitor.hh b/tiger-compiler/src/desugar/bounds-checking-visitor.hh
new file mode 100644
index 0000000..65e955d
--- /dev/null
+++ b/tiger-compiler/src/desugar/bounds-checking-visitor.hh
@@ -0,0 +1,46 @@
+/**
+ ** \file desugar/bounds-checking-visitor.hh
+ ** \brief Declaration of desugar::BoundsCheckingVisitor.
+ */
+
+#pragma once
+
+#include <map>
+
+#include <astclone/cloner.hh>
+#include <parse/tweast.hh>
+
+namespace desugar
+{
+ /// \brief Add dynamic array bounds checks while duplicating an AST.
+ class BoundsCheckingVisitor : public astclone::Cloner
+ {
+ public:
+ /// Parent type.
+ using super_type = astclone::Cloner;
+
+ // Import overloaded virtual functions.
+ using super_type::operator();
+
+ /// Build a BoundsCheckingVisitor.
+ BoundsCheckingVisitor();
+
+ /// \name Visit methods.
+ /// \{
+ // FIXME: Some code was deleted here.
+ /// \}
+
+ private:
+ /// The bounds checking runtime.
+ ///
+ /// Additional definitions to insert in the prelude.
+ static const std::string prelude;
+
+ // Symbols would be nicer, but maps of symbols are
+ // inconvenient since there is no default ctor.
+ using boxes_type = std::map<const type::Array*, std::string>;
+ /// Map from an array type to the corresponding `box' type name.
+ boxes_type boxes_;
+ };
+
+} // namespace desugar