Commit f37ee0f3 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile/internal/syntax: track column position at function end

Fixes #19576.

Change-Id: I11034fb08e989f6eb7d54bde873b92804223598d
Reviewed-on: https://go-review.googlesource.com/38291
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent c8f38b33
...@@ -325,7 +325,7 @@ func (p *noder) funcDecl(fun *syntax.FuncDecl) *Node { ...@@ -325,7 +325,7 @@ func (p *noder) funcDecl(fun *syntax.FuncDecl) *Node {
yyerror("go:nosplit and go:systemstack cannot be combined") yyerror("go:nosplit and go:systemstack cannot be combined")
} }
f.Func.Pragma = pragma f.Func.Pragma = pragma
lineno = makePos(fun.Pos().Base(), fun.EndLine, 0) lineno = Ctxt.PosTable.XPos(fun.Rbrace)
f.Func.Endlineno = lineno f.Func.Endlineno = lineno
funcbody(f) funcbody(f)
...@@ -451,14 +451,14 @@ func (p *noder) expr(expr syntax.Expr) *Node { ...@@ -451,14 +451,14 @@ func (p *noder) expr(expr syntax.Expr) *Node {
l[i] = p.wrapname(expr.ElemList[i], e) l[i] = p.wrapname(expr.ElemList[i], e)
} }
n.List.Set(l) n.List.Set(l)
lineno = makePos(expr.Pos().Base(), expr.EndLine, 0) lineno = Ctxt.PosTable.XPos(expr.Rbrace)
return n return n
case *syntax.KeyValueExpr: case *syntax.KeyValueExpr:
return p.nod(expr, OKEY, p.expr(expr.Key), p.wrapname(expr.Value, p.expr(expr.Value))) return p.nod(expr, OKEY, p.expr(expr.Key), p.wrapname(expr.Value, p.expr(expr.Value)))
case *syntax.FuncLit: case *syntax.FuncLit:
closurehdr(p.typeExpr(expr.Type)) closurehdr(p.typeExpr(expr.Type))
body := p.stmts(expr.Body) body := p.stmts(expr.Body)
lineno = makePos(expr.Pos().Base(), expr.EndLine, 0) lineno = Ctxt.PosTable.XPos(expr.Rbrace)
return p.setlineno(expr, closurebody(body)) return p.setlineno(expr, closurebody(body))
case *syntax.ParenExpr: case *syntax.ParenExpr:
return p.nod(expr, OPAREN, p.expr(expr.X), nil) return p.nod(expr, OPAREN, p.expr(expr.X), nil)
......
...@@ -100,13 +100,13 @@ type ( ...@@ -100,13 +100,13 @@ type (
// func Receiver Name Type { Body } // func Receiver Name Type { Body }
// func Receiver Name Type // func Receiver Name Type
FuncDecl struct { FuncDecl struct {
Attr map[string]bool // go:attr map Attr map[string]bool // go:attr map
Recv *Field // nil means regular function Recv *Field // nil means regular function
Name *Name Name *Name
Type *FuncType Type *FuncType
Body []Stmt // nil means no body (forward declaration) Body []Stmt // nil means no body (forward declaration)
Pragma Pragma // TODO(mdempsky): Cleaner solution. Pragma Pragma // TODO(mdempsky): Cleaner solution.
EndLine uint // TODO(mdempsky): Cleaner solution. Rbrace src.Pos // TODO(mdempsky): Cleaner solution.
decl decl
} }
) )
...@@ -146,8 +146,8 @@ type ( ...@@ -146,8 +146,8 @@ type (
CompositeLit struct { CompositeLit struct {
Type Expr // nil means no literal type Type Expr // nil means no literal type
ElemList []Expr ElemList []Expr
NKeys int // number of elements with keys NKeys int // number of elements with keys
EndLine uint // TODO(mdempsky): Cleaner solution. Rbrace src.Pos // TODO(mdempsky): Cleaner solution.
expr expr
} }
...@@ -159,9 +159,9 @@ type ( ...@@ -159,9 +159,9 @@ type (
// func Type { Body } // func Type { Body }
FuncLit struct { FuncLit struct {
Type *FuncType Type *FuncType
Body []Stmt Body []Stmt
EndLine uint // TODO(mdempsky): Cleaner solution. Rbrace src.Pos // TODO(mdempsky): Cleaner solution.
expr expr
} }
......
...@@ -480,10 +480,13 @@ func (p *parser) funcDecl() *FuncDecl { ...@@ -480,10 +480,13 @@ func (p *parser) funcDecl() *FuncDecl {
f.Name = p.name() f.Name = p.name()
f.Type = p.funcType() f.Type = p.funcType()
f.Body = p.funcBody() if p.got(_Lbrace) {
f.Body = p.funcBody()
f.Rbrace = p.pos()
p.want(_Rbrace)
}
f.Pragma = p.pragma f.Pragma = p.pragma
f.EndLine = p.line
// TODO(gri) deal with function properties // TODO(gri) deal with function properties
// if noescape && body != nil { // if noescape && body != nil {
...@@ -700,18 +703,17 @@ func (p *parser) operand(keep_parens bool) Expr { ...@@ -700,18 +703,17 @@ func (p *parser) operand(keep_parens bool) Expr {
pos := p.pos() pos := p.pos()
p.next() p.next()
t := p.funcType() t := p.funcType()
if p.tok == _Lbrace { if p.got(_Lbrace) {
p.fnest++
p.xnest++ p.xnest++
f := new(FuncLit) f := new(FuncLit)
f.pos = pos f.pos = pos
f.Type = t f.Type = t
f.Body = p.funcBody() f.Body = p.funcBody()
f.EndLine = p.line f.Rbrace = p.pos()
p.want(_Rbrace)
p.xnest-- p.xnest--
p.fnest--
return f return f
} }
return t return t
...@@ -920,7 +922,7 @@ func (p *parser) complitexpr() *CompositeLit { ...@@ -920,7 +922,7 @@ func (p *parser) complitexpr() *CompositeLit {
} }
} }
x.EndLine = p.line x.Rbrace = p.pos()
p.xnest-- p.xnest--
p.want(_Rbrace) p.want(_Rbrace)
...@@ -1148,18 +1150,14 @@ func (p *parser) funcBody() []Stmt { ...@@ -1148,18 +1150,14 @@ func (p *parser) funcBody() []Stmt {
defer p.trace("funcBody")() defer p.trace("funcBody")()
} }
if p.got(_Lbrace) { p.fnest++
p.fnest++ body := p.stmtList()
body := p.stmtList() p.fnest--
p.fnest--
p.want(_Rbrace)
if body == nil {
body = []Stmt{new(EmptyStmt)}
}
return body
}
return nil if body == nil {
body = []Stmt{new(EmptyStmt)}
}
return body
} }
// Result = Parameters | Type . // Result = Parameters | Type .
......
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