diff --git a/data/skeletons/glr2.cc b/data/skeletons/glr2.cc index 93c6e52b..0a97937c 100644 --- a/data/skeletons/glr2.cc +++ b/data/skeletons/glr2.cc @@ -1467,13 +1467,34 @@ class state_stack { bool yyexpandGLRStack() { - if (YYMAXDEPTH - YYHEADROOM < yyitems.size()) + const size_t oldsize = yyitems.size(); + if (YYMAXDEPTH - YYHEADROOM < oldsize) return false; - const size_t yynewSize = YYMAXDEPTH < 2 * yyitems.size() ? YYMAXDEPTH : 2 * yyitems.size(); - yyitems.reserve(yynewSize); + const size_t yynewSize = YYMAXDEPTH < 2 * oldsize ? YYMAXDEPTH : 2 * oldsize; + const glr_stack_item *oldbase = &yyitems[0]; + + yyitems.reserve (yynewSize); + const glr_stack_item *newbase = &yyitems[0]; + + // Adjust the pointers. Perform raw pointer arithmetics, as there + // is no reason for objects to be aligned on their size. + const ptrdiff_t disp + = reinterpret_cast (newbase) - reinterpret_cast (oldbase); + if (yysplitPoint) + const_cast (yysplitPoint) + = reinterpret_cast (reinterpret_cast (const_cast (yysplitPoint)) + disp); + + for (std::vector::iterator + i = yytops.begin (), + yyend = yytops.end (); + i != yyend; ++i) + if (glr_state_not_null (*i)) + *i = reinterpret_cast(reinterpret_cast(*i) + disp); + return true; } - public: + +public: #else bool yyexpandGLRStackIfNeeded () { @@ -1486,11 +1507,12 @@ class state_stack { } bool - reduceToOneStack() { - const std::vector::iterator yybegin = yytops.begin(); - const std::vector::iterator yyend = yytops.end(); - const std::vector::iterator yyit = - std::find_if(yybegin, yyend, glr_state_not_null); + reduceToOneStack () + { + typedef std::vector::iterator iterator; + const iterator yybegin = yytops.begin(); + const iterator yyend = yytops.end(); + const iterator yyit = std::find_if(yybegin, yyend, glr_state_not_null); if (yyit == yyend) return false; for (state_set_index yyk = create_state_set_index(yyit + 1 - yybegin); diff --git a/tests/glr-regression.at b/tests/glr-regression.at index 01c0b037..1a6eae4b 100644 --- a/tests/glr-regression.at +++ b/tests/glr-regression.at @@ -1388,7 +1388,6 @@ m4_pushdef([AT_TEST], [AT_SETUP([Incorrect lookahead during nondeterministic GLR: $1]) AT_BISON_OPTION_PUSHDEFS([%glr-parser %locations $1]) -AT_GLR2_CC_IF([AT_XFAIL_IF([true])]) AT_DATA_GRAMMAR([glr-regr14.y], [[