summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/ast/chunk.hxx
blob: a3c3ada4353cac57d3efeb1608e13c4382f88454 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/**
 ** \file ast/chunk.hxx
 ** \brief Implementation of ast::Chunk.
 */

#pragma once

#include <ast/chunk.hh>
#include <ast/visitor.hh>
#include <misc/algorithm.hh>

namespace ast
{
  template <typename D>
  Chunk<D>::Chunk(const Location& location, Ds* decs)
    : ChunkInterface(location)
    , decs_(decs)
  {}

  template <typename D>
  Chunk<D>::Chunk(const Location& location)
    : ChunkInterface(location)
  {}

  template <typename D> Chunk<D>::~Chunk()
  {
    misc::deep_clear(*decs_);
    delete decs_;
  }

  template <typename D> inline void Chunk<D>::accept(Visitor& v) { v(*this); }

  template <typename D> inline void Chunk<D>::accept(ConstVisitor& v) const
  {
    v(*this);
  }

  template <typename D>
  inline constexpr typename Chunk<D>::reference
  Chunk<D>::operator[](size_type pos)
  {
    return decs_->operator[](pos);
  }

  template <typename D>
  inline constexpr typename Chunk<D>::const_reference
  Chunk<D>::operator[](size_type pos) const
  {
    return decs_->operator[](pos);
  }

  template <typename D> inline typename Chunk<D>::Ds& Chunk<D>::decs_get()
  {
    return *decs_;
  }

  template <typename D>
  inline const typename Chunk<D>::Ds& Chunk<D>::decs_get() const
  {
    return *decs_;
  }

  template <typename D> inline typename Chunk<D>::iterator Chunk<D>::begin()
  {
    return decs_->begin();
  }

  template <typename D>
  inline typename Chunk<D>::const_iterator Chunk<D>::begin() const
  {
    return decs_->begin();
  }

  template <typename D> inline typename Chunk<D>::iterator Chunk<D>::end()
  {
    return decs_->end();
  }

  template <typename D>
  inline typename Chunk<D>::const_iterator Chunk<D>::end() const
  {
    return decs_->end();
  }

  template <typename D> inline constexpr bool Chunk<D>::empty() const noexcept
  {
    return decs_->empty();
  }

  template <typename D>
  inline constexpr typename Chunk<D>::iterator
  Chunk<D>::erase(const_iterator pos)
  {
    return decs_->erase(pos);
  }

  template <typename D>
  inline constexpr typename Chunk<D>::iterator
  Chunk<D>::erase(const_iterator first, const_iterator last)
  {
    return decs_->erase(first, last);
  }

  template <typename D> Chunk<D>& Chunk<D>::push_front(D& d)
  {
    location_set(location_get() + d.location_get());
    decs_->insert(decs_->begin(), &d);
    return *this;
  }

  template <typename D> Chunk<D>& Chunk<D>::emplace_back(D& d)
  {
    location_set(location_get() + d.location_get());
    decs_->emplace_back(&d);
    return *this;
  }

} // namespace ast