cmd/compile/internal/syntax: removed gcCompat code needed to pass orig. tests

The gcCompat mode was introduced to match the new parser's node position
setup exactly with the positions used by the original parser. Some of the
gcCompat adjustments were required to satisfy syntax error test cases,
and the rest were required to make toolstash cmp pass.

This change removes the former gcCompat adjustments and instead adjusts
the respective test cases as necessary. In some cases this makes the error
lines consistent with the ones reported by gccgo.

Where it has changed, the position associated with a given syntactic construct
is the position (line/col number) of the left-most token belonging to the
construct.

Change-Id: I5b60c00c5999a895c4d6d6e9b383c6405ccf725c
Reviewed-on: https://go-review.googlesource.com/36695
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Robert Griesemer 2017-02-09 16:00:23 -08:00
parent 09762ccff7
commit 3fd3171c2c
9 changed files with 57 additions and 62 deletions

View file

@ -358,7 +358,7 @@ func (p *parser) importDecl(group *Group) Decl {
d.LocalPkgName = n
p.next()
}
if p.tok == _Literal && (gcCompat || p.kind == StringLit) {
if p.tok == _Literal && p.kind == StringLit {
d.Path = p.oliteral()
} else {
p.syntax_error("missing import path; require quoted string")
@ -637,16 +637,13 @@ func (p *parser) callStmt() *CallStmt {
s := new(CallStmt)
s.init(p)
s.Tok = p.tok
s.Tok = p.tok // _Defer or _Go
p.next()
x := p.pexpr(p.tok == _Lparen) // keep_parens so we can report error below
switch x := x.(type) {
case *CallExpr:
s.Call = x
if gcCompat {
s.node = x.node
}
case *ParenExpr:
p.error(fmt.Sprintf("expression in %s must not be parenthesized", s.Tok))
// already progressed, no need to advance
@ -1127,9 +1124,6 @@ func (p *parser) structType() *StructType {
break
}
}
if gcCompat {
typ.init(p)
}
p.want(_Rbrace)
return typ
@ -1154,9 +1148,6 @@ func (p *parser) interfaceType() *InterfaceType {
break
}
}
if gcCompat {
typ.init(p)
}
p.want(_Rbrace)
return typ
@ -1554,8 +1545,7 @@ func (p *parser) simpleStmt(lhs Expr, rangeOk bool) SimpleStmt {
return p.newAssignStmt(0, lhs, p.exprList())
case _Define:
var n node
n.init(p)
pos := p.pos()
p.next()
if rangeOk && p.got(_Range) {
@ -1580,9 +1570,7 @@ func (p *parser) simpleStmt(lhs Expr, rangeOk bool) SimpleStmt {
}
as := p.newAssignStmt(Def, lhs, rhs)
if gcCompat {
as.node = n
}
as.pos = pos // TODO(gri) pass this into newAssignStmt
return as
default:
@ -1856,9 +1844,6 @@ func (p *parser) caseClause() *CaseClause {
p.advance(_Case, _Default, _Rbrace)
}
if gcCompat {
c.init(p)
}
p.want(_Colon)
c.Body = p.stmtList()