[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 6/8] glr2.cc: move strong_index_alias into implementation file
From: |
Akim Demaille |
Subject: |
[PATCH 6/8] glr2.cc: move strong_index_alias into implementation file |
Date: |
Sat, 16 Jan 2021 07:20:13 +0100 |
* data/skeletons/glr2.cc: here.
Fix coding style issues.
---
data/skeletons/glr2.cc | 166 ++++++++++++++++++++++-------------------
1 file changed, 89 insertions(+), 77 deletions(-)
diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index b5bf6082..8e295469 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -195,76 +195,6 @@ m4_define([b4_shared_declarations],
]b4_namespace_open[
-template <typename Parameter>
-class strong_index_alias
-{
-public:
- static strong_index_alias create(std::ptrdiff_t value) {
- strong_index_alias result;
- result.value_ = value;
- return result;
- }
-
- std::ptrdiff_t const& get() const { return value_; }
-
- size_t uget() const { return static_cast<size_t>(value_); }
-
- strong_index_alias operator+(std::ptrdiff_t other) const {
- return strong_index_alias(get() + other);
- }
-
- void operator+=(std::ptrdiff_t other) {
- value_ += other;
- }
-
- strong_index_alias operator-(std::ptrdiff_t other) {
- return strong_index_alias(get() - other);
- }
-
- void operator-=(std::ptrdiff_t other) {
- value_ -= other;
- }
-
- size_t operator-(strong_index_alias other) {
- return strong_index_alias(get() - other.get());
- }
-
- strong_index_alias& operator++() {
- ++value_;
- return *this;
- }
-
- bool isValid() const {
- return value_ != INVALID_INDEX;
- }
-
- void setInvalid() {
- value_ = INVALID_INDEX;
- }
-
- bool operator==(strong_index_alias other) {
- return get() == other.get();
- }
-
- bool operator!=(strong_index_alias other) {
- return get() != other.get();
- }
-
- bool operator<(strong_index_alias other) {
- return get() < other.get();
- }
-
-private:
- static const std::ptrdiff_t INVALID_INDEX;
-
- // WARNING: 0-initialized.
- std::ptrdiff_t value_;
-};
-
-template<typename T>
-const std::ptrdiff_t strong_index_alias<T>::INVALID_INDEX =
- std::numeric_limits<std::ptrdiff_t>::max();
-
]b4_bison_locations_if([m4_ifndef([b4_location_file],
[b4_location_define])])[
@@ -662,6 +592,95 @@ static void yypdumpstack (const glr_stack& yystack)
# define YYSTACKEXPANDABLE 1
#endif
+template <typename Parameter>
+class strong_index_alias
+{
+public:
+ static strong_index_alias create (std::ptrdiff_t value)
+ {
+ strong_index_alias result;
+ result.value_ = value;
+ return result;
+ }
+
+ std::ptrdiff_t const& get () const { return value_; }
+
+ size_t uget () const { return static_cast<size_t> (value_); }
+
+ strong_index_alias operator+ (std::ptrdiff_t other) const
+ {
+ return strong_index_alias (get () + other);
+ }
+
+ void operator+= (std::ptrdiff_t other)
+ {
+ value_ += other;
+ }
+
+ strong_index_alias operator- (std::ptrdiff_t other)
+ {
+ return strong_index_alias (get () - other);
+ }
+
+ void operator-= (std::ptrdiff_t other)
+ {
+ value_ -= other;
+ }
+
+ size_t operator- (strong_index_alias other)
+ {
+ return strong_index_alias (get () - other.get ());
+ }
+
+ strong_index_alias& operator++ ()
+ {
+ ++value_;
+ return *this;
+ }
+
+ bool isValid () const
+ {
+ return value_ != INVALID_INDEX;
+ }
+
+ void setInvalid()
+ {
+ value_ = INVALID_INDEX;
+ }
+
+ bool operator== (strong_index_alias other)
+ {
+ return get () == other.get ();
+ }
+
+ bool operator!= (strong_index_alias other)
+ {
+ return get () != other.get ();
+ }
+
+ bool operator< (strong_index_alias other)
+ {
+ return get () < other.get ();
+ }
+
+private:
+ static const std::ptrdiff_t INVALID_INDEX;
+
+ // WARNING: 0-initialized.
+ std::ptrdiff_t value_;
+};
+
+template<typename T>
+const std::ptrdiff_t strong_index_alias<T>::INVALID_INDEX =
+ std::numeric_limits<std::ptrdiff_t>::max ();
+
+typedef strong_index_alias<struct glr_state_set_tag> state_set_index;
+
+state_set_index create_state_set_index (std::ptrdiff_t value)
+{
+ return state_set_index::create (value);
+}
+
/** State numbers, as in LALR(1) machine */
typedef int state_num;
@@ -674,13 +693,6 @@ class semantic_option;
class glr_stack_item;
class glr_stack;
-typedef ]b4_namespace_ref[::strong_index_alias<struct glr_state_set_tag>
state_set_index;
-
-state_set_index create_state_set_index(std::ptrdiff_t value)
-{
- return state_set_index::create(value);
-}
-
/** Accessing symbol of state YYSTATE. */
static inline yysymbol_kind_t
yy_accessing_symbol (state_num yystate)
--
2.30.0
- [PATCH 0/8] glr2.cc: clean up, Akim Demaille, 2021/01/16
- [PATCH 1/8] glr2.cc: move parser::parse into glr_stack, Akim Demaille, 2021/01/16
- [PATCH 2/8] glr2.cc: make yygetToken a member of glr_stack, Akim Demaille, 2021/01/16
- [PATCH 3/8] glr2.cc: move free-functions into glr_stack, Akim Demaille, 2021/01/16
- [PATCH 4/8] glr2.cc: more free functions about the automaton into glr_stack, Akim Demaille, 2021/01/16
- [PATCH 5/8] glr2.cc: remove some useless qualifications, Akim Demaille, 2021/01/16
- [PATCH 6/8] glr2.cc: move strong_index_alias into implementation file,
Akim Demaille <=
- [PATCH 7/8] glr2.cc: formatting changes, Akim Demaille, 2021/01/16
- [PATCH 8/8] glr2.cc: don't prepare for subclassing, Akim Demaille, 2021/01/16