1*cda5da8dSAndroid Build Coastguard Worker # C++ GLR skeleton for Bison 2*cda5da8dSAndroid Build Coastguard Worker 3*cda5da8dSAndroid Build Coastguard Worker # Copyright (C) 2002-2015, 2018-2021 Free Software Foundation, Inc. 4*cda5da8dSAndroid Build Coastguard Worker 5*cda5da8dSAndroid Build Coastguard Worker # This program is free software: you can redistribute it and/or modify 6*cda5da8dSAndroid Build Coastguard Worker # it under the terms of the GNU General Public License as published by 7*cda5da8dSAndroid Build Coastguard Worker # the Free Software Foundation, either version 3 of the License, or 8*cda5da8dSAndroid Build Coastguard Worker # (at your option) any later version. 9*cda5da8dSAndroid Build Coastguard Worker # 10*cda5da8dSAndroid Build Coastguard Worker # This program is distributed in the hope that it will be useful, 11*cda5da8dSAndroid Build Coastguard Worker # but WITHOUT ANY WARRANTY; without even the implied warranty of 12*cda5da8dSAndroid Build Coastguard Worker # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*cda5da8dSAndroid Build Coastguard Worker # GNU General Public License for more details. 14*cda5da8dSAndroid Build Coastguard Worker # 15*cda5da8dSAndroid Build Coastguard Worker # You should have received a copy of the GNU General Public License 16*cda5da8dSAndroid Build Coastguard Worker # along with this program. If not, see <https://www.gnu.org/licenses/>. 17*cda5da8dSAndroid Build Coastguard Worker 18*cda5da8dSAndroid Build Coastguard Worker m4_include(b4_skeletonsdir/[c++.m4]) 19*cda5da8dSAndroid Build Coastguard Worker 20*cda5da8dSAndroid Build Coastguard Worker # api.value.type=variant is valid. 21*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_value_type_setup_variant]) 22*cda5da8dSAndroid Build Coastguard Worker 23*cda5da8dSAndroid Build Coastguard Worker # b4_tname_if(TNAME-NEEDED, TNAME-NOT-NEEDED) 24*cda5da8dSAndroid Build Coastguard Worker # ------------------------------------------- 25*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_tname_if], 26*cda5da8dSAndroid Build Coastguard Worker [m4_case(b4_percent_define_get([[parse.error]]), 27*cda5da8dSAndroid Build Coastguard Worker [verbose], [$1], 28*cda5da8dSAndroid Build Coastguard Worker [b4_token_table_if([$1], 29*cda5da8dSAndroid Build Coastguard Worker [$2])])]) 30*cda5da8dSAndroid Build Coastguard Worker 31*cda5da8dSAndroid Build Coastguard Worker b4_bison_locations_if([ 32*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_location_constructors]) 33*cda5da8dSAndroid Build Coastguard Worker m4_include(b4_skeletonsdir/[location.cc])]) 34*cda5da8dSAndroid Build Coastguard Worker b4_variant_if([m4_include(b4_skeletonsdir/[variant.hh])]) 35*cda5da8dSAndroid Build Coastguard Worker 36*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_parser_class], 37*cda5da8dSAndroid Build Coastguard Worker [b4_percent_define_get([[api.parser.class]])]) 38*cda5da8dSAndroid Build Coastguard Worker 39*cda5da8dSAndroid Build Coastguard Worker ]m4_define([b4_define_symbol_kind], 40*cda5da8dSAndroid Build Coastguard Worker [m4_format([#define %-15s %s], 41*cda5da8dSAndroid Build Coastguard Worker b4_symbol($][1, kind_base), 42*cda5da8dSAndroid Build Coastguard Worker b4_namespace_ref[::]b4_parser_class[::symbol_kind::]b4_symbol($1, kind_base)) 43*cda5da8dSAndroid Build Coastguard Worker ]) 44*cda5da8dSAndroid Build Coastguard Worker 45*cda5da8dSAndroid Build Coastguard Worker 46*cda5da8dSAndroid Build Coastguard Worker # b4_integral_parser_table_define(TABLE-NAME, CONTENT, COMMENT) 47*cda5da8dSAndroid Build Coastguard Worker # ------------------------------------------------------------- 48*cda5da8dSAndroid Build Coastguard Worker # Define "yy<TABLE-NAME>" whose contents is CONTENT. Does not use "static", 49*cda5da8dSAndroid Build Coastguard Worker # should be in unnamed namespace. 50*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_integral_parser_table_define], 51*cda5da8dSAndroid Build Coastguard Worker [m4_ifvaln([$3], [ b4_comment([$3])])dnl 52*cda5da8dSAndroid Build Coastguard Worker const b4_int_type_for([$2]) yy$1[[]] = 53*cda5da8dSAndroid Build Coastguard Worker { 54*cda5da8dSAndroid Build Coastguard Worker $2 55*cda5da8dSAndroid Build Coastguard Worker };dnl 56*cda5da8dSAndroid Build Coastguard Worker ]) 57*cda5da8dSAndroid Build Coastguard Worker 58*cda5da8dSAndroid Build Coastguard Worker 59*cda5da8dSAndroid Build Coastguard Worker ## ---------------- ## 60*cda5da8dSAndroid Build Coastguard Worker ## Default values. ## 61*cda5da8dSAndroid Build Coastguard Worker ## ---------------- ## 62*cda5da8dSAndroid Build Coastguard Worker 63*cda5da8dSAndroid Build Coastguard Worker # Stack parameters. 64*cda5da8dSAndroid Build Coastguard Worker m4_define_default([b4_stack_depth_max], [10000]) 65*cda5da8dSAndroid Build Coastguard Worker m4_define_default([b4_stack_depth_init], [200]) 66*cda5da8dSAndroid Build Coastguard Worker 67*cda5da8dSAndroid Build Coastguard Worker 68*cda5da8dSAndroid Build Coastguard Worker 69*cda5da8dSAndroid Build Coastguard Worker ## ------------ ## 70*cda5da8dSAndroid Build Coastguard Worker ## Interfaces. ## 71*cda5da8dSAndroid Build Coastguard Worker ## ------------ ## 72*cda5da8dSAndroid Build Coastguard Worker 73*cda5da8dSAndroid Build Coastguard Worker # b4_user_formals 74*cda5da8dSAndroid Build Coastguard Worker # --------------- 75*cda5da8dSAndroid Build Coastguard Worker # The possible parse-params formal arguments preceded by a comma. 76*cda5da8dSAndroid Build Coastguard Worker # 77*cda5da8dSAndroid Build Coastguard Worker # This is not shared with yacc.c in c.m4 because GLR relies on ISO C 78*cda5da8dSAndroid Build Coastguard Worker # formal argument declarations. 79*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_user_formals], 80*cda5da8dSAndroid Build Coastguard Worker [m4_ifset([b4_parse_param], [, b4_formals(b4_parse_param)])]) 81*cda5da8dSAndroid Build Coastguard Worker 82*cda5da8dSAndroid Build Coastguard Worker 83*cda5da8dSAndroid Build Coastguard Worker # b4_symbol_kind(NUM) 84*cda5da8dSAndroid Build Coastguard Worker # ------------------- 85*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_symbol_kind], 86*cda5da8dSAndroid Build Coastguard Worker [symbol_kind::b4_symbol_kind_base($@)]) 87*cda5da8dSAndroid Build Coastguard Worker 88*cda5da8dSAndroid Build Coastguard Worker 89*cda5da8dSAndroid Build Coastguard Worker ## ----------------- ## 90*cda5da8dSAndroid Build Coastguard Worker ## Semantic Values. ## 91*cda5da8dSAndroid Build Coastguard Worker ## ----------------- ## 92*cda5da8dSAndroid Build Coastguard Worker 93*cda5da8dSAndroid Build Coastguard Worker 94*cda5da8dSAndroid Build Coastguard Worker # b4_lhs_value(SYMBOL-NUM, [TYPE]) 95*cda5da8dSAndroid Build Coastguard Worker # -------------------------------- 96*cda5da8dSAndroid Build Coastguard Worker # See README. 97*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_lhs_value], 98*cda5da8dSAndroid Build Coastguard Worker [b4_symbol_value([(*yyvalp)], [$1], [$2])]) 99*cda5da8dSAndroid Build Coastguard Worker 100*cda5da8dSAndroid Build Coastguard Worker 101*cda5da8dSAndroid Build Coastguard Worker # b4_rhs_data(RULE-LENGTH, POS) 102*cda5da8dSAndroid Build Coastguard Worker # ----------------------------- 103*cda5da8dSAndroid Build Coastguard Worker # See README. 104*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_rhs_data], 105*cda5da8dSAndroid Build Coastguard Worker [(static_cast<glr_stack_item const *>(yyvsp))@{YYFILL (b4_subtract([$2], [$1]))@}.getState()]) 106*cda5da8dSAndroid Build Coastguard Worker 107*cda5da8dSAndroid Build Coastguard Worker 108*cda5da8dSAndroid Build Coastguard Worker # b4_rhs_value(RULE-LENGTH, POS, SYMBOL-NUM, [TYPE]) 109*cda5da8dSAndroid Build Coastguard Worker # -------------------------------------------------- 110*cda5da8dSAndroid Build Coastguard Worker # Expansion of $$ or $<TYPE>$, for symbol SYMBOL-NUM. 111*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_rhs_value], 112*cda5da8dSAndroid Build Coastguard Worker [b4_symbol_value([b4_rhs_data([$1], [$2]).value ()], [$3], [$4])]) 113*cda5da8dSAndroid Build Coastguard Worker 114*cda5da8dSAndroid Build Coastguard Worker 115*cda5da8dSAndroid Build Coastguard Worker 116*cda5da8dSAndroid Build Coastguard Worker ## ----------- ## 117*cda5da8dSAndroid Build Coastguard Worker ## Locations. ## 118*cda5da8dSAndroid Build Coastguard Worker ## ----------- ## 119*cda5da8dSAndroid Build Coastguard Worker 120*cda5da8dSAndroid Build Coastguard Worker # b4_lhs_location() 121*cda5da8dSAndroid Build Coastguard Worker # ----------------- 122*cda5da8dSAndroid Build Coastguard Worker # Expansion of @$. 123*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_lhs_location], 124*cda5da8dSAndroid Build Coastguard Worker [(*yylocp)]) 125*cda5da8dSAndroid Build Coastguard Worker 126*cda5da8dSAndroid Build Coastguard Worker 127*cda5da8dSAndroid Build Coastguard Worker # b4_rhs_location(RULE-LENGTH, NUM) 128*cda5da8dSAndroid Build Coastguard Worker # --------------------------------- 129*cda5da8dSAndroid Build Coastguard Worker # Expansion of @NUM, where the current rule has RULE-LENGTH symbols 130*cda5da8dSAndroid Build Coastguard Worker # on RHS. 131*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_rhs_location], 132*cda5da8dSAndroid Build Coastguard Worker [(b4_rhs_data([$1], [$2]).yyloc)]) 133*cda5da8dSAndroid Build Coastguard Worker 134*cda5da8dSAndroid Build Coastguard Worker 135*cda5da8dSAndroid Build Coastguard Worker # b4_symbol_action(SYMBOL-NUM, KIND) 136*cda5da8dSAndroid Build Coastguard Worker # ---------------------------------- 137*cda5da8dSAndroid Build Coastguard Worker # Run the action KIND (destructor or printer) for SYMBOL-NUM. 138*cda5da8dSAndroid Build Coastguard Worker # Same as in C, but using references instead of pointers. 139*cda5da8dSAndroid Build Coastguard Worker # 140*cda5da8dSAndroid Build Coastguard Worker # Currently we need two different b4_symbol_action: once for the 141*cda5da8dSAndroid Build Coastguard Worker # self-contained symbols, and another time for yy_destroy_ and 142*cda5da8dSAndroid Build Coastguard Worker # yy_symbol_value_print_, which don't use genuine symbols yet. 143*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_symbol_action], 144*cda5da8dSAndroid Build Coastguard Worker [b4_symbol_if([$1], [has_$2], 145*cda5da8dSAndroid Build Coastguard Worker [m4_pushdef([b4_symbol_value], m4_defn([b4_symbol_value_template]))[]dnl 146*cda5da8dSAndroid Build Coastguard Worker b4_dollar_pushdef([yysym.value], 147*cda5da8dSAndroid Build Coastguard Worker [$1], 148*cda5da8dSAndroid Build Coastguard Worker [], 149*cda5da8dSAndroid Build Coastguard Worker [yysym.location])dnl 150*cda5da8dSAndroid Build Coastguard Worker _b4_symbol_case([$1])[]dnl 151*cda5da8dSAndroid Build Coastguard Worker b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl 152*cda5da8dSAndroid Build Coastguard Worker b4_symbol([$1], [$2]) 153*cda5da8dSAndroid Build Coastguard Worker b4_syncline([@oline@], [@ofile@])dnl 154*cda5da8dSAndroid Build Coastguard Worker break; 155*cda5da8dSAndroid Build Coastguard Worker 156*cda5da8dSAndroid Build Coastguard Worker m4_popdef([b4_symbol_value])[]dnl 157*cda5da8dSAndroid Build Coastguard Worker b4_dollar_popdef[]dnl 158*cda5da8dSAndroid Build Coastguard Worker ])]) 159*cda5da8dSAndroid Build Coastguard Worker 160*cda5da8dSAndroid Build Coastguard Worker 161*cda5da8dSAndroid Build Coastguard Worker # b4_symbol_action_for_yyval(SYMBOL-NUM, KIND) 162*cda5da8dSAndroid Build Coastguard Worker # -------------------------------------------- 163*cda5da8dSAndroid Build Coastguard Worker # Run the action KIND (destructor or printer) for SYMBOL-NUM. 164*cda5da8dSAndroid Build Coastguard Worker # Same as in C, but using references instead of pointers. 165*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_symbol_action_for_yyval], 166*cda5da8dSAndroid Build Coastguard Worker [b4_symbol_if([$1], [has_$2], 167*cda5da8dSAndroid Build Coastguard Worker [b4_dollar_pushdef([yyval], 168*cda5da8dSAndroid Build Coastguard Worker [$1], 169*cda5da8dSAndroid Build Coastguard Worker [], 170*cda5da8dSAndroid Build Coastguard Worker [yyloc])dnl 171*cda5da8dSAndroid Build Coastguard Worker _b4_symbol_case([$1])[]dnl 172*cda5da8dSAndroid Build Coastguard Worker b4_syncline([b4_symbol([$1], [$2_line])], [b4_symbol([$1], [$2_file])])dnl 173*cda5da8dSAndroid Build Coastguard Worker b4_symbol([$1], [$2]) 174*cda5da8dSAndroid Build Coastguard Worker b4_syncline([@oline@], [@ofile@])dnl 175*cda5da8dSAndroid Build Coastguard Worker break; 176*cda5da8dSAndroid Build Coastguard Worker 177*cda5da8dSAndroid Build Coastguard Worker b4_dollar_popdef[]dnl 178*cda5da8dSAndroid Build Coastguard Worker ])]) 179*cda5da8dSAndroid Build Coastguard Worker 180*cda5da8dSAndroid Build Coastguard Worker 181*cda5da8dSAndroid Build Coastguard Worker # b4_call_merger(MERGER-NUM, MERGER-NAME, SYMBOL-SUM) 182*cda5da8dSAndroid Build Coastguard Worker # --------------------------------------------------- 183*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_call_merger], 184*cda5da8dSAndroid Build Coastguard Worker [b4_case([$1], 185*cda5da8dSAndroid Build Coastguard Worker [ b4_symbol_if([$3], [has_type], 186*cda5da8dSAndroid Build Coastguard Worker [b4_variant_if([yy0.as< b4_symbol($3, type) > () = $2 (yy0.as< b4_symbol($3, type) >(), yy1.as< b4_symbol($3, type) >());], 187*cda5da8dSAndroid Build Coastguard Worker [yy0.b4_symbol($3, slot) = $2 (yy0, yy1);])], 188*cda5da8dSAndroid Build Coastguard Worker [yy0 = $2 (yy0, yy1);])])]) 189*cda5da8dSAndroid Build Coastguard Worker 190*cda5da8dSAndroid Build Coastguard Worker # b4_yylex 191*cda5da8dSAndroid Build Coastguard Worker # -------- 192*cda5da8dSAndroid Build Coastguard Worker # Call yylex. 193*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_yylex], 194*cda5da8dSAndroid Build Coastguard Worker [b4_token_ctor_if( 195*cda5da8dSAndroid Build Coastguard Worker [b4_function_call([yylex], 196*cda5da8dSAndroid Build Coastguard Worker [symbol_type], m4_ifdef([b4_lex_param], b4_lex_param))], 197*cda5da8dSAndroid Build Coastguard Worker [b4_function_call([yylex], [int], 198*cda5da8dSAndroid Build Coastguard Worker [[value_type *], [&this->yyla.value]][]dnl 199*cda5da8dSAndroid Build Coastguard Worker b4_locations_if([, [[location_type *], [&this->yyla.location]]])dnl 200*cda5da8dSAndroid Build Coastguard Worker m4_ifdef([b4_lex_param], [, ]b4_lex_param))])]) 201*cda5da8dSAndroid Build Coastguard Worker 202*cda5da8dSAndroid Build Coastguard Worker 203*cda5da8dSAndroid Build Coastguard Worker # b4_shared_declarations(hh|cc) 204*cda5da8dSAndroid Build Coastguard Worker # ----------------------------- 205*cda5da8dSAndroid Build Coastguard Worker # Declaration that might either go into the header (if --header, $1 = hh) 206*cda5da8dSAndroid Build Coastguard Worker # or in the implementation file. 207*cda5da8dSAndroid Build Coastguard Worker m4_define([b4_shared_declarations], 208*cda5da8dSAndroid Build Coastguard Worker [b4_percent_code_get([[requires]])[ 209*cda5da8dSAndroid Build Coastguard Worker #include <algorithm> 210*cda5da8dSAndroid Build Coastguard Worker #include <cstddef> // ptrdiff_t 211*cda5da8dSAndroid Build Coastguard Worker #include <cstring> // memcpy 212*cda5da8dSAndroid Build Coastguard Worker #include <iostream> 213*cda5da8dSAndroid Build Coastguard Worker #include <iomanip> 214*cda5da8dSAndroid Build Coastguard Worker #include <limits> 215*cda5da8dSAndroid Build Coastguard Worker #include <stdexcept> 216*cda5da8dSAndroid Build Coastguard Worker #include <stdint.h> 217*cda5da8dSAndroid Build Coastguard Worker #include <string> 218*cda5da8dSAndroid Build Coastguard Worker #include <vector> 219*cda5da8dSAndroid Build Coastguard Worker 220*cda5da8dSAndroid Build Coastguard Worker ]b4_cxx_portability[ 221*cda5da8dSAndroid Build Coastguard Worker ]m4_ifdef([b4_location_include], 222*cda5da8dSAndroid Build Coastguard Worker [[# include ]b4_location_include])[ 223*cda5da8dSAndroid Build Coastguard Worker ]b4_variant_if([b4_variant_includes])[ 224*cda5da8dSAndroid Build Coastguard Worker 225*cda5da8dSAndroid Build Coastguard Worker ]b4_YYDEBUG_define[ 226*cda5da8dSAndroid Build Coastguard Worker 227*cda5da8dSAndroid Build Coastguard Worker ]b4_namespace_open[ 228*cda5da8dSAndroid Build Coastguard Worker 229*cda5da8dSAndroid Build Coastguard Worker ]b4_bison_locations_if([m4_ifndef([b4_location_file], 230*cda5da8dSAndroid Build Coastguard Worker [b4_location_define])])[ 231*cda5da8dSAndroid Build Coastguard Worker 232*cda5da8dSAndroid Build Coastguard Worker /// A Bison parser. 233*cda5da8dSAndroid Build Coastguard Worker class ]b4_parser_class[ 234*cda5da8dSAndroid Build Coastguard Worker { 235*cda5da8dSAndroid Build Coastguard Worker public: 236*cda5da8dSAndroid Build Coastguard Worker ]b4_public_types_declare[ 237*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_type_define[ 238*cda5da8dSAndroid Build Coastguard Worker 239*cda5da8dSAndroid Build Coastguard Worker // FIXME: should be private eventually. 240*cda5da8dSAndroid Build Coastguard Worker class glr_stack; 241*cda5da8dSAndroid Build Coastguard Worker class glr_state; 242*cda5da8dSAndroid Build Coastguard Worker 243*cda5da8dSAndroid Build Coastguard Worker /// Build a parser object. 244*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[ (]b4_parse_param_decl[); 245*cda5da8dSAndroid Build Coastguard Worker ~]b4_parser_class[ (); 246*cda5da8dSAndroid Build Coastguard Worker 247*cda5da8dSAndroid Build Coastguard Worker /// Parse. An alias for parse (). 248*cda5da8dSAndroid Build Coastguard Worker /// \returns 0 iff parsing succeeded. 249*cda5da8dSAndroid Build Coastguard Worker int operator() (); 250*cda5da8dSAndroid Build Coastguard Worker 251*cda5da8dSAndroid Build Coastguard Worker /// Parse. 252*cda5da8dSAndroid Build Coastguard Worker /// \returns 0 iff parsing succeeded. 253*cda5da8dSAndroid Build Coastguard Worker int parse (); 254*cda5da8dSAndroid Build Coastguard Worker 255*cda5da8dSAndroid Build Coastguard Worker #if ]b4_api_PREFIX[DEBUG 256*cda5da8dSAndroid Build Coastguard Worker /// The current debugging stream. 257*cda5da8dSAndroid Build Coastguard Worker std::ostream& debug_stream () const; 258*cda5da8dSAndroid Build Coastguard Worker /// Set the current debugging stream. 259*cda5da8dSAndroid Build Coastguard Worker void set_debug_stream (std::ostream &); 260*cda5da8dSAndroid Build Coastguard Worker 261*cda5da8dSAndroid Build Coastguard Worker /// Type for debugging levels. 262*cda5da8dSAndroid Build Coastguard Worker using debug_level_type = int; 263*cda5da8dSAndroid Build Coastguard Worker /// The current debugging level. 264*cda5da8dSAndroid Build Coastguard Worker debug_level_type debug_level () const; 265*cda5da8dSAndroid Build Coastguard Worker /// Set the current debugging level. 266*cda5da8dSAndroid Build Coastguard Worker void set_debug_level (debug_level_type l); 267*cda5da8dSAndroid Build Coastguard Worker #endif 268*cda5da8dSAndroid Build Coastguard Worker 269*cda5da8dSAndroid Build Coastguard Worker /// Report a syntax error.]b4_locations_if([[ 270*cda5da8dSAndroid Build Coastguard Worker /// \param loc where the syntax error is found.]])[ 271*cda5da8dSAndroid Build Coastguard Worker /// \param msg a description of the syntax error. 272*cda5da8dSAndroid Build Coastguard Worker void error (]b4_locations_if([[const location_type& loc, ]])[const std::string& msg); 273*cda5da8dSAndroid Build Coastguard Worker 274*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_error_bmatch( 275*cda5da8dSAndroid Build Coastguard Worker [custom\|detailed], 276*cda5da8dSAndroid Build Coastguard Worker [[ /// The user-facing name of the symbol whose (internal) number is 277*cda5da8dSAndroid Build Coastguard Worker /// YYSYMBOL. No bounds checking. 278*cda5da8dSAndroid Build Coastguard Worker static const char *symbol_name (symbol_kind_type yysymbol);]], 279*cda5da8dSAndroid Build Coastguard Worker [simple], 280*cda5da8dSAndroid Build Coastguard Worker [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ 281*cda5da8dSAndroid Build Coastguard Worker /// The user-facing name of the symbol whose (internal) number is 282*cda5da8dSAndroid Build Coastguard Worker /// YYSYMBOL. No bounds checking. 283*cda5da8dSAndroid Build Coastguard Worker static const char *symbol_name (symbol_kind_type yysymbol); 284*cda5da8dSAndroid Build Coastguard Worker #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ 285*cda5da8dSAndroid Build Coastguard Worker ]], 286*cda5da8dSAndroid Build Coastguard Worker [verbose], 287*cda5da8dSAndroid Build Coastguard Worker [[ /// The user-facing name of the symbol whose (internal) number is 288*cda5da8dSAndroid Build Coastguard Worker /// YYSYMBOL. No bounds checking. 289*cda5da8dSAndroid Build Coastguard Worker static std::string symbol_name (symbol_kind_type yysymbol);]])[ 290*cda5da8dSAndroid Build Coastguard Worker 291*cda5da8dSAndroid Build Coastguard Worker ]b4_token_constructor_define[ 292*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ 293*cda5da8dSAndroid Build Coastguard Worker class context 294*cda5da8dSAndroid Build Coastguard Worker { 295*cda5da8dSAndroid Build Coastguard Worker public: 296*cda5da8dSAndroid Build Coastguard Worker context (glr_stack& yystack, const symbol_type& yyla); 297*cda5da8dSAndroid Build Coastguard Worker const symbol_type& lookahead () const YY_NOEXCEPT { return yyla_; } 298*cda5da8dSAndroid Build Coastguard Worker symbol_kind_type token () const YY_NOEXCEPT { return yyla_.kind (); }]b4_locations_if([[ 299*cda5da8dSAndroid Build Coastguard Worker const location_type& location () const YY_NOEXCEPT { return yyla_.location; } 300*cda5da8dSAndroid Build Coastguard Worker ]])[ 301*cda5da8dSAndroid Build Coastguard Worker /// Put in YYARG at most YYARGN of the expected tokens, and return the 302*cda5da8dSAndroid Build Coastguard Worker /// number of tokens stored in YYARG. If YYARG is null, return the 303*cda5da8dSAndroid Build Coastguard Worker /// number of expected tokens (guaranteed to be less than YYNTOKENS). 304*cda5da8dSAndroid Build Coastguard Worker int expected_tokens (symbol_kind_type yyarg[], int yyargn) const; 305*cda5da8dSAndroid Build Coastguard Worker 306*cda5da8dSAndroid Build Coastguard Worker private: 307*cda5da8dSAndroid Build Coastguard Worker glr_stack& yystack_; 308*cda5da8dSAndroid Build Coastguard Worker const symbol_type& yyla_; 309*cda5da8dSAndroid Build Coastguard Worker }; 310*cda5da8dSAndroid Build Coastguard Worker ]])[ 311*cda5da8dSAndroid Build Coastguard Worker # if ]b4_api_PREFIX[DEBUG 312*cda5da8dSAndroid Build Coastguard Worker public: 313*cda5da8dSAndroid Build Coastguard Worker /// \brief Report a symbol value on the debug stream. 314*cda5da8dSAndroid Build Coastguard Worker /// \param yykind The symbol kind. 315*cda5da8dSAndroid Build Coastguard Worker /// \param yyval Its semantic value.]b4_locations_if([[ 316*cda5da8dSAndroid Build Coastguard Worker /// \param yyloc Its location.]])[ 317*cda5da8dSAndroid Build Coastguard Worker void yy_symbol_value_print_ (symbol_kind_type yykind, 318*cda5da8dSAndroid Build Coastguard Worker const value_type& yyval]b4_locations_if([[, 319*cda5da8dSAndroid Build Coastguard Worker const location_type& yyloc]])[) const; 320*cda5da8dSAndroid Build Coastguard Worker /// \brief Report a symbol on the debug stream. 321*cda5da8dSAndroid Build Coastguard Worker /// \param yykind The symbol kind. 322*cda5da8dSAndroid Build Coastguard Worker /// \param yyval Its semantic value.]b4_locations_if([[ 323*cda5da8dSAndroid Build Coastguard Worker /// \param yyloc Its location.]])[ 324*cda5da8dSAndroid Build Coastguard Worker void yy_symbol_print_ (symbol_kind_type yykind, 325*cda5da8dSAndroid Build Coastguard Worker const value_type& yyval]b4_locations_if([[, 326*cda5da8dSAndroid Build Coastguard Worker const location_type& yyloc]])[) const; 327*cda5da8dSAndroid Build Coastguard Worker private: 328*cda5da8dSAndroid Build Coastguard Worker /// Debug stream. 329*cda5da8dSAndroid Build Coastguard Worker std::ostream* yycdebug_; 330*cda5da8dSAndroid Build Coastguard Worker #endif 331*cda5da8dSAndroid Build Coastguard Worker 332*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_error_bmatch( 333*cda5da8dSAndroid Build Coastguard Worker [custom], [[ 334*cda5da8dSAndroid Build Coastguard Worker private: 335*cda5da8dSAndroid Build Coastguard Worker /// Report a syntax error 336*cda5da8dSAndroid Build Coastguard Worker /// \param yyctx the context in which the error occurred. 337*cda5da8dSAndroid Build Coastguard Worker void report_syntax_error (const context& yyctx) const;]], 338*cda5da8dSAndroid Build Coastguard Worker [detailed\|verbose], [[ 339*cda5da8dSAndroid Build Coastguard Worker private: 340*cda5da8dSAndroid Build Coastguard Worker /// The arguments of the error message. 341*cda5da8dSAndroid Build Coastguard Worker int yy_syntax_error_arguments_ (const context& yyctx, 342*cda5da8dSAndroid Build Coastguard Worker symbol_kind_type yyarg[], int yyargn) const; 343*cda5da8dSAndroid Build Coastguard Worker 344*cda5da8dSAndroid Build Coastguard Worker /// Generate an error message. 345*cda5da8dSAndroid Build Coastguard Worker /// \param yyctx the context in which the error occurred. 346*cda5da8dSAndroid Build Coastguard Worker virtual std::string yysyntax_error_ (const context& yyctx) const;]])[ 347*cda5da8dSAndroid Build Coastguard Worker 348*cda5da8dSAndroid Build Coastguard Worker /// Convert a scanner token kind \a t to a symbol kind. 349*cda5da8dSAndroid Build Coastguard Worker /// In theory \a t should be a token_kind_type, but character literals 350*cda5da8dSAndroid Build Coastguard Worker /// are valid, yet not members of the token_kind_type enum. 351*cda5da8dSAndroid Build Coastguard Worker static symbol_kind_type yytranslate_ (int t) YY_NOEXCEPT; 352*cda5da8dSAndroid Build Coastguard Worker 353*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_error_bmatch( 354*cda5da8dSAndroid Build Coastguard Worker [simple], 355*cda5da8dSAndroid Build Coastguard Worker [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ 356*cda5da8dSAndroid Build Coastguard Worker /// For a symbol, its name in clear. 357*cda5da8dSAndroid Build Coastguard Worker static const char* const yytname_[]; 358*cda5da8dSAndroid Build Coastguard Worker #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ 359*cda5da8dSAndroid Build Coastguard Worker ]], 360*cda5da8dSAndroid Build Coastguard Worker [verbose], 361*cda5da8dSAndroid Build Coastguard Worker [[ /// Convert the symbol name \a n to a form suitable for a diagnostic. 362*cda5da8dSAndroid Build Coastguard Worker static std::string yytnamerr_ (const char *yystr); 363*cda5da8dSAndroid Build Coastguard Worker 364*cda5da8dSAndroid Build Coastguard Worker /// For a symbol, its name in clear. 365*cda5da8dSAndroid Build Coastguard Worker static const char* const yytname_[]; 366*cda5da8dSAndroid Build Coastguard Worker ]])[ 367*cda5da8dSAndroid Build Coastguard Worker 368*cda5da8dSAndroid Build Coastguard Worker /// \brief Reclaim the memory associated to a symbol. 369*cda5da8dSAndroid Build Coastguard Worker /// \param yymsg Why this token is reclaimed. 370*cda5da8dSAndroid Build Coastguard Worker /// If null, print nothing. 371*cda5da8dSAndroid Build Coastguard Worker /// \param yykind The symbol kind. 372*cda5da8dSAndroid Build Coastguard Worker void yy_destroy_ (const char* yymsg, symbol_kind_type yykind, 373*cda5da8dSAndroid Build Coastguard Worker value_type& yyval]b4_locations_if([[, 374*cda5da8dSAndroid Build Coastguard Worker location_type& yyloc]])[); 375*cda5da8dSAndroid Build Coastguard Worker 376*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_param_vars[ 377*cda5da8dSAndroid Build Coastguard Worker // Needs access to yy_destroy_, report_syntax_error, etc. 378*cda5da8dSAndroid Build Coastguard Worker friend glr_stack; 379*cda5da8dSAndroid Build Coastguard Worker }; 380*cda5da8dSAndroid Build Coastguard Worker 381*cda5da8dSAndroid Build Coastguard Worker ]b4_token_ctor_if([b4_yytranslate_define([$1])[ 382*cda5da8dSAndroid Build Coastguard Worker ]b4_public_types_define([$1])])[ 383*cda5da8dSAndroid Build Coastguard Worker ]b4_namespace_close[ 384*cda5da8dSAndroid Build Coastguard Worker 385*cda5da8dSAndroid Build Coastguard Worker ]b4_percent_code_get([[provides]])[ 386*cda5da8dSAndroid Build Coastguard Worker ]])[ 387*cda5da8dSAndroid Build Coastguard Worker 388*cda5da8dSAndroid Build Coastguard Worker 389*cda5da8dSAndroid Build Coastguard Worker ## -------------- ## 390*cda5da8dSAndroid Build Coastguard Worker ## Output files. ## 391*cda5da8dSAndroid Build Coastguard Worker ## -------------- ## 392*cda5da8dSAndroid Build Coastguard Worker 393*cda5da8dSAndroid Build Coastguard Worker 394*cda5da8dSAndroid Build Coastguard Worker # ------------- # 395*cda5da8dSAndroid Build Coastguard Worker # Header file. # 396*cda5da8dSAndroid Build Coastguard Worker # ------------- # 397*cda5da8dSAndroid Build Coastguard Worker 398*cda5da8dSAndroid Build Coastguard Worker ]b4_header_if([[ 399*cda5da8dSAndroid Build Coastguard Worker ]b4_output_begin([b4_spec_header_file])[ 400*cda5da8dSAndroid Build Coastguard Worker ]b4_copyright([Skeleton interface for Bison GLR parsers in C++], 401*cda5da8dSAndroid Build Coastguard Worker [2002-2015, 2018-2021])[ 402*cda5da8dSAndroid Build Coastguard Worker // C++ GLR parser skeleton written by Valentin Tolmer. 403*cda5da8dSAndroid Build Coastguard Worker 404*cda5da8dSAndroid Build Coastguard Worker ]b4_disclaimer[ 405*cda5da8dSAndroid Build Coastguard Worker ]b4_cpp_guard_open([b4_spec_mapped_header_file])[ 406*cda5da8dSAndroid Build Coastguard Worker ]b4_shared_declarations([hh])[ 407*cda5da8dSAndroid Build Coastguard Worker ]b4_cpp_guard_close([b4_spec_mapped_header_file])[ 408*cda5da8dSAndroid Build Coastguard Worker ]b4_output_end])[ 409*cda5da8dSAndroid Build Coastguard Worker 410*cda5da8dSAndroid Build Coastguard Worker 411*cda5da8dSAndroid Build Coastguard Worker # --------------------- # 412*cda5da8dSAndroid Build Coastguard Worker # Implementation file. # 413*cda5da8dSAndroid Build Coastguard Worker # --------------------- # 414*cda5da8dSAndroid Build Coastguard Worker 415*cda5da8dSAndroid Build Coastguard Worker ]b4_output_begin([b4_parser_file_name])[ 416*cda5da8dSAndroid Build Coastguard Worker ]b4_copyright([Skeleton implementation for Bison GLR parsers in C], 417*cda5da8dSAndroid Build Coastguard Worker [2002-2015, 2018-2021])[ 418*cda5da8dSAndroid Build Coastguard Worker // C++ GLR parser skeleton written by Valentin Tolmer. 419*cda5da8dSAndroid Build Coastguard Worker 420*cda5da8dSAndroid Build Coastguard Worker ]b4_disclaimer[ 421*cda5da8dSAndroid Build Coastguard Worker ]b4_identification[ 422*cda5da8dSAndroid Build Coastguard Worker 423*cda5da8dSAndroid Build Coastguard Worker ]b4_percent_code_get([[top]])[ 424*cda5da8dSAndroid Build Coastguard Worker ]m4_if(b4_prefix, [yy], [], 425*cda5da8dSAndroid Build Coastguard Worker [[/* Substitute the variable and function names. */ 426*cda5da8dSAndroid Build Coastguard Worker #define yyparse ]b4_prefix[parse 427*cda5da8dSAndroid Build Coastguard Worker #define yylex ]b4_prefix[lex 428*cda5da8dSAndroid Build Coastguard Worker #define yyerror ]b4_prefix[error 429*cda5da8dSAndroid Build Coastguard Worker #define yydebug ]b4_prefix[debug]])[ 430*cda5da8dSAndroid Build Coastguard Worker 431*cda5da8dSAndroid Build Coastguard Worker ]b4_user_pre_prologue[ 432*cda5da8dSAndroid Build Coastguard Worker 433*cda5da8dSAndroid Build Coastguard Worker ]b4_null_define[ 434*cda5da8dSAndroid Build Coastguard Worker 435*cda5da8dSAndroid Build Coastguard Worker ]b4_header_if([[#include "@basename(]b4_spec_header_file[@)"]], 436*cda5da8dSAndroid Build Coastguard Worker [b4_shared_declarations([cc])])[ 437*cda5da8dSAndroid Build Coastguard Worker 438*cda5da8dSAndroid Build Coastguard Worker namespace 439*cda5da8dSAndroid Build Coastguard Worker { 440*cda5da8dSAndroid Build Coastguard Worker /* Default (constant) value used for initialization for null 441*cda5da8dSAndroid Build Coastguard Worker right-hand sides. Unlike the standard yacc.c template, here we set 442*cda5da8dSAndroid Build Coastguard Worker the default value of $$ to a zeroed-out value. Since the default 443*cda5da8dSAndroid Build Coastguard Worker value is undefined, this behavior is technically correct. */ 444*cda5da8dSAndroid Build Coastguard Worker ]b4_namespace_ref[::]b4_parser_class[::value_type yyval_default; 445*cda5da8dSAndroid Build Coastguard Worker } 446*cda5da8dSAndroid Build Coastguard Worker 447*cda5da8dSAndroid Build Coastguard Worker ]b4_user_post_prologue[ 448*cda5da8dSAndroid Build Coastguard Worker ]b4_percent_code_get[ 449*cda5da8dSAndroid Build Coastguard Worker 450*cda5da8dSAndroid Build Coastguard Worker #include <cstdio> 451*cda5da8dSAndroid Build Coastguard Worker #include <cstdlib> 452*cda5da8dSAndroid Build Coastguard Worker 453*cda5da8dSAndroid Build Coastguard Worker #ifndef YY_ 454*cda5da8dSAndroid Build Coastguard Worker # if defined YYENABLE_NLS && YYENABLE_NLS 455*cda5da8dSAndroid Build Coastguard Worker # if ENABLE_NLS 456*cda5da8dSAndroid Build Coastguard Worker # include <libintl.h> /* INFRINGES ON USER NAME SPACE */ 457*cda5da8dSAndroid Build Coastguard Worker # define YY_(Msgid) dgettext ("bison-runtime", Msgid) 458*cda5da8dSAndroid Build Coastguard Worker # endif 459*cda5da8dSAndroid Build Coastguard Worker # endif 460*cda5da8dSAndroid Build Coastguard Worker # ifndef YY_ 461*cda5da8dSAndroid Build Coastguard Worker # define YY_(Msgid) Msgid 462*cda5da8dSAndroid Build Coastguard Worker # endif 463*cda5da8dSAndroid Build Coastguard Worker #endif 464*cda5da8dSAndroid Build Coastguard Worker 465*cda5da8dSAndroid Build Coastguard Worker // Whether we are compiled with exception support. 466*cda5da8dSAndroid Build Coastguard Worker #ifndef YY_EXCEPTIONS 467*cda5da8dSAndroid Build Coastguard Worker # if defined __GNUC__ && !defined __EXCEPTIONS 468*cda5da8dSAndroid Build Coastguard Worker # define YY_EXCEPTIONS 0 469*cda5da8dSAndroid Build Coastguard Worker # else 470*cda5da8dSAndroid Build Coastguard Worker # define YY_EXCEPTIONS 1 471*cda5da8dSAndroid Build Coastguard Worker # endif 472*cda5da8dSAndroid Build Coastguard Worker #endif 473*cda5da8dSAndroid Build Coastguard Worker 474*cda5da8dSAndroid Build Coastguard Worker #ifndef YYFREE 475*cda5da8dSAndroid Build Coastguard Worker # define YYFREE free 476*cda5da8dSAndroid Build Coastguard Worker #endif 477*cda5da8dSAndroid Build Coastguard Worker #ifndef YYMALLOC 478*cda5da8dSAndroid Build Coastguard Worker # define YYMALLOC malloc 479*cda5da8dSAndroid Build Coastguard Worker #endif 480*cda5da8dSAndroid Build Coastguard Worker 481*cda5da8dSAndroid Build Coastguard Worker #ifndef YYSETJMP 482*cda5da8dSAndroid Build Coastguard Worker # include <setjmp.h> 483*cda5da8dSAndroid Build Coastguard Worker # define YYJMP_BUF jmp_buf 484*cda5da8dSAndroid Build Coastguard Worker # define YYSETJMP(Env) setjmp (Env) 485*cda5da8dSAndroid Build Coastguard Worker /* Pacify Clang and ICC. */ 486*cda5da8dSAndroid Build Coastguard Worker # define YYLONGJMP(Env, Val) \ 487*cda5da8dSAndroid Build Coastguard Worker do { \ 488*cda5da8dSAndroid Build Coastguard Worker longjmp (Env, Val); \ 489*cda5da8dSAndroid Build Coastguard Worker YYASSERT (0); \ 490*cda5da8dSAndroid Build Coastguard Worker } while (false) 491*cda5da8dSAndroid Build Coastguard Worker #endif 492*cda5da8dSAndroid Build Coastguard Worker 493*cda5da8dSAndroid Build Coastguard Worker ]b4_attribute_define([noreturn])[ 494*cda5da8dSAndroid Build Coastguard Worker 495*cda5da8dSAndroid Build Coastguard Worker #if defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ 496*cda5da8dSAndroid Build Coastguard Worker # define YY_IGNORE_NULL_DEREFERENCE_BEGIN \ 497*cda5da8dSAndroid Build Coastguard Worker _Pragma ("GCC diagnostic push") \ 498*cda5da8dSAndroid Build Coastguard Worker _Pragma ("GCC diagnostic ignored \"-Wnull-dereference\"") 499*cda5da8dSAndroid Build Coastguard Worker # define YY_IGNORE_NULL_DEREFERENCE_END \ 500*cda5da8dSAndroid Build Coastguard Worker _Pragma ("GCC diagnostic pop") 501*cda5da8dSAndroid Build Coastguard Worker #else 502*cda5da8dSAndroid Build Coastguard Worker # define YY_IGNORE_NULL_DEREFERENCE_BEGIN 503*cda5da8dSAndroid Build Coastguard Worker # define YY_IGNORE_NULL_DEREFERENCE_END 504*cda5da8dSAndroid Build Coastguard Worker #endif 505*cda5da8dSAndroid Build Coastguard Worker 506*cda5da8dSAndroid Build Coastguard Worker ]b4_null_define[ 507*cda5da8dSAndroid Build Coastguard Worker ]b4_cast_define[ 508*cda5da8dSAndroid Build Coastguard Worker 509*cda5da8dSAndroid Build Coastguard Worker // FIXME: Use the same conventions as lalr1.cc. 510*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_assert_if[ 511*cda5da8dSAndroid Build Coastguard Worker #ifndef YYASSERT 512*cda5da8dSAndroid Build Coastguard Worker # define YYASSERT(Condition) ((void) ((Condition) || (abort (), 0))) 513*cda5da8dSAndroid Build Coastguard Worker #endif 514*cda5da8dSAndroid Build Coastguard Worker 515*cda5da8dSAndroid Build Coastguard Worker #ifdef YYDEBUG 516*cda5da8dSAndroid Build Coastguard Worker # define YYDASSERT(Condition) YYASSERT(Condition) 517*cda5da8dSAndroid Build Coastguard Worker #else 518*cda5da8dSAndroid Build Coastguard Worker # define YYDASSERT(Condition) 519*cda5da8dSAndroid Build Coastguard Worker #endif 520*cda5da8dSAndroid Build Coastguard Worker 521*cda5da8dSAndroid Build Coastguard Worker /* YYFINAL -- State number of the termination state. */ 522*cda5da8dSAndroid Build Coastguard Worker #define YYFINAL ]b4_final_state_number[ 523*cda5da8dSAndroid Build Coastguard Worker /* YYLAST -- Last index in YYTABLE. */ 524*cda5da8dSAndroid Build Coastguard Worker #define YYLAST ]b4_last[ 525*cda5da8dSAndroid Build Coastguard Worker 526*cda5da8dSAndroid Build Coastguard Worker /* YYNTOKENS -- Number of terminals. */ 527*cda5da8dSAndroid Build Coastguard Worker #define YYNTOKENS ]b4_tokens_number[ 528*cda5da8dSAndroid Build Coastguard Worker /* YYNNTS -- Number of nonterminals. */ 529*cda5da8dSAndroid Build Coastguard Worker #define YYNNTS ]b4_nterms_number[ 530*cda5da8dSAndroid Build Coastguard Worker /* YYNRULES -- Number of rules. */ 531*cda5da8dSAndroid Build Coastguard Worker #define YYNRULES ]b4_rules_number[ 532*cda5da8dSAndroid Build Coastguard Worker /* YYNSTATES -- Number of states. */ 533*cda5da8dSAndroid Build Coastguard Worker #define YYNSTATES ]b4_states_number[ 534*cda5da8dSAndroid Build Coastguard Worker /* YYMAXRHS -- Maximum number of symbols on right-hand side of rule. */ 535*cda5da8dSAndroid Build Coastguard Worker #define YYMAXRHS ]b4_r2_max[ 536*cda5da8dSAndroid Build Coastguard Worker /* YYMAXLEFT -- Maximum number of symbols to the left of a handle 537*cda5da8dSAndroid Build Coastguard Worker accessed by $0, $-1, etc., in any rule. */ 538*cda5da8dSAndroid Build Coastguard Worker #define YYMAXLEFT ]b4_max_left_semantic_context[ 539*cda5da8dSAndroid Build Coastguard Worker 540*cda5da8dSAndroid Build Coastguard Worker namespace 541*cda5da8dSAndroid Build Coastguard Worker { 542*cda5da8dSAndroid Build Coastguard Worker #if ]b4_api_PREFIX[DEBUG 543*cda5da8dSAndroid Build Coastguard Worker /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ 544*cda5da8dSAndroid Build Coastguard Worker const ]b4_int_type_for([b4_rline])[ yyrline[] = 545*cda5da8dSAndroid Build Coastguard Worker { 546*cda5da8dSAndroid Build Coastguard Worker ]b4_rline[ 547*cda5da8dSAndroid Build Coastguard Worker }; 548*cda5da8dSAndroid Build Coastguard Worker #endif 549*cda5da8dSAndroid Build Coastguard Worker 550*cda5da8dSAndroid Build Coastguard Worker #define YYPACT_NINF ]b4_pact_ninf[ 551*cda5da8dSAndroid Build Coastguard Worker #define YYTABLE_NINF ]b4_table_ninf[ 552*cda5da8dSAndroid Build Coastguard Worker 553*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_tables_define[ 554*cda5da8dSAndroid Build Coastguard Worker 555*cda5da8dSAndroid Build Coastguard Worker /* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */ 556*cda5da8dSAndroid Build Coastguard Worker const ]b4_int_type_for([b4_dprec])[ yydprec[] = 557*cda5da8dSAndroid Build Coastguard Worker { 558*cda5da8dSAndroid Build Coastguard Worker ]b4_dprec[ 559*cda5da8dSAndroid Build Coastguard Worker }; 560*cda5da8dSAndroid Build Coastguard Worker 561*cda5da8dSAndroid Build Coastguard Worker /* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */ 562*cda5da8dSAndroid Build Coastguard Worker const ]b4_int_type_for([b4_merger])[ yymerger[] = 563*cda5da8dSAndroid Build Coastguard Worker { 564*cda5da8dSAndroid Build Coastguard Worker ]b4_merger[ 565*cda5da8dSAndroid Build Coastguard Worker }; 566*cda5da8dSAndroid Build Coastguard Worker 567*cda5da8dSAndroid Build Coastguard Worker /* YYIMMEDIATE[RULE-NUM] -- True iff rule #RULE-NUM is not to be deferred, as 568*cda5da8dSAndroid Build Coastguard Worker in the case of predicates. */ 569*cda5da8dSAndroid Build Coastguard Worker const bool yyimmediate[] = 570*cda5da8dSAndroid Build Coastguard Worker { 571*cda5da8dSAndroid Build Coastguard Worker ]b4_immediate[ 572*cda5da8dSAndroid Build Coastguard Worker }; 573*cda5da8dSAndroid Build Coastguard Worker 574*cda5da8dSAndroid Build Coastguard Worker /* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of 575*cda5da8dSAndroid Build Coastguard Worker list of conflicting reductions corresponding to action entry for 576*cda5da8dSAndroid Build Coastguard Worker state STATE-NUM in yytable. 0 means no conflicts. The list in 577*cda5da8dSAndroid Build Coastguard Worker yyconfl is terminated by a rule number of 0. */ 578*cda5da8dSAndroid Build Coastguard Worker const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] = 579*cda5da8dSAndroid Build Coastguard Worker { 580*cda5da8dSAndroid Build Coastguard Worker ]b4_conflict_list_heads[ 581*cda5da8dSAndroid Build Coastguard Worker }; 582*cda5da8dSAndroid Build Coastguard Worker 583*cda5da8dSAndroid Build Coastguard Worker /* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by 584*cda5da8dSAndroid Build Coastguard Worker 0, pointed into by YYCONFLP. */ 585*cda5da8dSAndroid Build Coastguard Worker ]dnl Do not use b4_int_type_for here, since there are places where 586*cda5da8dSAndroid Build Coastguard Worker dnl pointers onto yyconfl are taken, whose type is "short*". 587*cda5da8dSAndroid Build Coastguard Worker dnl We probably ought to introduce a type for confl. 588*cda5da8dSAndroid Build Coastguard Worker [const short yyconfl[] = 589*cda5da8dSAndroid Build Coastguard Worker { 590*cda5da8dSAndroid Build Coastguard Worker ]b4_conflicting_rules[ 591*cda5da8dSAndroid Build Coastguard Worker }; 592*cda5da8dSAndroid Build Coastguard Worker } // namespace 593*cda5da8dSAndroid Build Coastguard Worker 594*cda5da8dSAndroid Build Coastguard Worker 595*cda5da8dSAndroid Build Coastguard Worker /* Error token number */ 596*cda5da8dSAndroid Build Coastguard Worker #define YYTERROR 1 597*cda5da8dSAndroid Build Coastguard Worker 598*cda5da8dSAndroid Build Coastguard Worker ]b4_locations_if([[ 599*cda5da8dSAndroid Build Coastguard Worker ]b4_yylloc_default_define[ 600*cda5da8dSAndroid Build Coastguard Worker # define YYRHSLOC(Rhs, K) ((Rhs)[K].getState().yyloc) 601*cda5da8dSAndroid Build Coastguard Worker ]])[ 602*cda5da8dSAndroid Build Coastguard Worker 603*cda5da8dSAndroid Build Coastguard Worker enum YYRESULTTAG { yyok, yyaccept, yyabort, yyerr }; 604*cda5da8dSAndroid Build Coastguard Worker 605*cda5da8dSAndroid Build Coastguard Worker #define YYCHK(YYE) \ 606*cda5da8dSAndroid Build Coastguard Worker do { \ 607*cda5da8dSAndroid Build Coastguard Worker YYRESULTTAG yychk_flag = YYE; \ 608*cda5da8dSAndroid Build Coastguard Worker if (yychk_flag != yyok) \ 609*cda5da8dSAndroid Build Coastguard Worker return yychk_flag; \ 610*cda5da8dSAndroid Build Coastguard Worker } while (false) 611*cda5da8dSAndroid Build Coastguard Worker 612*cda5da8dSAndroid Build Coastguard Worker #if ]b4_api_PREFIX[DEBUG 613*cda5da8dSAndroid Build Coastguard Worker 614*cda5da8dSAndroid Build Coastguard Worker #define YYCDEBUG if (!yydebug) {} else std::cerr 615*cda5da8dSAndroid Build Coastguard Worker 616*cda5da8dSAndroid Build Coastguard Worker # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ 617*cda5da8dSAndroid Build Coastguard Worker do { \ 618*cda5da8dSAndroid Build Coastguard Worker if (yydebug) \ 619*cda5da8dSAndroid Build Coastguard Worker { \ 620*cda5da8dSAndroid Build Coastguard Worker std::cerr << Title << ' '; \ 621*cda5da8dSAndroid Build Coastguard Worker yyparser.yy_symbol_print_ (Kind, Value]b4_locations_if([, Location])[); \ 622*cda5da8dSAndroid Build Coastguard Worker std::cerr << '\n'; \ 623*cda5da8dSAndroid Build Coastguard Worker } \ 624*cda5da8dSAndroid Build Coastguard Worker } while (false) 625*cda5da8dSAndroid Build Coastguard Worker 626*cda5da8dSAndroid Build Coastguard Worker # define YY_REDUCE_PRINT(Args) \ 627*cda5da8dSAndroid Build Coastguard Worker do { \ 628*cda5da8dSAndroid Build Coastguard Worker if (yydebug) \ 629*cda5da8dSAndroid Build Coastguard Worker yystateStack.yy_reduce_print Args; \ 630*cda5da8dSAndroid Build Coastguard Worker } while (false) 631*cda5da8dSAndroid Build Coastguard Worker 632*cda5da8dSAndroid Build Coastguard Worker /* Nonzero means print parse trace. It is left uninitialized so that 633*cda5da8dSAndroid Build Coastguard Worker multiple parsers can coexist. */ 634*cda5da8dSAndroid Build Coastguard Worker int yydebug; 635*cda5da8dSAndroid Build Coastguard Worker 636*cda5da8dSAndroid Build Coastguard Worker namespace 637*cda5da8dSAndroid Build Coastguard Worker { 638*cda5da8dSAndroid Build Coastguard Worker using glr_stack = ]b4_namespace_ref[::]b4_parser_class[::glr_stack; 639*cda5da8dSAndroid Build Coastguard Worker using glr_state = ]b4_namespace_ref[::]b4_parser_class[::glr_state; 640*cda5da8dSAndroid Build Coastguard Worker 641*cda5da8dSAndroid Build Coastguard Worker void yypstack (const glr_stack& yystack, size_t yyk) 642*cda5da8dSAndroid Build Coastguard Worker YY_ATTRIBUTE_UNUSED; 643*cda5da8dSAndroid Build Coastguard Worker void yypdumpstack (const glr_stack& yystack) 644*cda5da8dSAndroid Build Coastguard Worker YY_ATTRIBUTE_UNUSED; 645*cda5da8dSAndroid Build Coastguard Worker } 646*cda5da8dSAndroid Build Coastguard Worker 647*cda5da8dSAndroid Build Coastguard Worker #else /* !]b4_api_PREFIX[DEBUG */ 648*cda5da8dSAndroid Build Coastguard Worker 649*cda5da8dSAndroid Build Coastguard Worker # define YYCDEBUG if (true) {} else std::cerr 650*cda5da8dSAndroid Build Coastguard Worker # define YY_SYMBOL_PRINT(Title, Kind, Value, Location) {} 651*cda5da8dSAndroid Build Coastguard Worker # define YY_REDUCE_PRINT(Args) {} 652*cda5da8dSAndroid Build Coastguard Worker 653*cda5da8dSAndroid Build Coastguard Worker #endif /* !]b4_api_PREFIX[DEBUG */ 654*cda5da8dSAndroid Build Coastguard Worker 655*cda5da8dSAndroid Build Coastguard Worker /* YYINITDEPTH -- initial size of the parser's stacks. */ 656*cda5da8dSAndroid Build Coastguard Worker #ifndef YYINITDEPTH 657*cda5da8dSAndroid Build Coastguard Worker # define YYINITDEPTH ]b4_stack_depth_init[ 658*cda5da8dSAndroid Build Coastguard Worker #endif 659*cda5da8dSAndroid Build Coastguard Worker 660*cda5da8dSAndroid Build Coastguard Worker /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only 661*cda5da8dSAndroid Build Coastguard Worker if the built-in stack extension method is used). 662*cda5da8dSAndroid Build Coastguard Worker 663*cda5da8dSAndroid Build Coastguard Worker Do not make this value too large; the results are undefined if 664*cda5da8dSAndroid Build Coastguard Worker SIZE_MAX < YYMAXDEPTH * sizeof (GLRStackItem) 665*cda5da8dSAndroid Build Coastguard Worker evaluated with infinite-precision integer arithmetic. */ 666*cda5da8dSAndroid Build Coastguard Worker 667*cda5da8dSAndroid Build Coastguard Worker #ifndef YYMAXDEPTH 668*cda5da8dSAndroid Build Coastguard Worker # define YYMAXDEPTH ]b4_stack_depth_max[ 669*cda5da8dSAndroid Build Coastguard Worker #endif 670*cda5da8dSAndroid Build Coastguard Worker 671*cda5da8dSAndroid Build Coastguard Worker /* Minimum number of free items on the stack allowed after an 672*cda5da8dSAndroid Build Coastguard Worker allocation. This is to allow allocation and initialization 673*cda5da8dSAndroid Build Coastguard Worker to be completed by functions that call yyexpandGLRStack before the 674*cda5da8dSAndroid Build Coastguard Worker stack is expanded, thus insuring that all necessary pointers get 675*cda5da8dSAndroid Build Coastguard Worker properly redirected to new data. */ 676*cda5da8dSAndroid Build Coastguard Worker #define YYHEADROOM 2 677*cda5da8dSAndroid Build Coastguard Worker 678*cda5da8dSAndroid Build Coastguard Worker #ifndef YYSTACKEXPANDABLE 679*cda5da8dSAndroid Build Coastguard Worker # define YYSTACKEXPANDABLE 1 680*cda5da8dSAndroid Build Coastguard Worker #endif 681*cda5da8dSAndroid Build Coastguard Worker 682*cda5da8dSAndroid Build Coastguard Worker namespace 683*cda5da8dSAndroid Build Coastguard Worker { 684*cda5da8dSAndroid Build Coastguard Worker template <typename Parameter> 685*cda5da8dSAndroid Build Coastguard Worker class strong_index_alias 686*cda5da8dSAndroid Build Coastguard Worker { 687*cda5da8dSAndroid Build Coastguard Worker public: 688*cda5da8dSAndroid Build Coastguard Worker static strong_index_alias create (std::ptrdiff_t value) 689*cda5da8dSAndroid Build Coastguard Worker { 690*cda5da8dSAndroid Build Coastguard Worker strong_index_alias result; 691*cda5da8dSAndroid Build Coastguard Worker result.value_ = value; 692*cda5da8dSAndroid Build Coastguard Worker return result; 693*cda5da8dSAndroid Build Coastguard Worker } 694*cda5da8dSAndroid Build Coastguard Worker 695*cda5da8dSAndroid Build Coastguard Worker std::ptrdiff_t const& get () const { return value_; } 696*cda5da8dSAndroid Build Coastguard Worker 697*cda5da8dSAndroid Build Coastguard Worker size_t uget () const { return static_cast<size_t> (value_); } 698*cda5da8dSAndroid Build Coastguard Worker 699*cda5da8dSAndroid Build Coastguard Worker strong_index_alias operator+ (std::ptrdiff_t other) const 700*cda5da8dSAndroid Build Coastguard Worker { 701*cda5da8dSAndroid Build Coastguard Worker return strong_index_alias (get () + other); 702*cda5da8dSAndroid Build Coastguard Worker } 703*cda5da8dSAndroid Build Coastguard Worker 704*cda5da8dSAndroid Build Coastguard Worker void operator+= (std::ptrdiff_t other) 705*cda5da8dSAndroid Build Coastguard Worker { 706*cda5da8dSAndroid Build Coastguard Worker value_ += other; 707*cda5da8dSAndroid Build Coastguard Worker } 708*cda5da8dSAndroid Build Coastguard Worker 709*cda5da8dSAndroid Build Coastguard Worker strong_index_alias operator- (std::ptrdiff_t other) 710*cda5da8dSAndroid Build Coastguard Worker { 711*cda5da8dSAndroid Build Coastguard Worker return strong_index_alias (get () - other); 712*cda5da8dSAndroid Build Coastguard Worker } 713*cda5da8dSAndroid Build Coastguard Worker 714*cda5da8dSAndroid Build Coastguard Worker void operator-= (std::ptrdiff_t other) 715*cda5da8dSAndroid Build Coastguard Worker { 716*cda5da8dSAndroid Build Coastguard Worker value_ -= other; 717*cda5da8dSAndroid Build Coastguard Worker } 718*cda5da8dSAndroid Build Coastguard Worker 719*cda5da8dSAndroid Build Coastguard Worker size_t operator- (strong_index_alias other) 720*cda5da8dSAndroid Build Coastguard Worker { 721*cda5da8dSAndroid Build Coastguard Worker return strong_index_alias (get () - other.get ()); 722*cda5da8dSAndroid Build Coastguard Worker } 723*cda5da8dSAndroid Build Coastguard Worker 724*cda5da8dSAndroid Build Coastguard Worker strong_index_alias& operator++ () 725*cda5da8dSAndroid Build Coastguard Worker { 726*cda5da8dSAndroid Build Coastguard Worker ++value_; 727*cda5da8dSAndroid Build Coastguard Worker return *this; 728*cda5da8dSAndroid Build Coastguard Worker } 729*cda5da8dSAndroid Build Coastguard Worker 730*cda5da8dSAndroid Build Coastguard Worker bool isValid () const 731*cda5da8dSAndroid Build Coastguard Worker { 732*cda5da8dSAndroid Build Coastguard Worker return value_ != INVALID_INDEX; 733*cda5da8dSAndroid Build Coastguard Worker } 734*cda5da8dSAndroid Build Coastguard Worker 735*cda5da8dSAndroid Build Coastguard Worker void setInvalid() 736*cda5da8dSAndroid Build Coastguard Worker { 737*cda5da8dSAndroid Build Coastguard Worker value_ = INVALID_INDEX; 738*cda5da8dSAndroid Build Coastguard Worker } 739*cda5da8dSAndroid Build Coastguard Worker 740*cda5da8dSAndroid Build Coastguard Worker bool operator== (strong_index_alias other) 741*cda5da8dSAndroid Build Coastguard Worker { 742*cda5da8dSAndroid Build Coastguard Worker return get () == other.get (); 743*cda5da8dSAndroid Build Coastguard Worker } 744*cda5da8dSAndroid Build Coastguard Worker 745*cda5da8dSAndroid Build Coastguard Worker bool operator!= (strong_index_alias other) 746*cda5da8dSAndroid Build Coastguard Worker { 747*cda5da8dSAndroid Build Coastguard Worker return get () != other.get (); 748*cda5da8dSAndroid Build Coastguard Worker } 749*cda5da8dSAndroid Build Coastguard Worker 750*cda5da8dSAndroid Build Coastguard Worker bool operator< (strong_index_alias other) 751*cda5da8dSAndroid Build Coastguard Worker { 752*cda5da8dSAndroid Build Coastguard Worker return get () < other.get (); 753*cda5da8dSAndroid Build Coastguard Worker } 754*cda5da8dSAndroid Build Coastguard Worker 755*cda5da8dSAndroid Build Coastguard Worker private: 756*cda5da8dSAndroid Build Coastguard Worker static const std::ptrdiff_t INVALID_INDEX; 757*cda5da8dSAndroid Build Coastguard Worker 758*cda5da8dSAndroid Build Coastguard Worker // WARNING: 0-initialized. 759*cda5da8dSAndroid Build Coastguard Worker std::ptrdiff_t value_; 760*cda5da8dSAndroid Build Coastguard Worker }; // class strong_index_alias 761*cda5da8dSAndroid Build Coastguard Worker 762*cda5da8dSAndroid Build Coastguard Worker template<typename T> 763*cda5da8dSAndroid Build Coastguard Worker const std::ptrdiff_t strong_index_alias<T>::INVALID_INDEX = 764*cda5da8dSAndroid Build Coastguard Worker std::numeric_limits<std::ptrdiff_t>::max (); 765*cda5da8dSAndroid Build Coastguard Worker 766*cda5da8dSAndroid Build Coastguard Worker using state_set_index = strong_index_alias<struct glr_state_set_tag>; 767*cda5da8dSAndroid Build Coastguard Worker 768*cda5da8dSAndroid Build Coastguard Worker state_set_index create_state_set_index (std::ptrdiff_t value) 769*cda5da8dSAndroid Build Coastguard Worker { 770*cda5da8dSAndroid Build Coastguard Worker return state_set_index::create (value); 771*cda5da8dSAndroid Build Coastguard Worker } 772*cda5da8dSAndroid Build Coastguard Worker 773*cda5da8dSAndroid Build Coastguard Worker /** State numbers, as in LALR(1) machine */ 774*cda5da8dSAndroid Build Coastguard Worker using state_num = int; 775*cda5da8dSAndroid Build Coastguard Worker 776*cda5da8dSAndroid Build Coastguard Worker /** Rule numbers, as in LALR(1) machine */ 777*cda5da8dSAndroid Build Coastguard Worker using rule_num = int; 778*cda5da8dSAndroid Build Coastguard Worker 779*cda5da8dSAndroid Build Coastguard Worker using parser_type = ]b4_namespace_ref[::]b4_parser_class[; 780*cda5da8dSAndroid Build Coastguard Worker using glr_state = parser_type::glr_state; 781*cda5da8dSAndroid Build Coastguard Worker using symbol_kind = parser_type::symbol_kind; 782*cda5da8dSAndroid Build Coastguard Worker using symbol_kind_type = parser_type::symbol_kind_type; 783*cda5da8dSAndroid Build Coastguard Worker using symbol_type = parser_type::symbol_type; 784*cda5da8dSAndroid Build Coastguard Worker using value_type = parser_type::value_type;]b4_locations_if([[ 785*cda5da8dSAndroid Build Coastguard Worker using location_type = parser_type::location_type;]])[ 786*cda5da8dSAndroid Build Coastguard Worker 787*cda5da8dSAndroid Build Coastguard Worker // Forward declarations. 788*cda5da8dSAndroid Build Coastguard Worker class glr_stack_item; 789*cda5da8dSAndroid Build Coastguard Worker class semantic_option; 790*cda5da8dSAndroid Build Coastguard Worker } // namespace 791*cda5da8dSAndroid Build Coastguard Worker 792*cda5da8dSAndroid Build Coastguard Worker namespace 793*cda5da8dSAndroid Build Coastguard Worker { 794*cda5da8dSAndroid Build Coastguard Worker /** Accessing symbol of state YYSTATE. */ 795*cda5da8dSAndroid Build Coastguard Worker inline symbol_kind_type 796*cda5da8dSAndroid Build Coastguard Worker yy_accessing_symbol (state_num yystate) 797*cda5da8dSAndroid Build Coastguard Worker { 798*cda5da8dSAndroid Build Coastguard Worker return YY_CAST (symbol_kind_type, yystos[yystate]); 799*cda5da8dSAndroid Build Coastguard Worker } 800*cda5da8dSAndroid Build Coastguard Worker 801*cda5da8dSAndroid Build Coastguard Worker /** Left-hand-side symbol for rule #YYRULE. */ 802*cda5da8dSAndroid Build Coastguard Worker inline symbol_kind_type 803*cda5da8dSAndroid Build Coastguard Worker yylhsNonterm (rule_num yyrule) 804*cda5da8dSAndroid Build Coastguard Worker { 805*cda5da8dSAndroid Build Coastguard Worker return static_cast<symbol_kind_type>(yyr1[yyrule]); 806*cda5da8dSAndroid Build Coastguard Worker } 807*cda5da8dSAndroid Build Coastguard Worker 808*cda5da8dSAndroid Build Coastguard Worker /** Number of symbols composing the right hand side of rule #RULE. */ 809*cda5da8dSAndroid Build Coastguard Worker inline int 810*cda5da8dSAndroid Build Coastguard Worker yyrhsLength (rule_num yyrule) 811*cda5da8dSAndroid Build Coastguard Worker { 812*cda5da8dSAndroid Build Coastguard Worker return yyr2[yyrule]; 813*cda5da8dSAndroid Build Coastguard Worker } 814*cda5da8dSAndroid Build Coastguard Worker } 815*cda5da8dSAndroid Build Coastguard Worker 816*cda5da8dSAndroid Build Coastguard Worker namespace ]b4_namespace_ref[ 817*cda5da8dSAndroid Build Coastguard Worker { 818*cda5da8dSAndroid Build Coastguard Worker class ]b4_parser_class[::glr_state 819*cda5da8dSAndroid Build Coastguard Worker { 820*cda5da8dSAndroid Build Coastguard Worker public: 821*cda5da8dSAndroid Build Coastguard Worker glr_state () 822*cda5da8dSAndroid Build Coastguard Worker : yyresolved (false) 823*cda5da8dSAndroid Build Coastguard Worker , yylrState (0) 824*cda5da8dSAndroid Build Coastguard Worker , yyposn (0) 825*cda5da8dSAndroid Build Coastguard Worker , yypred (0) 826*cda5da8dSAndroid Build Coastguard Worker , yyfirstVal (0)]b4_locations_if([[ 827*cda5da8dSAndroid Build Coastguard Worker , yyloc ()]])[]b4_parse_assert_if([[ 828*cda5da8dSAndroid Build Coastguard Worker , magic_ (MAGIC)]])[ 829*cda5da8dSAndroid Build Coastguard Worker {} 830*cda5da8dSAndroid Build Coastguard Worker 831*cda5da8dSAndroid Build Coastguard Worker /// Build with a semantic value. 832*cda5da8dSAndroid Build Coastguard Worker glr_state (state_num lrState, size_t posn, const value_type& val]b4_locations_if([[, const location_type& loc]])[) 833*cda5da8dSAndroid Build Coastguard Worker : yyresolved (true) 834*cda5da8dSAndroid Build Coastguard Worker , yylrState (lrState) 835*cda5da8dSAndroid Build Coastguard Worker , yyposn (posn) 836*cda5da8dSAndroid Build Coastguard Worker , yypred (0) 837*cda5da8dSAndroid Build Coastguard Worker , yyval (]b4_variant_if([], [[val]])[)]b4_locations_if([[ 838*cda5da8dSAndroid Build Coastguard Worker , yyloc (loc)]])[]b4_parse_assert_if([[ 839*cda5da8dSAndroid Build Coastguard Worker , magic_ (MAGIC)]])[ 840*cda5da8dSAndroid Build Coastguard Worker {]b4_variant_if([[ 841*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_variant([yy_accessing_symbol (lrState)], 842*cda5da8dSAndroid Build Coastguard Worker [yyval], [copy], [val])])[} 843*cda5da8dSAndroid Build Coastguard Worker 844*cda5da8dSAndroid Build Coastguard Worker /// Build with a semantic option. 845*cda5da8dSAndroid Build Coastguard Worker glr_state (state_num lrState, size_t posn) 846*cda5da8dSAndroid Build Coastguard Worker : yyresolved (false) 847*cda5da8dSAndroid Build Coastguard Worker , yylrState (lrState) 848*cda5da8dSAndroid Build Coastguard Worker , yyposn (posn) 849*cda5da8dSAndroid Build Coastguard Worker , yypred (0) 850*cda5da8dSAndroid Build Coastguard Worker , yyfirstVal (0)]b4_locations_if([[ 851*cda5da8dSAndroid Build Coastguard Worker , yyloc ()]])[]b4_parse_assert_if([[ 852*cda5da8dSAndroid Build Coastguard Worker , magic_ (MAGIC)]])[ 853*cda5da8dSAndroid Build Coastguard Worker {} 854*cda5da8dSAndroid Build Coastguard Worker 855*cda5da8dSAndroid Build Coastguard Worker glr_state (const glr_state& other) 856*cda5da8dSAndroid Build Coastguard Worker : yyresolved (other.yyresolved) 857*cda5da8dSAndroid Build Coastguard Worker , yylrState (other.yylrState) 858*cda5da8dSAndroid Build Coastguard Worker , yyposn (other.yyposn) 859*cda5da8dSAndroid Build Coastguard Worker , yypred (0)]b4_locations_if([[ 860*cda5da8dSAndroid Build Coastguard Worker , yyloc (other.yyloc)]])[]b4_parse_assert_if([[ 861*cda5da8dSAndroid Build Coastguard Worker , magic_ (MAGIC)]])[ 862*cda5da8dSAndroid Build Coastguard Worker { 863*cda5da8dSAndroid Build Coastguard Worker setPred (other.pred ()); 864*cda5da8dSAndroid Build Coastguard Worker if (other.yyresolved)]b4_variant_if([[ 865*cda5da8dSAndroid Build Coastguard Worker { 866*cda5da8dSAndroid Build Coastguard Worker new (&yyval) value_type (); 867*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_variant([yy_accessing_symbol (other.yylrState)], 868*cda5da8dSAndroid Build Coastguard Worker [yyval], [copy], [other.value ()])[ 869*cda5da8dSAndroid Build Coastguard Worker }]], [[ 870*cda5da8dSAndroid Build Coastguard Worker new (&yyval) value_type (other.value ());]])[ 871*cda5da8dSAndroid Build Coastguard Worker else 872*cda5da8dSAndroid Build Coastguard Worker { 873*cda5da8dSAndroid Build Coastguard Worker yyfirstVal = 0; 874*cda5da8dSAndroid Build Coastguard Worker setFirstVal (other.firstVal ()); 875*cda5da8dSAndroid Build Coastguard Worker }]b4_parse_assert_if([[ 876*cda5da8dSAndroid Build Coastguard Worker check_();]])[ 877*cda5da8dSAndroid Build Coastguard Worker } 878*cda5da8dSAndroid Build Coastguard Worker 879*cda5da8dSAndroid Build Coastguard Worker ~glr_state () 880*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 881*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 882*cda5da8dSAndroid Build Coastguard Worker if (yyresolved) 883*cda5da8dSAndroid Build Coastguard Worker {]b4_variant_if([[ 884*cda5da8dSAndroid Build Coastguard Worker symbol_kind_type yykind = yy_accessing_symbol (yylrState); 885*cda5da8dSAndroid Build Coastguard Worker // FIXME: User destructors. 886*cda5da8dSAndroid Build Coastguard Worker // Value type destructor. 887*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_variant([[yykind]], [[yyval]], [[template destroy]])])[ 888*cda5da8dSAndroid Build Coastguard Worker yyval.~value_type (); 889*cda5da8dSAndroid Build Coastguard Worker }]b4_parse_assert_if([[ 890*cda5da8dSAndroid Build Coastguard Worker magic_ = 0;]])[ 891*cda5da8dSAndroid Build Coastguard Worker } 892*cda5da8dSAndroid Build Coastguard Worker 893*cda5da8dSAndroid Build Coastguard Worker glr_state& operator= (const glr_state& other) 894*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 895*cda5da8dSAndroid Build Coastguard Worker check_ (); 896*cda5da8dSAndroid Build Coastguard Worker other.check_ ();]])[ 897*cda5da8dSAndroid Build Coastguard Worker if (!yyresolved && other.yyresolved) 898*cda5da8dSAndroid Build Coastguard Worker new (&yyval) value_type; 899*cda5da8dSAndroid Build Coastguard Worker yyresolved = other.yyresolved; 900*cda5da8dSAndroid Build Coastguard Worker yylrState = other.yylrState; 901*cda5da8dSAndroid Build Coastguard Worker yyposn = other.yyposn; 902*cda5da8dSAndroid Build Coastguard Worker setPred (other.pred ()); 903*cda5da8dSAndroid Build Coastguard Worker if (other.yyresolved)]b4_variant_if([[ 904*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_variant([yy_accessing_symbol (other.yylrState)], 905*cda5da8dSAndroid Build Coastguard Worker [yyval], [copy], [other.value ()])], [[ 906*cda5da8dSAndroid Build Coastguard Worker value () = other.value ();]])[ 907*cda5da8dSAndroid Build Coastguard Worker else 908*cda5da8dSAndroid Build Coastguard Worker setFirstVal (other.firstVal ());]b4_locations_if([[ 909*cda5da8dSAndroid Build Coastguard Worker yyloc = other.yyloc;]])[ 910*cda5da8dSAndroid Build Coastguard Worker return *this; 911*cda5da8dSAndroid Build Coastguard Worker } 912*cda5da8dSAndroid Build Coastguard Worker 913*cda5da8dSAndroid Build Coastguard Worker /** Type tag for the semantic value. If true, yyval applies, otherwise 914*cda5da8dSAndroid Build Coastguard Worker * yyfirstVal applies. */ 915*cda5da8dSAndroid Build Coastguard Worker bool yyresolved; 916*cda5da8dSAndroid Build Coastguard Worker /** Number of corresponding LALR(1) machine state. */ 917*cda5da8dSAndroid Build Coastguard Worker state_num yylrState; 918*cda5da8dSAndroid Build Coastguard Worker /** Source position of the last token produced by my symbol */ 919*cda5da8dSAndroid Build Coastguard Worker size_t yyposn; 920*cda5da8dSAndroid Build Coastguard Worker 921*cda5da8dSAndroid Build Coastguard Worker /// Only call pred() and setPred() on objects in yyitems, not temporaries. 922*cda5da8dSAndroid Build Coastguard Worker glr_state* pred (); 923*cda5da8dSAndroid Build Coastguard Worker const glr_state* pred () const; 924*cda5da8dSAndroid Build Coastguard Worker void setPred (const glr_state* state); 925*cda5da8dSAndroid Build Coastguard Worker 926*cda5da8dSAndroid Build Coastguard Worker /// Only call firstVal() and setFirstVal() on objects in yyitems, not 927*cda5da8dSAndroid Build Coastguard Worker /// temporaries. 928*cda5da8dSAndroid Build Coastguard Worker semantic_option* firstVal (); 929*cda5da8dSAndroid Build Coastguard Worker const semantic_option* firstVal () const; 930*cda5da8dSAndroid Build Coastguard Worker void setFirstVal (const semantic_option* option); 931*cda5da8dSAndroid Build Coastguard Worker 932*cda5da8dSAndroid Build Coastguard Worker value_type& value () 933*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 934*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 935*cda5da8dSAndroid Build Coastguard Worker return yyval; 936*cda5da8dSAndroid Build Coastguard Worker } 937*cda5da8dSAndroid Build Coastguard Worker 938*cda5da8dSAndroid Build Coastguard Worker const value_type& value () const 939*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 940*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 941*cda5da8dSAndroid Build Coastguard Worker return yyval; 942*cda5da8dSAndroid Build Coastguard Worker } 943*cda5da8dSAndroid Build Coastguard Worker 944*cda5da8dSAndroid Build Coastguard Worker void 945*cda5da8dSAndroid Build Coastguard Worker destroy (char const *yymsg, ]b4_namespace_ref[::]b4_parser_class[& yyparser); 946*cda5da8dSAndroid Build Coastguard Worker 947*cda5da8dSAndroid Build Coastguard Worker /* DEBUGGING ONLY */ 948*cda5da8dSAndroid Build Coastguard Worker #if ]b4_api_PREFIX[DEBUG 949*cda5da8dSAndroid Build Coastguard Worker void yy_yypstack () const 950*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 951*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 952*cda5da8dSAndroid Build Coastguard Worker if (pred () != YY_NULLPTR) 953*cda5da8dSAndroid Build Coastguard Worker { 954*cda5da8dSAndroid Build Coastguard Worker pred ()->yy_yypstack (); 955*cda5da8dSAndroid Build Coastguard Worker std::cerr << " -> "; 956*cda5da8dSAndroid Build Coastguard Worker } 957*cda5da8dSAndroid Build Coastguard Worker std::cerr << yylrState << "@@" << yyposn; 958*cda5da8dSAndroid Build Coastguard Worker } 959*cda5da8dSAndroid Build Coastguard Worker #endif 960*cda5da8dSAndroid Build Coastguard Worker 961*cda5da8dSAndroid Build Coastguard Worker std::ptrdiff_t indexIn (const glr_stack_item* array) const YY_ATTRIBUTE_UNUSED; 962*cda5da8dSAndroid Build Coastguard Worker 963*cda5da8dSAndroid Build Coastguard Worker glr_stack_item* asItem () 964*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 965*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 966*cda5da8dSAndroid Build Coastguard Worker return asItem(this); 967*cda5da8dSAndroid Build Coastguard Worker } 968*cda5da8dSAndroid Build Coastguard Worker 969*cda5da8dSAndroid Build Coastguard Worker const glr_stack_item* asItem () const 970*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 971*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 972*cda5da8dSAndroid Build Coastguard Worker return asItem (this); 973*cda5da8dSAndroid Build Coastguard Worker } 974*cda5da8dSAndroid Build Coastguard Worker 975*cda5da8dSAndroid Build Coastguard Worker private: 976*cda5da8dSAndroid Build Coastguard Worker template <typename T> 977*cda5da8dSAndroid Build Coastguard Worker static const glr_stack_item* asItem (const T* state) 978*cda5da8dSAndroid Build Coastguard Worker { 979*cda5da8dSAndroid Build Coastguard Worker return reinterpret_cast<const glr_stack_item*>(state); 980*cda5da8dSAndroid Build Coastguard Worker } 981*cda5da8dSAndroid Build Coastguard Worker template <typename T> 982*cda5da8dSAndroid Build Coastguard Worker static glr_stack_item* asItem (T* state) 983*cda5da8dSAndroid Build Coastguard Worker { 984*cda5da8dSAndroid Build Coastguard Worker return reinterpret_cast<glr_stack_item*> (state); 985*cda5da8dSAndroid Build Coastguard Worker } 986*cda5da8dSAndroid Build Coastguard Worker static const char *as_pointer_ (const glr_state *state) 987*cda5da8dSAndroid Build Coastguard Worker { 988*cda5da8dSAndroid Build Coastguard Worker return reinterpret_cast<const char *> (state); 989*cda5da8dSAndroid Build Coastguard Worker } 990*cda5da8dSAndroid Build Coastguard Worker static char *as_pointer_ (glr_state *state) 991*cda5da8dSAndroid Build Coastguard Worker { 992*cda5da8dSAndroid Build Coastguard Worker return reinterpret_cast<char *> (state); 993*cda5da8dSAndroid Build Coastguard Worker } 994*cda5da8dSAndroid Build Coastguard Worker /** Preceding state in this stack */ 995*cda5da8dSAndroid Build Coastguard Worker std::ptrdiff_t yypred; 996*cda5da8dSAndroid Build Coastguard Worker union { 997*cda5da8dSAndroid Build Coastguard Worker /** First in a chain of alternative reductions producing the 998*cda5da8dSAndroid Build Coastguard Worker * nonterminal corresponding to this state, threaded through 999*cda5da8dSAndroid Build Coastguard Worker * yyfirstVal. Value "0" means empty. */ 1000*cda5da8dSAndroid Build Coastguard Worker std::ptrdiff_t yyfirstVal; 1001*cda5da8dSAndroid Build Coastguard Worker /** Semantic value for this state. */ 1002*cda5da8dSAndroid Build Coastguard Worker value_type yyval; 1003*cda5da8dSAndroid Build Coastguard Worker };]b4_locations_if([[ 1004*cda5da8dSAndroid Build Coastguard Worker // FIXME: Why public? 1005*cda5da8dSAndroid Build Coastguard Worker public: 1006*cda5da8dSAndroid Build Coastguard Worker /** Source location for this state. */ 1007*cda5da8dSAndroid Build Coastguard Worker location_type yyloc;]])[ 1008*cda5da8dSAndroid Build Coastguard Worker 1009*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_assert_if([[ 1010*cda5da8dSAndroid Build Coastguard Worker public: 1011*cda5da8dSAndroid Build Coastguard Worker // Check invariants. 1012*cda5da8dSAndroid Build Coastguard Worker void check_ () const 1013*cda5da8dSAndroid Build Coastguard Worker { 1014*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_NULL_DEREFERENCE_BEGIN 1015*cda5da8dSAndroid Build Coastguard Worker YYASSERT (this->magic_ == MAGIC); 1016*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_NULL_DEREFERENCE_END 1017*cda5da8dSAndroid Build Coastguard Worker } 1018*cda5da8dSAndroid Build Coastguard Worker 1019*cda5da8dSAndroid Build Coastguard Worker // A magic number to check our pointer arithmetic is sane. 1020*cda5da8dSAndroid Build Coastguard Worker enum { MAGIC = 713705 }; 1021*cda5da8dSAndroid Build Coastguard Worker unsigned int magic_;]])[ 1022*cda5da8dSAndroid Build Coastguard Worker }; // class ]b4_parser_class[::glr_state 1023*cda5da8dSAndroid Build Coastguard Worker } // namespace ]b4_namespace_ref[ 1024*cda5da8dSAndroid Build Coastguard Worker 1025*cda5da8dSAndroid Build Coastguard Worker 1026*cda5da8dSAndroid Build Coastguard Worker namespace 1027*cda5da8dSAndroid Build Coastguard Worker { 1028*cda5da8dSAndroid Build Coastguard Worker /** A stack of GLRState representing the different heads during 1029*cda5da8dSAndroid Build Coastguard Worker * nondeterministic evaluation. */ 1030*cda5da8dSAndroid Build Coastguard Worker class glr_state_set 1031*cda5da8dSAndroid Build Coastguard Worker { 1032*cda5da8dSAndroid Build Coastguard Worker public: 1033*cda5da8dSAndroid Build Coastguard Worker /** Initialize YYSET to a singleton set containing an empty stack. */ 1034*cda5da8dSAndroid Build Coastguard Worker glr_state_set () 1035*cda5da8dSAndroid Build Coastguard Worker : yylastDeleted (YY_NULLPTR) 1036*cda5da8dSAndroid Build Coastguard Worker { 1037*cda5da8dSAndroid Build Coastguard Worker yystates.push_back (YY_NULLPTR); 1038*cda5da8dSAndroid Build Coastguard Worker yylookaheadNeeds.push_back (false); 1039*cda5da8dSAndroid Build Coastguard Worker } 1040*cda5da8dSAndroid Build Coastguard Worker 1041*cda5da8dSAndroid Build Coastguard Worker // Behave like a vector of states. 1042*cda5da8dSAndroid Build Coastguard Worker glr_state*& operator[] (state_set_index index) 1043*cda5da8dSAndroid Build Coastguard Worker { 1044*cda5da8dSAndroid Build Coastguard Worker return yystates[index.uget()]; 1045*cda5da8dSAndroid Build Coastguard Worker } 1046*cda5da8dSAndroid Build Coastguard Worker 1047*cda5da8dSAndroid Build Coastguard Worker glr_state* operator[] (state_set_index index) const 1048*cda5da8dSAndroid Build Coastguard Worker { 1049*cda5da8dSAndroid Build Coastguard Worker return yystates[index.uget()]; 1050*cda5da8dSAndroid Build Coastguard Worker } 1051*cda5da8dSAndroid Build Coastguard Worker 1052*cda5da8dSAndroid Build Coastguard Worker size_t size () const 1053*cda5da8dSAndroid Build Coastguard Worker { 1054*cda5da8dSAndroid Build Coastguard Worker return yystates.size (); 1055*cda5da8dSAndroid Build Coastguard Worker } 1056*cda5da8dSAndroid Build Coastguard Worker 1057*cda5da8dSAndroid Build Coastguard Worker std::vector<glr_state*>::iterator begin () 1058*cda5da8dSAndroid Build Coastguard Worker { 1059*cda5da8dSAndroid Build Coastguard Worker return yystates.begin (); 1060*cda5da8dSAndroid Build Coastguard Worker } 1061*cda5da8dSAndroid Build Coastguard Worker 1062*cda5da8dSAndroid Build Coastguard Worker std::vector<glr_state*>::iterator end () 1063*cda5da8dSAndroid Build Coastguard Worker { 1064*cda5da8dSAndroid Build Coastguard Worker return yystates.end (); 1065*cda5da8dSAndroid Build Coastguard Worker } 1066*cda5da8dSAndroid Build Coastguard Worker 1067*cda5da8dSAndroid Build Coastguard Worker bool lookaheadNeeds (state_set_index index) const 1068*cda5da8dSAndroid Build Coastguard Worker { 1069*cda5da8dSAndroid Build Coastguard Worker return yylookaheadNeeds[index.uget ()]; 1070*cda5da8dSAndroid Build Coastguard Worker } 1071*cda5da8dSAndroid Build Coastguard Worker 1072*cda5da8dSAndroid Build Coastguard Worker bool setLookaheadNeeds (state_set_index index, bool value) 1073*cda5da8dSAndroid Build Coastguard Worker { 1074*cda5da8dSAndroid Build Coastguard Worker return yylookaheadNeeds[index.uget ()] = value; 1075*cda5da8dSAndroid Build Coastguard Worker } 1076*cda5da8dSAndroid Build Coastguard Worker 1077*cda5da8dSAndroid Build Coastguard Worker /** Invalidate stack #YYK. */ 1078*cda5da8dSAndroid Build Coastguard Worker void 1079*cda5da8dSAndroid Build Coastguard Worker yymarkStackDeleted (state_set_index yyk) 1080*cda5da8dSAndroid Build Coastguard Worker { 1081*cda5da8dSAndroid Build Coastguard Worker size_t k = yyk.uget (); 1082*cda5da8dSAndroid Build Coastguard Worker if (yystates[k] != YY_NULLPTR) 1083*cda5da8dSAndroid Build Coastguard Worker yylastDeleted = yystates[k]; 1084*cda5da8dSAndroid Build Coastguard Worker yystates[k] = YY_NULLPTR; 1085*cda5da8dSAndroid Build Coastguard Worker } 1086*cda5da8dSAndroid Build Coastguard Worker 1087*cda5da8dSAndroid Build Coastguard Worker /** Undelete the last stack in *this that was marked as deleted. Can 1088*cda5da8dSAndroid Build Coastguard Worker only be done once after a deletion, and only when all other stacks have 1089*cda5da8dSAndroid Build Coastguard Worker been deleted. */ 1090*cda5da8dSAndroid Build Coastguard Worker void 1091*cda5da8dSAndroid Build Coastguard Worker yyundeleteLastStack () 1092*cda5da8dSAndroid Build Coastguard Worker { 1093*cda5da8dSAndroid Build Coastguard Worker if (yylastDeleted == YY_NULLPTR || !yystates.empty ()) 1094*cda5da8dSAndroid Build Coastguard Worker return; 1095*cda5da8dSAndroid Build Coastguard Worker yystates.push_back (yylastDeleted); 1096*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Restoring last deleted stack as stack #0.\n"; 1097*cda5da8dSAndroid Build Coastguard Worker clearLastDeleted (); 1098*cda5da8dSAndroid Build Coastguard Worker } 1099*cda5da8dSAndroid Build Coastguard Worker 1100*cda5da8dSAndroid Build Coastguard Worker /** Remove the dead stacks (yystates[i] == YY_NULLPTR) and shift the later 1101*cda5da8dSAndroid Build Coastguard Worker * ones. */ 1102*cda5da8dSAndroid Build Coastguard Worker void 1103*cda5da8dSAndroid Build Coastguard Worker yyremoveDeletes () 1104*cda5da8dSAndroid Build Coastguard Worker { 1105*cda5da8dSAndroid Build Coastguard Worker size_t newsize = yystates.size (); 1106*cda5da8dSAndroid Build Coastguard Worker /* j is the number of live stacks we have seen. */ 1107*cda5da8dSAndroid Build Coastguard Worker for (size_t i = 0, j = 0; j < newsize; ++i) 1108*cda5da8dSAndroid Build Coastguard Worker { 1109*cda5da8dSAndroid Build Coastguard Worker if (yystates[i] == YY_NULLPTR) 1110*cda5da8dSAndroid Build Coastguard Worker { 1111*cda5da8dSAndroid Build Coastguard Worker if (i == j) 1112*cda5da8dSAndroid Build Coastguard Worker { 1113*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Removing dead stacks.\n"; 1114*cda5da8dSAndroid Build Coastguard Worker } 1115*cda5da8dSAndroid Build Coastguard Worker newsize -= 1; 1116*cda5da8dSAndroid Build Coastguard Worker } 1117*cda5da8dSAndroid Build Coastguard Worker else 1118*cda5da8dSAndroid Build Coastguard Worker { 1119*cda5da8dSAndroid Build Coastguard Worker yystates[j] = yystates[i]; 1120*cda5da8dSAndroid Build Coastguard Worker /* In the current implementation, it's unnecessary to copy 1121*cda5da8dSAndroid Build Coastguard Worker yylookaheadNeeds[i] since, after 1122*cda5da8dSAndroid Build Coastguard Worker yyremoveDeletes returns, the parser immediately either enters 1123*cda5da8dSAndroid Build Coastguard Worker deterministic operation or shifts a token. However, it doesn't 1124*cda5da8dSAndroid Build Coastguard Worker hurt, and the code might evolve to need it. */ 1125*cda5da8dSAndroid Build Coastguard Worker yylookaheadNeeds[j] = yylookaheadNeeds[i]; 1126*cda5da8dSAndroid Build Coastguard Worker if (j != i) 1127*cda5da8dSAndroid Build Coastguard Worker { 1128*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Rename stack " << i << " -> " << j << ".\n"; 1129*cda5da8dSAndroid Build Coastguard Worker } 1130*cda5da8dSAndroid Build Coastguard Worker j += 1; 1131*cda5da8dSAndroid Build Coastguard Worker } 1132*cda5da8dSAndroid Build Coastguard Worker } 1133*cda5da8dSAndroid Build Coastguard Worker yystates.resize (newsize); 1134*cda5da8dSAndroid Build Coastguard Worker yylookaheadNeeds.resize (newsize); 1135*cda5da8dSAndroid Build Coastguard Worker } 1136*cda5da8dSAndroid Build Coastguard Worker 1137*cda5da8dSAndroid Build Coastguard Worker 1138*cda5da8dSAndroid Build Coastguard Worker state_set_index 1139*cda5da8dSAndroid Build Coastguard Worker yysplitStack (state_set_index yyk) 1140*cda5da8dSAndroid Build Coastguard Worker { 1141*cda5da8dSAndroid Build Coastguard Worker const size_t k = yyk.uget (); 1142*cda5da8dSAndroid Build Coastguard Worker yystates.push_back (yystates[k]); 1143*cda5da8dSAndroid Build Coastguard Worker yylookaheadNeeds.push_back (yylookaheadNeeds[k]); 1144*cda5da8dSAndroid Build Coastguard Worker return create_state_set_index (static_cast<std::ptrdiff_t> (yystates.size () - 1)); 1145*cda5da8dSAndroid Build Coastguard Worker } 1146*cda5da8dSAndroid Build Coastguard Worker 1147*cda5da8dSAndroid Build Coastguard Worker void clearLastDeleted () 1148*cda5da8dSAndroid Build Coastguard Worker { 1149*cda5da8dSAndroid Build Coastguard Worker yylastDeleted = YY_NULLPTR; 1150*cda5da8dSAndroid Build Coastguard Worker } 1151*cda5da8dSAndroid Build Coastguard Worker 1152*cda5da8dSAndroid Build Coastguard Worker private: 1153*cda5da8dSAndroid Build Coastguard Worker 1154*cda5da8dSAndroid Build Coastguard Worker std::vector<glr_state*> yystates; 1155*cda5da8dSAndroid Build Coastguard Worker /** During nondeterministic operation, yylookaheadNeeds tracks which 1156*cda5da8dSAndroid Build Coastguard Worker * stacks have actually needed the current lookahead. During deterministic 1157*cda5da8dSAndroid Build Coastguard Worker * operation, yylookaheadNeeds[0] is not maintained since it would merely 1158*cda5da8dSAndroid Build Coastguard Worker * duplicate !yyla.empty (). */ 1159*cda5da8dSAndroid Build Coastguard Worker std::vector<bool> yylookaheadNeeds; 1160*cda5da8dSAndroid Build Coastguard Worker 1161*cda5da8dSAndroid Build Coastguard Worker /** The last stack we invalidated. */ 1162*cda5da8dSAndroid Build Coastguard Worker glr_state* yylastDeleted; 1163*cda5da8dSAndroid Build Coastguard Worker }; // class glr_state_set 1164*cda5da8dSAndroid Build Coastguard Worker } // namespace 1165*cda5da8dSAndroid Build Coastguard Worker 1166*cda5da8dSAndroid Build Coastguard Worker namespace 1167*cda5da8dSAndroid Build Coastguard Worker { 1168*cda5da8dSAndroid Build Coastguard Worker class semantic_option 1169*cda5da8dSAndroid Build Coastguard Worker { 1170*cda5da8dSAndroid Build Coastguard Worker public: 1171*cda5da8dSAndroid Build Coastguard Worker semantic_option () 1172*cda5da8dSAndroid Build Coastguard Worker : yyrule (0) 1173*cda5da8dSAndroid Build Coastguard Worker , yystate (0) 1174*cda5da8dSAndroid Build Coastguard Worker , yynext (0) 1175*cda5da8dSAndroid Build Coastguard Worker , yyla ()]b4_parse_assert_if([[ 1176*cda5da8dSAndroid Build Coastguard Worker , magic_ (MAGIC)]])[ 1177*cda5da8dSAndroid Build Coastguard Worker {} 1178*cda5da8dSAndroid Build Coastguard Worker 1179*cda5da8dSAndroid Build Coastguard Worker semantic_option (rule_num rule) 1180*cda5da8dSAndroid Build Coastguard Worker : yyrule (rule) 1181*cda5da8dSAndroid Build Coastguard Worker , yystate (0) 1182*cda5da8dSAndroid Build Coastguard Worker , yynext (0) 1183*cda5da8dSAndroid Build Coastguard Worker , yyla ()]b4_parse_assert_if([[ 1184*cda5da8dSAndroid Build Coastguard Worker , magic_ (MAGIC)]])[ 1185*cda5da8dSAndroid Build Coastguard Worker {} 1186*cda5da8dSAndroid Build Coastguard Worker 1187*cda5da8dSAndroid Build Coastguard Worker semantic_option (const semantic_option& that) 1188*cda5da8dSAndroid Build Coastguard Worker : yyrule (that.yyrule) 1189*cda5da8dSAndroid Build Coastguard Worker , yystate (that.yystate) 1190*cda5da8dSAndroid Build Coastguard Worker , yynext (that.yynext) 1191*cda5da8dSAndroid Build Coastguard Worker , yyla (that.yyla)]b4_parse_assert_if([[ 1192*cda5da8dSAndroid Build Coastguard Worker , magic_ (MAGIC)]])[ 1193*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1194*cda5da8dSAndroid Build Coastguard Worker that.check_ ();]])[ 1195*cda5da8dSAndroid Build Coastguard Worker } 1196*cda5da8dSAndroid Build Coastguard Worker 1197*cda5da8dSAndroid Build Coastguard Worker // Needed for the assignment in yynewSemanticOption. 1198*cda5da8dSAndroid Build Coastguard Worker semantic_option& operator= (const semantic_option& that) 1199*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1200*cda5da8dSAndroid Build Coastguard Worker check_ (); 1201*cda5da8dSAndroid Build Coastguard Worker that.check_ ();]])[ 1202*cda5da8dSAndroid Build Coastguard Worker yyrule = that.yyrule; 1203*cda5da8dSAndroid Build Coastguard Worker yystate = that.yystate; 1204*cda5da8dSAndroid Build Coastguard Worker yynext = that.yynext; 1205*cda5da8dSAndroid Build Coastguard Worker yyla = that.yyla; 1206*cda5da8dSAndroid Build Coastguard Worker return *this; 1207*cda5da8dSAndroid Build Coastguard Worker } 1208*cda5da8dSAndroid Build Coastguard Worker 1209*cda5da8dSAndroid Build Coastguard Worker /// Only call state() and setState() on objects in yyitems, not temporaries. 1210*cda5da8dSAndroid Build Coastguard Worker glr_state* state(); 1211*cda5da8dSAndroid Build Coastguard Worker const glr_state* state() const; 1212*cda5da8dSAndroid Build Coastguard Worker void setState(const glr_state* s); 1213*cda5da8dSAndroid Build Coastguard Worker 1214*cda5da8dSAndroid Build Coastguard Worker const semantic_option* next () const YY_ATTRIBUTE_UNUSED; 1215*cda5da8dSAndroid Build Coastguard Worker semantic_option* next (); 1216*cda5da8dSAndroid Build Coastguard Worker void setNext (const semantic_option* s); 1217*cda5da8dSAndroid Build Coastguard Worker 1218*cda5da8dSAndroid Build Coastguard Worker std::ptrdiff_t indexIn (const glr_stack_item* array) const YY_ATTRIBUTE_UNUSED; 1219*cda5da8dSAndroid Build Coastguard Worker 1220*cda5da8dSAndroid Build Coastguard Worker /** True iff YYY0 and YYY1 represent identical options at the top level. 1221*cda5da8dSAndroid Build Coastguard Worker * That is, they represent the same rule applied to RHS symbols 1222*cda5da8dSAndroid Build Coastguard Worker * that produce the same terminal symbols. */ 1223*cda5da8dSAndroid Build Coastguard Worker bool 1224*cda5da8dSAndroid Build Coastguard Worker isIdenticalTo (const semantic_option& yyy1) const 1225*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1226*cda5da8dSAndroid Build Coastguard Worker check_ (); 1227*cda5da8dSAndroid Build Coastguard Worker yyy1.check_ ();]])[ 1228*cda5da8dSAndroid Build Coastguard Worker if (this->yyrule == yyy1.yyrule) 1229*cda5da8dSAndroid Build Coastguard Worker { 1230*cda5da8dSAndroid Build Coastguard Worker const glr_state *yys0, *yys1; 1231*cda5da8dSAndroid Build Coastguard Worker int yyn; 1232*cda5da8dSAndroid Build Coastguard Worker for (yys0 = this->state(), 1233*cda5da8dSAndroid Build Coastguard Worker yys1 = yyy1.state(), 1234*cda5da8dSAndroid Build Coastguard Worker yyn = yyrhsLength (this->yyrule); 1235*cda5da8dSAndroid Build Coastguard Worker yyn > 0; 1236*cda5da8dSAndroid Build Coastguard Worker yys0 = yys0->pred(), 1237*cda5da8dSAndroid Build Coastguard Worker yys1 = yys1->pred(), yyn -= 1) 1238*cda5da8dSAndroid Build Coastguard Worker if (yys0->yyposn != yys1->yyposn) 1239*cda5da8dSAndroid Build Coastguard Worker return false; 1240*cda5da8dSAndroid Build Coastguard Worker return true; 1241*cda5da8dSAndroid Build Coastguard Worker } 1242*cda5da8dSAndroid Build Coastguard Worker else 1243*cda5da8dSAndroid Build Coastguard Worker return false; 1244*cda5da8dSAndroid Build Coastguard Worker } 1245*cda5da8dSAndroid Build Coastguard Worker 1246*cda5da8dSAndroid Build Coastguard Worker /** Assuming identicalOptions (YYY0,YYY1), destructively merge the 1247*cda5da8dSAndroid Build Coastguard Worker * alternative semantic values for the RHS-symbols of YYY1 and YYY0. */ 1248*cda5da8dSAndroid Build Coastguard Worker void 1249*cda5da8dSAndroid Build Coastguard Worker mergeWith (semantic_option& yyy1) 1250*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1251*cda5da8dSAndroid Build Coastguard Worker check_ (); 1252*cda5da8dSAndroid Build Coastguard Worker yyy1.check_ ();]])[ 1253*cda5da8dSAndroid Build Coastguard Worker glr_state *yys0 = this->state (); 1254*cda5da8dSAndroid Build Coastguard Worker glr_state *yys1 = yyy1.state (); 1255*cda5da8dSAndroid Build Coastguard Worker for (int yyn = yyrhsLength (this->yyrule); 1256*cda5da8dSAndroid Build Coastguard Worker yyn > 0; 1257*cda5da8dSAndroid Build Coastguard Worker yyn -= 1, yys0 = yys0->pred (), yys1 = yys1->pred ()) 1258*cda5da8dSAndroid Build Coastguard Worker { 1259*cda5da8dSAndroid Build Coastguard Worker if (yys0 == yys1) 1260*cda5da8dSAndroid Build Coastguard Worker break; 1261*cda5da8dSAndroid Build Coastguard Worker else if (yys0->yyresolved) 1262*cda5da8dSAndroid Build Coastguard Worker { 1263*cda5da8dSAndroid Build Coastguard Worker yys1->yyresolved = true;]b4_variant_if([[ 1264*cda5da8dSAndroid Build Coastguard Worker YYASSERT (yys1->yylrState == yys0->yylrState); 1265*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_variant([yy_accessing_symbol (yys0->yylrState)], 1266*cda5da8dSAndroid Build Coastguard Worker [yys1->value ()], [copy], [yys0->value ()])], [[ 1267*cda5da8dSAndroid Build Coastguard Worker yys1->value () = yys0->value ();]])[ 1268*cda5da8dSAndroid Build Coastguard Worker } 1269*cda5da8dSAndroid Build Coastguard Worker else if (yys1->yyresolved) 1270*cda5da8dSAndroid Build Coastguard Worker { 1271*cda5da8dSAndroid Build Coastguard Worker yys0->yyresolved = true;]b4_variant_if([[ 1272*cda5da8dSAndroid Build Coastguard Worker YYASSERT (yys0->yylrState == yys1->yylrState); 1273*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_variant([yy_accessing_symbol (yys1->yylrState)], 1274*cda5da8dSAndroid Build Coastguard Worker [yys0->value ()], [copy], [yys1->value ()])], [[ 1275*cda5da8dSAndroid Build Coastguard Worker yys0->value () = yys1->value ();]])[ 1276*cda5da8dSAndroid Build Coastguard Worker } 1277*cda5da8dSAndroid Build Coastguard Worker else 1278*cda5da8dSAndroid Build Coastguard Worker { 1279*cda5da8dSAndroid Build Coastguard Worker semantic_option* yyz0prev = YY_NULLPTR; 1280*cda5da8dSAndroid Build Coastguard Worker semantic_option* yyz0 = yys0->firstVal(); 1281*cda5da8dSAndroid Build Coastguard Worker semantic_option* yyz1 = yys1->firstVal(); 1282*cda5da8dSAndroid Build Coastguard Worker while (true) 1283*cda5da8dSAndroid Build Coastguard Worker { 1284*cda5da8dSAndroid Build Coastguard Worker if (yyz1 == yyz0 || yyz1 == YY_NULLPTR) 1285*cda5da8dSAndroid Build Coastguard Worker break; 1286*cda5da8dSAndroid Build Coastguard Worker else if (yyz0 == YY_NULLPTR) 1287*cda5da8dSAndroid Build Coastguard Worker { 1288*cda5da8dSAndroid Build Coastguard Worker if (yyz0prev != YY_NULLPTR) 1289*cda5da8dSAndroid Build Coastguard Worker yyz0prev->setNext (yyz1); 1290*cda5da8dSAndroid Build Coastguard Worker else 1291*cda5da8dSAndroid Build Coastguard Worker yys0->setFirstVal (yyz1); 1292*cda5da8dSAndroid Build Coastguard Worker break; 1293*cda5da8dSAndroid Build Coastguard Worker } 1294*cda5da8dSAndroid Build Coastguard Worker else if (yyz0 < yyz1) 1295*cda5da8dSAndroid Build Coastguard Worker { 1296*cda5da8dSAndroid Build Coastguard Worker semantic_option* yyz = yyz0; 1297*cda5da8dSAndroid Build Coastguard Worker if (yyz0prev != YY_NULLPTR) 1298*cda5da8dSAndroid Build Coastguard Worker yyz0prev->setNext(yyz1); 1299*cda5da8dSAndroid Build Coastguard Worker else 1300*cda5da8dSAndroid Build Coastguard Worker yys0->setFirstVal(yyz1); 1301*cda5da8dSAndroid Build Coastguard Worker yyz1 = yyz1->next(); 1302*cda5da8dSAndroid Build Coastguard Worker yyz0->setNext(yyz); 1303*cda5da8dSAndroid Build Coastguard Worker } 1304*cda5da8dSAndroid Build Coastguard Worker yyz0prev = yyz0; 1305*cda5da8dSAndroid Build Coastguard Worker yyz0 = yyz0->next(); 1306*cda5da8dSAndroid Build Coastguard Worker } 1307*cda5da8dSAndroid Build Coastguard Worker yys1->setFirstVal(yys0->firstVal()); 1308*cda5da8dSAndroid Build Coastguard Worker } 1309*cda5da8dSAndroid Build Coastguard Worker } 1310*cda5da8dSAndroid Build Coastguard Worker } 1311*cda5da8dSAndroid Build Coastguard Worker 1312*cda5da8dSAndroid Build Coastguard Worker #if ]b4_api_PREFIX[DEBUG 1313*cda5da8dSAndroid Build Coastguard Worker void yyreportTree (size_t yyindent = 2) const 1314*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1315*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 1316*cda5da8dSAndroid Build Coastguard Worker int yynrhs = yyrhsLength (this->yyrule); 1317*cda5da8dSAndroid Build Coastguard Worker const glr_state* yystates[1 + YYMAXRHS]; 1318*cda5da8dSAndroid Build Coastguard Worker glr_state yyleftmost_state; 1319*cda5da8dSAndroid Build Coastguard Worker 1320*cda5da8dSAndroid Build Coastguard Worker { 1321*cda5da8dSAndroid Build Coastguard Worker const glr_state* yys = this->state(); 1322*cda5da8dSAndroid Build Coastguard Worker for (int yyi = yynrhs; 0 < yyi; yyi -= 1) 1323*cda5da8dSAndroid Build Coastguard Worker { 1324*cda5da8dSAndroid Build Coastguard Worker yystates[yyi] = yys; 1325*cda5da8dSAndroid Build Coastguard Worker yys = yys->pred(); 1326*cda5da8dSAndroid Build Coastguard Worker } 1327*cda5da8dSAndroid Build Coastguard Worker if (yys == YY_NULLPTR) 1328*cda5da8dSAndroid Build Coastguard Worker { 1329*cda5da8dSAndroid Build Coastguard Worker yyleftmost_state.yyposn = 0; 1330*cda5da8dSAndroid Build Coastguard Worker yystates[0] = &yyleftmost_state; 1331*cda5da8dSAndroid Build Coastguard Worker } 1332*cda5da8dSAndroid Build Coastguard Worker else 1333*cda5da8dSAndroid Build Coastguard Worker yystates[0] = yys; 1334*cda5da8dSAndroid Build Coastguard Worker } 1335*cda5da8dSAndroid Build Coastguard Worker 1336*cda5da8dSAndroid Build Coastguard Worker std::string yylhs = ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yylhsNonterm (this->yyrule)); 1337*cda5da8dSAndroid Build Coastguard Worker YYASSERT(this->state()); 1338*cda5da8dSAndroid Build Coastguard Worker if (this->state()->yyposn < yystates[0]->yyposn + 1) 1339*cda5da8dSAndroid Build Coastguard Worker std::cerr << std::string(yyindent, ' ') << yylhs << " -> <Rule " 1340*cda5da8dSAndroid Build Coastguard Worker << this->yyrule - 1 << ", empty>\n"; 1341*cda5da8dSAndroid Build Coastguard Worker else 1342*cda5da8dSAndroid Build Coastguard Worker std::cerr << std::string(yyindent, ' ') << yylhs << " -> <Rule " 1343*cda5da8dSAndroid Build Coastguard Worker << this->yyrule - 1 << ", tokens " 1344*cda5da8dSAndroid Build Coastguard Worker << yystates[0]->yyposn + 1 << " .. " 1345*cda5da8dSAndroid Build Coastguard Worker << this->state()->yyposn << ">\n"; 1346*cda5da8dSAndroid Build Coastguard Worker for (int yyi = 1; yyi <= yynrhs; yyi += 1) 1347*cda5da8dSAndroid Build Coastguard Worker { 1348*cda5da8dSAndroid Build Coastguard Worker if (yystates[yyi]->yyresolved) 1349*cda5da8dSAndroid Build Coastguard Worker { 1350*cda5da8dSAndroid Build Coastguard Worker std::string yysym = ]b4_namespace_ref[::]b4_parser_class[::symbol_name (yy_accessing_symbol (yystates[yyi]->yylrState)); 1351*cda5da8dSAndroid Build Coastguard Worker if (yystates[yyi-1]->yyposn+1 > yystates[yyi]->yyposn) 1352*cda5da8dSAndroid Build Coastguard Worker std::cerr << std::string(yyindent + 2, ' ') << yysym 1353*cda5da8dSAndroid Build Coastguard Worker << " <empty>\n"; 1354*cda5da8dSAndroid Build Coastguard Worker else 1355*cda5da8dSAndroid Build Coastguard Worker std::cerr << std::string(yyindent + 2, ' ') << yysym 1356*cda5da8dSAndroid Build Coastguard Worker << " <tokens " << yystates[yyi-1]->yyposn + 1 1357*cda5da8dSAndroid Build Coastguard Worker << " .. " << yystates[yyi]->yyposn << ">\n"; 1358*cda5da8dSAndroid Build Coastguard Worker } 1359*cda5da8dSAndroid Build Coastguard Worker else 1360*cda5da8dSAndroid Build Coastguard Worker yystates[yyi]->firstVal ()->yyreportTree (yyindent+2); 1361*cda5da8dSAndroid Build Coastguard Worker } 1362*cda5da8dSAndroid Build Coastguard Worker } 1363*cda5da8dSAndroid Build Coastguard Worker #endif 1364*cda5da8dSAndroid Build Coastguard Worker 1365*cda5da8dSAndroid Build Coastguard Worker /** Rule number for this reduction */ 1366*cda5da8dSAndroid Build Coastguard Worker rule_num yyrule; 1367*cda5da8dSAndroid Build Coastguard Worker 1368*cda5da8dSAndroid Build Coastguard Worker private: 1369*cda5da8dSAndroid Build Coastguard Worker template <typename T> 1370*cda5da8dSAndroid Build Coastguard Worker static const glr_stack_item* asItem(const T* state) 1371*cda5da8dSAndroid Build Coastguard Worker { 1372*cda5da8dSAndroid Build Coastguard Worker return reinterpret_cast<const glr_stack_item*>(state); 1373*cda5da8dSAndroid Build Coastguard Worker } 1374*cda5da8dSAndroid Build Coastguard Worker template <typename T> 1375*cda5da8dSAndroid Build Coastguard Worker static glr_stack_item* asItem(T* state) 1376*cda5da8dSAndroid Build Coastguard Worker { 1377*cda5da8dSAndroid Build Coastguard Worker return reinterpret_cast<glr_stack_item*>(state); 1378*cda5da8dSAndroid Build Coastguard Worker } 1379*cda5da8dSAndroid Build Coastguard Worker /** The last RHS state in the list of states to be reduced. */ 1380*cda5da8dSAndroid Build Coastguard Worker std::ptrdiff_t yystate; 1381*cda5da8dSAndroid Build Coastguard Worker /** Next sibling in chain of options. To facilitate merging, 1382*cda5da8dSAndroid Build Coastguard Worker * options are chained in decreasing order by address. */ 1383*cda5da8dSAndroid Build Coastguard Worker std::ptrdiff_t yynext; 1384*cda5da8dSAndroid Build Coastguard Worker 1385*cda5da8dSAndroid Build Coastguard Worker public: 1386*cda5da8dSAndroid Build Coastguard Worker /** The lookahead for this reduction. */ 1387*cda5da8dSAndroid Build Coastguard Worker symbol_type yyla; 1388*cda5da8dSAndroid Build Coastguard Worker 1389*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_assert_if([[ 1390*cda5da8dSAndroid Build Coastguard Worker public: 1391*cda5da8dSAndroid Build Coastguard Worker // Check invariants. 1392*cda5da8dSAndroid Build Coastguard Worker void check_ () const 1393*cda5da8dSAndroid Build Coastguard Worker { 1394*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_NULL_DEREFERENCE_BEGIN 1395*cda5da8dSAndroid Build Coastguard Worker YYASSERT (this->magic_ == MAGIC); 1396*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_NULL_DEREFERENCE_END 1397*cda5da8dSAndroid Build Coastguard Worker } 1398*cda5da8dSAndroid Build Coastguard Worker 1399*cda5da8dSAndroid Build Coastguard Worker // A magic number to check our pointer arithmetic is sane. 1400*cda5da8dSAndroid Build Coastguard Worker enum { MAGIC = 0xeff1cace }; 1401*cda5da8dSAndroid Build Coastguard Worker unsigned int magic_;]])[ 1402*cda5da8dSAndroid Build Coastguard Worker }; // class semantic_option 1403*cda5da8dSAndroid Build Coastguard Worker } // namespace 1404*cda5da8dSAndroid Build Coastguard Worker 1405*cda5da8dSAndroid Build Coastguard Worker namespace 1406*cda5da8dSAndroid Build Coastguard Worker { 1407*cda5da8dSAndroid Build Coastguard Worker /** Type of the items in the GLR stack. 1408*cda5da8dSAndroid Build Coastguard Worker * It can be either a glr_state or a semantic_option. The is_state_ field 1409*cda5da8dSAndroid Build Coastguard Worker * indicates which item of the union is valid. */ 1410*cda5da8dSAndroid Build Coastguard Worker class glr_stack_item 1411*cda5da8dSAndroid Build Coastguard Worker { 1412*cda5da8dSAndroid Build Coastguard Worker public: 1413*cda5da8dSAndroid Build Coastguard Worker glr_stack_item (bool state = true) 1414*cda5da8dSAndroid Build Coastguard Worker : is_state_ (state)]b4_parse_assert_if([[ 1415*cda5da8dSAndroid Build Coastguard Worker , magic_ (MAGIC)]])[ 1416*cda5da8dSAndroid Build Coastguard Worker { 1417*cda5da8dSAndroid Build Coastguard Worker if (is_state_) 1418*cda5da8dSAndroid Build Coastguard Worker new (&raw_) glr_state; 1419*cda5da8dSAndroid Build Coastguard Worker else 1420*cda5da8dSAndroid Build Coastguard Worker new (&raw_) semantic_option; 1421*cda5da8dSAndroid Build Coastguard Worker } 1422*cda5da8dSAndroid Build Coastguard Worker 1423*cda5da8dSAndroid Build Coastguard Worker glr_stack_item (const glr_stack_item& other) YY_NOEXCEPT YY_NOTHROW 1424*cda5da8dSAndroid Build Coastguard Worker : is_state_ (other.is_state_)]b4_parse_assert_if([[ 1425*cda5da8dSAndroid Build Coastguard Worker , magic_ (MAGIC)]])[ 1426*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1427*cda5da8dSAndroid Build Coastguard Worker other.check_ ();]])[ 1428*cda5da8dSAndroid Build Coastguard Worker std::memcpy (raw_, other.raw_, union_size); 1429*cda5da8dSAndroid Build Coastguard Worker } 1430*cda5da8dSAndroid Build Coastguard Worker 1431*cda5da8dSAndroid Build Coastguard Worker glr_stack_item& operator= (glr_stack_item other) 1432*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1433*cda5da8dSAndroid Build Coastguard Worker check_ (); 1434*cda5da8dSAndroid Build Coastguard Worker other.check_ ();]])[ 1435*cda5da8dSAndroid Build Coastguard Worker std::swap (is_state_, other.is_state_); 1436*cda5da8dSAndroid Build Coastguard Worker std::swap (raw_, other.raw_); 1437*cda5da8dSAndroid Build Coastguard Worker return *this; 1438*cda5da8dSAndroid Build Coastguard Worker } 1439*cda5da8dSAndroid Build Coastguard Worker 1440*cda5da8dSAndroid Build Coastguard Worker ~glr_stack_item () 1441*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1442*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 1443*cda5da8dSAndroid Build Coastguard Worker if (is_state ()) 1444*cda5da8dSAndroid Build Coastguard Worker getState ().~glr_state (); 1445*cda5da8dSAndroid Build Coastguard Worker else 1446*cda5da8dSAndroid Build Coastguard Worker getOption ().~semantic_option (); 1447*cda5da8dSAndroid Build Coastguard Worker } 1448*cda5da8dSAndroid Build Coastguard Worker 1449*cda5da8dSAndroid Build Coastguard Worker void setState (const glr_state &state) 1450*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1451*cda5da8dSAndroid Build Coastguard Worker check_ (); 1452*cda5da8dSAndroid Build Coastguard Worker state.check_ ();]])[ 1453*cda5da8dSAndroid Build Coastguard Worker if (this != state.asItem ()) 1454*cda5da8dSAndroid Build Coastguard Worker { 1455*cda5da8dSAndroid Build Coastguard Worker if (is_state_) 1456*cda5da8dSAndroid Build Coastguard Worker getState ().~glr_state (); 1457*cda5da8dSAndroid Build Coastguard Worker else 1458*cda5da8dSAndroid Build Coastguard Worker getOption ().~semantic_option (); 1459*cda5da8dSAndroid Build Coastguard Worker new (&raw_) glr_state (state); 1460*cda5da8dSAndroid Build Coastguard Worker is_state_ = true; 1461*cda5da8dSAndroid Build Coastguard Worker } 1462*cda5da8dSAndroid Build Coastguard Worker } 1463*cda5da8dSAndroid Build Coastguard Worker 1464*cda5da8dSAndroid Build Coastguard Worker glr_state& getState () 1465*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1466*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 1467*cda5da8dSAndroid Build Coastguard Worker YYDASSERT (is_state ()); 1468*cda5da8dSAndroid Build Coastguard Worker void *yyp = raw_; 1469*cda5da8dSAndroid Build Coastguard Worker glr_state& res = *static_cast<glr_state*> (yyp);]b4_parse_assert_if([[ 1470*cda5da8dSAndroid Build Coastguard Worker res.check_ ();]])[ 1471*cda5da8dSAndroid Build Coastguard Worker return res; 1472*cda5da8dSAndroid Build Coastguard Worker } 1473*cda5da8dSAndroid Build Coastguard Worker 1474*cda5da8dSAndroid Build Coastguard Worker const glr_state& getState () const 1475*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1476*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 1477*cda5da8dSAndroid Build Coastguard Worker YYDASSERT (is_state ()); 1478*cda5da8dSAndroid Build Coastguard Worker const void *yyp = raw_; 1479*cda5da8dSAndroid Build Coastguard Worker const glr_state& res = *static_cast<const glr_state*> (yyp);]b4_parse_assert_if([[ 1480*cda5da8dSAndroid Build Coastguard Worker res.check_ ();]])[ 1481*cda5da8dSAndroid Build Coastguard Worker return res; 1482*cda5da8dSAndroid Build Coastguard Worker } 1483*cda5da8dSAndroid Build Coastguard Worker 1484*cda5da8dSAndroid Build Coastguard Worker semantic_option& getOption () 1485*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1486*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 1487*cda5da8dSAndroid Build Coastguard Worker YYDASSERT (!is_state ()); 1488*cda5da8dSAndroid Build Coastguard Worker void *yyp = raw_; 1489*cda5da8dSAndroid Build Coastguard Worker return *static_cast<semantic_option*> (yyp); 1490*cda5da8dSAndroid Build Coastguard Worker } 1491*cda5da8dSAndroid Build Coastguard Worker const semantic_option& getOption () const 1492*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1493*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 1494*cda5da8dSAndroid Build Coastguard Worker YYDASSERT (!is_state ()); 1495*cda5da8dSAndroid Build Coastguard Worker const void *yyp = raw_; 1496*cda5da8dSAndroid Build Coastguard Worker return *static_cast<const semantic_option*> (yyp); 1497*cda5da8dSAndroid Build Coastguard Worker } 1498*cda5da8dSAndroid Build Coastguard Worker bool is_state () const 1499*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1500*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 1501*cda5da8dSAndroid Build Coastguard Worker return is_state_; 1502*cda5da8dSAndroid Build Coastguard Worker } 1503*cda5da8dSAndroid Build Coastguard Worker 1504*cda5da8dSAndroid Build Coastguard Worker private: 1505*cda5da8dSAndroid Build Coastguard Worker /// The possible contents of raw_. Since they have constructors, they cannot 1506*cda5da8dSAndroid Build Coastguard Worker /// be directly included in the union. 1507*cda5da8dSAndroid Build Coastguard Worker union contents 1508*cda5da8dSAndroid Build Coastguard Worker { 1509*cda5da8dSAndroid Build Coastguard Worker char yystate[sizeof (glr_state)]; 1510*cda5da8dSAndroid Build Coastguard Worker char yyoption[sizeof (semantic_option)]; 1511*cda5da8dSAndroid Build Coastguard Worker }; 1512*cda5da8dSAndroid Build Coastguard Worker enum { union_size = sizeof (contents) }; 1513*cda5da8dSAndroid Build Coastguard Worker union { 1514*cda5da8dSAndroid Build Coastguard Worker /// Strongest alignment constraints. 1515*cda5da8dSAndroid Build Coastguard Worker long double yyalign_me; 1516*cda5da8dSAndroid Build Coastguard Worker /// A buffer large enough to store the contents. 1517*cda5da8dSAndroid Build Coastguard Worker char raw_[union_size]; 1518*cda5da8dSAndroid Build Coastguard Worker }; 1519*cda5da8dSAndroid Build Coastguard Worker /** Type tag for the union. */ 1520*cda5da8dSAndroid Build Coastguard Worker bool is_state_; 1521*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_assert_if([[ 1522*cda5da8dSAndroid Build Coastguard Worker public: 1523*cda5da8dSAndroid Build Coastguard Worker // Check invariants. 1524*cda5da8dSAndroid Build Coastguard Worker void check_ () const 1525*cda5da8dSAndroid Build Coastguard Worker { 1526*cda5da8dSAndroid Build Coastguard Worker YYASSERT (this->magic_ == MAGIC); 1527*cda5da8dSAndroid Build Coastguard Worker YYASSERT (this->is_state_ == false || this->is_state_ == true); 1528*cda5da8dSAndroid Build Coastguard Worker } 1529*cda5da8dSAndroid Build Coastguard Worker // A magic number to check our pointer arithmetic is sane. 1530*cda5da8dSAndroid Build Coastguard Worker enum { MAGIC = 0xDEAD1ACC }; // 3735886540. 1531*cda5da8dSAndroid Build Coastguard Worker const unsigned int magic_;]])[ 1532*cda5da8dSAndroid Build Coastguard Worker }; // class glr_stack_item 1533*cda5da8dSAndroid Build Coastguard Worker } // namespace 1534*cda5da8dSAndroid Build Coastguard Worker 1535*cda5da8dSAndroid Build Coastguard Worker glr_state* glr_state::pred () 1536*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1537*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 1538*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_NULL_DEREFERENCE_BEGIN 1539*cda5da8dSAndroid Build Coastguard Worker return yypred ? &asItem (as_pointer_ (this) - yypred)->getState () : YY_NULLPTR; 1540*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_NULL_DEREFERENCE_END 1541*cda5da8dSAndroid Build Coastguard Worker } 1542*cda5da8dSAndroid Build Coastguard Worker 1543*cda5da8dSAndroid Build Coastguard Worker const glr_state* glr_state::pred () const 1544*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1545*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 1546*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_NULL_DEREFERENCE_BEGIN 1547*cda5da8dSAndroid Build Coastguard Worker return yypred ? &asItem (as_pointer_ (this) - yypred)->getState () : YY_NULLPTR; 1548*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_NULL_DEREFERENCE_END 1549*cda5da8dSAndroid Build Coastguard Worker } 1550*cda5da8dSAndroid Build Coastguard Worker 1551*cda5da8dSAndroid Build Coastguard Worker void glr_state::setPred (const glr_state* state) 1552*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1553*cda5da8dSAndroid Build Coastguard Worker check_ (); 1554*cda5da8dSAndroid Build Coastguard Worker if (state) 1555*cda5da8dSAndroid Build Coastguard Worker state->check_ ();]])[ 1556*cda5da8dSAndroid Build Coastguard Worker yypred = state ? as_pointer_ (this) - as_pointer_ (state) : 0; 1557*cda5da8dSAndroid Build Coastguard Worker } 1558*cda5da8dSAndroid Build Coastguard Worker 1559*cda5da8dSAndroid Build Coastguard Worker semantic_option* glr_state::firstVal () 1560*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1561*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 1562*cda5da8dSAndroid Build Coastguard Worker return yyfirstVal ? &(asItem(this) - yyfirstVal)->getOption() : YY_NULLPTR; 1563*cda5da8dSAndroid Build Coastguard Worker } 1564*cda5da8dSAndroid Build Coastguard Worker 1565*cda5da8dSAndroid Build Coastguard Worker const semantic_option* glr_state::firstVal () const 1566*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1567*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 1568*cda5da8dSAndroid Build Coastguard Worker return yyfirstVal ? &(asItem(this) - yyfirstVal)->getOption() : YY_NULLPTR; 1569*cda5da8dSAndroid Build Coastguard Worker } 1570*cda5da8dSAndroid Build Coastguard Worker 1571*cda5da8dSAndroid Build Coastguard Worker void glr_state::setFirstVal (const semantic_option* option) 1572*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1573*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 1574*cda5da8dSAndroid Build Coastguard Worker yyfirstVal = option ? asItem(this) - asItem(option) : 0; 1575*cda5da8dSAndroid Build Coastguard Worker } 1576*cda5da8dSAndroid Build Coastguard Worker 1577*cda5da8dSAndroid Build Coastguard Worker std::ptrdiff_t glr_state::indexIn (const glr_stack_item* array) const 1578*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1579*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 1580*cda5da8dSAndroid Build Coastguard Worker return asItem(this) - array; 1581*cda5da8dSAndroid Build Coastguard Worker } 1582*cda5da8dSAndroid Build Coastguard Worker 1583*cda5da8dSAndroid Build Coastguard Worker std::ptrdiff_t semantic_option::indexIn (const glr_stack_item* array) const 1584*cda5da8dSAndroid Build Coastguard Worker { 1585*cda5da8dSAndroid Build Coastguard Worker return asItem(this) - array; 1586*cda5da8dSAndroid Build Coastguard Worker } 1587*cda5da8dSAndroid Build Coastguard Worker 1588*cda5da8dSAndroid Build Coastguard Worker glr_state* semantic_option::state () 1589*cda5da8dSAndroid Build Coastguard Worker { 1590*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_NULL_DEREFERENCE_BEGIN 1591*cda5da8dSAndroid Build Coastguard Worker return yystate ? &(asItem(this) - yystate)->getState() : YY_NULLPTR; 1592*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_NULL_DEREFERENCE_END 1593*cda5da8dSAndroid Build Coastguard Worker } 1594*cda5da8dSAndroid Build Coastguard Worker 1595*cda5da8dSAndroid Build Coastguard Worker const glr_state* semantic_option::state () const 1596*cda5da8dSAndroid Build Coastguard Worker { 1597*cda5da8dSAndroid Build Coastguard Worker return yystate ? &(asItem(this) - yystate)->getState() : YY_NULLPTR; 1598*cda5da8dSAndroid Build Coastguard Worker } 1599*cda5da8dSAndroid Build Coastguard Worker 1600*cda5da8dSAndroid Build Coastguard Worker void semantic_option::setState (const glr_state* s) 1601*cda5da8dSAndroid Build Coastguard Worker { 1602*cda5da8dSAndroid Build Coastguard Worker yystate = s ? asItem(this) - asItem(s) : 0; 1603*cda5da8dSAndroid Build Coastguard Worker } 1604*cda5da8dSAndroid Build Coastguard Worker 1605*cda5da8dSAndroid Build Coastguard Worker const semantic_option* semantic_option::next () const 1606*cda5da8dSAndroid Build Coastguard Worker { 1607*cda5da8dSAndroid Build Coastguard Worker return yynext ? &(asItem(this) - yynext)->getOption() : YY_NULLPTR; 1608*cda5da8dSAndroid Build Coastguard Worker } 1609*cda5da8dSAndroid Build Coastguard Worker 1610*cda5da8dSAndroid Build Coastguard Worker semantic_option* semantic_option::next () 1611*cda5da8dSAndroid Build Coastguard Worker { 1612*cda5da8dSAndroid Build Coastguard Worker return yynext ? &(asItem(this) - yynext)->getOption() : YY_NULLPTR; 1613*cda5da8dSAndroid Build Coastguard Worker } 1614*cda5da8dSAndroid Build Coastguard Worker 1615*cda5da8dSAndroid Build Coastguard Worker void semantic_option::setNext (const semantic_option* s) 1616*cda5da8dSAndroid Build Coastguard Worker { 1617*cda5da8dSAndroid Build Coastguard Worker yynext = s ? asItem(this) - asItem(s) : 0; 1618*cda5da8dSAndroid Build Coastguard Worker } 1619*cda5da8dSAndroid Build Coastguard Worker 1620*cda5da8dSAndroid Build Coastguard Worker void glr_state::destroy (char const* yymsg, ]b4_namespace_ref[::]b4_parser_class[& yyparser) 1621*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_assert_if([[ 1622*cda5da8dSAndroid Build Coastguard Worker check_ ();]])[ 1623*cda5da8dSAndroid Build Coastguard Worker if (yyresolved) 1624*cda5da8dSAndroid Build Coastguard Worker yyparser.yy_destroy_ (yymsg, yy_accessing_symbol(yylrState), 1625*cda5da8dSAndroid Build Coastguard Worker value ()]b4_locations_if([, yyloc])[); 1626*cda5da8dSAndroid Build Coastguard Worker else 1627*cda5da8dSAndroid Build Coastguard Worker { 1628*cda5da8dSAndroid Build Coastguard Worker #if ]b4_api_PREFIX[DEBUG 1629*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << yymsg 1630*cda5da8dSAndroid Build Coastguard Worker << (firstVal() ? " unresolved " : " incomplete ") 1631*cda5da8dSAndroid Build Coastguard Worker << (yy_accessing_symbol (yylrState) < YYNTOKENS ? "token" : "nterm") 1632*cda5da8dSAndroid Build Coastguard Worker << ' ' << yyparser.symbol_name (yy_accessing_symbol (yylrState)) 1633*cda5da8dSAndroid Build Coastguard Worker << " ("]b4_locations_if([[ 1634*cda5da8dSAndroid Build Coastguard Worker << yyloc << ": "]])[ 1635*cda5da8dSAndroid Build Coastguard Worker << ")\n"; 1636*cda5da8dSAndroid Build Coastguard Worker #endif 1637*cda5da8dSAndroid Build Coastguard Worker if (firstVal() != YY_NULLPTR) 1638*cda5da8dSAndroid Build Coastguard Worker { 1639*cda5da8dSAndroid Build Coastguard Worker semantic_option& yyoption = *firstVal (); 1640*cda5da8dSAndroid Build Coastguard Worker glr_state *yyrh = yyoption.state (); 1641*cda5da8dSAndroid Build Coastguard Worker for (int yyn = yyrhsLength (yyoption.yyrule); yyn > 0; yyn -= 1) 1642*cda5da8dSAndroid Build Coastguard Worker { 1643*cda5da8dSAndroid Build Coastguard Worker yyrh->destroy (yymsg, yyparser); 1644*cda5da8dSAndroid Build Coastguard Worker yyrh = yyrh->pred(); 1645*cda5da8dSAndroid Build Coastguard Worker } 1646*cda5da8dSAndroid Build Coastguard Worker } 1647*cda5da8dSAndroid Build Coastguard Worker } 1648*cda5da8dSAndroid Build Coastguard Worker } 1649*cda5da8dSAndroid Build Coastguard Worker 1650*cda5da8dSAndroid Build Coastguard Worker 1651*cda5da8dSAndroid Build Coastguard Worker #undef YYFILL 1652*cda5da8dSAndroid Build Coastguard Worker #define YYFILL(N) yyfill (yyvsp, yylow, (N), yynormal) 1653*cda5da8dSAndroid Build Coastguard Worker 1654*cda5da8dSAndroid Build Coastguard Worker namespace 1655*cda5da8dSAndroid Build Coastguard Worker { 1656*cda5da8dSAndroid Build Coastguard Worker class state_stack 1657*cda5da8dSAndroid Build Coastguard Worker { 1658*cda5da8dSAndroid Build Coastguard Worker public: 1659*cda5da8dSAndroid Build Coastguard Worker using parser_type = ]b4_namespace_ref[::]b4_parser_class[; 1660*cda5da8dSAndroid Build Coastguard Worker using symbol_kind = parser_type::symbol_kind; 1661*cda5da8dSAndroid Build Coastguard Worker using value_type = parser_type::value_type;]b4_locations_if([[ 1662*cda5da8dSAndroid Build Coastguard Worker using location_type = parser_type::location_type;]])[ 1663*cda5da8dSAndroid Build Coastguard Worker 1664*cda5da8dSAndroid Build Coastguard Worker /** Initialize to a single empty stack, with total maximum 1665*cda5da8dSAndroid Build Coastguard Worker * capacity for all stacks of YYSIZE. */ 1666*cda5da8dSAndroid Build Coastguard Worker state_stack (size_t yysize) 1667*cda5da8dSAndroid Build Coastguard Worker : yysplitPoint (YY_NULLPTR) 1668*cda5da8dSAndroid Build Coastguard Worker { 1669*cda5da8dSAndroid Build Coastguard Worker yyitems.reserve (yysize); 1670*cda5da8dSAndroid Build Coastguard Worker } 1671*cda5da8dSAndroid Build Coastguard Worker 1672*cda5da8dSAndroid Build Coastguard Worker #if YYSTACKEXPANDABLE 1673*cda5da8dSAndroid Build Coastguard Worker /** Returns false if it tried to expand but could not. */ 1674*cda5da8dSAndroid Build Coastguard Worker bool 1675*cda5da8dSAndroid Build Coastguard Worker yyexpandGLRStackIfNeeded () 1676*cda5da8dSAndroid Build Coastguard Worker { 1677*cda5da8dSAndroid Build Coastguard Worker return YYHEADROOM <= spaceLeft () || yyexpandGLRStack (); 1678*cda5da8dSAndroid Build Coastguard Worker } 1679*cda5da8dSAndroid Build Coastguard Worker 1680*cda5da8dSAndroid Build Coastguard Worker private: 1681*cda5da8dSAndroid Build Coastguard Worker /** If *this is expandable, extend it. WARNING: Pointers into the 1682*cda5da8dSAndroid Build Coastguard Worker stack from outside should be considered invalid after this call. 1683*cda5da8dSAndroid Build Coastguard Worker We always expand when there are 1 or fewer items left AFTER an 1684*cda5da8dSAndroid Build Coastguard Worker allocation, so that we can avoid having external pointers exist 1685*cda5da8dSAndroid Build Coastguard Worker across an allocation. */ 1686*cda5da8dSAndroid Build Coastguard Worker bool 1687*cda5da8dSAndroid Build Coastguard Worker yyexpandGLRStack () 1688*cda5da8dSAndroid Build Coastguard Worker { 1689*cda5da8dSAndroid Build Coastguard Worker const size_t oldsize = yyitems.size(); 1690*cda5da8dSAndroid Build Coastguard Worker if (YYMAXDEPTH - YYHEADROOM < oldsize) 1691*cda5da8dSAndroid Build Coastguard Worker return false; 1692*cda5da8dSAndroid Build Coastguard Worker const size_t yynewSize = YYMAXDEPTH < 2 * oldsize ? YYMAXDEPTH : 2 * oldsize; 1693*cda5da8dSAndroid Build Coastguard Worker const glr_stack_item *oldbase = &yyitems[0]; 1694*cda5da8dSAndroid Build Coastguard Worker 1695*cda5da8dSAndroid Build Coastguard Worker yyitems.reserve (yynewSize); 1696*cda5da8dSAndroid Build Coastguard Worker const glr_stack_item *newbase = &yyitems[0]; 1697*cda5da8dSAndroid Build Coastguard Worker 1698*cda5da8dSAndroid Build Coastguard Worker // Adjust the pointers. Perform raw pointer arithmetic, as there 1699*cda5da8dSAndroid Build Coastguard Worker // is no reason for objects to be aligned on their size. 1700*cda5da8dSAndroid Build Coastguard Worker const ptrdiff_t disp 1701*cda5da8dSAndroid Build Coastguard Worker = reinterpret_cast<const char*> (newbase) - reinterpret_cast<const char*> (oldbase); 1702*cda5da8dSAndroid Build Coastguard Worker if (yysplitPoint) 1703*cda5da8dSAndroid Build Coastguard Worker const_cast<glr_state*&> (yysplitPoint) 1704*cda5da8dSAndroid Build Coastguard Worker = reinterpret_cast<glr_state*> (reinterpret_cast<char*> (const_cast<glr_state*> (yysplitPoint)) + disp); 1705*cda5da8dSAndroid Build Coastguard Worker 1706*cda5da8dSAndroid Build Coastguard Worker for (std::vector<glr_state*>::iterator 1707*cda5da8dSAndroid Build Coastguard Worker i = yytops.begin (), 1708*cda5da8dSAndroid Build Coastguard Worker yyend = yytops.end (); 1709*cda5da8dSAndroid Build Coastguard Worker i != yyend; ++i) 1710*cda5da8dSAndroid Build Coastguard Worker if (glr_state_not_null (*i)) 1711*cda5da8dSAndroid Build Coastguard Worker *i = reinterpret_cast<glr_state*>(reinterpret_cast<char*>(*i) + disp); 1712*cda5da8dSAndroid Build Coastguard Worker 1713*cda5da8dSAndroid Build Coastguard Worker return true; 1714*cda5da8dSAndroid Build Coastguard Worker } 1715*cda5da8dSAndroid Build Coastguard Worker 1716*cda5da8dSAndroid Build Coastguard Worker public: 1717*cda5da8dSAndroid Build Coastguard Worker #else 1718*cda5da8dSAndroid Build Coastguard Worker bool yyexpandGLRStackIfNeeded () 1719*cda5da8dSAndroid Build Coastguard Worker { 1720*cda5da8dSAndroid Build Coastguard Worker return YYHEADROOM <= spaceLeft (); 1721*cda5da8dSAndroid Build Coastguard Worker } 1722*cda5da8dSAndroid Build Coastguard Worker #endif 1723*cda5da8dSAndroid Build Coastguard Worker #undef YYSTACKEXPANDABLE 1724*cda5da8dSAndroid Build Coastguard Worker 1725*cda5da8dSAndroid Build Coastguard Worker static bool glr_state_not_null (glr_state* s) 1726*cda5da8dSAndroid Build Coastguard Worker { 1727*cda5da8dSAndroid Build Coastguard Worker return s != YY_NULLPTR; 1728*cda5da8dSAndroid Build Coastguard Worker } 1729*cda5da8dSAndroid Build Coastguard Worker 1730*cda5da8dSAndroid Build Coastguard Worker bool 1731*cda5da8dSAndroid Build Coastguard Worker reduceToOneStack () 1732*cda5da8dSAndroid Build Coastguard Worker { 1733*cda5da8dSAndroid Build Coastguard Worker using iterator = std::vector<glr_state*>::iterator; 1734*cda5da8dSAndroid Build Coastguard Worker const iterator yybegin = yytops.begin(); 1735*cda5da8dSAndroid Build Coastguard Worker const iterator yyend = yytops.end(); 1736*cda5da8dSAndroid Build Coastguard Worker const iterator yyit = std::find_if(yybegin, yyend, glr_state_not_null); 1737*cda5da8dSAndroid Build Coastguard Worker if (yyit == yyend) 1738*cda5da8dSAndroid Build Coastguard Worker return false; 1739*cda5da8dSAndroid Build Coastguard Worker for (state_set_index yyk = create_state_set_index(yyit + 1 - yybegin); 1740*cda5da8dSAndroid Build Coastguard Worker yyk.uget() != numTops(); ++yyk) 1741*cda5da8dSAndroid Build Coastguard Worker yytops.yymarkStackDeleted (yyk); 1742*cda5da8dSAndroid Build Coastguard Worker yytops.yyremoveDeletes (); 1743*cda5da8dSAndroid Build Coastguard Worker yycompressStack (); 1744*cda5da8dSAndroid Build Coastguard Worker return true; 1745*cda5da8dSAndroid Build Coastguard Worker } 1746*cda5da8dSAndroid Build Coastguard Worker 1747*cda5da8dSAndroid Build Coastguard Worker /** Called when returning to deterministic operation to clean up the extra 1748*cda5da8dSAndroid Build Coastguard Worker * stacks. */ 1749*cda5da8dSAndroid Build Coastguard Worker void 1750*cda5da8dSAndroid Build Coastguard Worker yycompressStack () 1751*cda5da8dSAndroid Build Coastguard Worker { 1752*cda5da8dSAndroid Build Coastguard Worker if (yytops.size() != 1 || !isSplit()) 1753*cda5da8dSAndroid Build Coastguard Worker return; 1754*cda5da8dSAndroid Build Coastguard Worker 1755*cda5da8dSAndroid Build Coastguard Worker // yyr is the state after the split point. 1756*cda5da8dSAndroid Build Coastguard Worker glr_state* yyr = YY_NULLPTR; 1757*cda5da8dSAndroid Build Coastguard Worker for (glr_state *yyp = firstTop(), *yyq = yyp->pred(); 1758*cda5da8dSAndroid Build Coastguard Worker yyp != yysplitPoint; 1759*cda5da8dSAndroid Build Coastguard Worker yyr = yyp, yyp = yyq, yyq = yyp->pred()) 1760*cda5da8dSAndroid Build Coastguard Worker yyp->setPred(yyr); 1761*cda5da8dSAndroid Build Coastguard Worker 1762*cda5da8dSAndroid Build Coastguard Worker // This const_cast is okay, since anyway we have access to the mutable 1763*cda5da8dSAndroid Build Coastguard Worker // yyitems into which yysplitPoint points. 1764*cda5da8dSAndroid Build Coastguard Worker glr_stack_item* nextFreeItem 1765*cda5da8dSAndroid Build Coastguard Worker = const_cast<glr_state*> (yysplitPoint)->asItem () + 1; 1766*cda5da8dSAndroid Build Coastguard Worker yysplitPoint = YY_NULLPTR; 1767*cda5da8dSAndroid Build Coastguard Worker yytops.clearLastDeleted (); 1768*cda5da8dSAndroid Build Coastguard Worker 1769*cda5da8dSAndroid Build Coastguard Worker while (yyr != YY_NULLPTR) 1770*cda5da8dSAndroid Build Coastguard Worker { 1771*cda5da8dSAndroid Build Coastguard Worker nextFreeItem->setState (*yyr); 1772*cda5da8dSAndroid Build Coastguard Worker glr_state& nextFreeState = nextFreeItem->getState(); 1773*cda5da8dSAndroid Build Coastguard Worker yyr = yyr->pred(); 1774*cda5da8dSAndroid Build Coastguard Worker nextFreeState.setPred(&(nextFreeItem - 1)->getState()); 1775*cda5da8dSAndroid Build Coastguard Worker setFirstTop (&nextFreeState); 1776*cda5da8dSAndroid Build Coastguard Worker ++nextFreeItem; 1777*cda5da8dSAndroid Build Coastguard Worker } 1778*cda5da8dSAndroid Build Coastguard Worker yyitems.resize(static_cast<size_t>(nextFreeItem - yyitems.data())); 1779*cda5da8dSAndroid Build Coastguard Worker } 1780*cda5da8dSAndroid Build Coastguard Worker 1781*cda5da8dSAndroid Build Coastguard Worker bool isSplit() const { 1782*cda5da8dSAndroid Build Coastguard Worker return yysplitPoint != YY_NULLPTR; 1783*cda5da8dSAndroid Build Coastguard Worker } 1784*cda5da8dSAndroid Build Coastguard Worker 1785*cda5da8dSAndroid Build Coastguard Worker // Present the interface of a vector of glr_stack_item. 1786*cda5da8dSAndroid Build Coastguard Worker std::vector<glr_stack_item>::const_iterator begin () const 1787*cda5da8dSAndroid Build Coastguard Worker { 1788*cda5da8dSAndroid Build Coastguard Worker return yyitems.begin (); 1789*cda5da8dSAndroid Build Coastguard Worker } 1790*cda5da8dSAndroid Build Coastguard Worker 1791*cda5da8dSAndroid Build Coastguard Worker std::vector<glr_stack_item>::const_iterator end () const 1792*cda5da8dSAndroid Build Coastguard Worker { 1793*cda5da8dSAndroid Build Coastguard Worker return yyitems.end (); 1794*cda5da8dSAndroid Build Coastguard Worker } 1795*cda5da8dSAndroid Build Coastguard Worker 1796*cda5da8dSAndroid Build Coastguard Worker size_t size() const 1797*cda5da8dSAndroid Build Coastguard Worker { 1798*cda5da8dSAndroid Build Coastguard Worker return yyitems.size (); 1799*cda5da8dSAndroid Build Coastguard Worker } 1800*cda5da8dSAndroid Build Coastguard Worker 1801*cda5da8dSAndroid Build Coastguard Worker glr_stack_item& operator[] (size_t i) 1802*cda5da8dSAndroid Build Coastguard Worker { 1803*cda5da8dSAndroid Build Coastguard Worker return yyitems[i]; 1804*cda5da8dSAndroid Build Coastguard Worker } 1805*cda5da8dSAndroid Build Coastguard Worker 1806*cda5da8dSAndroid Build Coastguard Worker glr_stack_item& stackItemAt (size_t index) 1807*cda5da8dSAndroid Build Coastguard Worker { 1808*cda5da8dSAndroid Build Coastguard Worker return yyitems[index]; 1809*cda5da8dSAndroid Build Coastguard Worker } 1810*cda5da8dSAndroid Build Coastguard Worker 1811*cda5da8dSAndroid Build Coastguard Worker size_t numTops () const 1812*cda5da8dSAndroid Build Coastguard Worker { 1813*cda5da8dSAndroid Build Coastguard Worker return yytops.size (); 1814*cda5da8dSAndroid Build Coastguard Worker } 1815*cda5da8dSAndroid Build Coastguard Worker 1816*cda5da8dSAndroid Build Coastguard Worker glr_state* firstTop () const 1817*cda5da8dSAndroid Build Coastguard Worker { 1818*cda5da8dSAndroid Build Coastguard Worker return yytops[create_state_set_index (0)]; 1819*cda5da8dSAndroid Build Coastguard Worker } 1820*cda5da8dSAndroid Build Coastguard Worker 1821*cda5da8dSAndroid Build Coastguard Worker glr_state* topAt (state_set_index i) const 1822*cda5da8dSAndroid Build Coastguard Worker { 1823*cda5da8dSAndroid Build Coastguard Worker return yytops[i]; 1824*cda5da8dSAndroid Build Coastguard Worker } 1825*cda5da8dSAndroid Build Coastguard Worker 1826*cda5da8dSAndroid Build Coastguard Worker void setFirstTop (glr_state* value) 1827*cda5da8dSAndroid Build Coastguard Worker { 1828*cda5da8dSAndroid Build Coastguard Worker yytops[create_state_set_index (0)] = value; 1829*cda5da8dSAndroid Build Coastguard Worker } 1830*cda5da8dSAndroid Build Coastguard Worker 1831*cda5da8dSAndroid Build Coastguard Worker void setTopAt (state_set_index i, glr_state* value) 1832*cda5da8dSAndroid Build Coastguard Worker { 1833*cda5da8dSAndroid Build Coastguard Worker yytops[i] = value; 1834*cda5da8dSAndroid Build Coastguard Worker } 1835*cda5da8dSAndroid Build Coastguard Worker 1836*cda5da8dSAndroid Build Coastguard Worker void pop_back () 1837*cda5da8dSAndroid Build Coastguard Worker { 1838*cda5da8dSAndroid Build Coastguard Worker yyitems.pop_back (); 1839*cda5da8dSAndroid Build Coastguard Worker } 1840*cda5da8dSAndroid Build Coastguard Worker 1841*cda5da8dSAndroid Build Coastguard Worker void pop_back (size_t n) 1842*cda5da8dSAndroid Build Coastguard Worker { 1843*cda5da8dSAndroid Build Coastguard Worker yyitems.resize (yyitems.size () - n); 1844*cda5da8dSAndroid Build Coastguard Worker } 1845*cda5da8dSAndroid Build Coastguard Worker 1846*cda5da8dSAndroid Build Coastguard Worker state_set_index 1847*cda5da8dSAndroid Build Coastguard Worker yysplitStack (state_set_index yyk) 1848*cda5da8dSAndroid Build Coastguard Worker { 1849*cda5da8dSAndroid Build Coastguard Worker if (!isSplit ()) 1850*cda5da8dSAndroid Build Coastguard Worker { 1851*cda5da8dSAndroid Build Coastguard Worker YYASSERT (yyk.get () == 0); 1852*cda5da8dSAndroid Build Coastguard Worker yysplitPoint = topAt (yyk); 1853*cda5da8dSAndroid Build Coastguard Worker } 1854*cda5da8dSAndroid Build Coastguard Worker return yytops.yysplitStack (yyk); 1855*cda5da8dSAndroid Build Coastguard Worker } 1856*cda5da8dSAndroid Build Coastguard Worker 1857*cda5da8dSAndroid Build Coastguard Worker /** Assuming that YYS is a GLRState somewhere on *this, update the 1858*cda5da8dSAndroid Build Coastguard Worker * splitpoint of *this, if needed, so that it is at least as deep as 1859*cda5da8dSAndroid Build Coastguard Worker * YYS. */ 1860*cda5da8dSAndroid Build Coastguard Worker void 1861*cda5da8dSAndroid Build Coastguard Worker yyupdateSplit (glr_state& yys) 1862*cda5da8dSAndroid Build Coastguard Worker { 1863*cda5da8dSAndroid Build Coastguard Worker if (isSplit() && &yys < yysplitPoint) 1864*cda5da8dSAndroid Build Coastguard Worker yysplitPoint = &yys; 1865*cda5da8dSAndroid Build Coastguard Worker } 1866*cda5da8dSAndroid Build Coastguard Worker 1867*cda5da8dSAndroid Build Coastguard Worker /** Return a fresh GLRState. 1868*cda5da8dSAndroid Build Coastguard Worker * Callers should call yyreserveStack afterwards to make sure there is 1869*cda5da8dSAndroid Build Coastguard Worker * sufficient headroom. */ 1870*cda5da8dSAndroid Build Coastguard Worker glr_state& yynewGLRState (const glr_state& newState) 1871*cda5da8dSAndroid Build Coastguard Worker { 1872*cda5da8dSAndroid Build Coastguard Worker glr_state& state = yyitems[yynewGLRStackItem (true)].getState (); 1873*cda5da8dSAndroid Build Coastguard Worker #if false && 201103L <= YY_CPLUSPLUS 1874*cda5da8dSAndroid Build Coastguard Worker state = std::move (newState); 1875*cda5da8dSAndroid Build Coastguard Worker #else 1876*cda5da8dSAndroid Build Coastguard Worker state = newState; 1877*cda5da8dSAndroid Build Coastguard Worker #endif 1878*cda5da8dSAndroid Build Coastguard Worker return state; 1879*cda5da8dSAndroid Build Coastguard Worker } 1880*cda5da8dSAndroid Build Coastguard Worker 1881*cda5da8dSAndroid Build Coastguard Worker /** Return a fresh SemanticOption. 1882*cda5da8dSAndroid Build Coastguard Worker * Callers should call yyreserveStack afterwards to make sure there is 1883*cda5da8dSAndroid Build Coastguard Worker * sufficient headroom. */ 1884*cda5da8dSAndroid Build Coastguard Worker semantic_option& yynewSemanticOption (semantic_option newOption) 1885*cda5da8dSAndroid Build Coastguard Worker { 1886*cda5da8dSAndroid Build Coastguard Worker semantic_option& option = yyitems[yynewGLRStackItem (false)].getOption (); 1887*cda5da8dSAndroid Build Coastguard Worker option = std::move (newOption); 1888*cda5da8dSAndroid Build Coastguard Worker return option; 1889*cda5da8dSAndroid Build Coastguard Worker } 1890*cda5da8dSAndroid Build Coastguard Worker 1891*cda5da8dSAndroid Build Coastguard Worker /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in 1892*cda5da8dSAndroid Build Coastguard Worker * YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. 1893*cda5da8dSAndroid Build Coastguard Worker * For convenience, always return YYLOW1. */ 1894*cda5da8dSAndroid Build Coastguard Worker int 1895*cda5da8dSAndroid Build Coastguard Worker yyfill (glr_stack_item *yyvsp, int &yylow, int yylow1, bool yynormal) 1896*cda5da8dSAndroid Build Coastguard Worker { 1897*cda5da8dSAndroid Build Coastguard Worker if (!yynormal && yylow1 < yylow) 1898*cda5da8dSAndroid Build Coastguard Worker { 1899*cda5da8dSAndroid Build Coastguard Worker yyfillin (yyvsp, yylow, yylow1); 1900*cda5da8dSAndroid Build Coastguard Worker yylow = yylow1; 1901*cda5da8dSAndroid Build Coastguard Worker } 1902*cda5da8dSAndroid Build Coastguard Worker return yylow1; 1903*cda5da8dSAndroid Build Coastguard Worker } 1904*cda5da8dSAndroid Build Coastguard Worker 1905*cda5da8dSAndroid Build Coastguard Worker /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting 1906*cda5da8dSAndroid Build Coastguard Worker * at YYVSP[YYLOW0].getState().pred(). Leaves YYVSP[YYLOW1].getState().pred() 1907*cda5da8dSAndroid Build Coastguard Worker * containing the pointer to the next state in the chain. */ 1908*cda5da8dSAndroid Build Coastguard Worker void 1909*cda5da8dSAndroid Build Coastguard Worker yyfillin (glr_stack_item *yyvsp, int yylow0, int yylow1) 1910*cda5da8dSAndroid Build Coastguard Worker { 1911*cda5da8dSAndroid Build Coastguard Worker glr_state* s = yyvsp[yylow0].getState().pred(); 1912*cda5da8dSAndroid Build Coastguard Worker YYASSERT(s != YY_NULLPTR); 1913*cda5da8dSAndroid Build Coastguard Worker for (int i = yylow0-1; i >= yylow1; i -= 1, s = s->pred()) 1914*cda5da8dSAndroid Build Coastguard Worker { 1915*cda5da8dSAndroid Build Coastguard Worker glr_state& yys = yyvsp[i].getState(); 1916*cda5da8dSAndroid Build Coastguard Worker #if ]b4_api_PREFIX[DEBUG 1917*cda5da8dSAndroid Build Coastguard Worker yys.yylrState = s->yylrState; 1918*cda5da8dSAndroid Build Coastguard Worker #endif 1919*cda5da8dSAndroid Build Coastguard Worker yys.yyresolved = s->yyresolved; 1920*cda5da8dSAndroid Build Coastguard Worker if (s->yyresolved) 1921*cda5da8dSAndroid Build Coastguard Worker {]b4_variant_if([[ 1922*cda5da8dSAndroid Build Coastguard Worker new (&yys.value ()) value_type (); 1923*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_variant([yy_accessing_symbol (s->yylrState)], 1924*cda5da8dSAndroid Build Coastguard Worker [yys.value ()], [copy], [s->value ()])], [[ 1925*cda5da8dSAndroid Build Coastguard Worker new (&yys.value ()) value_type (s->value ());]])[ 1926*cda5da8dSAndroid Build Coastguard Worker } 1927*cda5da8dSAndroid Build Coastguard Worker else 1928*cda5da8dSAndroid Build Coastguard Worker /* The effect of using yyval or yyloc (in an immediate 1929*cda5da8dSAndroid Build Coastguard Worker * rule) is undefined. */ 1930*cda5da8dSAndroid Build Coastguard Worker yys.setFirstVal (YY_NULLPTR);]b4_locations_if([[ 1931*cda5da8dSAndroid Build Coastguard Worker yys.yyloc = s->yyloc;]])[ 1932*cda5da8dSAndroid Build Coastguard Worker yys.setPred(s->pred()); 1933*cda5da8dSAndroid Build Coastguard Worker } 1934*cda5da8dSAndroid Build Coastguard Worker } 1935*cda5da8dSAndroid Build Coastguard Worker 1936*cda5da8dSAndroid Build Coastguard Worker #if ]b4_api_PREFIX[DEBUG 1937*cda5da8dSAndroid Build Coastguard Worker 1938*cda5da8dSAndroid Build Coastguard Worker /*----------------------------------------------------------------------. 1939*cda5da8dSAndroid Build Coastguard Worker | Report that stack #YYK of *YYSTACKP is going to be reduced by YYRULE. | 1940*cda5da8dSAndroid Build Coastguard Worker `----------------------------------------------------------------------*/ 1941*cda5da8dSAndroid Build Coastguard Worker 1942*cda5da8dSAndroid Build Coastguard Worker void 1943*cda5da8dSAndroid Build Coastguard Worker yy_reduce_print (bool yynormal, glr_stack_item* yyvsp, state_set_index yyk, 1944*cda5da8dSAndroid Build Coastguard Worker rule_num yyrule, parser_type& yyparser) 1945*cda5da8dSAndroid Build Coastguard Worker { 1946*cda5da8dSAndroid Build Coastguard Worker int yynrhs = yyrhsLength (yyrule);]b4_locations_if([ 1947*cda5da8dSAndroid Build Coastguard Worker int yylow = 1;])[ 1948*cda5da8dSAndroid Build Coastguard Worker int yyi; 1949*cda5da8dSAndroid Build Coastguard Worker std::cerr << "Reducing stack " << yyk.get() << " by rule " << yyrule - 1 1950*cda5da8dSAndroid Build Coastguard Worker << " (line " << int (yyrline[yyrule]) << "):\n"; 1951*cda5da8dSAndroid Build Coastguard Worker if (! yynormal) 1952*cda5da8dSAndroid Build Coastguard Worker yyfillin (yyvsp, 1, -yynrhs); 1953*cda5da8dSAndroid Build Coastguard Worker /* The symbols being reduced. */ 1954*cda5da8dSAndroid Build Coastguard Worker for (yyi = 0; yyi < yynrhs; yyi++) 1955*cda5da8dSAndroid Build Coastguard Worker { 1956*cda5da8dSAndroid Build Coastguard Worker std::cerr << " $" << yyi + 1 << " = "; 1957*cda5da8dSAndroid Build Coastguard Worker yyparser.yy_symbol_print_ 1958*cda5da8dSAndroid Build Coastguard Worker (yy_accessing_symbol (yyvsp[yyi - yynrhs + 1].getState().yylrState), 1959*cda5da8dSAndroid Build Coastguard Worker yyvsp[yyi - yynrhs + 1].getState().value ()]b4_locations_if([[, 1960*cda5da8dSAndroid Build Coastguard Worker ]b4_rhs_location(yynrhs, yyi + 1)])[); 1961*cda5da8dSAndroid Build Coastguard Worker if (!yyvsp[yyi - yynrhs + 1].getState().yyresolved) 1962*cda5da8dSAndroid Build Coastguard Worker std::cerr << " (unresolved)"; 1963*cda5da8dSAndroid Build Coastguard Worker std::cerr << '\n'; 1964*cda5da8dSAndroid Build Coastguard Worker } 1965*cda5da8dSAndroid Build Coastguard Worker } 1966*cda5da8dSAndroid Build Coastguard Worker 1967*cda5da8dSAndroid Build Coastguard Worker 1968*cda5da8dSAndroid Build Coastguard Worker #define YYINDEX(YYX) \ 1969*cda5da8dSAndroid Build Coastguard Worker ((YYX) == YY_NULLPTR ? -1 : (YYX)->indexIn (yyitems.data ())) 1970*cda5da8dSAndroid Build Coastguard Worker 1971*cda5da8dSAndroid Build Coastguard Worker void 1972*cda5da8dSAndroid Build Coastguard Worker dumpStack () const 1973*cda5da8dSAndroid Build Coastguard Worker { 1974*cda5da8dSAndroid Build Coastguard Worker for (size_t yyi = 0; yyi < size(); ++yyi) 1975*cda5da8dSAndroid Build Coastguard Worker { 1976*cda5da8dSAndroid Build Coastguard Worker const glr_stack_item& item = yyitems[yyi]; 1977*cda5da8dSAndroid Build Coastguard Worker std::cerr << std::setw(3) << yyi << ". "; 1978*cda5da8dSAndroid Build Coastguard Worker if (item.is_state()) 1979*cda5da8dSAndroid Build Coastguard Worker { 1980*cda5da8dSAndroid Build Coastguard Worker std::cerr << "Res: " << item.getState().yyresolved 1981*cda5da8dSAndroid Build Coastguard Worker << ", LR State: " << item.getState().yylrState 1982*cda5da8dSAndroid Build Coastguard Worker << ", posn: " << item.getState().yyposn 1983*cda5da8dSAndroid Build Coastguard Worker << ", pred: " << YYINDEX(item.getState().pred()); 1984*cda5da8dSAndroid Build Coastguard Worker if (! item.getState().yyresolved) 1985*cda5da8dSAndroid Build Coastguard Worker std::cerr << ", firstVal: " 1986*cda5da8dSAndroid Build Coastguard Worker << YYINDEX(item.getState().firstVal()); 1987*cda5da8dSAndroid Build Coastguard Worker } 1988*cda5da8dSAndroid Build Coastguard Worker else 1989*cda5da8dSAndroid Build Coastguard Worker { 1990*cda5da8dSAndroid Build Coastguard Worker std::cerr << "Option. rule: " << item.getOption().yyrule - 1 1991*cda5da8dSAndroid Build Coastguard Worker << ", state: " << YYINDEX(item.getOption().state()) 1992*cda5da8dSAndroid Build Coastguard Worker << ", next: " << YYINDEX(item.getOption().next()); 1993*cda5da8dSAndroid Build Coastguard Worker } 1994*cda5da8dSAndroid Build Coastguard Worker std::cerr << '\n'; 1995*cda5da8dSAndroid Build Coastguard Worker } 1996*cda5da8dSAndroid Build Coastguard Worker std::cerr << "Tops:"; 1997*cda5da8dSAndroid Build Coastguard Worker for (state_set_index yyi = create_state_set_index(0); yyi.uget() < numTops(); ++yyi) { 1998*cda5da8dSAndroid Build Coastguard Worker std::cerr << yyi.get() << ": " << YYINDEX(topAt(yyi)) << "; "; 1999*cda5da8dSAndroid Build Coastguard Worker } 2000*cda5da8dSAndroid Build Coastguard Worker std::cerr << '\n'; 2001*cda5da8dSAndroid Build Coastguard Worker } 2002*cda5da8dSAndroid Build Coastguard Worker 2003*cda5da8dSAndroid Build Coastguard Worker #undef YYINDEX 2004*cda5da8dSAndroid Build Coastguard Worker #endif 2005*cda5da8dSAndroid Build Coastguard Worker 2006*cda5da8dSAndroid Build Coastguard Worker YYRESULTTAG 2007*cda5da8dSAndroid Build Coastguard Worker yyreportAmbiguity (const semantic_option& yyx0, 2008*cda5da8dSAndroid Build Coastguard Worker const semantic_option& yyx1, parser_type& yyparser]b4_locations_if([, const location_type& yyloc])[) 2009*cda5da8dSAndroid Build Coastguard Worker { 2010*cda5da8dSAndroid Build Coastguard Worker YY_USE (yyx0); 2011*cda5da8dSAndroid Build Coastguard Worker YY_USE (yyx1); 2012*cda5da8dSAndroid Build Coastguard Worker 2013*cda5da8dSAndroid Build Coastguard Worker #if ]b4_api_PREFIX[DEBUG 2014*cda5da8dSAndroid Build Coastguard Worker std::cerr << "Ambiguity detected.\n" 2015*cda5da8dSAndroid Build Coastguard Worker "Option 1,\n"; 2016*cda5da8dSAndroid Build Coastguard Worker yyx0.yyreportTree (); 2017*cda5da8dSAndroid Build Coastguard Worker std::cerr << "\nOption 2,\n"; 2018*cda5da8dSAndroid Build Coastguard Worker yyx1.yyreportTree (); 2019*cda5da8dSAndroid Build Coastguard Worker std::cerr << '\n'; 2020*cda5da8dSAndroid Build Coastguard Worker #endif 2021*cda5da8dSAndroid Build Coastguard Worker 2022*cda5da8dSAndroid Build Coastguard Worker yyparser.error (]b4_locations_if([yyloc, ])[YY_("syntax is ambiguous")); 2023*cda5da8dSAndroid Build Coastguard Worker return yyabort; 2024*cda5da8dSAndroid Build Coastguard Worker } 2025*cda5da8dSAndroid Build Coastguard Worker 2026*cda5da8dSAndroid Build Coastguard Worker #if ]b4_api_PREFIX[DEBUG 2027*cda5da8dSAndroid Build Coastguard Worker /* Print YYS (possibly NULL) and its predecessors. */ 2028*cda5da8dSAndroid Build Coastguard Worker void 2029*cda5da8dSAndroid Build Coastguard Worker yypstates (const glr_state* yys) const 2030*cda5da8dSAndroid Build Coastguard Worker { 2031*cda5da8dSAndroid Build Coastguard Worker if (yys != YY_NULLPTR) 2032*cda5da8dSAndroid Build Coastguard Worker yys->yy_yypstack(); 2033*cda5da8dSAndroid Build Coastguard Worker else 2034*cda5da8dSAndroid Build Coastguard Worker std::cerr << "<null>"; 2035*cda5da8dSAndroid Build Coastguard Worker std::cerr << '\n'; 2036*cda5da8dSAndroid Build Coastguard Worker } 2037*cda5da8dSAndroid Build Coastguard Worker #endif 2038*cda5da8dSAndroid Build Coastguard Worker 2039*cda5da8dSAndroid Build Coastguard Worker private: 2040*cda5da8dSAndroid Build Coastguard Worker size_t spaceLeft() const 2041*cda5da8dSAndroid Build Coastguard Worker { 2042*cda5da8dSAndroid Build Coastguard Worker return yyitems.capacity() - yyitems.size(); 2043*cda5da8dSAndroid Build Coastguard Worker } 2044*cda5da8dSAndroid Build Coastguard Worker 2045*cda5da8dSAndroid Build Coastguard Worker /** Return a fresh GLRStackItem in this. The item is an LR state 2046*cda5da8dSAndroid Build Coastguard Worker * if YYIS_STATE, and otherwise a semantic option. Callers should call 2047*cda5da8dSAndroid Build Coastguard Worker * yyreserveStack afterwards to make sure there is sufficient 2048*cda5da8dSAndroid Build Coastguard Worker * headroom. */ 2049*cda5da8dSAndroid Build Coastguard Worker size_t 2050*cda5da8dSAndroid Build Coastguard Worker yynewGLRStackItem (bool yyis_state) 2051*cda5da8dSAndroid Build Coastguard Worker { 2052*cda5da8dSAndroid Build Coastguard Worker YYDASSERT(yyitems.size() < yyitems.capacity()); 2053*cda5da8dSAndroid Build Coastguard Worker yyitems.push_back(glr_stack_item(yyis_state)); 2054*cda5da8dSAndroid Build Coastguard Worker return yyitems.size() - 1; 2055*cda5da8dSAndroid Build Coastguard Worker } 2056*cda5da8dSAndroid Build Coastguard Worker 2057*cda5da8dSAndroid Build Coastguard Worker 2058*cda5da8dSAndroid Build Coastguard Worker public: 2059*cda5da8dSAndroid Build Coastguard Worker std::vector<glr_stack_item> yyitems; 2060*cda5da8dSAndroid Build Coastguard Worker // Where the stack splits. Anything below this address is deterministic. 2061*cda5da8dSAndroid Build Coastguard Worker const glr_state* yysplitPoint; 2062*cda5da8dSAndroid Build Coastguard Worker glr_state_set yytops; 2063*cda5da8dSAndroid Build Coastguard Worker }; // class state_stack 2064*cda5da8dSAndroid Build Coastguard Worker } // namespace 2065*cda5da8dSAndroid Build Coastguard Worker 2066*cda5da8dSAndroid Build Coastguard Worker #undef YYFILL 2067*cda5da8dSAndroid Build Coastguard Worker #define YYFILL(N) yystateStack.yyfill (yyvsp, yylow, (N), yynormal) 2068*cda5da8dSAndroid Build Coastguard Worker 2069*cda5da8dSAndroid Build Coastguard Worker namespace ]b4_namespace_ref[ 2070*cda5da8dSAndroid Build Coastguard Worker { 2071*cda5da8dSAndroid Build Coastguard Worker class ]b4_parser_class[::glr_stack 2072*cda5da8dSAndroid Build Coastguard Worker { 2073*cda5da8dSAndroid Build Coastguard Worker public: 2074*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ 2075*cda5da8dSAndroid Build Coastguard Worker // Needs access to yypact_value_is_default, etc. 2076*cda5da8dSAndroid Build Coastguard Worker friend context; 2077*cda5da8dSAndroid Build Coastguard Worker ]])[ 2078*cda5da8dSAndroid Build Coastguard Worker 2079*cda5da8dSAndroid Build Coastguard Worker glr_stack (size_t yysize, parser_type& yyparser_yyarg]m4_ifset([b4_parse_param], [, b4_parse_param_decl])[) 2080*cda5da8dSAndroid Build Coastguard Worker : yyerrState (0) 2081*cda5da8dSAndroid Build Coastguard Worker , yystateStack (yysize) 2082*cda5da8dSAndroid Build Coastguard Worker , yyerrcnt (0) 2083*cda5da8dSAndroid Build Coastguard Worker , yyla () 2084*cda5da8dSAndroid Build Coastguard Worker , yyparser (yyparser_yyarg)]m4_ifset([b4_parse_param], [,b4_parse_param_cons])[ 2085*cda5da8dSAndroid Build Coastguard Worker {} 2086*cda5da8dSAndroid Build Coastguard Worker 2087*cda5da8dSAndroid Build Coastguard Worker ~glr_stack () 2088*cda5da8dSAndroid Build Coastguard Worker { 2089*cda5da8dSAndroid Build Coastguard Worker if (!this->yyla.empty ()) 2090*cda5da8dSAndroid Build Coastguard Worker yyparser.yy_destroy_ ("Cleanup: discarding lookahead", 2091*cda5da8dSAndroid Build Coastguard Worker this->yyla.kind (), this->yyla.value]b4_locations_if([, this->yyla.location])[); 2092*cda5da8dSAndroid Build Coastguard Worker popall_ (); 2093*cda5da8dSAndroid Build Coastguard Worker } 2094*cda5da8dSAndroid Build Coastguard Worker 2095*cda5da8dSAndroid Build Coastguard Worker int yyerrState; 2096*cda5da8dSAndroid Build Coastguard Worker ]b4_locations_if([[ /* To compute the location of the error token. */ 2097*cda5da8dSAndroid Build Coastguard Worker glr_stack_item yyerror_range[3];]])[ 2098*cda5da8dSAndroid Build Coastguard Worker state_stack yystateStack; 2099*cda5da8dSAndroid Build Coastguard Worker int yyerrcnt; 2100*cda5da8dSAndroid Build Coastguard Worker symbol_type yyla; 2101*cda5da8dSAndroid Build Coastguard Worker YYJMP_BUF yyexception_buffer; 2102*cda5da8dSAndroid Build Coastguard Worker parser_type& yyparser; 2103*cda5da8dSAndroid Build Coastguard Worker 2104*cda5da8dSAndroid Build Coastguard Worker #define YYCHK1(YYE) \ 2105*cda5da8dSAndroid Build Coastguard Worker do { \ 2106*cda5da8dSAndroid Build Coastguard Worker switch (YYE) { \ 2107*cda5da8dSAndroid Build Coastguard Worker case yyok: \ 2108*cda5da8dSAndroid Build Coastguard Worker break; \ 2109*cda5da8dSAndroid Build Coastguard Worker case yyabort: \ 2110*cda5da8dSAndroid Build Coastguard Worker goto yyabortlab; \ 2111*cda5da8dSAndroid Build Coastguard Worker case yyaccept: \ 2112*cda5da8dSAndroid Build Coastguard Worker goto yyacceptlab; \ 2113*cda5da8dSAndroid Build Coastguard Worker case yyerr: \ 2114*cda5da8dSAndroid Build Coastguard Worker goto yyuser_error; \ 2115*cda5da8dSAndroid Build Coastguard Worker default: \ 2116*cda5da8dSAndroid Build Coastguard Worker goto yybuglab; \ 2117*cda5da8dSAndroid Build Coastguard Worker } \ 2118*cda5da8dSAndroid Build Coastguard Worker } while (false) 2119*cda5da8dSAndroid Build Coastguard Worker 2120*cda5da8dSAndroid Build Coastguard Worker int 2121*cda5da8dSAndroid Build Coastguard Worker parse () 2122*cda5da8dSAndroid Build Coastguard Worker { 2123*cda5da8dSAndroid Build Coastguard Worker int yyresult; 2124*cda5da8dSAndroid Build Coastguard Worker size_t yyposn; 2125*cda5da8dSAndroid Build Coastguard Worker 2126*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Starting parse\n"; 2127*cda5da8dSAndroid Build Coastguard Worker 2128*cda5da8dSAndroid Build Coastguard Worker this->yyla.clear (); 2129*cda5da8dSAndroid Build Coastguard Worker ]m4_ifdef([b4_initial_action], [ 2130*cda5da8dSAndroid Build Coastguard Worker b4_dollar_pushdef([yyla.value], [], [], [yyla.location])dnl 2131*cda5da8dSAndroid Build Coastguard Worker b4_user_initial_action 2132*cda5da8dSAndroid Build Coastguard Worker b4_dollar_popdef])[]dnl 2133*cda5da8dSAndroid Build Coastguard Worker [ 2134*cda5da8dSAndroid Build Coastguard Worker switch (YYSETJMP (this->yyexception_buffer)) 2135*cda5da8dSAndroid Build Coastguard Worker { 2136*cda5da8dSAndroid Build Coastguard Worker case 0: break; 2137*cda5da8dSAndroid Build Coastguard Worker case 1: goto yyabortlab; 2138*cda5da8dSAndroid Build Coastguard Worker case 2: goto yyexhaustedlab; 2139*cda5da8dSAndroid Build Coastguard Worker default: goto yybuglab; 2140*cda5da8dSAndroid Build Coastguard Worker } 2141*cda5da8dSAndroid Build Coastguard Worker this->yyglrShift (create_state_set_index(0), 0, 0, this->yyla.value]b4_locations_if([, this->yyla.location])[); 2142*cda5da8dSAndroid Build Coastguard Worker yyposn = 0; 2143*cda5da8dSAndroid Build Coastguard Worker 2144*cda5da8dSAndroid Build Coastguard Worker while (true) 2145*cda5da8dSAndroid Build Coastguard Worker { 2146*cda5da8dSAndroid Build Coastguard Worker /* For efficiency, we have two loops, the first of which is 2147*cda5da8dSAndroid Build Coastguard Worker specialized to deterministic operation (single stack, no 2148*cda5da8dSAndroid Build Coastguard Worker potential ambiguity). */ 2149*cda5da8dSAndroid Build Coastguard Worker /* Standard mode */ 2150*cda5da8dSAndroid Build Coastguard Worker while (true) 2151*cda5da8dSAndroid Build Coastguard Worker { 2152*cda5da8dSAndroid Build Coastguard Worker const state_num yystate = this->firstTopState()->yylrState; 2153*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Entering state " << yystate << '\n'; 2154*cda5da8dSAndroid Build Coastguard Worker if (yystate == YYFINAL) 2155*cda5da8dSAndroid Build Coastguard Worker goto yyacceptlab; 2156*cda5da8dSAndroid Build Coastguard Worker if (yy_is_defaulted_state (yystate)) 2157*cda5da8dSAndroid Build Coastguard Worker { 2158*cda5da8dSAndroid Build Coastguard Worker const rule_num yyrule = yy_default_action (yystate); 2159*cda5da8dSAndroid Build Coastguard Worker if (yyrule == 0) 2160*cda5da8dSAndroid Build Coastguard Worker {]b4_locations_if([[ 2161*cda5da8dSAndroid Build Coastguard Worker this->yyerror_range[1].getState().yyloc = this->yyla.location;]])[ 2162*cda5da8dSAndroid Build Coastguard Worker this->yyreportSyntaxError (); 2163*cda5da8dSAndroid Build Coastguard Worker goto yyuser_error; 2164*cda5da8dSAndroid Build Coastguard Worker } 2165*cda5da8dSAndroid Build Coastguard Worker YYCHK1 (this->yyglrReduce (create_state_set_index(0), yyrule, true)); 2166*cda5da8dSAndroid Build Coastguard Worker } 2167*cda5da8dSAndroid Build Coastguard Worker else 2168*cda5da8dSAndroid Build Coastguard Worker { 2169*cda5da8dSAndroid Build Coastguard Worker yyget_token (); 2170*cda5da8dSAndroid Build Coastguard Worker const short* yyconflicts; 2171*cda5da8dSAndroid Build Coastguard Worker const int yyaction = yygetLRActions (yystate, this->yyla.kind (), yyconflicts); 2172*cda5da8dSAndroid Build Coastguard Worker if (*yyconflicts != 0) 2173*cda5da8dSAndroid Build Coastguard Worker break; 2174*cda5da8dSAndroid Build Coastguard Worker if (yy_is_shift_action (yyaction)) 2175*cda5da8dSAndroid Build Coastguard Worker { 2176*cda5da8dSAndroid Build Coastguard Worker YY_SYMBOL_PRINT ("Shifting", this->yyla.kind (), this->yyla.value, this->yyla.location); 2177*cda5da8dSAndroid Build Coastguard Worker yyposn += 1; 2178*cda5da8dSAndroid Build Coastguard Worker // FIXME: we should move yylval. 2179*cda5da8dSAndroid Build Coastguard Worker this->yyglrShift (create_state_set_index(0), yyaction, yyposn, this->yyla.value]b4_locations_if([, this->yyla.location])[); 2180*cda5da8dSAndroid Build Coastguard Worker yyla.clear (); 2181*cda5da8dSAndroid Build Coastguard Worker if (0 < this->yyerrState) 2182*cda5da8dSAndroid Build Coastguard Worker this->yyerrState -= 1; 2183*cda5da8dSAndroid Build Coastguard Worker } 2184*cda5da8dSAndroid Build Coastguard Worker else if (yy_is_error_action (yyaction)) 2185*cda5da8dSAndroid Build Coastguard Worker {]b4_locations_if([[ 2186*cda5da8dSAndroid Build Coastguard Worker this->yyerror_range[1].getState().yyloc = this->yyla.location;]])[ 2187*cda5da8dSAndroid Build Coastguard Worker /* Don't issue an error message again for exceptions 2188*cda5da8dSAndroid Build Coastguard Worker thrown from the scanner. */ 2189*cda5da8dSAndroid Build Coastguard Worker if (this->yyla.kind () != ]b4_symbol(error, kind)[) 2190*cda5da8dSAndroid Build Coastguard Worker this->yyreportSyntaxError (); 2191*cda5da8dSAndroid Build Coastguard Worker goto yyuser_error; 2192*cda5da8dSAndroid Build Coastguard Worker } 2193*cda5da8dSAndroid Build Coastguard Worker else 2194*cda5da8dSAndroid Build Coastguard Worker YYCHK1 (this->yyglrReduce (create_state_set_index(0), -yyaction, true)); 2195*cda5da8dSAndroid Build Coastguard Worker } 2196*cda5da8dSAndroid Build Coastguard Worker } 2197*cda5da8dSAndroid Build Coastguard Worker 2198*cda5da8dSAndroid Build Coastguard Worker while (true) 2199*cda5da8dSAndroid Build Coastguard Worker { 2200*cda5da8dSAndroid Build Coastguard Worker for (state_set_index yys = create_state_set_index(0); yys.uget() < this->yystateStack.numTops(); ++yys) 2201*cda5da8dSAndroid Build Coastguard Worker this->yystateStack.yytops.setLookaheadNeeds(yys, !this->yyla.empty ()); 2202*cda5da8dSAndroid Build Coastguard Worker 2203*cda5da8dSAndroid Build Coastguard Worker /* yyprocessOneStack returns one of three things: 2204*cda5da8dSAndroid Build Coastguard Worker 2205*cda5da8dSAndroid Build Coastguard Worker - An error flag. If the caller is yyprocessOneStack, it 2206*cda5da8dSAndroid Build Coastguard Worker immediately returns as well. When the caller is finally 2207*cda5da8dSAndroid Build Coastguard Worker yyparse, it jumps to an error label via YYCHK1. 2208*cda5da8dSAndroid Build Coastguard Worker 2209*cda5da8dSAndroid Build Coastguard Worker - yyok, but yyprocessOneStack has invoked yymarkStackDeleted 2210*cda5da8dSAndroid Build Coastguard Worker (yys), which sets the top state of yys to NULL. Thus, 2211*cda5da8dSAndroid Build Coastguard Worker yyparse's following invocation of yyremoveDeletes will remove 2212*cda5da8dSAndroid Build Coastguard Worker the stack. 2213*cda5da8dSAndroid Build Coastguard Worker 2214*cda5da8dSAndroid Build Coastguard Worker - yyok, when ready to shift a token. 2215*cda5da8dSAndroid Build Coastguard Worker 2216*cda5da8dSAndroid Build Coastguard Worker Except in the first case, yyparse will invoke yyremoveDeletes and 2217*cda5da8dSAndroid Build Coastguard Worker then shift the next token onto all remaining stacks. This 2218*cda5da8dSAndroid Build Coastguard Worker synchronization of the shift (that is, after all preceding 2219*cda5da8dSAndroid Build Coastguard Worker reductions on all stacks) helps prevent double destructor calls 2220*cda5da8dSAndroid Build Coastguard Worker on yylval in the event of memory exhaustion. */ 2221*cda5da8dSAndroid Build Coastguard Worker 2222*cda5da8dSAndroid Build Coastguard Worker for (state_set_index yys = create_state_set_index (0); yys.uget () < this->yystateStack.numTops (); ++yys) 2223*cda5da8dSAndroid Build Coastguard Worker YYCHK1 (this->yyprocessOneStack (yys, yyposn]b4_locations_if([, &this->yyla.location])[)); 2224*cda5da8dSAndroid Build Coastguard Worker this->yystateStack.yytops.yyremoveDeletes (); 2225*cda5da8dSAndroid Build Coastguard Worker if (this->yystateStack.yytops.size() == 0) 2226*cda5da8dSAndroid Build Coastguard Worker { 2227*cda5da8dSAndroid Build Coastguard Worker this->yystateStack.yytops.yyundeleteLastStack (); 2228*cda5da8dSAndroid Build Coastguard Worker if (this->yystateStack.yytops.size() == 0) 2229*cda5da8dSAndroid Build Coastguard Worker this->yyFail (]b4_locations_if([&this->yyla.location, ])[YY_("syntax error")); 2230*cda5da8dSAndroid Build Coastguard Worker YYCHK1 (this->yyresolveStack ()); 2231*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Returning to deterministic operation.\n";]b4_locations_if([[ 2232*cda5da8dSAndroid Build Coastguard Worker this->yyerror_range[1].getState ().yyloc = this->yyla.location;]])[ 2233*cda5da8dSAndroid Build Coastguard Worker this->yyreportSyntaxError (); 2234*cda5da8dSAndroid Build Coastguard Worker goto yyuser_error; 2235*cda5da8dSAndroid Build Coastguard Worker } 2236*cda5da8dSAndroid Build Coastguard Worker 2237*cda5da8dSAndroid Build Coastguard Worker /* If any yyglrShift call fails, it will fail after shifting. Thus, 2238*cda5da8dSAndroid Build Coastguard Worker a copy of yylval will already be on stack 0 in the event of a 2239*cda5da8dSAndroid Build Coastguard Worker failure in the following loop. Thus, yyla is emptied 2240*cda5da8dSAndroid Build Coastguard Worker before the loop to make sure the user destructor for yylval isn't 2241*cda5da8dSAndroid Build Coastguard Worker called twice. */ 2242*cda5da8dSAndroid Build Coastguard Worker symbol_kind_type yytoken_to_shift = this->yyla.kind (); 2243*cda5da8dSAndroid Build Coastguard Worker this->yyla.kind_ = ]b4_symbol(empty, kind)[; 2244*cda5da8dSAndroid Build Coastguard Worker yyposn += 1; 2245*cda5da8dSAndroid Build Coastguard Worker for (state_set_index yys = create_state_set_index (0); yys.uget () < this->yystateStack.numTops (); ++yys) 2246*cda5da8dSAndroid Build Coastguard Worker { 2247*cda5da8dSAndroid Build Coastguard Worker const state_num yystate = this->topState (yys)->yylrState; 2248*cda5da8dSAndroid Build Coastguard Worker const short* yyconflicts; 2249*cda5da8dSAndroid Build Coastguard Worker const int yyaction = yygetLRActions (yystate, yytoken_to_shift, yyconflicts); 2250*cda5da8dSAndroid Build Coastguard Worker /* Note that yyconflicts were handled by yyprocessOneStack. */ 2251*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "On stack " << yys.get() << ", "; 2252*cda5da8dSAndroid Build Coastguard Worker YY_SYMBOL_PRINT ("shifting", yytoken_to_shift, this->yyla.value, this->yyla.location); 2253*cda5da8dSAndroid Build Coastguard Worker this->yyglrShift (yys, yyaction, yyposn, this->yyla.value]b4_locations_if([, this->yyla.location])[); 2254*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Stack " << yys.get() << " now in state " 2255*cda5da8dSAndroid Build Coastguard Worker << this->topState(yys)->yylrState << '\n'; 2256*cda5da8dSAndroid Build Coastguard Worker } 2257*cda5da8dSAndroid Build Coastguard Worker ]b4_variant_if([[ 2258*cda5da8dSAndroid Build Coastguard Worker // FIXME: User destructors. 2259*cda5da8dSAndroid Build Coastguard Worker // Value type destructor. 2260*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_variant([[yytoken_to_shift]], [[this->yyla.value]], [[template destroy]])])[ 2261*cda5da8dSAndroid Build Coastguard Worker 2262*cda5da8dSAndroid Build Coastguard Worker if (this->yystateStack.yytops.size () == 1) 2263*cda5da8dSAndroid Build Coastguard Worker { 2264*cda5da8dSAndroid Build Coastguard Worker YYCHK1 (this->yyresolveStack ()); 2265*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Returning to deterministic operation.\n"; 2266*cda5da8dSAndroid Build Coastguard Worker this->yystateStack.yycompressStack (); 2267*cda5da8dSAndroid Build Coastguard Worker break; 2268*cda5da8dSAndroid Build Coastguard Worker } 2269*cda5da8dSAndroid Build Coastguard Worker } 2270*cda5da8dSAndroid Build Coastguard Worker continue; 2271*cda5da8dSAndroid Build Coastguard Worker yyuser_error: 2272*cda5da8dSAndroid Build Coastguard Worker this->yyrecoverSyntaxError (]b4_locations_if([&this->yyla.location])[); 2273*cda5da8dSAndroid Build Coastguard Worker yyposn = this->firstTopState()->yyposn; 2274*cda5da8dSAndroid Build Coastguard Worker } 2275*cda5da8dSAndroid Build Coastguard Worker 2276*cda5da8dSAndroid Build Coastguard Worker yyacceptlab: 2277*cda5da8dSAndroid Build Coastguard Worker yyresult = 0; 2278*cda5da8dSAndroid Build Coastguard Worker goto yyreturn; 2279*cda5da8dSAndroid Build Coastguard Worker 2280*cda5da8dSAndroid Build Coastguard Worker yybuglab: 2281*cda5da8dSAndroid Build Coastguard Worker YYASSERT (false); 2282*cda5da8dSAndroid Build Coastguard Worker goto yyabortlab; 2283*cda5da8dSAndroid Build Coastguard Worker 2284*cda5da8dSAndroid Build Coastguard Worker yyabortlab: 2285*cda5da8dSAndroid Build Coastguard Worker yyresult = 1; 2286*cda5da8dSAndroid Build Coastguard Worker goto yyreturn; 2287*cda5da8dSAndroid Build Coastguard Worker 2288*cda5da8dSAndroid Build Coastguard Worker yyexhaustedlab: 2289*cda5da8dSAndroid Build Coastguard Worker yyparser.error (]b4_locations_if([this->yyla.location, ])[YY_("memory exhausted")); 2290*cda5da8dSAndroid Build Coastguard Worker yyresult = 2; 2291*cda5da8dSAndroid Build Coastguard Worker goto yyreturn; 2292*cda5da8dSAndroid Build Coastguard Worker 2293*cda5da8dSAndroid Build Coastguard Worker yyreturn: 2294*cda5da8dSAndroid Build Coastguard Worker return yyresult; 2295*cda5da8dSAndroid Build Coastguard Worker } 2296*cda5da8dSAndroid Build Coastguard Worker #undef YYCHK1 2297*cda5da8dSAndroid Build Coastguard Worker 2298*cda5da8dSAndroid Build Coastguard Worker void yyreserveGlrStack () 2299*cda5da8dSAndroid Build Coastguard Worker { 2300*cda5da8dSAndroid Build Coastguard Worker if (!yystateStack.yyexpandGLRStackIfNeeded ()) 2301*cda5da8dSAndroid Build Coastguard Worker yyMemoryExhausted (); 2302*cda5da8dSAndroid Build Coastguard Worker } 2303*cda5da8dSAndroid Build Coastguard Worker 2304*cda5da8dSAndroid Build Coastguard Worker _Noreturn void 2305*cda5da8dSAndroid Build Coastguard Worker yyMemoryExhausted () 2306*cda5da8dSAndroid Build Coastguard Worker { 2307*cda5da8dSAndroid Build Coastguard Worker YYLONGJMP (yyexception_buffer, 2); 2308*cda5da8dSAndroid Build Coastguard Worker } 2309*cda5da8dSAndroid Build Coastguard Worker 2310*cda5da8dSAndroid Build Coastguard Worker _Noreturn void 2311*cda5da8dSAndroid Build Coastguard Worker yyFail (]b4_locations_if([location_type* yylocp, ])[const char* yymsg) 2312*cda5da8dSAndroid Build Coastguard Worker { 2313*cda5da8dSAndroid Build Coastguard Worker if (yymsg != YY_NULLPTR) 2314*cda5da8dSAndroid Build Coastguard Worker yyparser.error (]b4_locations_if([*yylocp, ])[yymsg); 2315*cda5da8dSAndroid Build Coastguard Worker YYLONGJMP (yyexception_buffer, 1); 2316*cda5da8dSAndroid Build Coastguard Worker } 2317*cda5da8dSAndroid Build Coastguard Worker 2318*cda5da8dSAndroid Build Coastguard Worker /* GLRStates */ 2319*cda5da8dSAndroid Build Coastguard Worker 2320*cda5da8dSAndroid Build Coastguard Worker 2321*cda5da8dSAndroid Build Coastguard Worker /** Add a new semantic action that will execute the action for rule 2322*cda5da8dSAndroid Build Coastguard Worker * YYRULE on the semantic values in YYRHS to the list of 2323*cda5da8dSAndroid Build Coastguard Worker * alternative actions for YYSTATE. Assumes that YYRHS comes from 2324*cda5da8dSAndroid Build Coastguard Worker * stack #YYK of *this. */ 2325*cda5da8dSAndroid Build Coastguard Worker void 2326*cda5da8dSAndroid Build Coastguard Worker yyaddDeferredAction (state_set_index yyk, glr_state* yystate, 2327*cda5da8dSAndroid Build Coastguard Worker glr_state* yyrhs, rule_num yyrule) 2328*cda5da8dSAndroid Build Coastguard Worker { 2329*cda5da8dSAndroid Build Coastguard Worker semantic_option& yyopt = yystateStack.yynewSemanticOption (semantic_option (yyrule)); 2330*cda5da8dSAndroid Build Coastguard Worker yyopt.setState (yyrhs); 2331*cda5da8dSAndroid Build Coastguard Worker yyopt.setNext (yystate->firstVal ()); 2332*cda5da8dSAndroid Build Coastguard Worker if (yystateStack.yytops.lookaheadNeeds (yyk)) 2333*cda5da8dSAndroid Build Coastguard Worker yyopt.yyla = this->yyla; 2334*cda5da8dSAndroid Build Coastguard Worker yystate->setFirstVal (&yyopt); 2335*cda5da8dSAndroid Build Coastguard Worker 2336*cda5da8dSAndroid Build Coastguard Worker yyreserveGlrStack (); 2337*cda5da8dSAndroid Build Coastguard Worker } 2338*cda5da8dSAndroid Build Coastguard Worker 2339*cda5da8dSAndroid Build Coastguard Worker #if ]b4_api_PREFIX[DEBUG 2340*cda5da8dSAndroid Build Coastguard Worker void yypdumpstack () const 2341*cda5da8dSAndroid Build Coastguard Worker { 2342*cda5da8dSAndroid Build Coastguard Worker yystateStack.dumpStack(); 2343*cda5da8dSAndroid Build Coastguard Worker } 2344*cda5da8dSAndroid Build Coastguard Worker #endif 2345*cda5da8dSAndroid Build Coastguard Worker 2346*cda5da8dSAndroid Build Coastguard Worker void 2347*cda5da8dSAndroid Build Coastguard Worker yyreportSyntaxError () 2348*cda5da8dSAndroid Build Coastguard Worker { 2349*cda5da8dSAndroid Build Coastguard Worker if (yyerrState != 0) 2350*cda5da8dSAndroid Build Coastguard Worker return; 2351*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_error_case( 2352*cda5da8dSAndroid Build Coastguard Worker [simple], [[ 2353*cda5da8dSAndroid Build Coastguard Worker std::string msg = YY_("syntax error"); 2354*cda5da8dSAndroid Build Coastguard Worker yyparser.error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]], 2355*cda5da8dSAndroid Build Coastguard Worker [custom], [[ 2356*cda5da8dSAndroid Build Coastguard Worker context yyctx (*this, yyla); 2357*cda5da8dSAndroid Build Coastguard Worker yyparser.report_syntax_error (yyctx);]], 2358*cda5da8dSAndroid Build Coastguard Worker [[ 2359*cda5da8dSAndroid Build Coastguard Worker context yyctx (*this, yyla); 2360*cda5da8dSAndroid Build Coastguard Worker std::string msg = yyparser.yysyntax_error_ (yyctx); 2361*cda5da8dSAndroid Build Coastguard Worker yyparser.error (]b4_join(b4_locations_if([yyla.location]), [[YY_MOVE (msg)]])[);]])[ 2362*cda5da8dSAndroid Build Coastguard Worker yyerrcnt += 1; 2363*cda5da8dSAndroid Build Coastguard Worker } 2364*cda5da8dSAndroid Build Coastguard Worker 2365*cda5da8dSAndroid Build Coastguard Worker /* Recover from a syntax error on this, assuming that yytoken, 2366*cda5da8dSAndroid Build Coastguard Worker yylval, and yylloc are the syntactic category, semantic value, and location 2367*cda5da8dSAndroid Build Coastguard Worker of the lookahead. */ 2368*cda5da8dSAndroid Build Coastguard Worker void 2369*cda5da8dSAndroid Build Coastguard Worker yyrecoverSyntaxError (]b4_locations_if([location_type* yylocp])[) 2370*cda5da8dSAndroid Build Coastguard Worker { 2371*cda5da8dSAndroid Build Coastguard Worker if (yyerrState == 3) 2372*cda5da8dSAndroid Build Coastguard Worker /* We just shifted the error token and (perhaps) took some 2373*cda5da8dSAndroid Build Coastguard Worker reductions. Skip tokens until we can proceed. */ 2374*cda5da8dSAndroid Build Coastguard Worker while (true) 2375*cda5da8dSAndroid Build Coastguard Worker { 2376*cda5da8dSAndroid Build Coastguard Worker if (this->yyla.kind () == ]b4_symbol(eof, kind)[) 2377*cda5da8dSAndroid Build Coastguard Worker yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR); 2378*cda5da8dSAndroid Build Coastguard Worker if (this->yyla.kind () != ]b4_symbol(empty, kind)[) 2379*cda5da8dSAndroid Build Coastguard Worker {]b4_locations_if([[ 2380*cda5da8dSAndroid Build Coastguard Worker /* We throw away the lookahead, but the error range 2381*cda5da8dSAndroid Build Coastguard Worker of the shifted error token must take it into account. */ 2382*cda5da8dSAndroid Build Coastguard Worker glr_state *yys = firstTopState(); 2383*cda5da8dSAndroid Build Coastguard Worker yyerror_range[1].getState().yyloc = yys->yyloc; 2384*cda5da8dSAndroid Build Coastguard Worker yyerror_range[2].getState().yyloc = this->yyla.location; 2385*cda5da8dSAndroid Build Coastguard Worker YYLLOC_DEFAULT ((yys->yyloc), yyerror_range, 2);]])[ 2386*cda5da8dSAndroid Build Coastguard Worker yyparser.yy_destroy_ ("Error: discarding", 2387*cda5da8dSAndroid Build Coastguard Worker this->yyla.kind (), this->yyla.value]b4_locations_if([, this->yyla.location])[);]b4_variant_if([[ 2388*cda5da8dSAndroid Build Coastguard Worker // Value type destructor. 2389*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_variant([[this->yyla.kind ()]], [[this->yyla.value]], [[template destroy]])])[ 2390*cda5da8dSAndroid Build Coastguard Worker this->yyla.kind_ = ]b4_symbol(empty, kind)[; 2391*cda5da8dSAndroid Build Coastguard Worker } 2392*cda5da8dSAndroid Build Coastguard Worker yyget_token (); 2393*cda5da8dSAndroid Build Coastguard Worker int yyj = yypact[firstTopState()->yylrState]; 2394*cda5da8dSAndroid Build Coastguard Worker if (yypact_value_is_default (yyj)) 2395*cda5da8dSAndroid Build Coastguard Worker return; 2396*cda5da8dSAndroid Build Coastguard Worker yyj += this->yyla.kind (); 2397*cda5da8dSAndroid Build Coastguard Worker if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != this->yyla.kind ()) 2398*cda5da8dSAndroid Build Coastguard Worker { 2399*cda5da8dSAndroid Build Coastguard Worker if (yydefact[firstTopState()->yylrState] != 0) 2400*cda5da8dSAndroid Build Coastguard Worker return; 2401*cda5da8dSAndroid Build Coastguard Worker } 2402*cda5da8dSAndroid Build Coastguard Worker else if (! yytable_value_is_error (yytable[yyj])) 2403*cda5da8dSAndroid Build Coastguard Worker return; 2404*cda5da8dSAndroid Build Coastguard Worker } 2405*cda5da8dSAndroid Build Coastguard Worker 2406*cda5da8dSAndroid Build Coastguard Worker if (!yystateStack.reduceToOneStack()) 2407*cda5da8dSAndroid Build Coastguard Worker yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR); 2408*cda5da8dSAndroid Build Coastguard Worker 2409*cda5da8dSAndroid Build Coastguard Worker /* Now pop stack until we find a state that shifts the error token. */ 2410*cda5da8dSAndroid Build Coastguard Worker yyerrState = 3; 2411*cda5da8dSAndroid Build Coastguard Worker while (firstTopState () != YY_NULLPTR) 2412*cda5da8dSAndroid Build Coastguard Worker { 2413*cda5da8dSAndroid Build Coastguard Worker glr_state *yys = firstTopState (); 2414*cda5da8dSAndroid Build Coastguard Worker int yyj = yypact[yys->yylrState]; 2415*cda5da8dSAndroid Build Coastguard Worker if (! yypact_value_is_default (yyj)) 2416*cda5da8dSAndroid Build Coastguard Worker { 2417*cda5da8dSAndroid Build Coastguard Worker yyj += YYTERROR; 2418*cda5da8dSAndroid Build Coastguard Worker if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR 2419*cda5da8dSAndroid Build Coastguard Worker && yy_is_shift_action (yytable[yyj])) 2420*cda5da8dSAndroid Build Coastguard Worker { 2421*cda5da8dSAndroid Build Coastguard Worker /* Shift the error token. */]b4_locations_if([[ 2422*cda5da8dSAndroid Build Coastguard Worker /* First adjust its location.*/ 2423*cda5da8dSAndroid Build Coastguard Worker location_type yyerrloc; 2424*cda5da8dSAndroid Build Coastguard Worker yyerror_range[2].getState().yyloc = this->yyla.location; 2425*cda5da8dSAndroid Build Coastguard Worker YYLLOC_DEFAULT (yyerrloc, (yyerror_range), 2);]])[ 2426*cda5da8dSAndroid Build Coastguard Worker YY_SYMBOL_PRINT ("Shifting", yy_accessing_symbol (yytable[yyj]), 2427*cda5da8dSAndroid Build Coastguard Worker this->yyla.value, yyerrloc); 2428*cda5da8dSAndroid Build Coastguard Worker yyglrShift (create_state_set_index(0), yytable[yyj], 2429*cda5da8dSAndroid Build Coastguard Worker yys->yyposn, yyla.value]b4_locations_if([, yyerrloc])[); 2430*cda5da8dSAndroid Build Coastguard Worker yys = firstTopState(); 2431*cda5da8dSAndroid Build Coastguard Worker break; 2432*cda5da8dSAndroid Build Coastguard Worker } 2433*cda5da8dSAndroid Build Coastguard Worker }]b4_locations_if([[ 2434*cda5da8dSAndroid Build Coastguard Worker yyerror_range[1].getState().yyloc = yys->yyloc;]])[ 2435*cda5da8dSAndroid Build Coastguard Worker if (yys->pred() != YY_NULLPTR) 2436*cda5da8dSAndroid Build Coastguard Worker yys->destroy ("Error: popping", yyparser); 2437*cda5da8dSAndroid Build Coastguard Worker yystateStack.setFirstTop(yys->pred()); 2438*cda5da8dSAndroid Build Coastguard Worker yystateStack.pop_back(); 2439*cda5da8dSAndroid Build Coastguard Worker } 2440*cda5da8dSAndroid Build Coastguard Worker if (firstTopState() == YY_NULLPTR) 2441*cda5da8dSAndroid Build Coastguard Worker yyFail (]b4_locations_if([yylocp, ])[YY_NULLPTR); 2442*cda5da8dSAndroid Build Coastguard Worker } 2443*cda5da8dSAndroid Build Coastguard Worker 2444*cda5da8dSAndroid Build Coastguard Worker YYRESULTTAG 2445*cda5da8dSAndroid Build Coastguard Worker yyprocessOneStack (state_set_index yyk, 2446*cda5da8dSAndroid Build Coastguard Worker size_t yyposn]b4_locations_if([, location_type* yylocp])[) 2447*cda5da8dSAndroid Build Coastguard Worker { 2448*cda5da8dSAndroid Build Coastguard Worker while (yystateStack.topAt(yyk) != YY_NULLPTR) 2449*cda5da8dSAndroid Build Coastguard Worker { 2450*cda5da8dSAndroid Build Coastguard Worker const state_num yystate = topState(yyk)->yylrState; 2451*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Stack " << yyk.get() 2452*cda5da8dSAndroid Build Coastguard Worker << " Entering state " << yystate << '\n'; 2453*cda5da8dSAndroid Build Coastguard Worker 2454*cda5da8dSAndroid Build Coastguard Worker YYASSERT (yystate != YYFINAL); 2455*cda5da8dSAndroid Build Coastguard Worker 2456*cda5da8dSAndroid Build Coastguard Worker if (yy_is_defaulted_state (yystate)) 2457*cda5da8dSAndroid Build Coastguard Worker { 2458*cda5da8dSAndroid Build Coastguard Worker const rule_num yyrule = yy_default_action (yystate); 2459*cda5da8dSAndroid Build Coastguard Worker if (yyrule == 0) 2460*cda5da8dSAndroid Build Coastguard Worker { 2461*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Stack " << yyk.get() << " dies.\n"; 2462*cda5da8dSAndroid Build Coastguard Worker yystateStack.yytops.yymarkStackDeleted (yyk); 2463*cda5da8dSAndroid Build Coastguard Worker return yyok; 2464*cda5da8dSAndroid Build Coastguard Worker } 2465*cda5da8dSAndroid Build Coastguard Worker const YYRESULTTAG yyflag 2466*cda5da8dSAndroid Build Coastguard Worker = yyglrReduce (yyk, yyrule, yyimmediate[yyrule]); 2467*cda5da8dSAndroid Build Coastguard Worker if (yyflag == yyerr) 2468*cda5da8dSAndroid Build Coastguard Worker { 2469*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Stack " << yyk.get() << " dies" 2470*cda5da8dSAndroid Build Coastguard Worker " (predicate failure or explicit user error).\n"; 2471*cda5da8dSAndroid Build Coastguard Worker yystateStack.yytops.yymarkStackDeleted (yyk); 2472*cda5da8dSAndroid Build Coastguard Worker return yyok; 2473*cda5da8dSAndroid Build Coastguard Worker } 2474*cda5da8dSAndroid Build Coastguard Worker if (yyflag != yyok) 2475*cda5da8dSAndroid Build Coastguard Worker return yyflag; 2476*cda5da8dSAndroid Build Coastguard Worker } 2477*cda5da8dSAndroid Build Coastguard Worker else 2478*cda5da8dSAndroid Build Coastguard Worker { 2479*cda5da8dSAndroid Build Coastguard Worker yystateStack.yytops.setLookaheadNeeds(yyk, true); 2480*cda5da8dSAndroid Build Coastguard Worker yyget_token (); 2481*cda5da8dSAndroid Build Coastguard Worker const short* yyconflicts; 2482*cda5da8dSAndroid Build Coastguard Worker const int yyaction = yygetLRActions (yystate, this->yyla.kind (), yyconflicts); 2483*cda5da8dSAndroid Build Coastguard Worker 2484*cda5da8dSAndroid Build Coastguard Worker for (; *yyconflicts != 0; ++yyconflicts) 2485*cda5da8dSAndroid Build Coastguard Worker { 2486*cda5da8dSAndroid Build Coastguard Worker state_set_index yynewStack = yystateStack.yysplitStack (yyk); 2487*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Splitting off stack " << yynewStack.get() 2488*cda5da8dSAndroid Build Coastguard Worker << " from " << yyk.get() << ".\n"; 2489*cda5da8dSAndroid Build Coastguard Worker YYRESULTTAG yyflag = 2490*cda5da8dSAndroid Build Coastguard Worker yyglrReduce (yynewStack, *yyconflicts, yyimmediate[*yyconflicts]); 2491*cda5da8dSAndroid Build Coastguard Worker if (yyflag == yyok) 2492*cda5da8dSAndroid Build Coastguard Worker YYCHK (yyprocessOneStack (yynewStack, 2493*cda5da8dSAndroid Build Coastguard Worker yyposn]b4_locations_if([, yylocp])[)); 2494*cda5da8dSAndroid Build Coastguard Worker else if (yyflag == yyerr) 2495*cda5da8dSAndroid Build Coastguard Worker { 2496*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Stack " << yynewStack.get() << " dies.\n"; 2497*cda5da8dSAndroid Build Coastguard Worker yystateStack.yytops.yymarkStackDeleted (yynewStack); 2498*cda5da8dSAndroid Build Coastguard Worker } 2499*cda5da8dSAndroid Build Coastguard Worker else 2500*cda5da8dSAndroid Build Coastguard Worker return yyflag; 2501*cda5da8dSAndroid Build Coastguard Worker } 2502*cda5da8dSAndroid Build Coastguard Worker 2503*cda5da8dSAndroid Build Coastguard Worker if (yy_is_shift_action (yyaction)) 2504*cda5da8dSAndroid Build Coastguard Worker break; 2505*cda5da8dSAndroid Build Coastguard Worker else if (yy_is_error_action (yyaction)) 2506*cda5da8dSAndroid Build Coastguard Worker { 2507*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Stack " << yyk.get() << " dies.\n"; 2508*cda5da8dSAndroid Build Coastguard Worker yystateStack.yytops.yymarkStackDeleted (yyk); 2509*cda5da8dSAndroid Build Coastguard Worker break; 2510*cda5da8dSAndroid Build Coastguard Worker } 2511*cda5da8dSAndroid Build Coastguard Worker else 2512*cda5da8dSAndroid Build Coastguard Worker { 2513*cda5da8dSAndroid Build Coastguard Worker YYRESULTTAG yyflag 2514*cda5da8dSAndroid Build Coastguard Worker = yyglrReduce (yyk, -yyaction, yyimmediate[-yyaction]); 2515*cda5da8dSAndroid Build Coastguard Worker if (yyflag == yyerr) 2516*cda5da8dSAndroid Build Coastguard Worker { 2517*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Stack " << yyk.get() << " dies" 2518*cda5da8dSAndroid Build Coastguard Worker " (predicate failure or explicit user error).\n"; 2519*cda5da8dSAndroid Build Coastguard Worker yystateStack.yytops.yymarkStackDeleted (yyk); 2520*cda5da8dSAndroid Build Coastguard Worker break; 2521*cda5da8dSAndroid Build Coastguard Worker } 2522*cda5da8dSAndroid Build Coastguard Worker else if (yyflag != yyok) 2523*cda5da8dSAndroid Build Coastguard Worker return yyflag; 2524*cda5da8dSAndroid Build Coastguard Worker } 2525*cda5da8dSAndroid Build Coastguard Worker } 2526*cda5da8dSAndroid Build Coastguard Worker } 2527*cda5da8dSAndroid Build Coastguard Worker return yyok; 2528*cda5da8dSAndroid Build Coastguard Worker } 2529*cda5da8dSAndroid Build Coastguard Worker 2530*cda5da8dSAndroid Build Coastguard Worker /** Perform user action for rule number YYN, with RHS length YYRHSLEN, 2531*cda5da8dSAndroid Build Coastguard Worker * and top stack item YYVSP. YYVALP points to place to put semantic 2532*cda5da8dSAndroid Build Coastguard Worker * value ($$), and yylocp points to place for location information 2533*cda5da8dSAndroid Build Coastguard Worker * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT, 2534*cda5da8dSAndroid Build Coastguard Worker * yyerr for YYERROR, yyabort for YYABORT. */ 2535*cda5da8dSAndroid Build Coastguard Worker YYRESULTTAG 2536*cda5da8dSAndroid Build Coastguard Worker yyuserAction (rule_num yyrule, int yyrhslen, glr_stack_item* yyvsp, state_set_index yyk, 2537*cda5da8dSAndroid Build Coastguard Worker value_type* yyvalp]b4_locations_if([, location_type* yylocp])[) 2538*cda5da8dSAndroid Build Coastguard Worker { 2539*cda5da8dSAndroid Build Coastguard Worker bool yynormal YY_ATTRIBUTE_UNUSED = !yystateStack.isSplit(); 2540*cda5da8dSAndroid Build Coastguard Worker int yylow = 1; 2541*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_param_use([yyvalp], [yylocp])dnl 2542*cda5da8dSAndroid Build Coastguard Worker [ YY_USE (yyk); 2543*cda5da8dSAndroid Build Coastguard Worker YY_USE (yyrhslen); 2544*cda5da8dSAndroid Build Coastguard Worker # undef yyerrok 2545*cda5da8dSAndroid Build Coastguard Worker # define yyerrok (yyerrState = 0) 2546*cda5da8dSAndroid Build Coastguard Worker # undef YYACCEPT 2547*cda5da8dSAndroid Build Coastguard Worker # define YYACCEPT return yyaccept 2548*cda5da8dSAndroid Build Coastguard Worker # undef YYABORT 2549*cda5da8dSAndroid Build Coastguard Worker # define YYABORT return yyabort 2550*cda5da8dSAndroid Build Coastguard Worker # undef YYERROR 2551*cda5da8dSAndroid Build Coastguard Worker # define YYERROR return yyerrok, yyerr 2552*cda5da8dSAndroid Build Coastguard Worker # undef YYRECOVERING 2553*cda5da8dSAndroid Build Coastguard Worker # define YYRECOVERING() (yyerrState != 0) 2554*cda5da8dSAndroid Build Coastguard Worker # undef yytoken 2555*cda5da8dSAndroid Build Coastguard Worker # define yytoken this->yyla.kind_ 2556*cda5da8dSAndroid Build Coastguard Worker # undef yyclearin 2557*cda5da8dSAndroid Build Coastguard Worker # define yyclearin (yytoken = ]b4_symbol(empty, kind)[) 2558*cda5da8dSAndroid Build Coastguard Worker # undef YYBACKUP 2559*cda5da8dSAndroid Build Coastguard Worker # define YYBACKUP(Token, Value) \ 2560*cda5da8dSAndroid Build Coastguard Worker return yyparser.error (]b4_locations_if([*yylocp, ])[YY_("syntax error: cannot back up")), \ 2561*cda5da8dSAndroid Build Coastguard Worker yyerrok, yyerr 2562*cda5da8dSAndroid Build Coastguard Worker 2563*cda5da8dSAndroid Build Coastguard Worker ]b4_variant_if([[ 2564*cda5da8dSAndroid Build Coastguard Worker /* Variants are always initialized to an empty instance of the 2565*cda5da8dSAndroid Build Coastguard Worker correct type. The default '$$ = $1' action is NOT applied 2566*cda5da8dSAndroid Build Coastguard Worker when using variants. */ 2567*cda5da8dSAndroid Build Coastguard Worker // However we really need to prepare yyvsp now if we want to get 2568*cda5da8dSAndroid Build Coastguard Worker // correct locations, so invoke YYFILL for $1 anyway. 2569*cda5da8dSAndroid Build Coastguard Worker (void) YYFILL (1-yyrhslen); 2570*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [(*yyvalp)], [emplace])], [[ 2571*cda5da8dSAndroid Build Coastguard Worker if (yyrhslen == 0) 2572*cda5da8dSAndroid Build Coastguard Worker *yyvalp = yyval_default; 2573*cda5da8dSAndroid Build Coastguard Worker else 2574*cda5da8dSAndroid Build Coastguard Worker *yyvalp = yyvsp[YYFILL (1-yyrhslen)].getState().value ();]])[]b4_locations_if([[ 2575*cda5da8dSAndroid Build Coastguard Worker /* Default location. */ 2576*cda5da8dSAndroid Build Coastguard Worker YYLLOC_DEFAULT ((*yylocp), (yyvsp - yyrhslen), yyrhslen); 2577*cda5da8dSAndroid Build Coastguard Worker yyerror_range[1].getState().yyloc = *yylocp; 2578*cda5da8dSAndroid Build Coastguard Worker ]])[ 2579*cda5da8dSAndroid Build Coastguard Worker /* If yyk == -1, we are running a deferred action on a temporary 2580*cda5da8dSAndroid Build Coastguard Worker stack. In that case, YY_REDUCE_PRINT must not play with YYFILL, 2581*cda5da8dSAndroid Build Coastguard Worker so pretend the stack is "normal". */ 2582*cda5da8dSAndroid Build Coastguard Worker YY_REDUCE_PRINT ((yynormal || yyk == create_state_set_index (-1), yyvsp, yyk, yyrule, yyparser)); 2583*cda5da8dSAndroid Build Coastguard Worker #if YY_EXCEPTIONS 2584*cda5da8dSAndroid Build Coastguard Worker try 2585*cda5da8dSAndroid Build Coastguard Worker { 2586*cda5da8dSAndroid Build Coastguard Worker #endif // YY_EXCEPTIONS 2587*cda5da8dSAndroid Build Coastguard Worker switch (yyrule) 2588*cda5da8dSAndroid Build Coastguard Worker { 2589*cda5da8dSAndroid Build Coastguard Worker ]b4_user_actions[ 2590*cda5da8dSAndroid Build Coastguard Worker default: break; 2591*cda5da8dSAndroid Build Coastguard Worker } 2592*cda5da8dSAndroid Build Coastguard Worker #if YY_EXCEPTIONS 2593*cda5da8dSAndroid Build Coastguard Worker } 2594*cda5da8dSAndroid Build Coastguard Worker catch (const syntax_error& yyexc) 2595*cda5da8dSAndroid Build Coastguard Worker { 2596*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Caught exception: " << yyexc.what() << '\n';]b4_locations_if([ 2597*cda5da8dSAndroid Build Coastguard Worker *yylocp = yyexc.location;])[ 2598*cda5da8dSAndroid Build Coastguard Worker yyparser.error (]b4_locations_if([*yylocp, ])[yyexc.what ()); 2599*cda5da8dSAndroid Build Coastguard Worker YYERROR; 2600*cda5da8dSAndroid Build Coastguard Worker } 2601*cda5da8dSAndroid Build Coastguard Worker #endif // YY_EXCEPTIONS 2602*cda5da8dSAndroid Build Coastguard Worker YY_SYMBOL_PRINT ("-> $$ =", yylhsNonterm (yyrule), *yyvalp, *yylocp); 2603*cda5da8dSAndroid Build Coastguard Worker 2604*cda5da8dSAndroid Build Coastguard Worker return yyok; 2605*cda5da8dSAndroid Build Coastguard Worker # undef yyerrok 2606*cda5da8dSAndroid Build Coastguard Worker # undef YYABORT 2607*cda5da8dSAndroid Build Coastguard Worker # undef YYACCEPT 2608*cda5da8dSAndroid Build Coastguard Worker # undef YYERROR 2609*cda5da8dSAndroid Build Coastguard Worker # undef YYBACKUP 2610*cda5da8dSAndroid Build Coastguard Worker # undef yytoken 2611*cda5da8dSAndroid Build Coastguard Worker # undef yyclearin 2612*cda5da8dSAndroid Build Coastguard Worker # undef YYRECOVERING 2613*cda5da8dSAndroid Build Coastguard Worker } 2614*cda5da8dSAndroid Build Coastguard Worker 2615*cda5da8dSAndroid Build Coastguard Worker YYRESULTTAG 2616*cda5da8dSAndroid Build Coastguard Worker yyresolveStack () 2617*cda5da8dSAndroid Build Coastguard Worker { 2618*cda5da8dSAndroid Build Coastguard Worker if (yystateStack.isSplit ()) 2619*cda5da8dSAndroid Build Coastguard Worker { 2620*cda5da8dSAndroid Build Coastguard Worker int yyn = 0; 2621*cda5da8dSAndroid Build Coastguard Worker for (glr_state* yys = firstTopState (); 2622*cda5da8dSAndroid Build Coastguard Worker yys != yystateStack.yysplitPoint; 2623*cda5da8dSAndroid Build Coastguard Worker yys = yys->pred ()) 2624*cda5da8dSAndroid Build Coastguard Worker yyn += 1; 2625*cda5da8dSAndroid Build Coastguard Worker YYCHK (yyresolveStates (*firstTopState (), yyn)); 2626*cda5da8dSAndroid Build Coastguard Worker } 2627*cda5da8dSAndroid Build Coastguard Worker return yyok; 2628*cda5da8dSAndroid Build Coastguard Worker } 2629*cda5da8dSAndroid Build Coastguard Worker 2630*cda5da8dSAndroid Build Coastguard Worker /** Pop the symbols consumed by reduction #YYRULE from the top of stack 2631*cda5da8dSAndroid Build Coastguard Worker * #YYK of *YYSTACKP, and perform the appropriate semantic action on their 2632*cda5da8dSAndroid Build Coastguard Worker * semantic values. Assumes that all ambiguities in semantic values 2633*cda5da8dSAndroid Build Coastguard Worker * have been previously resolved. Set *YYVALP to the resulting value, 2634*cda5da8dSAndroid Build Coastguard Worker * and *YYLOCP to the computed location (if any). Return value is as 2635*cda5da8dSAndroid Build Coastguard Worker * for userAction. */ 2636*cda5da8dSAndroid Build Coastguard Worker YYRESULTTAG 2637*cda5da8dSAndroid Build Coastguard Worker yydoAction (state_set_index yyk, rule_num yyrule, 2638*cda5da8dSAndroid Build Coastguard Worker value_type* yyvalp]b4_locations_if([, location_type* yylocp])[) 2639*cda5da8dSAndroid Build Coastguard Worker { 2640*cda5da8dSAndroid Build Coastguard Worker const int yynrhs = yyrhsLength (yyrule); 2641*cda5da8dSAndroid Build Coastguard Worker 2642*cda5da8dSAndroid Build Coastguard Worker if (!yystateStack.isSplit()) 2643*cda5da8dSAndroid Build Coastguard Worker { 2644*cda5da8dSAndroid Build Coastguard Worker /* Standard special case: single stack. */ 2645*cda5da8dSAndroid Build Coastguard Worker YYASSERT (yyk.get() == 0); 2646*cda5da8dSAndroid Build Coastguard Worker glr_stack_item* yyrhs = yystateStack.firstTop()->asItem(); 2647*cda5da8dSAndroid Build Coastguard Worker const YYRESULTTAG res 2648*cda5da8dSAndroid Build Coastguard Worker = yyuserAction (yyrule, yynrhs, yyrhs, yyk, yyvalp]b4_locations_if([, yylocp])[); 2649*cda5da8dSAndroid Build Coastguard Worker yystateStack.pop_back(static_cast<size_t>(yynrhs)); 2650*cda5da8dSAndroid Build Coastguard Worker yystateStack.setFirstTop(&yystateStack[yystateStack.size() - 1].getState()); 2651*cda5da8dSAndroid Build Coastguard Worker return res; 2652*cda5da8dSAndroid Build Coastguard Worker } 2653*cda5da8dSAndroid Build Coastguard Worker else 2654*cda5da8dSAndroid Build Coastguard Worker { 2655*cda5da8dSAndroid Build Coastguard Worker glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; 2656*cda5da8dSAndroid Build Coastguard Worker glr_state* yys = yystateStack.topAt(yyk); 2657*cda5da8dSAndroid Build Coastguard Worker yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yys);]b4_locations_if([[ 2658*cda5da8dSAndroid Build Coastguard Worker if (yynrhs == 0) 2659*cda5da8dSAndroid Build Coastguard Worker /* Set default location. */ 2660*cda5da8dSAndroid Build Coastguard Worker yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yys->yyloc;]])[ 2661*cda5da8dSAndroid Build Coastguard Worker for (int yyi = 0; yyi < yynrhs; yyi += 1) 2662*cda5da8dSAndroid Build Coastguard Worker { 2663*cda5da8dSAndroid Build Coastguard Worker yys = yys->pred(); 2664*cda5da8dSAndroid Build Coastguard Worker YYASSERT (yys != YY_NULLPTR); 2665*cda5da8dSAndroid Build Coastguard Worker } 2666*cda5da8dSAndroid Build Coastguard Worker yystateStack.yyupdateSplit (*yys); 2667*cda5da8dSAndroid Build Coastguard Worker yystateStack.setTopAt(yyk, yys); 2668*cda5da8dSAndroid Build Coastguard Worker return yyuserAction (yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, 2669*cda5da8dSAndroid Build Coastguard Worker yyk, 2670*cda5da8dSAndroid Build Coastguard Worker yyvalp]b4_locations_if([, yylocp])[); 2671*cda5da8dSAndroid Build Coastguard Worker } 2672*cda5da8dSAndroid Build Coastguard Worker } 2673*cda5da8dSAndroid Build Coastguard Worker 2674*cda5da8dSAndroid Build Coastguard Worker /** Pop items off stack #YYK of *YYSTACKP according to grammar rule YYRULE, 2675*cda5da8dSAndroid Build Coastguard Worker * and push back on the resulting nonterminal symbol. Perform the 2676*cda5da8dSAndroid Build Coastguard Worker * semantic action associated with YYRULE and store its value with the 2677*cda5da8dSAndroid Build Coastguard Worker * newly pushed state, if YYFORCEEVAL or if *YYSTACKP is currently 2678*cda5da8dSAndroid Build Coastguard Worker * unambiguous. Otherwise, store the deferred semantic action with 2679*cda5da8dSAndroid Build Coastguard Worker * the new state. If the new state would have an identical input 2680*cda5da8dSAndroid Build Coastguard Worker * position, LR state, and predecessor to an existing state on the stack, 2681*cda5da8dSAndroid Build Coastguard Worker * it is identified with that existing state, eliminating stack #YYK from 2682*cda5da8dSAndroid Build Coastguard Worker * *YYSTACKP. In this case, the semantic value is 2683*cda5da8dSAndroid Build Coastguard Worker * added to the options for the existing state's semantic value. 2684*cda5da8dSAndroid Build Coastguard Worker */ 2685*cda5da8dSAndroid Build Coastguard Worker YYRESULTTAG 2686*cda5da8dSAndroid Build Coastguard Worker yyglrReduce (state_set_index yyk, rule_num yyrule, bool yyforceEval) 2687*cda5da8dSAndroid Build Coastguard Worker { 2688*cda5da8dSAndroid Build Coastguard Worker size_t yyposn = topState(yyk)->yyposn; 2689*cda5da8dSAndroid Build Coastguard Worker 2690*cda5da8dSAndroid Build Coastguard Worker if (yyforceEval || !yystateStack.isSplit()) 2691*cda5da8dSAndroid Build Coastguard Worker { 2692*cda5da8dSAndroid Build Coastguard Worker value_type val;]b4_locations_if([[ 2693*cda5da8dSAndroid Build Coastguard Worker location_type loc;]])[ 2694*cda5da8dSAndroid Build Coastguard Worker 2695*cda5da8dSAndroid Build Coastguard Worker YYRESULTTAG yyflag = yydoAction (yyk, yyrule, &val]b4_locations_if([, &loc])[); 2696*cda5da8dSAndroid Build Coastguard Worker if (yyflag == yyerr && yystateStack.isSplit()) 2697*cda5da8dSAndroid Build Coastguard Worker {]b4_parse_trace_if([[ 2698*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Parse on stack " << yyk.get () 2699*cda5da8dSAndroid Build Coastguard Worker << " rejected by rule " << yyrule - 1 2700*cda5da8dSAndroid Build Coastguard Worker << " (line " << int (yyrline[yyrule]) << ").\n"; 2701*cda5da8dSAndroid Build Coastguard Worker ]])[} 2702*cda5da8dSAndroid Build Coastguard Worker if (yyflag != yyok) 2703*cda5da8dSAndroid Build Coastguard Worker return yyflag; 2704*cda5da8dSAndroid Build Coastguard Worker yyglrShift (yyk, 2705*cda5da8dSAndroid Build Coastguard Worker yyLRgotoState (topState(yyk)->yylrState, 2706*cda5da8dSAndroid Build Coastguard Worker yylhsNonterm (yyrule)), 2707*cda5da8dSAndroid Build Coastguard Worker yyposn, val]b4_locations_if([, loc])[);]b4_variant_if([[ 2708*cda5da8dSAndroid Build Coastguard Worker // FIXME: User destructors. 2709*cda5da8dSAndroid Build Coastguard Worker // Value type destructor. 2710*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_variant([[yylhsNonterm (yyrule)]], [[val]], [[template destroy]])])[ 2711*cda5da8dSAndroid Build Coastguard Worker } 2712*cda5da8dSAndroid Build Coastguard Worker else 2713*cda5da8dSAndroid Build Coastguard Worker { 2714*cda5da8dSAndroid Build Coastguard Worker glr_state *yys = yystateStack.topAt(yyk); 2715*cda5da8dSAndroid Build Coastguard Worker glr_state *yys0 = yys; 2716*cda5da8dSAndroid Build Coastguard Worker for (int yyn = yyrhsLength (yyrule); 0 < yyn; yyn -= 1) 2717*cda5da8dSAndroid Build Coastguard Worker { 2718*cda5da8dSAndroid Build Coastguard Worker yys = yys->pred(); 2719*cda5da8dSAndroid Build Coastguard Worker YYASSERT (yys != YY_NULLPTR); 2720*cda5da8dSAndroid Build Coastguard Worker } 2721*cda5da8dSAndroid Build Coastguard Worker yystateStack.yyupdateSplit (*yys); 2722*cda5da8dSAndroid Build Coastguard Worker state_num yynewLRState = yyLRgotoState (yys->yylrState, yylhsNonterm (yyrule));]b4_parse_trace_if([[ 2723*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Reduced stack " << yyk.get () 2724*cda5da8dSAndroid Build Coastguard Worker << " by rule " << yyrule - 1 << " (line " << int (yyrline[yyrule]) 2725*cda5da8dSAndroid Build Coastguard Worker << "); action deferred. Now in state " << yynewLRState 2726*cda5da8dSAndroid Build Coastguard Worker << ".\n";]])[ 2727*cda5da8dSAndroid Build Coastguard Worker for (state_set_index yyi = create_state_set_index(0); yyi.uget() < yystateStack.numTops(); ++yyi) 2728*cda5da8dSAndroid Build Coastguard Worker if (yyi != yyk && yystateStack.topAt(yyi) != YY_NULLPTR) 2729*cda5da8dSAndroid Build Coastguard Worker { 2730*cda5da8dSAndroid Build Coastguard Worker const glr_state* yysplit = yystateStack.yysplitPoint; 2731*cda5da8dSAndroid Build Coastguard Worker glr_state* yyp = yystateStack.topAt(yyi); 2732*cda5da8dSAndroid Build Coastguard Worker while (yyp != yys && yyp != yysplit 2733*cda5da8dSAndroid Build Coastguard Worker && yyp->yyposn >= yyposn) 2734*cda5da8dSAndroid Build Coastguard Worker { 2735*cda5da8dSAndroid Build Coastguard Worker if (yyp->yylrState == yynewLRState 2736*cda5da8dSAndroid Build Coastguard Worker && yyp->pred() == yys) 2737*cda5da8dSAndroid Build Coastguard Worker { 2738*cda5da8dSAndroid Build Coastguard Worker yyaddDeferredAction (yyk, yyp, yys0, yyrule); 2739*cda5da8dSAndroid Build Coastguard Worker yystateStack.yytops.yymarkStackDeleted (yyk); 2740*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Merging stack " << yyk.get () 2741*cda5da8dSAndroid Build Coastguard Worker << " into stack " << yyi.get () << ".\n"; 2742*cda5da8dSAndroid Build Coastguard Worker return yyok; 2743*cda5da8dSAndroid Build Coastguard Worker } 2744*cda5da8dSAndroid Build Coastguard Worker yyp = yyp->pred(); 2745*cda5da8dSAndroid Build Coastguard Worker } 2746*cda5da8dSAndroid Build Coastguard Worker } 2747*cda5da8dSAndroid Build Coastguard Worker yystateStack.setTopAt(yyk, yys); 2748*cda5da8dSAndroid Build Coastguard Worker yyglrShiftDefer (yyk, yynewLRState, yyposn, yys0, yyrule); 2749*cda5da8dSAndroid Build Coastguard Worker } 2750*cda5da8dSAndroid Build Coastguard Worker return yyok; 2751*cda5da8dSAndroid Build Coastguard Worker } 2752*cda5da8dSAndroid Build Coastguard Worker 2753*cda5da8dSAndroid Build Coastguard Worker /** Shift stack #YYK of *YYSTACKP, to a new state corresponding to LR 2754*cda5da8dSAndroid Build Coastguard Worker * state YYLRSTATE, at input position YYPOSN, with the (unresolved) 2755*cda5da8dSAndroid Build Coastguard Worker * semantic value of YYRHS under the action for YYRULE. */ 2756*cda5da8dSAndroid Build Coastguard Worker void 2757*cda5da8dSAndroid Build Coastguard Worker yyglrShiftDefer (state_set_index yyk, state_num yylrState, 2758*cda5da8dSAndroid Build Coastguard Worker size_t yyposn, glr_state* yyrhs, rule_num yyrule) 2759*cda5da8dSAndroid Build Coastguard Worker { 2760*cda5da8dSAndroid Build Coastguard Worker glr_state& yynewState = yystateStack.yynewGLRState ( 2761*cda5da8dSAndroid Build Coastguard Worker glr_state (yylrState, yyposn)); 2762*cda5da8dSAndroid Build Coastguard Worker yynewState.setPred (yystateStack.topAt (yyk)); 2763*cda5da8dSAndroid Build Coastguard Worker yystateStack.setTopAt (yyk, &yynewState); 2764*cda5da8dSAndroid Build Coastguard Worker 2765*cda5da8dSAndroid Build Coastguard Worker /* Invokes yyreserveStack. */ 2766*cda5da8dSAndroid Build Coastguard Worker yyaddDeferredAction (yyk, &yynewState, yyrhs, yyrule); 2767*cda5da8dSAndroid Build Coastguard Worker } 2768*cda5da8dSAndroid Build Coastguard Worker 2769*cda5da8dSAndroid Build Coastguard Worker /** Shift to a new state on stack #YYK of *YYSTACKP, corresponding to LR 2770*cda5da8dSAndroid Build Coastguard Worker * state YYLRSTATE, at input position YYPOSN, with (resolved) semantic 2771*cda5da8dSAndroid Build Coastguard Worker * value YYVAL_ARG and source location YYLOC_ARG. */ 2772*cda5da8dSAndroid Build Coastguard Worker void 2773*cda5da8dSAndroid Build Coastguard Worker yyglrShift (state_set_index yyk, state_num yylrState, 2774*cda5da8dSAndroid Build Coastguard Worker size_t yyposn, 2775*cda5da8dSAndroid Build Coastguard Worker const value_type& yyval_arg]b4_locations_if([, const location_type& yyloc_arg])[) 2776*cda5da8dSAndroid Build Coastguard Worker { 2777*cda5da8dSAndroid Build Coastguard Worker glr_state& yynewState = yystateStack.yynewGLRState ( 2778*cda5da8dSAndroid Build Coastguard Worker glr_state (yylrState, yyposn, yyval_arg]b4_locations_if([, yyloc_arg])[)); 2779*cda5da8dSAndroid Build Coastguard Worker yynewState.setPred (yystateStack.topAt(yyk)); 2780*cda5da8dSAndroid Build Coastguard Worker yystateStack.setTopAt (yyk, &yynewState); 2781*cda5da8dSAndroid Build Coastguard Worker yyreserveGlrStack (); 2782*cda5da8dSAndroid Build Coastguard Worker } 2783*cda5da8dSAndroid Build Coastguard Worker 2784*cda5da8dSAndroid Build Coastguard Worker #if ]b4_api_PREFIX[DEBUG 2785*cda5da8dSAndroid Build Coastguard Worker void 2786*cda5da8dSAndroid Build Coastguard Worker yypstack (state_set_index yyk) const 2787*cda5da8dSAndroid Build Coastguard Worker { 2788*cda5da8dSAndroid Build Coastguard Worker yystateStack.yypstates (yystateStack.topAt (yyk)); 2789*cda5da8dSAndroid Build Coastguard Worker } 2790*cda5da8dSAndroid Build Coastguard Worker #endif 2791*cda5da8dSAndroid Build Coastguard Worker 2792*cda5da8dSAndroid Build Coastguard Worker glr_state* topState(state_set_index i) { 2793*cda5da8dSAndroid Build Coastguard Worker return yystateStack.topAt(i); 2794*cda5da8dSAndroid Build Coastguard Worker } 2795*cda5da8dSAndroid Build Coastguard Worker 2796*cda5da8dSAndroid Build Coastguard Worker glr_state* firstTopState() { 2797*cda5da8dSAndroid Build Coastguard Worker return yystateStack.firstTop(); 2798*cda5da8dSAndroid Build Coastguard Worker } 2799*cda5da8dSAndroid Build Coastguard Worker 2800*cda5da8dSAndroid Build Coastguard Worker private: 2801*cda5da8dSAndroid Build Coastguard Worker 2802*cda5da8dSAndroid Build Coastguard Worker void popall_ () 2803*cda5da8dSAndroid Build Coastguard Worker { 2804*cda5da8dSAndroid Build Coastguard Worker /* If the stack is well-formed, pop the stack until it is empty, 2805*cda5da8dSAndroid Build Coastguard Worker destroying its entries as we go. But free the stack regardless 2806*cda5da8dSAndroid Build Coastguard Worker of whether it is well-formed. */ 2807*cda5da8dSAndroid Build Coastguard Worker for (state_set_index k = create_state_set_index(0); k.uget() < yystateStack.numTops(); k += 1) 2808*cda5da8dSAndroid Build Coastguard Worker if (yystateStack.topAt(k) != YY_NULLPTR) 2809*cda5da8dSAndroid Build Coastguard Worker { 2810*cda5da8dSAndroid Build Coastguard Worker while (yystateStack.topAt(k) != YY_NULLPTR) 2811*cda5da8dSAndroid Build Coastguard Worker { 2812*cda5da8dSAndroid Build Coastguard Worker glr_state* state = topState(k);]b4_locations_if([[ 2813*cda5da8dSAndroid Build Coastguard Worker yyerror_range[1].getState().yyloc = state->yyloc;]])[ 2814*cda5da8dSAndroid Build Coastguard Worker if (state->pred() != YY_NULLPTR) 2815*cda5da8dSAndroid Build Coastguard Worker state->destroy ("Cleanup: popping", yyparser); 2816*cda5da8dSAndroid Build Coastguard Worker yystateStack.setTopAt(k, state->pred()); 2817*cda5da8dSAndroid Build Coastguard Worker yystateStack.pop_back(); 2818*cda5da8dSAndroid Build Coastguard Worker } 2819*cda5da8dSAndroid Build Coastguard Worker break; 2820*cda5da8dSAndroid Build Coastguard Worker } 2821*cda5da8dSAndroid Build Coastguard Worker } 2822*cda5da8dSAndroid Build Coastguard Worker 2823*cda5da8dSAndroid Build Coastguard Worker /** Resolve the previous YYN states starting at and including state YYS 2824*cda5da8dSAndroid Build Coastguard Worker * on *YYSTACKP. If result != yyok, some states may have been left 2825*cda5da8dSAndroid Build Coastguard Worker * unresolved possibly with empty semantic option chains. Regardless 2826*cda5da8dSAndroid Build Coastguard Worker * of whether result = yyok, each state has been left with consistent 2827*cda5da8dSAndroid Build Coastguard Worker * data so that destroy can be invoked if necessary. */ 2828*cda5da8dSAndroid Build Coastguard Worker YYRESULTTAG 2829*cda5da8dSAndroid Build Coastguard Worker yyresolveStates (glr_state& yys, int yyn) 2830*cda5da8dSAndroid Build Coastguard Worker { 2831*cda5da8dSAndroid Build Coastguard Worker if (0 < yyn) 2832*cda5da8dSAndroid Build Coastguard Worker { 2833*cda5da8dSAndroid Build Coastguard Worker YYASSERT (yys.pred() != YY_NULLPTR); 2834*cda5da8dSAndroid Build Coastguard Worker YYCHK (yyresolveStates (*yys.pred(), yyn-1)); 2835*cda5da8dSAndroid Build Coastguard Worker if (! yys.yyresolved) 2836*cda5da8dSAndroid Build Coastguard Worker YYCHK (yyresolveValue (yys)); 2837*cda5da8dSAndroid Build Coastguard Worker } 2838*cda5da8dSAndroid Build Coastguard Worker return yyok; 2839*cda5da8dSAndroid Build Coastguard Worker } 2840*cda5da8dSAndroid Build Coastguard Worker 2841*cda5da8dSAndroid Build Coastguard Worker static void 2842*cda5da8dSAndroid Build Coastguard Worker yyuserMerge (int yyn, value_type& yy0, value_type& yy1) 2843*cda5da8dSAndroid Build Coastguard Worker { 2844*cda5da8dSAndroid Build Coastguard Worker YY_USE (yy0); 2845*cda5da8dSAndroid Build Coastguard Worker YY_USE (yy1); 2846*cda5da8dSAndroid Build Coastguard Worker 2847*cda5da8dSAndroid Build Coastguard Worker switch (yyn) 2848*cda5da8dSAndroid Build Coastguard Worker { 2849*cda5da8dSAndroid Build Coastguard Worker ]b4_mergers[ 2850*cda5da8dSAndroid Build Coastguard Worker default: break; 2851*cda5da8dSAndroid Build Coastguard Worker } 2852*cda5da8dSAndroid Build Coastguard Worker } 2853*cda5da8dSAndroid Build Coastguard Worker 2854*cda5da8dSAndroid Build Coastguard Worker /** Resolve the ambiguity represented in state YYS in *YYSTACKP, 2855*cda5da8dSAndroid Build Coastguard Worker * perform the indicated actions, and set the semantic value of YYS. 2856*cda5da8dSAndroid Build Coastguard Worker * If result != yyok, the chain of semantic options in YYS has been 2857*cda5da8dSAndroid Build Coastguard Worker * cleared instead or it has been left unmodified except that 2858*cda5da8dSAndroid Build Coastguard Worker * redundant options may have been removed. Regardless of whether 2859*cda5da8dSAndroid Build Coastguard Worker * result = yyok, YYS has been left with consistent data so that 2860*cda5da8dSAndroid Build Coastguard Worker * destroy can be invoked if necessary. */ 2861*cda5da8dSAndroid Build Coastguard Worker YYRESULTTAG 2862*cda5da8dSAndroid Build Coastguard Worker yyresolveValue (glr_state& yys) 2863*cda5da8dSAndroid Build Coastguard Worker { 2864*cda5da8dSAndroid Build Coastguard Worker semantic_option* yybest = yys.firstVal(); 2865*cda5da8dSAndroid Build Coastguard Worker YYASSERT(yybest != YY_NULLPTR); 2866*cda5da8dSAndroid Build Coastguard Worker bool yymerge = false; 2867*cda5da8dSAndroid Build Coastguard Worker YYRESULTTAG yyflag;]b4_locations_if([ 2868*cda5da8dSAndroid Build Coastguard Worker location_type *yylocp = &yys.yyloc;])[ 2869*cda5da8dSAndroid Build Coastguard Worker 2870*cda5da8dSAndroid Build Coastguard Worker semantic_option* yypPrev = yybest; 2871*cda5da8dSAndroid Build Coastguard Worker for (semantic_option* yyp = yybest->next(); 2872*cda5da8dSAndroid Build Coastguard Worker yyp != YY_NULLPTR; ) 2873*cda5da8dSAndroid Build Coastguard Worker { 2874*cda5da8dSAndroid Build Coastguard Worker if (yybest->isIdenticalTo (*yyp)) 2875*cda5da8dSAndroid Build Coastguard Worker { 2876*cda5da8dSAndroid Build Coastguard Worker yybest->mergeWith (*yyp); 2877*cda5da8dSAndroid Build Coastguard Worker yypPrev->setNext(yyp->next()); 2878*cda5da8dSAndroid Build Coastguard Worker yyp = yypPrev->next(); 2879*cda5da8dSAndroid Build Coastguard Worker } 2880*cda5da8dSAndroid Build Coastguard Worker else 2881*cda5da8dSAndroid Build Coastguard Worker { 2882*cda5da8dSAndroid Build Coastguard Worker switch (yypreference (*yybest, *yyp)) 2883*cda5da8dSAndroid Build Coastguard Worker { 2884*cda5da8dSAndroid Build Coastguard Worker case 0:]b4_locations_if([[ 2885*cda5da8dSAndroid Build Coastguard Worker yyresolveLocations (yys, 1);]])[ 2886*cda5da8dSAndroid Build Coastguard Worker return yystateStack.yyreportAmbiguity (*yybest, *yyp, yyparser]b4_locations_if([, *yylocp])[); 2887*cda5da8dSAndroid Build Coastguard Worker break; 2888*cda5da8dSAndroid Build Coastguard Worker case 1: 2889*cda5da8dSAndroid Build Coastguard Worker yymerge = true; 2890*cda5da8dSAndroid Build Coastguard Worker break; 2891*cda5da8dSAndroid Build Coastguard Worker case 2: 2892*cda5da8dSAndroid Build Coastguard Worker break; 2893*cda5da8dSAndroid Build Coastguard Worker case 3: 2894*cda5da8dSAndroid Build Coastguard Worker yybest = yyp; 2895*cda5da8dSAndroid Build Coastguard Worker yymerge = false; 2896*cda5da8dSAndroid Build Coastguard Worker break; 2897*cda5da8dSAndroid Build Coastguard Worker default: 2898*cda5da8dSAndroid Build Coastguard Worker /* This cannot happen so it is not worth a YYASSERT (false), 2899*cda5da8dSAndroid Build Coastguard Worker but some compilers complain if the default case is 2900*cda5da8dSAndroid Build Coastguard Worker omitted. */ 2901*cda5da8dSAndroid Build Coastguard Worker break; 2902*cda5da8dSAndroid Build Coastguard Worker } 2903*cda5da8dSAndroid Build Coastguard Worker yypPrev = yyp; 2904*cda5da8dSAndroid Build Coastguard Worker yyp = yyp->next(); 2905*cda5da8dSAndroid Build Coastguard Worker } 2906*cda5da8dSAndroid Build Coastguard Worker } 2907*cda5da8dSAndroid Build Coastguard Worker 2908*cda5da8dSAndroid Build Coastguard Worker value_type val; 2909*cda5da8dSAndroid Build Coastguard Worker if (yymerge) 2910*cda5da8dSAndroid Build Coastguard Worker { 2911*cda5da8dSAndroid Build Coastguard Worker int yyprec = yydprec[yybest->yyrule]; 2912*cda5da8dSAndroid Build Coastguard Worker yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[); 2913*cda5da8dSAndroid Build Coastguard Worker if (yyflag == yyok) 2914*cda5da8dSAndroid Build Coastguard Worker for (semantic_option* yyp = yybest->next(); 2915*cda5da8dSAndroid Build Coastguard Worker yyp != YY_NULLPTR; 2916*cda5da8dSAndroid Build Coastguard Worker yyp = yyp->next()) 2917*cda5da8dSAndroid Build Coastguard Worker { 2918*cda5da8dSAndroid Build Coastguard Worker if (yyprec == yydprec[yyp->yyrule]) 2919*cda5da8dSAndroid Build Coastguard Worker { 2920*cda5da8dSAndroid Build Coastguard Worker value_type yyval_other;]b4_locations_if([ 2921*cda5da8dSAndroid Build Coastguard Worker location_type yydummy;])[ 2922*cda5da8dSAndroid Build Coastguard Worker yyflag = yyresolveAction (*yyp, &yyval_other]b4_locations_if([, &yydummy])[); 2923*cda5da8dSAndroid Build Coastguard Worker if (yyflag != yyok) 2924*cda5da8dSAndroid Build Coastguard Worker { 2925*cda5da8dSAndroid Build Coastguard Worker yyparser.yy_destroy_ ("Cleanup: discarding incompletely merged value for", 2926*cda5da8dSAndroid Build Coastguard Worker yy_accessing_symbol (yys.yylrState), 2927*cda5da8dSAndroid Build Coastguard Worker this->yyla.value]b4_locations_if([, *yylocp])[); 2928*cda5da8dSAndroid Build Coastguard Worker break; 2929*cda5da8dSAndroid Build Coastguard Worker } 2930*cda5da8dSAndroid Build Coastguard Worker yyuserMerge (yymerger[yyp->yyrule], val, yyval_other);]b4_variant_if([[ 2931*cda5da8dSAndroid Build Coastguard Worker // FIXME: User destructors. 2932*cda5da8dSAndroid Build Coastguard Worker // Value type destructor. 2933*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[yyval_other]], [[template destroy]])])[ 2934*cda5da8dSAndroid Build Coastguard Worker } 2935*cda5da8dSAndroid Build Coastguard Worker } 2936*cda5da8dSAndroid Build Coastguard Worker } 2937*cda5da8dSAndroid Build Coastguard Worker else 2938*cda5da8dSAndroid Build Coastguard Worker yyflag = yyresolveAction (*yybest, &val]b4_locations_if([, yylocp])[); 2939*cda5da8dSAndroid Build Coastguard Worker 2940*cda5da8dSAndroid Build Coastguard Worker if (yyflag == yyok) 2941*cda5da8dSAndroid Build Coastguard Worker { 2942*cda5da8dSAndroid Build Coastguard Worker yys.yyresolved = true; 2943*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN]b4_variant_if([[ 2944*cda5da8dSAndroid Build Coastguard Worker new (&yys.value ()) value_type (); 2945*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_variant([yy_accessing_symbol (yys.yylrState)], 2946*cda5da8dSAndroid Build Coastguard Worker [yys.value ()], [copy], [val])], [[ 2947*cda5da8dSAndroid Build Coastguard Worker new (&yys.value ()) value_type (val);]])[ 2948*cda5da8dSAndroid Build Coastguard Worker 2949*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_MAYBE_UNINITIALIZED_END 2950*cda5da8dSAndroid Build Coastguard Worker } 2951*cda5da8dSAndroid Build Coastguard Worker else 2952*cda5da8dSAndroid Build Coastguard Worker yys.setFirstVal(YY_NULLPTR); 2953*cda5da8dSAndroid Build Coastguard Worker ]b4_variant_if([[ 2954*cda5da8dSAndroid Build Coastguard Worker // FIXME: User destructors. 2955*cda5da8dSAndroid Build Coastguard Worker // Value type destructor. 2956*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_variant([[yy_accessing_symbol (yys.yylrState)]], [[val]], [[template destroy]])])[ 2957*cda5da8dSAndroid Build Coastguard Worker return yyflag; 2958*cda5da8dSAndroid Build Coastguard Worker } 2959*cda5da8dSAndroid Build Coastguard Worker 2960*cda5da8dSAndroid Build Coastguard Worker /** Resolve the states for the RHS of YYOPT on *YYSTACKP, perform its 2961*cda5da8dSAndroid Build Coastguard Worker * user action, and return the semantic value and location in *YYVALP 2962*cda5da8dSAndroid Build Coastguard Worker * and *YYLOCP. Regardless of whether result = yyok, all RHS states 2963*cda5da8dSAndroid Build Coastguard Worker * have been destroyed (assuming the user action destroys all RHS 2964*cda5da8dSAndroid Build Coastguard Worker * semantic values if invoked). */ 2965*cda5da8dSAndroid Build Coastguard Worker YYRESULTTAG 2966*cda5da8dSAndroid Build Coastguard Worker yyresolveAction (semantic_option& yyopt, value_type* yyvalp]b4_locations_if([, location_type* yylocp])[) 2967*cda5da8dSAndroid Build Coastguard Worker { 2968*cda5da8dSAndroid Build Coastguard Worker glr_state* yyoptState = yyopt.state(); 2969*cda5da8dSAndroid Build Coastguard Worker YYASSERT(yyoptState != YY_NULLPTR); 2970*cda5da8dSAndroid Build Coastguard Worker int yynrhs = yyrhsLength (yyopt.yyrule); 2971*cda5da8dSAndroid Build Coastguard Worker YYRESULTTAG yyflag = yyresolveStates (*yyoptState, yynrhs); 2972*cda5da8dSAndroid Build Coastguard Worker if (yyflag != yyok) 2973*cda5da8dSAndroid Build Coastguard Worker { 2974*cda5da8dSAndroid Build Coastguard Worker for (glr_state *yys = yyoptState; yynrhs > 0; yys = yys->pred(), yynrhs -= 1) 2975*cda5da8dSAndroid Build Coastguard Worker yys->destroy ("Cleanup: popping", yyparser); 2976*cda5da8dSAndroid Build Coastguard Worker return yyflag; 2977*cda5da8dSAndroid Build Coastguard Worker } 2978*cda5da8dSAndroid Build Coastguard Worker 2979*cda5da8dSAndroid Build Coastguard Worker glr_stack_item yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; 2980*cda5da8dSAndroid Build Coastguard Worker yyrhsVals[YYMAXRHS + YYMAXLEFT].getState().setPred(yyopt.state());]b4_locations_if([[ 2981*cda5da8dSAndroid Build Coastguard Worker if (yynrhs == 0) 2982*cda5da8dSAndroid Build Coastguard Worker /* Set default location. */ 2983*cda5da8dSAndroid Build Coastguard Worker yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].getState().yyloc = yyoptState->yyloc;]])[ 2984*cda5da8dSAndroid Build Coastguard Worker { 2985*cda5da8dSAndroid Build Coastguard Worker symbol_type yyla_current = std::move (this->yyla); 2986*cda5da8dSAndroid Build Coastguard Worker this->yyla = std::move (yyopt.yyla); 2987*cda5da8dSAndroid Build Coastguard Worker yyflag = yyuserAction (yyopt.yyrule, yynrhs, 2988*cda5da8dSAndroid Build Coastguard Worker yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, 2989*cda5da8dSAndroid Build Coastguard Worker create_state_set_index (-1), 2990*cda5da8dSAndroid Build Coastguard Worker yyvalp]b4_locations_if([, yylocp])[); 2991*cda5da8dSAndroid Build Coastguard Worker this->yyla = std::move (yyla_current); 2992*cda5da8dSAndroid Build Coastguard Worker } 2993*cda5da8dSAndroid Build Coastguard Worker return yyflag; 2994*cda5da8dSAndroid Build Coastguard Worker }]b4_locations_if([[ 2995*cda5da8dSAndroid Build Coastguard Worker 2996*cda5da8dSAndroid Build Coastguard Worker /** Resolve the locations for each of the YYN1 states in *YYSTACKP, 2997*cda5da8dSAndroid Build Coastguard Worker * ending at YYS1. Has no effect on previously resolved states. 2998*cda5da8dSAndroid Build Coastguard Worker * The first semantic option of a state is always chosen. */ 2999*cda5da8dSAndroid Build Coastguard Worker void 3000*cda5da8dSAndroid Build Coastguard Worker yyresolveLocations (glr_state &yys1, int yyn1) 3001*cda5da8dSAndroid Build Coastguard Worker { 3002*cda5da8dSAndroid Build Coastguard Worker if (0 < yyn1) 3003*cda5da8dSAndroid Build Coastguard Worker { 3004*cda5da8dSAndroid Build Coastguard Worker yyresolveLocations (*yys1.pred(), yyn1 - 1); 3005*cda5da8dSAndroid Build Coastguard Worker if (!yys1.yyresolved) 3006*cda5da8dSAndroid Build Coastguard Worker { 3007*cda5da8dSAndroid Build Coastguard Worker glr_stack_item yyrhsloc[1 + YYMAXRHS]; 3008*cda5da8dSAndroid Build Coastguard Worker YYASSERT (yys1.firstVal() != YY_NULLPTR); 3009*cda5da8dSAndroid Build Coastguard Worker semantic_option& yyoption = *yys1.firstVal(); 3010*cda5da8dSAndroid Build Coastguard Worker const int yynrhs = yyrhsLength (yyoption.yyrule); 3011*cda5da8dSAndroid Build Coastguard Worker if (0 < yynrhs) 3012*cda5da8dSAndroid Build Coastguard Worker { 3013*cda5da8dSAndroid Build Coastguard Worker yyresolveLocations (*yyoption.state(), yynrhs); 3014*cda5da8dSAndroid Build Coastguard Worker const glr_state *yys = yyoption.state(); 3015*cda5da8dSAndroid Build Coastguard Worker for (int yyn = yynrhs; yyn > 0; yyn -= 1) 3016*cda5da8dSAndroid Build Coastguard Worker { 3017*cda5da8dSAndroid Build Coastguard Worker yyrhsloc[yyn].getState().yyloc = yys->yyloc; 3018*cda5da8dSAndroid Build Coastguard Worker yys = yys->pred(); 3019*cda5da8dSAndroid Build Coastguard Worker } 3020*cda5da8dSAndroid Build Coastguard Worker } 3021*cda5da8dSAndroid Build Coastguard Worker else 3022*cda5da8dSAndroid Build Coastguard Worker { 3023*cda5da8dSAndroid Build Coastguard Worker /* Both yyresolveAction and yyresolveLocations traverse the GSS 3024*cda5da8dSAndroid Build Coastguard Worker in reverse rightmost order. It is only necessary to invoke 3025*cda5da8dSAndroid Build Coastguard Worker yyresolveLocations on a subforest for which yyresolveAction 3026*cda5da8dSAndroid Build Coastguard Worker would have been invoked next had an ambiguity not been 3027*cda5da8dSAndroid Build Coastguard Worker detected. Thus the location of the previous state (but not 3028*cda5da8dSAndroid Build Coastguard Worker necessarily the previous state itself) is guaranteed to be 3029*cda5da8dSAndroid Build Coastguard Worker resolved already. */ 3030*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_NULL_DEREFERENCE_BEGIN 3031*cda5da8dSAndroid Build Coastguard Worker yyrhsloc[0].getState().yyloc = yyoption.state()->yyloc; 3032*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_NULL_DEREFERENCE_END 3033*cda5da8dSAndroid Build Coastguard Worker } 3034*cda5da8dSAndroid Build Coastguard Worker YYLLOC_DEFAULT ((yys1.yyloc), yyrhsloc, yynrhs); 3035*cda5da8dSAndroid Build Coastguard Worker } 3036*cda5da8dSAndroid Build Coastguard Worker } 3037*cda5da8dSAndroid Build Coastguard Worker }]])[ 3038*cda5da8dSAndroid Build Coastguard Worker 3039*cda5da8dSAndroid Build Coastguard Worker /** If yytoken is empty, fetch the next token. */ 3040*cda5da8dSAndroid Build Coastguard Worker void 3041*cda5da8dSAndroid Build Coastguard Worker yyget_token () 3042*cda5da8dSAndroid Build Coastguard Worker { 3043*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_param_use()dnl 3044*cda5da8dSAndroid Build Coastguard Worker [ if (this->yyla.empty ()) 3045*cda5da8dSAndroid Build Coastguard Worker { 3046*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Reading a token\n"; 3047*cda5da8dSAndroid Build Coastguard Worker #if YY_EXCEPTIONS 3048*cda5da8dSAndroid Build Coastguard Worker try 3049*cda5da8dSAndroid Build Coastguard Worker #endif // YY_EXCEPTIONS 3050*cda5da8dSAndroid Build Coastguard Worker {]b4_token_ctor_if([[ 3051*cda5da8dSAndroid Build Coastguard Worker symbol_type yylookahead (]b4_yylex[); 3052*cda5da8dSAndroid Build Coastguard Worker yyla.move (yylookahead);]], [[ 3053*cda5da8dSAndroid Build Coastguard Worker yyla.kind_ = yyparser.yytranslate_ (]b4_yylex[);]])[ 3054*cda5da8dSAndroid Build Coastguard Worker } 3055*cda5da8dSAndroid Build Coastguard Worker #if YY_EXCEPTIONS 3056*cda5da8dSAndroid Build Coastguard Worker catch (const parser_type::syntax_error& yyexc) 3057*cda5da8dSAndroid Build Coastguard Worker { 3058*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Caught exception: " << yyexc.what () << '\n';]b4_locations_if([ 3059*cda5da8dSAndroid Build Coastguard Worker this->yyla.location = yyexc.location;])[ 3060*cda5da8dSAndroid Build Coastguard Worker yyparser.error (]b4_locations_if([this->yyla.location, ])[yyexc.what ()); 3061*cda5da8dSAndroid Build Coastguard Worker // Map errors caught in the scanner to the error token, so that error 3062*cda5da8dSAndroid Build Coastguard Worker // handling is started. 3063*cda5da8dSAndroid Build Coastguard Worker this->yyla.kind_ = ]b4_symbol(error, kind)[; 3064*cda5da8dSAndroid Build Coastguard Worker } 3065*cda5da8dSAndroid Build Coastguard Worker } 3066*cda5da8dSAndroid Build Coastguard Worker #endif // YY_EXCEPTIONS 3067*cda5da8dSAndroid Build Coastguard Worker if (this->yyla.kind () == ]b4_symbol(eof, kind)[) 3068*cda5da8dSAndroid Build Coastguard Worker YYCDEBUG << "Now at end of input.\n"; 3069*cda5da8dSAndroid Build Coastguard Worker else 3070*cda5da8dSAndroid Build Coastguard Worker YY_SYMBOL_PRINT ("Next token is", this->yyla.kind (), this->yyla.value, this->yyla.location); 3071*cda5da8dSAndroid Build Coastguard Worker } 3072*cda5da8dSAndroid Build Coastguard Worker 3073*cda5da8dSAndroid Build Coastguard Worker 3074*cda5da8dSAndroid Build Coastguard Worker /* Bison grammar-table manipulation. */ 3075*cda5da8dSAndroid Build Coastguard Worker 3076*cda5da8dSAndroid Build Coastguard Worker /** The action to take in YYSTATE on seeing YYTOKEN. 3077*cda5da8dSAndroid Build Coastguard Worker * Result R means 3078*cda5da8dSAndroid Build Coastguard Worker * R < 0: Reduce on rule -R. 3079*cda5da8dSAndroid Build Coastguard Worker * R = 0: Error. 3080*cda5da8dSAndroid Build Coastguard Worker * R > 0: Shift to state R. 3081*cda5da8dSAndroid Build Coastguard Worker * Set *YYCONFLICTS to a pointer into yyconfl to a 0-terminated list 3082*cda5da8dSAndroid Build Coastguard Worker * of conflicting reductions. 3083*cda5da8dSAndroid Build Coastguard Worker */ 3084*cda5da8dSAndroid Build Coastguard Worker static int 3085*cda5da8dSAndroid Build Coastguard Worker yygetLRActions (state_num yystate, symbol_kind_type yytoken, const short*& yyconflicts) 3086*cda5da8dSAndroid Build Coastguard Worker { 3087*cda5da8dSAndroid Build Coastguard Worker int yyindex = yypact[yystate] + yytoken; 3088*cda5da8dSAndroid Build Coastguard Worker if (yytoken == ]b4_symbol(error, kind)[) 3089*cda5da8dSAndroid Build Coastguard Worker { 3090*cda5da8dSAndroid Build Coastguard Worker // This is the error token. 3091*cda5da8dSAndroid Build Coastguard Worker yyconflicts = yyconfl; 3092*cda5da8dSAndroid Build Coastguard Worker return 0; 3093*cda5da8dSAndroid Build Coastguard Worker } 3094*cda5da8dSAndroid Build Coastguard Worker else if (yy_is_defaulted_state (yystate) 3095*cda5da8dSAndroid Build Coastguard Worker || yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken) 3096*cda5da8dSAndroid Build Coastguard Worker { 3097*cda5da8dSAndroid Build Coastguard Worker yyconflicts = yyconfl; 3098*cda5da8dSAndroid Build Coastguard Worker return -yydefact[yystate]; 3099*cda5da8dSAndroid Build Coastguard Worker } 3100*cda5da8dSAndroid Build Coastguard Worker else if (! yytable_value_is_error (yytable[yyindex])) 3101*cda5da8dSAndroid Build Coastguard Worker { 3102*cda5da8dSAndroid Build Coastguard Worker yyconflicts = yyconfl + yyconflp[yyindex]; 3103*cda5da8dSAndroid Build Coastguard Worker return yytable[yyindex]; 3104*cda5da8dSAndroid Build Coastguard Worker } 3105*cda5da8dSAndroid Build Coastguard Worker else 3106*cda5da8dSAndroid Build Coastguard Worker { 3107*cda5da8dSAndroid Build Coastguard Worker yyconflicts = yyconfl + yyconflp[yyindex]; 3108*cda5da8dSAndroid Build Coastguard Worker return 0; 3109*cda5da8dSAndroid Build Coastguard Worker } 3110*cda5da8dSAndroid Build Coastguard Worker } 3111*cda5da8dSAndroid Build Coastguard Worker 3112*cda5da8dSAndroid Build Coastguard Worker /** Compute post-reduction state. 3113*cda5da8dSAndroid Build Coastguard Worker * \param yystate the current state 3114*cda5da8dSAndroid Build Coastguard Worker * \param yysym the nonterminal to push on the stack 3115*cda5da8dSAndroid Build Coastguard Worker */ 3116*cda5da8dSAndroid Build Coastguard Worker static state_num 3117*cda5da8dSAndroid Build Coastguard Worker yyLRgotoState (state_num yystate, symbol_kind_type yysym) 3118*cda5da8dSAndroid Build Coastguard Worker { 3119*cda5da8dSAndroid Build Coastguard Worker const int yyr = yypgoto[yysym - YYNTOKENS] + yystate; 3120*cda5da8dSAndroid Build Coastguard Worker if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate) 3121*cda5da8dSAndroid Build Coastguard Worker return yytable[yyr]; 3122*cda5da8dSAndroid Build Coastguard Worker else 3123*cda5da8dSAndroid Build Coastguard Worker return yydefgoto[yysym - YYNTOKENS]; 3124*cda5da8dSAndroid Build Coastguard Worker } 3125*cda5da8dSAndroid Build Coastguard Worker 3126*cda5da8dSAndroid Build Coastguard Worker static bool 3127*cda5da8dSAndroid Build Coastguard Worker yypact_value_is_default (state_num yystate) 3128*cda5da8dSAndroid Build Coastguard Worker { 3129*cda5da8dSAndroid Build Coastguard Worker return ]b4_table_value_equals([[pact]], [[yystate]], [b4_pact_ninf], [YYPACT_NINF])[; 3130*cda5da8dSAndroid Build Coastguard Worker } 3131*cda5da8dSAndroid Build Coastguard Worker 3132*cda5da8dSAndroid Build Coastguard Worker static bool 3133*cda5da8dSAndroid Build Coastguard Worker yytable_value_is_error (int yytable_value YY_ATTRIBUTE_UNUSED) 3134*cda5da8dSAndroid Build Coastguard Worker { 3135*cda5da8dSAndroid Build Coastguard Worker return ]b4_table_value_equals([[table]], [[yytable_value]], [b4_table_ninf], [YYTABLE_NINF])[; 3136*cda5da8dSAndroid Build Coastguard Worker } 3137*cda5da8dSAndroid Build Coastguard Worker 3138*cda5da8dSAndroid Build Coastguard Worker static bool 3139*cda5da8dSAndroid Build Coastguard Worker yy_is_shift_action (int yyaction) YY_NOEXCEPT 3140*cda5da8dSAndroid Build Coastguard Worker { 3141*cda5da8dSAndroid Build Coastguard Worker return 0 < yyaction; 3142*cda5da8dSAndroid Build Coastguard Worker } 3143*cda5da8dSAndroid Build Coastguard Worker 3144*cda5da8dSAndroid Build Coastguard Worker static bool 3145*cda5da8dSAndroid Build Coastguard Worker yy_is_error_action (int yyaction) YY_NOEXCEPT 3146*cda5da8dSAndroid Build Coastguard Worker { 3147*cda5da8dSAndroid Build Coastguard Worker return yyaction == 0; 3148*cda5da8dSAndroid Build Coastguard Worker } 3149*cda5da8dSAndroid Build Coastguard Worker 3150*cda5da8dSAndroid Build Coastguard Worker /** Whether LR state YYSTATE has only a default reduction 3151*cda5da8dSAndroid Build Coastguard Worker * (regardless of token). */ 3152*cda5da8dSAndroid Build Coastguard Worker static bool 3153*cda5da8dSAndroid Build Coastguard Worker yy_is_defaulted_state (state_num yystate) 3154*cda5da8dSAndroid Build Coastguard Worker { 3155*cda5da8dSAndroid Build Coastguard Worker return yypact_value_is_default (yypact[yystate]); 3156*cda5da8dSAndroid Build Coastguard Worker } 3157*cda5da8dSAndroid Build Coastguard Worker 3158*cda5da8dSAndroid Build Coastguard Worker /** The default reduction for YYSTATE, assuming it has one. */ 3159*cda5da8dSAndroid Build Coastguard Worker static rule_num 3160*cda5da8dSAndroid Build Coastguard Worker yy_default_action (state_num yystate) 3161*cda5da8dSAndroid Build Coastguard Worker { 3162*cda5da8dSAndroid Build Coastguard Worker return yydefact[yystate]; 3163*cda5da8dSAndroid Build Coastguard Worker } 3164*cda5da8dSAndroid Build Coastguard Worker 3165*cda5da8dSAndroid Build Coastguard Worker /* GLRStacks */ 3166*cda5da8dSAndroid Build Coastguard Worker 3167*cda5da8dSAndroid Build Coastguard Worker /** Y0 and Y1 represent two possible actions to take in a given 3168*cda5da8dSAndroid Build Coastguard Worker * parsing state; return 0 if no combination is possible, 3169*cda5da8dSAndroid Build Coastguard Worker * 1 if user-mergeable, 2 if Y0 is preferred, 3 if Y1 is preferred. */ 3170*cda5da8dSAndroid Build Coastguard Worker static int 3171*cda5da8dSAndroid Build Coastguard Worker yypreference (const semantic_option& y0, const semantic_option& y1) 3172*cda5da8dSAndroid Build Coastguard Worker { 3173*cda5da8dSAndroid Build Coastguard Worker const rule_num r0 = y0.yyrule, r1 = y1.yyrule; 3174*cda5da8dSAndroid Build Coastguard Worker const int p0 = yydprec[r0], p1 = yydprec[r1]; 3175*cda5da8dSAndroid Build Coastguard Worker 3176*cda5da8dSAndroid Build Coastguard Worker if (p0 == p1) 3177*cda5da8dSAndroid Build Coastguard Worker { 3178*cda5da8dSAndroid Build Coastguard Worker if (yymerger[r0] == 0 || yymerger[r0] != yymerger[r1]) 3179*cda5da8dSAndroid Build Coastguard Worker return 0; 3180*cda5da8dSAndroid Build Coastguard Worker else 3181*cda5da8dSAndroid Build Coastguard Worker return 1; 3182*cda5da8dSAndroid Build Coastguard Worker } 3183*cda5da8dSAndroid Build Coastguard Worker else if (p0 == 0 || p1 == 0) 3184*cda5da8dSAndroid Build Coastguard Worker return 0; 3185*cda5da8dSAndroid Build Coastguard Worker else if (p0 < p1) 3186*cda5da8dSAndroid Build Coastguard Worker return 3; 3187*cda5da8dSAndroid Build Coastguard Worker else if (p1 < p0) 3188*cda5da8dSAndroid Build Coastguard Worker return 2; 3189*cda5da8dSAndroid Build Coastguard Worker else 3190*cda5da8dSAndroid Build Coastguard Worker return 0; 3191*cda5da8dSAndroid Build Coastguard Worker } 3192*cda5da8dSAndroid Build Coastguard Worker 3193*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_param_vars[ 3194*cda5da8dSAndroid Build Coastguard Worker }; // class ]b4_parser_class[::glr_stack 3195*cda5da8dSAndroid Build Coastguard Worker } // namespace ]b4_namespace_ref[ 3196*cda5da8dSAndroid Build Coastguard Worker 3197*cda5da8dSAndroid Build Coastguard Worker 3198*cda5da8dSAndroid Build Coastguard Worker #if ]b4_api_PREFIX[DEBUG 3199*cda5da8dSAndroid Build Coastguard Worker namespace 3200*cda5da8dSAndroid Build Coastguard Worker { 3201*cda5da8dSAndroid Build Coastguard Worker void 3202*cda5da8dSAndroid Build Coastguard Worker yypstack (const glr_stack& yystack, size_t yyk) 3203*cda5da8dSAndroid Build Coastguard Worker { 3204*cda5da8dSAndroid Build Coastguard Worker yystack.yypstack (create_state_set_index (static_cast<std::ptrdiff_t> (yyk))); 3205*cda5da8dSAndroid Build Coastguard Worker } 3206*cda5da8dSAndroid Build Coastguard Worker 3207*cda5da8dSAndroid Build Coastguard Worker void 3208*cda5da8dSAndroid Build Coastguard Worker yypdumpstack (const glr_stack& yystack) 3209*cda5da8dSAndroid Build Coastguard Worker { 3210*cda5da8dSAndroid Build Coastguard Worker yystack.yypdumpstack (); 3211*cda5da8dSAndroid Build Coastguard Worker } 3212*cda5da8dSAndroid Build Coastguard Worker } 3213*cda5da8dSAndroid Build Coastguard Worker #endif 3214*cda5da8dSAndroid Build Coastguard Worker 3215*cda5da8dSAndroid Build Coastguard Worker ]b4_namespace_open[ 3216*cda5da8dSAndroid Build Coastguard Worker /// Build a parser object. 3217*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class::b4_parser_class[ (]b4_parse_param_decl[)]m4_ifset([b4_parse_param], [ 3218*cda5da8dSAndroid Build Coastguard Worker :])[ 3219*cda5da8dSAndroid Build Coastguard Worker #if ]b4_api_PREFIX[DEBUG 3220*cda5da8dSAndroid Build Coastguard Worker ]m4_ifset([b4_parse_param], [ ], [ :])[yycdebug_ (&std::cerr)]m4_ifset([b4_parse_param], [,])[ 3221*cda5da8dSAndroid Build Coastguard Worker #endif]b4_parse_param_cons[ 3222*cda5da8dSAndroid Build Coastguard Worker {} 3223*cda5da8dSAndroid Build Coastguard Worker 3224*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class::~b4_parser_class[ () 3225*cda5da8dSAndroid Build Coastguard Worker {} 3226*cda5da8dSAndroid Build Coastguard Worker 3227*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::syntax_error::~syntax_error () YY_NOEXCEPT YY_NOTHROW 3228*cda5da8dSAndroid Build Coastguard Worker {} 3229*cda5da8dSAndroid Build Coastguard Worker 3230*cda5da8dSAndroid Build Coastguard Worker int 3231*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::operator() () 3232*cda5da8dSAndroid Build Coastguard Worker { 3233*cda5da8dSAndroid Build Coastguard Worker return parse (); 3234*cda5da8dSAndroid Build Coastguard Worker } 3235*cda5da8dSAndroid Build Coastguard Worker 3236*cda5da8dSAndroid Build Coastguard Worker int 3237*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::parse () 3238*cda5da8dSAndroid Build Coastguard Worker { 3239*cda5da8dSAndroid Build Coastguard Worker glr_stack yystack(YYINITDEPTH, *this]b4_user_args[); 3240*cda5da8dSAndroid Build Coastguard Worker return yystack.parse (); 3241*cda5da8dSAndroid Build Coastguard Worker } 3242*cda5da8dSAndroid Build Coastguard Worker 3243*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_error_bmatch([custom\|detailed], 3244*cda5da8dSAndroid Build Coastguard Worker [[ const char * 3245*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) 3246*cda5da8dSAndroid Build Coastguard Worker { 3247*cda5da8dSAndroid Build Coastguard Worker static const char *const yy_sname[] = 3248*cda5da8dSAndroid Build Coastguard Worker { 3249*cda5da8dSAndroid Build Coastguard Worker ]b4_symbol_names[ 3250*cda5da8dSAndroid Build Coastguard Worker };]b4_has_translations_if([[ 3251*cda5da8dSAndroid Build Coastguard Worker /* YYTRANSLATABLE[SYMBOL-NUM] -- Whether YY_SNAME[SYMBOL-NUM] is 3252*cda5da8dSAndroid Build Coastguard Worker internationalizable. */ 3253*cda5da8dSAndroid Build Coastguard Worker static ]b4_int_type_for([b4_translatable])[ yytranslatable[] = 3254*cda5da8dSAndroid Build Coastguard Worker { 3255*cda5da8dSAndroid Build Coastguard Worker ]b4_translatable[ 3256*cda5da8dSAndroid Build Coastguard Worker }; 3257*cda5da8dSAndroid Build Coastguard Worker return (yysymbol < YYNTOKENS && yytranslatable[yysymbol] 3258*cda5da8dSAndroid Build Coastguard Worker ? _(yy_sname[yysymbol]) 3259*cda5da8dSAndroid Build Coastguard Worker : yy_sname[yysymbol]);]], [[ 3260*cda5da8dSAndroid Build Coastguard Worker return yy_sname[yysymbol];]])[ 3261*cda5da8dSAndroid Build Coastguard Worker } 3262*cda5da8dSAndroid Build Coastguard Worker ]], 3263*cda5da8dSAndroid Build Coastguard Worker [simple], 3264*cda5da8dSAndroid Build Coastguard Worker [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ 3265*cda5da8dSAndroid Build Coastguard Worker const char * 3266*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) 3267*cda5da8dSAndroid Build Coastguard Worker { 3268*cda5da8dSAndroid Build Coastguard Worker return yytname_[yysymbol]; 3269*cda5da8dSAndroid Build Coastguard Worker } 3270*cda5da8dSAndroid Build Coastguard Worker #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[ 3271*cda5da8dSAndroid Build Coastguard Worker ]], 3272*cda5da8dSAndroid Build Coastguard Worker [verbose], 3273*cda5da8dSAndroid Build Coastguard Worker [[ /* Return YYSTR after stripping away unnecessary quotes and 3274*cda5da8dSAndroid Build Coastguard Worker backslashes, so that it's suitable for yyerror. The heuristic is 3275*cda5da8dSAndroid Build Coastguard Worker that double-quoting is unnecessary unless the string contains an 3276*cda5da8dSAndroid Build Coastguard Worker apostrophe, a comma, or backslash (other than backslash-backslash). 3277*cda5da8dSAndroid Build Coastguard Worker YYSTR is taken from yytname. */ 3278*cda5da8dSAndroid Build Coastguard Worker std::string 3279*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::yytnamerr_ (const char *yystr) 3280*cda5da8dSAndroid Build Coastguard Worker { 3281*cda5da8dSAndroid Build Coastguard Worker if (*yystr == '"') 3282*cda5da8dSAndroid Build Coastguard Worker { 3283*cda5da8dSAndroid Build Coastguard Worker std::string yyr; 3284*cda5da8dSAndroid Build Coastguard Worker char const *yyp = yystr; 3285*cda5da8dSAndroid Build Coastguard Worker 3286*cda5da8dSAndroid Build Coastguard Worker for (;;) 3287*cda5da8dSAndroid Build Coastguard Worker switch (*++yyp) 3288*cda5da8dSAndroid Build Coastguard Worker { 3289*cda5da8dSAndroid Build Coastguard Worker case '\'': 3290*cda5da8dSAndroid Build Coastguard Worker case ',': 3291*cda5da8dSAndroid Build Coastguard Worker goto do_not_strip_quotes; 3292*cda5da8dSAndroid Build Coastguard Worker 3293*cda5da8dSAndroid Build Coastguard Worker case '\\': 3294*cda5da8dSAndroid Build Coastguard Worker if (*++yyp != '\\') 3295*cda5da8dSAndroid Build Coastguard Worker goto do_not_strip_quotes; 3296*cda5da8dSAndroid Build Coastguard Worker else 3297*cda5da8dSAndroid Build Coastguard Worker goto append; 3298*cda5da8dSAndroid Build Coastguard Worker 3299*cda5da8dSAndroid Build Coastguard Worker append: 3300*cda5da8dSAndroid Build Coastguard Worker default: 3301*cda5da8dSAndroid Build Coastguard Worker yyr += *yyp; 3302*cda5da8dSAndroid Build Coastguard Worker break; 3303*cda5da8dSAndroid Build Coastguard Worker 3304*cda5da8dSAndroid Build Coastguard Worker case '"': 3305*cda5da8dSAndroid Build Coastguard Worker return yyr; 3306*cda5da8dSAndroid Build Coastguard Worker } 3307*cda5da8dSAndroid Build Coastguard Worker do_not_strip_quotes: ; 3308*cda5da8dSAndroid Build Coastguard Worker } 3309*cda5da8dSAndroid Build Coastguard Worker 3310*cda5da8dSAndroid Build Coastguard Worker return yystr; 3311*cda5da8dSAndroid Build Coastguard Worker } 3312*cda5da8dSAndroid Build Coastguard Worker 3313*cda5da8dSAndroid Build Coastguard Worker std::string 3314*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::symbol_name (symbol_kind_type yysymbol) 3315*cda5da8dSAndroid Build Coastguard Worker { 3316*cda5da8dSAndroid Build Coastguard Worker return yytnamerr_ (yytname_[yysymbol]); 3317*cda5da8dSAndroid Build Coastguard Worker } 3318*cda5da8dSAndroid Build Coastguard Worker ]])[ 3319*cda5da8dSAndroid Build Coastguard Worker 3320*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_error_bmatch([simple\|verbose], 3321*cda5da8dSAndroid Build Coastguard Worker [[#if ]b4_api_PREFIX[DEBUG]b4_tname_if([[ || 1]])[ 3322*cda5da8dSAndroid Build Coastguard Worker // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. 3323*cda5da8dSAndroid Build Coastguard Worker // First, the terminals, then, starting at \a YYNTOKENS, nonterminals. 3324*cda5da8dSAndroid Build Coastguard Worker const char* 3325*cda5da8dSAndroid Build Coastguard Worker const ]b4_parser_class[::yytname_[] = 3326*cda5da8dSAndroid Build Coastguard Worker { 3327*cda5da8dSAndroid Build Coastguard Worker ]b4_tname[ 3328*cda5da8dSAndroid Build Coastguard Worker }; 3329*cda5da8dSAndroid Build Coastguard Worker #endif 3330*cda5da8dSAndroid Build Coastguard Worker ]])[ 3331*cda5da8dSAndroid Build Coastguard Worker 3332*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_error_bmatch([custom\|detailed\|verbose], [[ 3333*cda5da8dSAndroid Build Coastguard Worker // ]b4_parser_class[::context. 3334*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::context::context (glr_stack& yystack, const symbol_type& yyla) 3335*cda5da8dSAndroid Build Coastguard Worker : yystack_ (yystack) 3336*cda5da8dSAndroid Build Coastguard Worker , yyla_ (yyla) 3337*cda5da8dSAndroid Build Coastguard Worker {} 3338*cda5da8dSAndroid Build Coastguard Worker 3339*cda5da8dSAndroid Build Coastguard Worker int 3340*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::context::expected_tokens (symbol_kind_type yyarg[], int yyargn) const 3341*cda5da8dSAndroid Build Coastguard Worker { 3342*cda5da8dSAndroid Build Coastguard Worker // Actual number of expected tokens 3343*cda5da8dSAndroid Build Coastguard Worker int yycount = 0; 3344*cda5da8dSAndroid Build Coastguard Worker const int yyn = yypact[yystack_.firstTopState()->yylrState]; 3345*cda5da8dSAndroid Build Coastguard Worker if (!yystack_.yypact_value_is_default (yyn)) 3346*cda5da8dSAndroid Build Coastguard Worker { 3347*cda5da8dSAndroid Build Coastguard Worker /* Start YYX at -YYN if negative to avoid negative indexes in 3348*cda5da8dSAndroid Build Coastguard Worker YYCHECK. In other words, skip the first -YYN actions for this 3349*cda5da8dSAndroid Build Coastguard Worker state because they are default actions. */ 3350*cda5da8dSAndroid Build Coastguard Worker const int yyxbegin = yyn < 0 ? -yyn : 0; 3351*cda5da8dSAndroid Build Coastguard Worker /* Stay within bounds of both yycheck and yytname. */ 3352*cda5da8dSAndroid Build Coastguard Worker const int yychecklim = YYLAST - yyn + 1; 3353*cda5da8dSAndroid Build Coastguard Worker const int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; 3354*cda5da8dSAndroid Build Coastguard Worker for (int yyx = yyxbegin; yyx < yyxend; ++yyx) 3355*cda5da8dSAndroid Build Coastguard Worker if (yycheck[yyx + yyn] == yyx && yyx != ]b4_symbol(error, kind)[ 3356*cda5da8dSAndroid Build Coastguard Worker && !yystack_.yytable_value_is_error (yytable[yyx + yyn])) 3357*cda5da8dSAndroid Build Coastguard Worker { 3358*cda5da8dSAndroid Build Coastguard Worker if (!yyarg) 3359*cda5da8dSAndroid Build Coastguard Worker ++yycount; 3360*cda5da8dSAndroid Build Coastguard Worker else if (yycount == yyargn) 3361*cda5da8dSAndroid Build Coastguard Worker return 0; 3362*cda5da8dSAndroid Build Coastguard Worker else 3363*cda5da8dSAndroid Build Coastguard Worker yyarg[yycount++] = YY_CAST (symbol_kind_type, yyx); 3364*cda5da8dSAndroid Build Coastguard Worker } 3365*cda5da8dSAndroid Build Coastguard Worker } 3366*cda5da8dSAndroid Build Coastguard Worker if (yyarg && yycount == 0 && 0 < yyargn) 3367*cda5da8dSAndroid Build Coastguard Worker yyarg[0] = ]b4_symbol(empty, kind)[; 3368*cda5da8dSAndroid Build Coastguard Worker return yycount; 3369*cda5da8dSAndroid Build Coastguard Worker } 3370*cda5da8dSAndroid Build Coastguard Worker 3371*cda5da8dSAndroid Build Coastguard Worker ]])[ 3372*cda5da8dSAndroid Build Coastguard Worker 3373*cda5da8dSAndroid Build Coastguard Worker ]b4_parse_error_bmatch([detailed\|verbose], [[ 3374*cda5da8dSAndroid Build Coastguard Worker int 3375*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::yy_syntax_error_arguments_ (const context& yyctx, 3376*cda5da8dSAndroid Build Coastguard Worker symbol_kind_type yyarg[], int yyargn) const 3377*cda5da8dSAndroid Build Coastguard Worker { 3378*cda5da8dSAndroid Build Coastguard Worker /* There are many possibilities here to consider: 3379*cda5da8dSAndroid Build Coastguard Worker - If this state is a consistent state with a default action, then 3380*cda5da8dSAndroid Build Coastguard Worker the only way this function was invoked is if the default action 3381*cda5da8dSAndroid Build Coastguard Worker is an error action. In that case, don't check for expected 3382*cda5da8dSAndroid Build Coastguard Worker tokens because there are none. 3383*cda5da8dSAndroid Build Coastguard Worker - The only way there can be no lookahead present (in yyla) is 3384*cda5da8dSAndroid Build Coastguard Worker if this state is a consistent state with a default action. 3385*cda5da8dSAndroid Build Coastguard Worker Thus, detecting the absence of a lookahead is sufficient to 3386*cda5da8dSAndroid Build Coastguard Worker determine that there is no unexpected or expected token to 3387*cda5da8dSAndroid Build Coastguard Worker report. In that case, just report a simple "syntax error". 3388*cda5da8dSAndroid Build Coastguard Worker - Don't assume there isn't a lookahead just because this state is 3389*cda5da8dSAndroid Build Coastguard Worker a consistent state with a default action. There might have 3390*cda5da8dSAndroid Build Coastguard Worker been a previous inconsistent state, consistent state with a 3391*cda5da8dSAndroid Build Coastguard Worker non-default action, or user semantic action that manipulated 3392*cda5da8dSAndroid Build Coastguard Worker yyla. (However, yyla is currently not documented for users.) 3393*cda5da8dSAndroid Build Coastguard Worker */ 3394*cda5da8dSAndroid Build Coastguard Worker 3395*cda5da8dSAndroid Build Coastguard Worker if (!yyctx.lookahead ().empty ()) 3396*cda5da8dSAndroid Build Coastguard Worker { 3397*cda5da8dSAndroid Build Coastguard Worker if (yyarg) 3398*cda5da8dSAndroid Build Coastguard Worker yyarg[0] = yyctx.token (); 3399*cda5da8dSAndroid Build Coastguard Worker int yyn = yyctx.expected_tokens (yyarg ? yyarg + 1 : yyarg, yyargn - 1); 3400*cda5da8dSAndroid Build Coastguard Worker return yyn + 1; 3401*cda5da8dSAndroid Build Coastguard Worker } 3402*cda5da8dSAndroid Build Coastguard Worker return 0; 3403*cda5da8dSAndroid Build Coastguard Worker } 3404*cda5da8dSAndroid Build Coastguard Worker 3405*cda5da8dSAndroid Build Coastguard Worker // Generate an error message. 3406*cda5da8dSAndroid Build Coastguard Worker std::string 3407*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::yysyntax_error_ (const context& yyctx) const 3408*cda5da8dSAndroid Build Coastguard Worker { 3409*cda5da8dSAndroid Build Coastguard Worker // Its maximum. 3410*cda5da8dSAndroid Build Coastguard Worker enum { YYARGS_MAX = 5 }; 3411*cda5da8dSAndroid Build Coastguard Worker // Arguments of yyformat. 3412*cda5da8dSAndroid Build Coastguard Worker symbol_kind_type yyarg[YYARGS_MAX]; 3413*cda5da8dSAndroid Build Coastguard Worker int yycount = yy_syntax_error_arguments_ (yyctx, yyarg, YYARGS_MAX); 3414*cda5da8dSAndroid Build Coastguard Worker 3415*cda5da8dSAndroid Build Coastguard Worker char const* yyformat = YY_NULLPTR; 3416*cda5da8dSAndroid Build Coastguard Worker switch (yycount) 3417*cda5da8dSAndroid Build Coastguard Worker { 3418*cda5da8dSAndroid Build Coastguard Worker #define YYCASE_(N, S) \ 3419*cda5da8dSAndroid Build Coastguard Worker case N: \ 3420*cda5da8dSAndroid Build Coastguard Worker yyformat = S; \ 3421*cda5da8dSAndroid Build Coastguard Worker break 3422*cda5da8dSAndroid Build Coastguard Worker default: // Avoid compiler warnings. 3423*cda5da8dSAndroid Build Coastguard Worker YYCASE_ (0, YY_("syntax error")); 3424*cda5da8dSAndroid Build Coastguard Worker YYCASE_ (1, YY_("syntax error, unexpected %s")); 3425*cda5da8dSAndroid Build Coastguard Worker YYCASE_ (2, YY_("syntax error, unexpected %s, expecting %s")); 3426*cda5da8dSAndroid Build Coastguard Worker YYCASE_ (3, YY_("syntax error, unexpected %s, expecting %s or %s")); 3427*cda5da8dSAndroid Build Coastguard Worker YYCASE_ (4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); 3428*cda5da8dSAndroid Build Coastguard Worker YYCASE_ (5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); 3429*cda5da8dSAndroid Build Coastguard Worker #undef YYCASE_ 3430*cda5da8dSAndroid Build Coastguard Worker } 3431*cda5da8dSAndroid Build Coastguard Worker 3432*cda5da8dSAndroid Build Coastguard Worker std::string yyres; 3433*cda5da8dSAndroid Build Coastguard Worker // Argument number. 3434*cda5da8dSAndroid Build Coastguard Worker std::ptrdiff_t yyi = 0; 3435*cda5da8dSAndroid Build Coastguard Worker for (char const* yyp = yyformat; *yyp; ++yyp) 3436*cda5da8dSAndroid Build Coastguard Worker if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) 3437*cda5da8dSAndroid Build Coastguard Worker { 3438*cda5da8dSAndroid Build Coastguard Worker yyres += symbol_name (yyarg[yyi++]); 3439*cda5da8dSAndroid Build Coastguard Worker ++yyp; 3440*cda5da8dSAndroid Build Coastguard Worker } 3441*cda5da8dSAndroid Build Coastguard Worker else 3442*cda5da8dSAndroid Build Coastguard Worker yyres += *yyp; 3443*cda5da8dSAndroid Build Coastguard Worker return yyres; 3444*cda5da8dSAndroid Build Coastguard Worker }]])[ 3445*cda5da8dSAndroid Build Coastguard Worker 3446*cda5da8dSAndroid Build Coastguard Worker void 3447*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::yy_destroy_ (const char* yymsg, symbol_kind_type yykind, 3448*cda5da8dSAndroid Build Coastguard Worker value_type& yyval]b4_locations_if([[, 3449*cda5da8dSAndroid Build Coastguard Worker location_type& yyloc]])[) 3450*cda5da8dSAndroid Build Coastguard Worker { 3451*cda5da8dSAndroid Build Coastguard Worker YY_USE (yyval);]b4_locations_if([[ 3452*cda5da8dSAndroid Build Coastguard Worker YY_USE (yyloc);]])[ 3453*cda5da8dSAndroid Build Coastguard Worker if (!yymsg) 3454*cda5da8dSAndroid Build Coastguard Worker yymsg = "Deleting"; 3455*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[& yyparser = *this; 3456*cda5da8dSAndroid Build Coastguard Worker YY_USE (yyparser); 3457*cda5da8dSAndroid Build Coastguard Worker YY_SYMBOL_PRINT (yymsg, yykind, yyval, yyloc); 3458*cda5da8dSAndroid Build Coastguard Worker 3459*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN 3460*cda5da8dSAndroid Build Coastguard Worker ]m4_do([m4_pushdef([b4_symbol_action], m4_defn([b4_symbol_action_for_yyval]))], 3461*cda5da8dSAndroid Build Coastguard Worker [b4_symbol_actions([destructor])], 3462*cda5da8dSAndroid Build Coastguard Worker [m4_popdef([b4_symbol_action])])[ 3463*cda5da8dSAndroid Build Coastguard Worker YY_IGNORE_MAYBE_UNINITIALIZED_END 3464*cda5da8dSAndroid Build Coastguard Worker } 3465*cda5da8dSAndroid Build Coastguard Worker 3466*cda5da8dSAndroid Build Coastguard Worker #if ]b4_api_PREFIX[DEBUG 3467*cda5da8dSAndroid Build Coastguard Worker /*--------------------. 3468*cda5da8dSAndroid Build Coastguard Worker | Print this symbol. | 3469*cda5da8dSAndroid Build Coastguard Worker `--------------------*/ 3470*cda5da8dSAndroid Build Coastguard Worker 3471*cda5da8dSAndroid Build Coastguard Worker void 3472*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::yy_symbol_value_print_ (symbol_kind_type yykind, 3473*cda5da8dSAndroid Build Coastguard Worker const value_type& yyval]b4_locations_if([[, 3474*cda5da8dSAndroid Build Coastguard Worker const location_type& yyloc]])[) const 3475*cda5da8dSAndroid Build Coastguard Worker {]b4_locations_if([[ 3476*cda5da8dSAndroid Build Coastguard Worker YY_USE (yyloc);]])[ 3477*cda5da8dSAndroid Build Coastguard Worker YY_USE (yyval); 3478*cda5da8dSAndroid Build Coastguard Worker std::ostream& yyo = debug_stream (); 3479*cda5da8dSAndroid Build Coastguard Worker YY_USE (yyo); 3480*cda5da8dSAndroid Build Coastguard Worker ]m4_do([m4_pushdef([b4_symbol_action], m4_defn([b4_symbol_action_for_yyval]))], 3481*cda5da8dSAndroid Build Coastguard Worker [b4_symbol_actions([printer])], 3482*cda5da8dSAndroid Build Coastguard Worker [m4_popdef([b4_symbol_action])])[ 3483*cda5da8dSAndroid Build Coastguard Worker } 3484*cda5da8dSAndroid Build Coastguard Worker 3485*cda5da8dSAndroid Build Coastguard Worker void 3486*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::yy_symbol_print_ (symbol_kind_type yykind, 3487*cda5da8dSAndroid Build Coastguard Worker const value_type& yyval]b4_locations_if([[, 3488*cda5da8dSAndroid Build Coastguard Worker const location_type& yyloc]])[) const 3489*cda5da8dSAndroid Build Coastguard Worker { 3490*cda5da8dSAndroid Build Coastguard Worker *yycdebug_ << (yykind < YYNTOKENS ? "token" : "nterm") 3491*cda5da8dSAndroid Build Coastguard Worker << ' ' << symbol_name (yykind) << " ("]b4_locations_if([[ 3492*cda5da8dSAndroid Build Coastguard Worker << yyloc << ": "]])[; 3493*cda5da8dSAndroid Build Coastguard Worker yy_symbol_value_print_ (yykind, yyval]b4_locations_if([[, yyloc]])[); 3494*cda5da8dSAndroid Build Coastguard Worker *yycdebug_ << ')'; 3495*cda5da8dSAndroid Build Coastguard Worker } 3496*cda5da8dSAndroid Build Coastguard Worker 3497*cda5da8dSAndroid Build Coastguard Worker std::ostream& 3498*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::debug_stream () const 3499*cda5da8dSAndroid Build Coastguard Worker { 3500*cda5da8dSAndroid Build Coastguard Worker return *yycdebug_; 3501*cda5da8dSAndroid Build Coastguard Worker } 3502*cda5da8dSAndroid Build Coastguard Worker 3503*cda5da8dSAndroid Build Coastguard Worker void 3504*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::set_debug_stream (std::ostream& o) 3505*cda5da8dSAndroid Build Coastguard Worker { 3506*cda5da8dSAndroid Build Coastguard Worker yycdebug_ = &o; 3507*cda5da8dSAndroid Build Coastguard Worker } 3508*cda5da8dSAndroid Build Coastguard Worker 3509*cda5da8dSAndroid Build Coastguard Worker 3510*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::debug_level_type 3511*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::debug_level () const 3512*cda5da8dSAndroid Build Coastguard Worker { 3513*cda5da8dSAndroid Build Coastguard Worker return yydebug; 3514*cda5da8dSAndroid Build Coastguard Worker } 3515*cda5da8dSAndroid Build Coastguard Worker 3516*cda5da8dSAndroid Build Coastguard Worker void 3517*cda5da8dSAndroid Build Coastguard Worker ]b4_parser_class[::set_debug_level (debug_level_type l) 3518*cda5da8dSAndroid Build Coastguard Worker { 3519*cda5da8dSAndroid Build Coastguard Worker // Actually, it is yydebug which is really used. 3520*cda5da8dSAndroid Build Coastguard Worker yydebug = l; 3521*cda5da8dSAndroid Build Coastguard Worker } 3522*cda5da8dSAndroid Build Coastguard Worker #endif // ]b4_api_PREFIX[DEBUG 3523*cda5da8dSAndroid Build Coastguard Worker 3524*cda5da8dSAndroid Build Coastguard Worker ]b4_token_ctor_if([], [b4_yytranslate_define([cc])])[ 3525*cda5da8dSAndroid Build Coastguard Worker 3526*cda5da8dSAndroid Build Coastguard Worker ]b4_token_ctor_if([], [[ 3527*cda5da8dSAndroid Build Coastguard Worker /*---------. 3528*cda5da8dSAndroid Build Coastguard Worker | symbol. | 3529*cda5da8dSAndroid Build Coastguard Worker `---------*/ 3530*cda5da8dSAndroid Build Coastguard Worker ]b4_public_types_define([cc])])[ 3531*cda5da8dSAndroid Build Coastguard Worker ]b4_namespace_close[]dnl 3532*cda5da8dSAndroid Build Coastguard Worker b4_epilogue[]dnl 3533*cda5da8dSAndroid Build Coastguard Worker b4_output_end 3534