summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/ast/var-dec.hh
blob: fd15b7e45f0597a75766a6f6ae69f71e5ebcace6 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
 ** \file ast/var-dec.hh
 ** \brief Declaration of ast::VarDec.
 */

#pragma once

#include <ast/dec.hh>
#include <ast/escapable.hh>
#include <ast/exp.hh>
#include <ast/name-ty.hh>

namespace ast
{
  /// VarDec.
  class VarDec
    : public Dec
    , public Escapable
  {
  public:
    /** \name Ctor & dtor.
     ** \{ */
    /// Construct a VarDec node.
    VarDec(const Location& location,
           misc::symbol name,
           NameTy* type_name,
           Exp* init);
    VarDec(const VarDec&) = delete;
    VarDec& operator=(const VarDec&) = delete;
    /// Destroy a VarDec node.
    ~VarDec() override;
    /** \} */

    /// \name Visitors entry point.
    /// \{ */
    /// Accept a const visitor \a v.
    void accept(ConstVisitor& v) const override;
    /// Accept a non-const visitor \a v.
    void accept(Visitor& v) override;
    /// \}

    /** \name Accessors.
     ** \{ */
    /// Return optional type of the declared variable.
    const NameTy* type_name_get() const;
    /// Return optional type of the declared variable.
    NameTy* type_name_get();
    /// Return the initial value (expression) assigned to the variable.
    const Exp* init_get() const;
    /// Return the initial value (expression) assigned to the variable.
    Exp* init_get();
    /** \} */

  protected:
    /// Optional type of the declared variable.
    NameTy* type_name_;
    /// The initial value (expression) assigned to the variable.
    Exp* init_;
  };
} // namespace ast
#include <ast/var-dec.hxx>