]> Cypherpunks repositories - gostls13.git/commitdiff
gc: bug274
authorRuss Cox <rsc@golang.org>
Thu, 15 Jul 2010 22:05:56 +0000 (15:05 -0700)
committerRuss Cox <rsc@golang.org>
Thu, 15 Jul 2010 22:05:56 +0000 (15:05 -0700)
R=ken2
CC=golang-dev
https://golang.org/cl/1742044

src/cmd/gc/go.h
src/cmd/gc/go.y
src/cmd/gc/lex.c
test/fixedbugs/bug274.go [moved from test/bugs/bug274.go with 100% similarity]

index 99e369ecaa8a240f0d6b0e4e6234e27b4b19baf4..f7591515fafd09531e267c211260ed13f300db56 100644 (file)
@@ -914,6 +914,8 @@ char*       lexname(int lex);
 void   mkpackage(char* pkgname);
 void   unimportfile(void);
 int32  yylex(void);
+extern int     yylast;
+extern int     yyprev;
 
 /*
  *     mparith1.c
index c46abaa564e8a729a1f32c762d0505f4e9ba41fc..8ded62be5ad716ad61e9472bd142d7104c7d632e 100644 (file)
@@ -515,10 +515,33 @@ switch_body:
        }
 
 caseblock:
-       case stmt_list
+       case
        {
+               // If the last token read by the lexer was consumed
+               // as part of the case, clear it (parser has cleared yychar).
+               // If the last token read by the lexer was the lookahead
+               // leave it alone (parser has it cached in yychar).
+               // This is so that the stmt_list action doesn't look at
+               // the case tokens if the stmt_list is empty.
+               yylast = yychar;
+       }
+       stmt_list
+       {
+               int last;
+
+               // This is the only place in the language where a statement
+               // list is not allowed to drop the final semicolon, because
+               // it's the only place where a statement list is not followed 
+               // by a closing brace.  Handle the error for pedantry.
+
+               // Find the final token of the statement list.
+               // yylast is lookahead; yyprev is last of stmt_list
+               last = yyprev;
+
+               if(last > 0 && last != ';' && yychar != '}')
+                       yyerror("missing statement after label");
                $$ = $1;
-               $$->nbody = $2;
+               $$->nbody = $3;
        }
 
 caseblock_list:
index 7b93001626809ae5448162c7acd339cc2c78582a..4399e28bd642c4017e8fc8cb641dfe9fc9bda59c 100644 (file)
@@ -14,6 +14,8 @@
 
 extern int yychar;
 int windows;
+int yyprev;
+int yylast;
 
 static void    lexinit(void);
 static void    lexfini(void);
@@ -1140,6 +1142,10 @@ yylex(void)
                curio.nlsemi = 0;
                break;
        }
+
+       // Track last two tokens returned by yylex.
+       yyprev = yylast;
+       yylast = lx;
        return lx;
 }
 
similarity index 100%
rename from test/bugs/bug274.go
rename to test/fixedbugs/bug274.go