Commit 3d4d5ad0 authored by Robert Griesemer's avatar Robert Griesemer

defer statement

R=r
OCL=23542
CL=23542
parent 1ce17918
...@@ -1186,11 +1186,11 @@ func (P *Parser) ParseSimpleStat(range_ok bool) *AST.Stat { ...@@ -1186,11 +1186,11 @@ func (P *Parser) ParseSimpleStat(range_ok bool) *AST.Stat {
} }
func (P *Parser) ParseGoStat() *AST.Stat { func (P *Parser) ParseInvocationStat(keyword int) *AST.Stat {
P.Trace("GoStat"); P.Trace("InvocationStat");
s := AST.NewStat(P.pos, Scanner.GO); s := AST.NewStat(P.pos, keyword);
P.Expect(Scanner.GO); P.Expect(keyword);
s.Expr = P.ParseExpression(1); s.Expr = P.ParseExpression(1);
P.Ecart(); P.Ecart();
...@@ -1434,8 +1434,8 @@ func (P *Parser) ParseStatement() *AST.Stat { ...@@ -1434,8 +1434,8 @@ func (P *Parser) ParseStatement() *AST.Stat {
Scanner.LBRACK, Scanner.STRUCT, // composite type Scanner.LBRACK, Scanner.STRUCT, // composite type
Scanner.MUL, Scanner.AND, Scanner.ARROW: // unary Scanner.MUL, Scanner.AND, Scanner.ARROW: // unary
s = P.ParseSimpleStat(false); s = P.ParseSimpleStat(false);
case Scanner.GO: case Scanner.GO, Scanner.DEFER:
s = P.ParseGoStat(); s = P.ParseInvocationStat(P.tok);
case Scanner.RETURN: case Scanner.RETURN:
s = P.ParseReturnStat(); s = P.ParseReturnStat();
case Scanner.BREAK, Scanner.CONTINUE, Scanner.GOTO, Scanner.FALLTHROUGH: case Scanner.BREAK, Scanner.CONTINUE, Scanner.GOTO, Scanner.FALLTHROUGH:
......
...@@ -776,7 +776,9 @@ func (P *Printer) Stat(s *AST.Stat) { ...@@ -776,7 +776,9 @@ func (P *Printer) Stat(s *AST.Stat) {
P.indentation--; P.indentation--;
P.newlines = 1; P.newlines = 1;
case Scanner.GO, Scanner.RETURN, Scanner.FALLTHROUGH, Scanner.BREAK, Scanner.CONTINUE, Scanner.GOTO: case
Scanner.GO, Scanner.DEFER, Scanner.RETURN, Scanner.FALLTHROUGH,
Scanner.BREAK, Scanner.CONTINUE, Scanner.GOTO:
P.Token(s.Pos, s.Tok); P.Token(s.Pos, s.Tok);
if s.Expr != nil { if s.Expr != nil {
P.separator = blank; P.separator = blank;
......
...@@ -84,6 +84,7 @@ const ( ...@@ -84,6 +84,7 @@ const (
CONTINUE; CONTINUE;
DEFAULT; DEFAULT;
DEFER;
ELSE; ELSE;
FALLTHROUGH; FALLTHROUGH;
FOR; FOR;
...@@ -185,6 +186,7 @@ func TokenString(tok int) string { ...@@ -185,6 +186,7 @@ func TokenString(tok int) string {
case CONTINUE: return "continue"; case CONTINUE: return "continue";
case DEFAULT: return "default"; case DEFAULT: return "default";
case DEFER: return "defer";
case ELSE: return "else"; case ELSE: return "else";
case FALLTHROUGH: return "fallthrough"; case FALLTHROUGH: return "fallthrough";
case FOR: return "for"; case FOR: return "for";
......
...@@ -123,7 +123,7 @@ func f3(a *[]int, m map[string] int) { ...@@ -123,7 +123,7 @@ func f3(a *[]int, m map[string] int) {
var i string; var i string;
var x int; var x int;
for i, x = range m { for i, x = range m {
println(i, x); defer println(i, x);
} }
} }
......
...@@ -27,7 +27,7 @@ apply1() { ...@@ -27,7 +27,7 @@ apply1() {
# the following have semantic errors: bug039.go | bug040.go # the following have semantic errors: bug039.go | bug040.go
method1.go | selftest1.go | func3.go | \ method1.go | selftest1.go | func3.go | \
bug014.go | bug025.go | bug029.go | bug032.go | bug039.go | bug040.go | bug050.go | bug068.go | \ bug014.go | bug025.go | bug029.go | bug032.go | bug039.go | bug040.go | bug050.go | bug068.go | \
bug088.go | bug083.go | bug106.go | bug125.go | bug126.go | bug132.go ) ;; bug088.go | bug083.go | bug106.go | bug125.go | bug126.go | bug132.go | bug133.go ) ;;
* ) $1 $2; count $F;; * ) $1 $2; count $F;;
esac esac
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment