mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
C++: use noexcept and constexpr
There are probably more opportunities for them. So far, I observed no performance improvements. * data/c++.m4, data/lalr1.cc, data/stack.hh: here.
This commit is contained in:
26
data/c++.m4
26
data/c++.m4
@@ -72,6 +72,20 @@ m4_define([b4_cxx_portability],
|
|||||||
# define YY_MOVE_REF(Type) Type&
|
# define YY_MOVE_REF(Type) Type&
|
||||||
# define YY_RVREF(Type) const Type&
|
# define YY_RVREF(Type) const Type&
|
||||||
# define YY_COPY(Type) const Type&
|
# define YY_COPY(Type) const Type&
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Support noexcept when possible.
|
||||||
|
#if 201103L <= YY_CPLUSPLUS
|
||||||
|
# define YY_NOEXCEPT noexcept
|
||||||
|
#else
|
||||||
|
# define YY_NOEXCEPT
|
||||||
|
#endif[]dnl
|
||||||
|
|
||||||
|
// Support noexcept when possible.
|
||||||
|
#if 201703 <= YY_CPLUSPLUS
|
||||||
|
# define YY_CONSTEXPR constexpr
|
||||||
|
#else
|
||||||
|
# define YY_CONSTEXPR
|
||||||
#endif[]dnl
|
#endif[]dnl
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -266,7 +280,7 @@ m4_define([b4_symbol_type_declare],
|
|||||||
void clear ();
|
void clear ();
|
||||||
|
|
||||||
/// Whether empty.
|
/// Whether empty.
|
||||||
bool empty () const;
|
bool empty () const YY_NOEXCEPT;
|
||||||
|
|
||||||
/// Destructive move, \a s is emptied into this.
|
/// Destructive move, \a s is emptied into this.
|
||||||
void move (basic_symbol& s);
|
void move (basic_symbol& s);
|
||||||
@@ -307,10 +321,10 @@ m4_define([b4_symbol_type_declare],
|
|||||||
|
|
||||||
/// The (internal) type number (corresponding to \a type).
|
/// The (internal) type number (corresponding to \a type).
|
||||||
/// \a empty when empty.
|
/// \a empty when empty.
|
||||||
symbol_number_type type_get () const;
|
symbol_number_type type_get () const YY_NOEXCEPT;
|
||||||
|
|
||||||
/// The token.
|
/// The token.
|
||||||
token_type token () const;
|
token_type token () const YY_NOEXCEPT;
|
||||||
|
|
||||||
/// The symbol type.
|
/// The symbol type.
|
||||||
/// \a empty_symbol when empty.
|
/// \a empty_symbol when empty.
|
||||||
@@ -402,7 +416,7 @@ m4_define([b4_public_types_define],
|
|||||||
|
|
||||||
template <typename Base>
|
template <typename Base>
|
||||||
bool
|
bool
|
||||||
]b4_parser_class_name[::basic_symbol<Base>::empty () const
|
]b4_parser_class_name[::basic_symbol<Base>::empty () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
return Base::type_get () == empty_symbol;
|
return Base::type_get () == empty_symbol;
|
||||||
}
|
}
|
||||||
@@ -445,13 +459,13 @@ m4_define([b4_public_types_define],
|
|||||||
}
|
}
|
||||||
|
|
||||||
]b4_inline([$1])[int
|
]b4_inline([$1])[int
|
||||||
]b4_parser_class_name[::by_type::type_get () const
|
]b4_parser_class_name[::by_type::type_get () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
]b4_token_ctor_if([[
|
]b4_token_ctor_if([[
|
||||||
]b4_inline([$1])b4_parser_class_name[::token_type
|
]b4_inline([$1])b4_parser_class_name[::token_type
|
||||||
]b4_parser_class_name[::by_type::token () const
|
]b4_parser_class_name[::by_type::token () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
// YYTOKNUM[NUM] -- (External) token number corresponding to the
|
// YYTOKNUM[NUM] -- (External) token number corresponding to the
|
||||||
// (internal) symbol number NUM (which must be that of a token). */
|
// (internal) symbol number NUM (which must be that of a token). */
|
||||||
|
|||||||
@@ -296,26 +296,26 @@ m4_define([b4_shared_declarations],
|
|||||||
struct by_state
|
struct by_state
|
||||||
{
|
{
|
||||||
/// Default constructor.
|
/// Default constructor.
|
||||||
by_state ();
|
by_state () YY_NOEXCEPT;
|
||||||
|
|
||||||
/// The symbol type as needed by the constructor.
|
/// The symbol type as needed by the constructor.
|
||||||
typedef state_type kind_type;
|
typedef state_type kind_type;
|
||||||
|
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
by_state (kind_type s);
|
by_state (kind_type s) YY_NOEXCEPT;
|
||||||
|
|
||||||
/// Copy constructor.
|
/// Copy constructor.
|
||||||
by_state (const by_state& other);
|
by_state (const by_state& other) YY_NOEXCEPT;
|
||||||
|
|
||||||
/// Record that this symbol is empty.
|
/// Record that this symbol is empty.
|
||||||
void clear ();
|
void clear () YY_NOEXCEPT;
|
||||||
|
|
||||||
/// Steal the symbol type from \a that.
|
/// Steal the symbol type from \a that.
|
||||||
void move (by_state& that);
|
void move (by_state& that);
|
||||||
|
|
||||||
/// The (internal) type number (corresponding to \a state).
|
/// The (internal) type number (corresponding to \a state).
|
||||||
/// \a empty_symbol when empty.
|
/// \a empty_symbol when empty.
|
||||||
symbol_number_type type_get () const;
|
symbol_number_type type_get () const YY_NOEXCEPT;
|
||||||
|
|
||||||
/// The state number used to denote an empty symbol.
|
/// The state number used to denote an empty symbol.
|
||||||
enum { empty_state = -1 };
|
enum { empty_state = -1 };
|
||||||
@@ -570,16 +570,16 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
]b4_token_ctor_if([], [b4_public_types_define([cc])])[
|
]b4_token_ctor_if([], [b4_public_types_define([cc])])[
|
||||||
|
|
||||||
// by_state.
|
// by_state.
|
||||||
]b4_parser_class_name[::by_state::by_state ()
|
]b4_parser_class_name[::by_state::by_state () YY_NOEXCEPT
|
||||||
: state (empty_state)
|
: state (empty_state)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
]b4_parser_class_name[::by_state::by_state (const by_state& other)
|
]b4_parser_class_name[::by_state::by_state (const by_state& other) YY_NOEXCEPT
|
||||||
: state (other.state)
|
: state (other.state)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void
|
void
|
||||||
]b4_parser_class_name[::by_state::clear ()
|
]b4_parser_class_name[::by_state::clear () YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
state = empty_state;
|
state = empty_state;
|
||||||
}
|
}
|
||||||
@@ -591,12 +591,12 @@ m4_if(b4_prefix, [yy], [],
|
|||||||
that.clear ();
|
that.clear ();
|
||||||
}
|
}
|
||||||
|
|
||||||
]b4_parser_class_name[::by_state::by_state (state_type s)
|
]b4_parser_class_name[::by_state::by_state (state_type s) YY_NOEXCEPT
|
||||||
: state (s)
|
: state (s)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
]b4_parser_class_name[::symbol_number_type
|
]b4_parser_class_name[::symbol_number_type
|
||||||
]b4_parser_class_name[::by_state::type_get () const
|
]b4_parser_class_name[::by_state::type_get () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
if (state == empty_state)
|
if (state == empty_state)
|
||||||
return empty_symbol;
|
return empty_symbol;
|
||||||
|
|||||||
@@ -86,33 +86,38 @@ m4_define([b4_stack_define],
|
|||||||
operator[](0).move (t);
|
operator[](0).move (t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Pop elements from the stack.
|
||||||
void
|
void
|
||||||
pop (int n = 1)
|
pop (int n = 1) YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
for (; 0 < n; --n)
|
for (; 0 < n; --n)
|
||||||
seq_.pop_back ();
|
seq_.pop_back ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Pop all elements from the stack.
|
||||||
void
|
void
|
||||||
clear ()
|
clear () YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
seq_.clear ();
|
seq_.clear ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Number of elements on the stack.
|
||||||
size_type
|
size_type
|
||||||
size () const
|
size () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
return seq_.size ();
|
return seq_.size ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Iterator on top of the stack (going downwards).
|
||||||
const_iterator
|
const_iterator
|
||||||
begin () const
|
begin () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
return seq_.rbegin ();
|
return seq_.rbegin ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Bottom of the stack.
|
||||||
const_iterator
|
const_iterator
|
||||||
end () const
|
end () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
return seq_.rend ();
|
return seq_.rend ();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ m4_define([b4_variant_define],
|
|||||||
typedef variant<S> self_type;
|
typedef variant<S> self_type;
|
||||||
|
|
||||||
/// Empty construction.
|
/// Empty construction.
|
||||||
variant ()
|
variant () YY_NOEXCEPT
|
||||||
: yybuffer_ ()]b4_parse_assert_if([
|
: yybuffer_ ()]b4_parse_assert_if([
|
||||||
, yytypeid_ (YY_NULLPTR)])[
|
, yytypeid_ (YY_NULLPTR)])[
|
||||||
{}
|
{}
|
||||||
@@ -109,7 +109,7 @@ m4_define([b4_variant_define],
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Destruction, allowed only if empty.
|
/// Destruction, allowed only if empty.
|
||||||
~variant ()
|
~variant () YY_NOEXCEPT
|
||||||
{]b4_parse_assert_if([
|
{]b4_parse_assert_if([
|
||||||
YYASSERT (!yytypeid_);
|
YYASSERT (!yytypeid_);
|
||||||
])[}
|
])[}
|
||||||
@@ -170,7 +170,7 @@ m4_define([b4_variant_define],
|
|||||||
/// Accessor to a built \a T.
|
/// Accessor to a built \a T.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T&
|
T&
|
||||||
as ()
|
as () YY_NOEXCEPT
|
||||||
{]b4_parse_assert_if([
|
{]b4_parse_assert_if([
|
||||||
YYASSERT (yytypeid_);
|
YYASSERT (yytypeid_);
|
||||||
YYASSERT (*yytypeid_ == typeid (T));
|
YYASSERT (*yytypeid_ == typeid (T));
|
||||||
@@ -181,7 +181,7 @@ m4_define([b4_variant_define],
|
|||||||
/// Const accessor to a built \a T (for %printer).
|
/// Const accessor to a built \a T (for %printer).
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const T&
|
const T&
|
||||||
as () const
|
as () const YY_NOEXCEPT
|
||||||
{]b4_parse_assert_if([
|
{]b4_parse_assert_if([
|
||||||
YYASSERT (yytypeid_);
|
YYASSERT (yytypeid_);
|
||||||
YYASSERT (*yytypeid_ == typeid (T));
|
YYASSERT (*yytypeid_ == typeid (T));
|
||||||
@@ -199,7 +199,7 @@ m4_define([b4_variant_define],
|
|||||||
/// variant::move ().
|
/// variant::move ().
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void
|
void
|
||||||
swap (self_type& other)
|
swap (self_type& other) YY_NOEXCEPT
|
||||||
{]b4_parse_assert_if([
|
{]b4_parse_assert_if([
|
||||||
YYASSERT (yytypeid_);
|
YYASSERT (yytypeid_);
|
||||||
YYASSERT (*yytypeid_ == *other.yytypeid_);])[
|
YYASSERT (*yytypeid_ == *other.yytypeid_);])[
|
||||||
@@ -258,7 +258,7 @@ m4_define([b4_variant_define],
|
|||||||
/// Accessor to raw memory as \a T.
|
/// Accessor to raw memory as \a T.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T*
|
T*
|
||||||
yyas_ ()
|
yyas_ () YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
void *yyp = yybuffer_.yyraw;
|
void *yyp = yybuffer_.yyraw;
|
||||||
return static_cast<T*> (yyp);
|
return static_cast<T*> (yyp);
|
||||||
@@ -267,7 +267,7 @@ m4_define([b4_variant_define],
|
|||||||
/// Const accessor to raw memory as \a T.
|
/// Const accessor to raw memory as \a T.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const T*
|
const T*
|
||||||
yyas_ () const
|
yyas_ () const YY_NOEXCEPT
|
||||||
{
|
{
|
||||||
const void *yyp = yybuffer_.yyraw;
|
const void *yyp = yybuffer_.yyraw;
|
||||||
return static_cast<const T*> (yyp);
|
return static_cast<const T*> (yyp);
|
||||||
|
|||||||
@@ -316,6 +316,7 @@ AT_CHECK([[$PERL -n -0777 -e '
|
|||||||
|YYPUSH_MORE(?:_DEFINED)?
|
|YYPUSH_MORE(?:_DEFINED)?
|
||||||
|YYUSE
|
|YYUSE
|
||||||
|YY_ATTRIBUTE(?:_PURE|_UNUSED)?
|
|YY_ATTRIBUTE(?:_PURE|_UNUSED)?
|
||||||
|
|YY_CONSTEXPR
|
||||||
|YY_COPY
|
|YY_COPY
|
||||||
|YY_CPLUSPLUS
|
|YY_CPLUSPLUS
|
||||||
|YY_IGNORE_MAYBE_UNINITIALIZED_(?:BEGIN|END)
|
|YY_IGNORE_MAYBE_UNINITIALIZED_(?:BEGIN|END)
|
||||||
@@ -323,6 +324,7 @@ AT_CHECK([[$PERL -n -0777 -e '
|
|||||||
|YY_MOVE
|
|YY_MOVE
|
||||||
|YY_MOVE_OR_COPY
|
|YY_MOVE_OR_COPY
|
||||||
|YY_MOVE_REF
|
|YY_MOVE_REF
|
||||||
|
|YY_NOEXCEPT
|
||||||
|YY_NULLPTR
|
|YY_NULLPTR
|
||||||
|YY_RVREF
|
|YY_RVREF
|
||||||
|YY_\w+_INCLUDED
|
|YY_\w+_INCLUDED
|
||||||
|
|||||||
Reference in New Issue
Block a user