From 2a07cb0f2df3e924f37f1df05e9d4aa632aeecc5 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 26 Dec 2020 07:30:45 +0100 Subject: [PATCH] glr2.cc: simplify * 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 (newsize), yystates.end ()); - yylookaheadNeeds.erase (yylookaheadNeeds.begin () + static_cast (newsize), - yylookaheadNeeds.end ()); + yystates.resize (newsize); + yylookaheadNeeds.resize (newsize); }