summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/ast/function-dec.hh
blob: 0a94e95f8af5886b06070bba7ee908049f5000d9 (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
62
63
64
65
66
67
68
69
70
71
72
/**
 ** \file ast/function-dec.hh
 ** \brief Declaration of ast::FunctionDec.
 */

#pragma once

#include <ast/chunk.hh>
#include <ast/dec.hh>
#include <ast/exp.hh>
#include <ast/name-ty.hh>
#include <ast/type-constructor.hh>
#include <ast/var-dec.hh>

namespace ast
{
  /// FunctionDec.
  class FunctionDec
    : public Dec
    , public TypeConstructor
  {
  public:
    /** \name Ctor & dtor.
     ** \{ */
    /// Construct a FunctionDec node.
    FunctionDec(const Location& location,
                misc::symbol name,
                VarChunk* formals,
                NameTy* result,
                Exp* body);
    FunctionDec(const FunctionDec&) = delete;
    FunctionDec& operator=(const FunctionDec&) = delete;
    /// Destroy a FunctionDec node.
    ~FunctionDec() 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 formal arguments.
    const VarChunk& formals_get() const;
    /// Return formal arguments.
    VarChunk& formals_get();
    /// Return result type.
    const NameTy* result_get() const;
    /// Return result type.
    NameTy* result_get();
    /// Return instructions.
    const Exp* body_get() const;
    /// Return instructions.
    Exp* body_get();
    /// Set instructions.
    void body_set(Exp*);
    /** \} */

  protected:
    /// Formal arguments.
    VarChunk* formals_;
    /// Result type.
    NameTy* result_;
    /// Instructions.
    Exp* body_;
  };
} // namespace ast
#include <ast/function-dec.hxx>