[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/6] glr2.cc: simplify
From: |
Akim Demaille |
Subject: |
[PATCH 5/6] glr2.cc: simplify |
Date: |
Sat, 26 Dec 2020 08:11:39 +0100 |
* data/skeletons/glr2.cc (glr_state_set::yyremoveDeletes): Use
vector::resize rather than vector::erase.
(glr_state::copyFrom): Merge into...
(glr_state::operator=): here.
Valentin wanted each assignment to be explicit, hence copyFrom rather
that operator=. But in 0a82316e54fead8c3f1cf41d2213c868ab88f508
(glr2.cc: example: use objects (not pointers) to represent the AST),
in order to get real objects to be processed correctly, we had to
introduce the assignment operator. Afterward, we also introduced a
full implementation of the copy-ctor, independent of copyFrom. As a
result, today the only invocation of copyFrom is from the assignment
operator. Simplify this.
---
data/skeletons/glr2.cc | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc
index 8790879e..af68077e 100644
--- a/data/skeletons/glr2.cc
+++ b/data/skeletons/glr2.cc
@@ -822,12 +822,6 @@ public:
}
glr_state& operator= (const glr_state& other)
- {
- copyFrom (other);
- return *this;
- }
-
- void copyFrom (const glr_state& other)
{]b4_parse_assert_if([[
check_ ();
other.check_ ();]])[
@@ -842,6 +836,7 @@ public:
else
setFirstVal (other.firstVal ());]b4_locations_if([[
yyloc = other.yyloc;]])[
+ return *this;
}
/** Type tag for the semantic value. If true, yysval applies, otherwise
@@ -1060,9 +1055,8 @@ class glr_state_set
j += 1;
}
}
- yystates.erase (yystates.begin () + static_cast<std::ptrdiff_t> (newsize),
yystates.end ());
- yylookaheadNeeds.erase (yylookaheadNeeds.begin () +
static_cast<std::ptrdiff_t> (newsize),
- yylookaheadNeeds.end ());
+ yystates.resize (newsize);
+ yylookaheadNeeds.resize (newsize);
}
--
2.29.2
- [PATCH 0/6] glr2.cc: more fixes, Akim Demaille, 2020/12/26
- [PATCH 1/6] glr: comment changes, Akim Demaille, 2020/12/26
- [PATCH 2/6] glr2.cc: beware of self-assignment, Akim Demaille, 2020/12/26
- [PATCH 3/6] glr2.cc: provide glr_state with a genuine copy-constructor, Akim Demaille, 2020/12/26
- [PATCH 4/6] glr2.cc: fix warnings about uninitialized locations, Akim Demaille, 2020/12/26
- [PATCH 5/6] glr2.cc: simplify,
Akim Demaille <=
- [PATCH 6/6] doc: more about sanitizers, Akim Demaille, 2020/12/26