summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/desugar/bounds-checking-visitor.hh
blob: 65e955d92ddd2df66e9c0157d7f97e717b872075 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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