aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/parser/state.ixx
blob: 6f9c4b7e4fd69638c68320b7a56e644410678f4b (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
// file      : xsde/cxx/parser/state.ixx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

namespace xsde
{
  namespace cxx
  {
    namespace parser
    {
      // stack
      //

      inline stack::
      ~stack ()
      {
        delete[] data_;
      }

      inline stack::
      stack (size_t el_size, void* first_el)
          : el_size_ (el_size), first_ (first_el),
            data_ (0), size_ (0), capacity_ (0)
      {
      }

      inline void stack::
      pop ()
      {
        --size_;
      }

      inline stack::error stack::
      push ()
      {
        if (size_ > capacity_)
          if (error e = grow ())
            return e;

        ++size_;

        return error_none;
      }

      inline void* stack::
      top ()
      {
        return size_ == 1 ? first_ : data_ + (size_ - 1) * el_size_;
      }

      inline size_t stack::
      element_size () const
      {
        return el_size_;
      }

      inline void stack::
      clear ()
      {
        size_ = 0;
      }

      // parser_stack
      //
      inline parser_stack::
      parser_stack (parser_state& first)
          : stack_ (sizeof (parser_state), &first)
      {
      }

      inline stack::error parser_stack::
      push (parser_state& s)
      {
        if (stack::error e = stack_.push ())
          return e;

        *static_cast<parser_state*> (stack_.top ()) = s;
        return stack::error_none;
      }

      inline void parser_stack::
      pop ()
      {
        stack_.pop ();
      }

      inline parser_state& parser_stack::
      top ()
      {
        return *static_cast<parser_state*> (stack_.top ());
      }

      inline void parser_stack::
      clear ()
      {
        stack_.clear ();
      }
    }
  }
}