1 # C++ skeleton for Bison
3 # Copyright (C) 2002-2015, 2018-2020 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # Name of the file containing the stack class, if we want this file.
22 b4_header_if([b4_required_version_if([30200], [],
23 [m4_define([b4_stack_file
], [stack
.hh
])])])
28 m4_define([b4_stack_define
],
29 [[ /// A stack with random access from its top.
30 template <typename T
, typename S
= std::vector
<T
> >
34 // Hide our reversed order.
35 typedef typename
S::iterator iterator
;
36 typedef typename
S::const_iterator const_iterator
;
37 typedef typename
S::size_type size_type
;
38 typedef typename
std::ptrdiff_t index_type
;
40 stack (size_type n
= 200)
44 #if 201103L <= YY_CPLUSPLUS
46 stack (const stack
&) = delete;
48 stack
& operator= (const stack
&) = delete;
53 /// Index 0 returns the topmost element.
55 operator[] (index_type i
) const
57 return seq_
[size_type (size () - 1 - i
)];
62 /// Index 0 returns the topmost element.
64 operator[] (index_type i
)
66 return seq_
[size_type (size () - 1 - i
)];
69 /// Steal the contents of \a t.
71 /// Close to move-semantics.
73 push (YY_MOVE_REF (T
) t
)
75 seq_
.push_back (T ());
76 operator[] (0).move (t
);
79 /// Pop elements from the stack.
81 pop (std::ptrdiff_t n
= 1) YY_NOEXCEPT
87 /// Pop all elements from the stack.
94 /// Number of elements on the stack.
96 size () const YY_NOEXCEPT
98 return index_type (seq_
.size ());
101 /// Iterator on top of the stack (going downwards).
103 begin () const YY_NOEXCEPT
105 return seq_
.begin ();
108 /// Bottom of the stack.
110 end () const YY_NOEXCEPT
115 /// Present a slice of the top of a stack.
119 slice (const stack
& stack
, index_type range
)
125 operator[] (index_type i
) const
127 return stack_
[range_
- i
];
136 #if YY_CPLUSPLUS < 201103L
138 stack (const stack
&);
140 stack
& operator= (const stack
&);
142 /// The wrapped container.
147 m4_ifdef([b4_stack_file
],
148 [b4_output_begin([b4_dir_prefix
], [b4_stack_file
])[
150 // Starting with Bison 3.2, this file is useless: the structure it
151 // used to define is now defined with the parser itself.
153 // To get rid of this file:
154 // 1. add '%require "3.2"' (or newer) to your grammar file
155 // 2. remove references to this file from your build system.