Skip to content

Commit eeb5d6f

Browse files
committed
glr2.cc: semantic_option: use a symbol
* data/skeletons/c++.m4 (basic_symbol): Add assignment operators. * data/skeletons/glr2.cc (semantic_option): Replace yytoken, yyvalue and yylocation by yyla.
1 parent 70441b5 commit eeb5d6f

File tree

2 files changed

+35
-39
lines changed

2 files changed

+35
-39
lines changed

data/skeletons/c++.m4

+21
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,17 @@ m4_define([b4_symbol_type_define],
347347
}
348348
349349
]b4_glr2_cc_if([[
350+
/// Copy assignment.
351+
basic_symbol& operator= (const basic_symbol& that)
352+
{
353+
Base::operator= (that);]b4_variant_if([[
354+
]b4_symbol_variant([this->kind ()], [value], [copy],
355+
[that.value])], [[
356+
value = that.value]])[;]b4_locations_if([[
357+
location = that.location;]])[
358+
return *this;
359+
}
360+
350361
/// Move assignment.
351362
basic_symbol& operator= (basic_symbol&& that)
352363
{
@@ -438,6 +449,9 @@ m4_define([b4_symbol_type_define],
438449
by_kind (const by_kind& that);
439450
440451
]b4_glr2_cc_if([[
452+
/// Copy assignment.
453+
by_kind& operator= (const by_kind& that);
454+
441455
/// Move assignment.
442456
by_kind& operator= (by_kind&& that);
443457
]])[
@@ -571,6 +585,13 @@ m4_define([b4_public_types_define],
571585
{}
572586
573587
]b4_glr2_cc_if([[
588+
]b4_inline([$1])]b4_parser_class[::by_kind&
589+
b4_parser_class[::by_kind::by_kind::operator= (const by_kind& that)
590+
{
591+
kind_ = that.kind_;
592+
return *this;
593+
}
594+
574595
]b4_inline([$1])]b4_parser_class[::by_kind&
575596
b4_parser_class[::by_kind::by_kind::operator= (by_kind&& that)
576597
{

data/skeletons/glr2.cc

+14-39
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,7 @@ namespace
780780
using glr_state = parser_type::glr_state;
781781
using symbol_kind = parser_type::symbol_kind;
782782
using symbol_kind_type = parser_type::symbol_kind_type;
783+
using symbol_type = parser_type::symbol_type;
783784
using value_type = parser_type::value_type;]b4_locations_if([[
784785
using location_type = parser_type::location_type;]])[
785786

@@ -1171,34 +1172,26 @@ namespace
11711172
: yyrule (0)
11721173
, yystate (0)
11731174
, yynext (0)
1174-
, yytoken (]b4_symbol(empty, kind)[)
1175-
, yyval ()]b4_locations_if([[
1176-
, yyloc ()]])[]b4_parse_assert_if([[
1175+
, yyla ()]b4_parse_assert_if([[
11771176
, magic_ (MAGIC)]])[
11781177
{}
11791178

11801179
semantic_option (rule_num rule)
11811180
: yyrule (rule)
11821181
, yystate (0)
11831182
, yynext (0)
1184-
, yytoken (]b4_symbol(empty, kind)[)
1185-
, yyval ()]b4_locations_if([[
1186-
, yyloc ()]])[]b4_parse_assert_if([[
1183+
, yyla ()]b4_parse_assert_if([[
11871184
, magic_ (MAGIC)]])[
11881185
{}
11891186

11901187
semantic_option (const semantic_option& that)
11911188
: yyrule (that.yyrule)
11921189
, yystate (that.yystate)
11931190
, yynext (that.yynext)
1194-
, yytoken (that.yytoken)
1195-
, yyval (]b4_variant_if([], [[that.yyval]])[)]b4_locations_if([[
1196-
, yyloc (that.yyloc)]])[]b4_parse_assert_if([[
1191+
, yyla (that.yyla)]b4_parse_assert_if([[
11971192
, magic_ (MAGIC)]])[
11981193
{]b4_parse_assert_if([[
1199-
that.check_ ();]])[]b4_variant_if([[
1200-
]b4_symbol_variant([yytoken],
1201-
[yyval], [copy], [that.yyval])])[
1194+
that.check_ ();]])[
12021195
}
12031196

12041197
// Needed for the assignment in yynewSemanticOption.
@@ -1209,11 +1202,7 @@ namespace
12091202
yyrule = that.yyrule;
12101203
yystate = that.yystate;
12111204
yynext = that.yynext;
1212-
yytoken = that.yytoken;]b4_variant_if([[
1213-
]b4_symbol_variant([yytoken],
1214-
[yyval], [copy], [that.yyval])], [[
1215-
yyval = that.yyval;]])[]b4_locations_if([[
1216-
yyloc = that.yyloc;]])[
1205+
yyla = that.yyla;
12171206
return *this;
12181207
}
12191208

@@ -1395,9 +1384,7 @@ namespace
13951384

13961385
public:
13971386
/** The lookahead for this reduction. */
1398-
symbol_kind_type yytoken;
1399-
value_type yyval;]b4_locations_if([[
1400-
location_type yyloc;]])[
1387+
symbol_type yyla;
14011388

14021389
]b4_parse_assert_if([[
14031390
public:
@@ -2339,19 +2326,12 @@ b4_dollar_popdef])[]dnl
23392326
yyaddDeferredAction (state_set_index yyk, glr_state* yystate,
23402327
glr_state* yyrhs, rule_num yyrule)
23412328
{
2342-
semantic_option& yynewOption =
2343-
yystateStack.yynewSemanticOption (semantic_option (yyrule));
2344-
yynewOption.setState(yyrhs);
2345-
yynewOption.setNext(yystate->firstVal());
2346-
if (yystateStack.yytops.lookaheadNeeds(yyk))
2347-
{
2348-
yynewOption.yytoken = this->yyla.kind ();]b4_variant_if([[
2349-
]b4_symbol_variant([this->yyla.kind ()],
2350-
[yynewOption.yyval], [copy], [this->yyla.value])], [[
2351-
yynewOption.yyval = this->yyla.value;]])[]b4_locations_if([
2352-
yynewOption.yyloc = this->yyla.location;])[
2353-
}
2354-
yystate->setFirstVal (&yynewOption);
2329+
semantic_option& yyopt = yystateStack.yynewSemanticOption (semantic_option (yyrule));
2330+
yyopt.setState (yyrhs);
2331+
yyopt.setNext (yystate->firstVal ());
2332+
if (yystateStack.yytops.lookaheadNeeds (yyk))
2333+
yyopt.yyla = this->yyla;
2334+
yystate->setFirstVal (&yyopt);
23552335

23562336
yyreserveGlrStack ();
23572337
}
@@ -3003,16 +2983,11 @@ b4_dollar_popdef])[]dnl
30032983
yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yyoptState->yyloc;]])[
30042984
{
30052985
symbol_type yyla_current = std::move (this->yyla);
3006-
this->yyla.kind_ = yyopt.yytoken;]b4_variant_if([[
3007-
]b4_symbol_variant([this->yyla.kind ()],
3008-
[this->yyla.value], [move], [yyopt.yyval])], [[
3009-
this->yyla.value = yyopt.yyval;]])[]b4_locations_if([
3010-
this->yyla.location = yyopt.yyloc;])[
2986+
this->yyla = std::move (yyopt.yyla);
30112987
yyflag = yyuserAction (yyopt.yyrule, yynrhs,
30122988
yyrhsVals + YYMAXRHS + YYMAXLEFT - 1,
30132989
create_state_set_index (-1),
30142990
yyvalp]b4_locations_if([, yylocp])[);
3015-
30162991
this->yyla = std::move (yyla_current);
30172992
}
30182993
return yyflag;

0 commit comments

Comments
 (0)