lemon: Sync with upstream, Jun 28, 2017

Change-Id: I4c6dbd018302fdf176e955e0e5e735a7aee22b10
Reviewed-on: https://code.wireshark.org/review/26669
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Anders 2018-03-28 07:22:19 +02:00 committed by Anders Broman
parent 6733df6e70
commit 85a0646490
2 changed files with 39 additions and 26 deletions

View File

@ -1530,8 +1530,7 @@ static char **azDefine = 0; /* Name of the -D macros */
/* This routine is called with the argument to each -D command-line option.
** Add the macro defined to the azDefine array.
*/
static void handle_D_option(void *arg){
char *z = (char *)arg;
static void handle_D_option(char *z) {
char **paz;
nDefine++;
azDefine = (char **) realloc(azDefine, sizeof(azDefine[0])*nDefine);
@ -1551,8 +1550,7 @@ static void handle_D_option(void *arg){
}
static char *user_templatename = NULL;
static void handle_T_option(void *arg){
char *z = (char *)arg;
static void handle_T_option(char *z) {
user_templatename = (char *) malloc( lemonStrlen(z)+1 );
MemoryCheck(user_templatename);
lemon_strcpy(user_templatename, z);
@ -3373,8 +3371,15 @@ PRIVATE int compute_action(struct lemon *lemp, struct action *ap)
{
int act;
switch( ap->type ){
case SHIFT: act = ap->x.stp->statenum; break;
case SHIFTREDUCE: act = ap->x.rp->iRule + lemp->nstate; break;
case SHIFT: act = ap->x.stp->statenum; break;
case SHIFTREDUCE: {
act = ap->x.rp->iRule + lemp->nstate;
/* Since a SHIFT is inherient after a prior REDUCE, convert any
** SHIFTREDUCE action with a nonterminal on the LHS into a simple
** REDUCE action: */
if (ap->sp->index >= lemp->nterminal) act += lemp->nrule;
break;
}
case REDUCE: act = ap->x.rp->iRule + lemp->nstate+lemp->nrule; break;
case ERROR: act = lemp->nstate + lemp->nrule*2; break;
case ACCEPT: act = lemp->nstate + lemp->nrule*2 + 1; break;
@ -4494,7 +4499,7 @@ void ReportTable(
** sequentually beginning with 0.
*/
for(rp=lemp->rule; rp; rp=rp->next){
fprintf(out," { %d, %d },\n",rp->lhs->index,rp->nrhs); lineno++;
fprintf(out, " { %d, %d },\n", rp->lhs->index, -rp->nrhs); lineno++;
}
tplt_xfer(lemp->name,in,out,&lineno);

View File

@ -221,6 +221,7 @@ struct yyParser {
yyStackEntry yystk0; /* First stack entry */
#else
yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
yyStackEntry *yystackEnd; /* Last entry in the stack */
#endif
};
typedef struct yyParser yyParser;
@ -338,6 +339,9 @@ static void ParseInit(void *yypParser){
pParser->yytos = pParser->yystack;
pParser->yystack[0].stateno = 0;
pParser->yystack[0].major = 0;
#if YYSTACKDEPTH>0
pParser->yystackEnd = &pParser->yystack[YYSTACKDEPTH - 1];
#endif
}
#ifndef Parse_ENGINEALWAYSONSTACK
@ -607,7 +611,7 @@ static void yy_shift(
}
#endif
#if YYSTACKDEPTH>0
if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH] ){
if (yypParser->yytos>yypParser->yystackEnd) {
yypParser->yytos--;
yyStackOverflow(yypParser);
return;
@ -635,8 +639,8 @@ static void yy_shift(
** is used during the reduce.
*/
static const struct {
YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
unsigned char nrhs; /* Number of right-hand side symbols in the rule */
YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
signed char nrhs; /* Negative of the number of RHS symbols in the rule */
} yyRuleInfo[] = {
%%
};
@ -661,7 +665,7 @@ static void yy_reduce(
if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
yysize = yyRuleInfo[yyruleno].nrhs;
fprintf(yyTraceFILE, "%sReduce [%s], go to state %d.\n", yyTracePrompt,
yyRuleName[yyruleno], yymsp[-yysize].stateno);
yyRuleName[yyruleno], yymsp[yysize].stateno);
}
#endif /* NDEBUG */
@ -676,7 +680,7 @@ static void yy_reduce(
}
#endif
#if YYSTACKDEPTH>0
if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH-1] ){
if (yypParser->yytos >= yypParser->yystackEnd) {
yyStackOverflow(yypParser);
return;
}
@ -707,20 +711,24 @@ static void yy_reduce(
assert( yyruleno<sizeof(yyRuleInfo)/sizeof(yyRuleInfo[0]) );
yygoto = yyRuleInfo[yyruleno].lhs;
yysize = yyRuleInfo[yyruleno].nrhs;
yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
if( yyact <= YY_MAX_SHIFTREDUCE ){
if( yyact>YY_MAX_SHIFT ){
yyact += YY_MIN_REDUCE - YY_MIN_SHIFTREDUCE;
}
yymsp -= yysize-1;
yypParser->yytos = yymsp;
yymsp->stateno = (YYACTIONTYPE)yyact;
yymsp->major = (YYCODETYPE)yygoto;
yyTraceShift(yypParser, yyact);
}else{
assert( yyact == YY_ACCEPT_ACTION );
yypParser->yytos -= yysize;
yy_accept(yypParser);
yyact = yy_find_reduce_action(yymsp[yysize].stateno, (YYCODETYPE)yygoto);
/* There are no SHIFTREDUCE actions on nonterminals because the table
** generator has simplified them to pure REDUCE actions. */
assert(!(yyact>YY_MAX_SHIFT && yyact <= YY_MAX_SHIFTREDUCE));
/* It is not possible for a REDUCE to be followed by an error */
assert(yyact != YY_ERROR_ACTION);
if (yyact == YY_ACCEPT_ACTION) {
yypParser->yytos += yysize;
yy_accept(yypParser);
} else {
yymsp += yysize + 1;
yypParser->yytos = yymsp;
yymsp->stateno = (YYACTIONTYPE)yyact;
yymsp->major = (YYCODETYPE)yygoto;
yyTraceShift(yypParser, yyact);
}
}