aboutsummaryrefslogtreecommitdiff
path: root/tool/lemon.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2016-02-17 01:46:19 +0000
committerdrh <drh@noemail.net>2016-02-17 01:46:19 +0000
commitdabd04c656f37ef45786c25cb73bf8b517303eda (patch)
tree2b89058472f781cf38405459179bff1d62a42414 /tool/lemon.c
parent4dd0d3f81909f6a74479c1ac98e1983bb9409897 (diff)
downloadsqlite-dabd04c656f37ef45786c25cb73bf8b517303eda.tar.gz
sqlite-dabd04c656f37ef45786c25cb73bf8b517303eda.zip
Further improvements to the Lemon-generated code for yy_reduce().
FossilOrigin-Name: ef95a7d6490e33a9af4bc7b4b622de7328742ca7
Diffstat (limited to 'tool/lemon.c')
-rw-r--r--tool/lemon.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/tool/lemon.c b/tool/lemon.c
index c678fa0da..1f81717c7 100644
--- a/tool/lemon.c
+++ b/tool/lemon.c
@@ -3469,10 +3469,14 @@ PRIVATE char *append_str(const char *zText, int n, int p1, int p2){
** zCode is a string that is the action associated with a rule. Expand
** the symbols in this string so that the refer to elements of the parser
** stack.
+**
+** Return 1 if the expanded code requires that "yylhsminor" local variable
+** to be defined.
*/
-PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){
+PRIVATE int translate_code(struct lemon *lemp, struct rule *rp){
char *cp, *xp;
int i;
+ int rc = 0; /* True if yylhsminor is used */
char lhsused = 0; /* True if the LHS element has been used */
char lhsdirect; /* True if LHS writes directly into stack */
char used[MAXRHS]; /* True for each RHS element which is used */
@@ -3523,9 +3527,7 @@ PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){
if( lhsdirect ){
sprintf(zLhs, "yymsp[%d].minor.yy%d",1-rp->nrhs,rp->lhs->dtnum);
}else{
- append_str(0,0,0,0);
- append_str(" YYMINORTYPE yylhsminor;\n", 0, 0, 0);
- rp->codePrefix = Strsafe(append_str(0,0,0,0));
+ rc = 1;
sprintf(zLhs, "yylhsminor.yy%d",rp->lhs->dtnum);
}
@@ -3630,6 +3632,8 @@ PRIVATE void translate_code(struct lemon *lemp, struct rule *rp){
/* Suffix code generation complete */
cp = append_str(0,0,0,0);
if( cp ) rp->codeSuffix = Strsafe(cp);
+
+ return rc;
}
/*
@@ -4298,8 +4302,12 @@ void ReportTable(
tplt_xfer(lemp->name,in,out,&lineno);
/* Generate code which execution during each REDUCE action */
+ i = 0;
for(rp=lemp->rule; rp; rp=rp->next){
- translate_code(lemp, rp);
+ i += translate_code(lemp, rp);
+ }
+ if( i ){
+ fprintf(out," YYMINORTYPE yylhsminor;\n"); lineno++;
}
/* First output rules other than the default: rule */
for(rp=lemp->rule; rp; rp=rp->next){