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

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: default avatarMatthew Dempsky <mdempsky@google.com>
parent 09762ccf
......@@ -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()
......
......@@ -151,7 +151,7 @@ func TestTraceSymbolize(t *testing.T) {
{"testing.tRunner", 0},
}},
{trace.EvGoCreate, []frame{
{"runtime/trace_test.TestTraceSymbolize", 39},
{"runtime/trace_test.TestTraceSymbolize", 37},
{"testing.tRunner", 0},
}},
{trace.EvGoStop, []frame{
......
......@@ -7,7 +7,7 @@
package p
type T interface {
M(interface {
M(interface { // ERROR "cannot export unnamed recursive interface"
T
}) // ERROR "cannot export unnamed recursive interface"
})
}
......@@ -9,7 +9,7 @@
// See golang.org/issue/9432.
package p
type foo struct { // GCCGO_ERROR "invalid recursive type"
type foo struct { // ERROR "invalid recursive type"
bar foo
blah foo
} // ERROR "invalid recursive type foo"
}
......@@ -21,35 +21,7 @@ import _ "go/parser"
//import "greek/αβ"
// Import paths must be strings.
import 42 // ERROR "import statement"
import 'a' // ERROR "import statement"
import 3.14 // ERROR "import statement"
import 0.25i // ERROR "import statement"
// Each of these pairs tests both `` vs "" strings
// and also use of invalid characters spelled out as
// escape sequences and written directly.
// For example `"\x00"` tests import "\x00"
// while "`\x00`" tests import `<actual-NUL-byte>`.
import "" // ERROR "import path"
import `` // ERROR "import path"
import "\x00" // ERROR "import path"
import `\x00` // ERROR "import path"
import "\x7f" // ERROR "import path"
import `\x7f` // ERROR "import path"
import "a!" // ERROR "import path"
import `a!` // ERROR "import path"
import "a b" // ERROR "import path"
import `a b` // ERROR "import path"
import "a\\b" // ERROR "import path"
import `a\\b` // ERROR "import path"
import "\"`a`\"" // ERROR "import path"
import `\"a\"` // ERROR "import path"
import "\x80\x80" // ERROR "import path"
import `\x80\x80` // ERROR "import path"
import "\xFFFD" // ERROR "import path"
import `\xFFFD` // ERROR "import path"
// Invalid local imports.
import "/foo" // ERROR "import path cannot be absolute path"
import "c:/foo" // ERROR "import path contains invalid character"
import 42 // ERROR "missing import path; require quoted string"
import 'a' // ERROR "missing import path; require quoted string"
import 3.14 // ERROR "missing import path; require quoted string"
import 0.25i // ERROR "missing import path; require quoted string"
// errorcheck
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Verify that invalid imports are rejected by the compiler.
// Does not compile.
package main
// Each of these pairs tests both `` vs "" strings
// and also use of invalid characters spelled out as
// escape sequences and written directly.
// For example `"\x00"` tests import "\x00"
// while "`\x00`" tests import `<actual-NUL-byte>`.
import "" // ERROR "import path"
import `` // ERROR "import path"
import "\x00" // ERROR "import path"
import `\x00` // ERROR "import path"
import "\x7f" // ERROR "import path"
import `\x7f` // ERROR "import path"
import "a!" // ERROR "import path"
import `a!` // ERROR "import path"
import "a b" // ERROR "import path"
import `a b` // ERROR "import path"
import "a\\b" // ERROR "import path"
import `a\\b` // ERROR "import path"
import "\"`a`\"" // ERROR "import path"
import `\"a\"` // ERROR "import path"
import "\x80\x80" // ERROR "import path"
import `\x80\x80` // ERROR "import path"
import "\xFFFD" // ERROR "import path"
import `\xFFFD` // ERROR "import path"
// Invalid local imports.
import "/foo" // ERROR "import path cannot be absolute path"
import "c:/foo" // ERROR "import path contains invalid character"
......@@ -679,9 +679,9 @@ type R struct{ *T } // ERRORAUTO "live at entry to \(\*R\)\.Foo: \.this ptr" "li
// In particular, at printint r must be live.
func f41(p, q *int) (r *int) { // ERROR "live at entry to f41: p q$"
r = p
defer func() {
defer func() { // ERROR "live at call to deferproc: q r$" "live at call to deferreturn: r$"
recover()
}() // ERROR "live at call to deferproc: q r$" "live at call to deferreturn: r$"
}()
printint(0) // ERROR "live at call to printint: q r$"
r = q
return // ERROR "live at call to deferreturn: r$"
......
......@@ -67,9 +67,9 @@ func f4(e interface{}) {
case struct {
i int "tag2"
}:
case struct {
case struct { // ERROR "duplicate case struct { i int .tag1. } in type switch"
i int "tag1"
}: // ERROR "duplicate case struct { i int .tag1. } in type switch"
}:
}
}
......
......@@ -26,10 +26,10 @@ func whatis(x interface{}) string {
w()
}:
return "rw"
case interface { // GCCGO_ERROR "duplicate"
case interface { // ERROR "duplicate"
w()
r()
}: // GC_ERROR "duplicate"
}:
return "wr"
}
......
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