1
0
mirror of https://github.com/golang/go synced 2024-11-22 04:14:42 -07:00

gc: bug219, bug239, bug240

Fixes #475.

R=ken2
CC=golang-dev
https://golang.org/cl/183157
This commit is contained in:
Russ Cox 2010-01-07 23:24:48 -08:00
parent c6f4d68667
commit 1b1f39eb86
4 changed files with 26 additions and 7 deletions

View File

@ -358,7 +358,6 @@ cannedimports(char *file, char *cp)
curio.cp = cp; curio.cp = cp;
curio.nlsemi = 0; curio.nlsemi = 0;
pkgmyname = S;
typecheckok = 1; typecheckok = 1;
incannedimport = 1; incannedimport = 1;
} }
@ -379,6 +378,12 @@ isfrog(int c)
return 0; return 0;
} }
typedef struct Loophack Loophack;
struct Loophack {
int v;
Loophack *next;
};
static int32 static int32
_yylex(void) _yylex(void)
{ {
@ -387,6 +392,8 @@ _yylex(void)
char *cp; char *cp;
Rune rune; Rune rune;
Sym *s; Sym *s;
static Loophack *lstk;
Loophack *h;
prevlineno = lineno; prevlineno = lineno;
@ -718,18 +725,27 @@ l0:
* non-parenthesized '{' becomes an LBODY. * non-parenthesized '{' becomes an LBODY.
* loophack is normally 0. * loophack is normally 0.
* a keyword makes it go up to 1. * a keyword makes it go up to 1.
* parens increment and decrement when loophack > 0. * parens push loophack onto a stack and go back to 0.
* a '{' with loophack == 1 becomes LBODY and disables loophack. * a '{' with loophack == 1 becomes LBODY and disables loophack.
* *
* i said it was clumsy. * i said it was clumsy.
*/ */
case '(': case '(':
if(loophack > 0) if(loophack || lstk != nil) {
loophack++; h = malloc(sizeof *h);
h->v = loophack;
h->next = lstk;
lstk = h;
loophack = 0;
}
goto lx; goto lx;
case ')': case ')':
if(loophack > 0) if(lstk != nil) {
loophack--; h = lstk;
loophack = h->v;
lstk = h->next;
free(h);
}
goto lx; goto lx;
case '{': case '{':
if(loophack == 1) { if(loophack == 1) {

View File

@ -14,6 +14,7 @@ func g1() {
if x := f(func() { if x := f(func() {
if {} if {}
}); { }); {
_ = x;
} }
} }
@ -22,6 +23,7 @@ func g2() {
if x := f(func() { if x := f(func() {
//if {} //if {}
}); { }); {
_ = x;
} }
} }
@ -31,5 +33,6 @@ func g3() {
if {} if {}
}); });
if { if {
_ = x;
} }
} }

View File

@ -6,7 +6,7 @@
package main package main
import . "unsafe" import . "unsafe" // ERROR "not used"
func main() { func main() {
var x int var x int