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 { ...@@ -358,7 +358,7 @@ func (p *parser) importDecl(group *Group) Decl {
d.LocalPkgName = n d.LocalPkgName = n
p.next() p.next()
} }
if p.tok == _Literal && (gcCompat || p.kind == StringLit) { if p.tok == _Literal && p.kind == StringLit {
d.Path = p.oliteral() d.Path = p.oliteral()
} else { } else {
p.syntax_error("missing import path; require quoted string") p.syntax_error("missing import path; require quoted string")
...@@ -637,16 +637,13 @@ func (p *parser) callStmt() *CallStmt { ...@@ -637,16 +637,13 @@ func (p *parser) callStmt() *CallStmt {
s := new(CallStmt) s := new(CallStmt)
s.init(p) s.init(p)
s.Tok = p.tok s.Tok = p.tok // _Defer or _Go
p.next() p.next()
x := p.pexpr(p.tok == _Lparen) // keep_parens so we can report error below x := p.pexpr(p.tok == _Lparen) // keep_parens so we can report error below
switch x := x.(type) { switch x := x.(type) {
case *CallExpr: case *CallExpr:
s.Call = x s.Call = x
if gcCompat {
s.node = x.node
}
case *ParenExpr: case *ParenExpr:
p.error(fmt.Sprintf("expression in %s must not be parenthesized", s.Tok)) p.error(fmt.Sprintf("expression in %s must not be parenthesized", s.Tok))
// already progressed, no need to advance // already progressed, no need to advance
...@@ -1127,9 +1124,6 @@ func (p *parser) structType() *StructType { ...@@ -1127,9 +1124,6 @@ func (p *parser) structType() *StructType {
break break
} }
} }
if gcCompat {
typ.init(p)
}
p.want(_Rbrace) p.want(_Rbrace)
return typ return typ
...@@ -1154,9 +1148,6 @@ func (p *parser) interfaceType() *InterfaceType { ...@@ -1154,9 +1148,6 @@ func (p *parser) interfaceType() *InterfaceType {
break break
} }
} }
if gcCompat {
typ.init(p)
}
p.want(_Rbrace) p.want(_Rbrace)
return typ return typ
...@@ -1554,8 +1545,7 @@ func (p *parser) simpleStmt(lhs Expr, rangeOk bool) SimpleStmt { ...@@ -1554,8 +1545,7 @@ func (p *parser) simpleStmt(lhs Expr, rangeOk bool) SimpleStmt {
return p.newAssignStmt(0, lhs, p.exprList()) return p.newAssignStmt(0, lhs, p.exprList())
case _Define: case _Define:
var n node pos := p.pos()
n.init(p)
p.next() p.next()
if rangeOk && p.got(_Range) { if rangeOk && p.got(_Range) {
...@@ -1580,9 +1570,7 @@ func (p *parser) simpleStmt(lhs Expr, rangeOk bool) SimpleStmt { ...@@ -1580,9 +1570,7 @@ func (p *parser) simpleStmt(lhs Expr, rangeOk bool) SimpleStmt {
} }
as := p.newAssignStmt(Def, lhs, rhs) as := p.newAssignStmt(Def, lhs, rhs)
if gcCompat { as.pos = pos // TODO(gri) pass this into newAssignStmt
as.node = n
}
return as return as
default: default:
...@@ -1856,9 +1844,6 @@ func (p *parser) caseClause() *CaseClause { ...@@ -1856,9 +1844,6 @@ func (p *parser) caseClause() *CaseClause {
p.advance(_Case, _Default, _Rbrace) p.advance(_Case, _Default, _Rbrace)
} }
if gcCompat {
c.init(p)
}
p.want(_Colon) p.want(_Colon)
c.Body = p.stmtList() c.Body = p.stmtList()
......
...@@ -151,7 +151,7 @@ func TestTraceSymbolize(t *testing.T) { ...@@ -151,7 +151,7 @@ func TestTraceSymbolize(t *testing.T) {
{"testing.tRunner", 0}, {"testing.tRunner", 0},
}}, }},
{trace.EvGoCreate, []frame{ {trace.EvGoCreate, []frame{
{"runtime/trace_test.TestTraceSymbolize", 39}, {"runtime/trace_test.TestTraceSymbolize", 37},
{"testing.tRunner", 0}, {"testing.tRunner", 0},
}}, }},
{trace.EvGoStop, []frame{ {trace.EvGoStop, []frame{
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
package p package p
type T interface { type T interface {
M(interface { M(interface { // ERROR "cannot export unnamed recursive interface"
T T
}) // ERROR "cannot export unnamed recursive interface" })
} }
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
// See golang.org/issue/9432. // See golang.org/issue/9432.
package p package p
type foo struct { // GCCGO_ERROR "invalid recursive type" type foo struct { // ERROR "invalid recursive type"
bar foo bar foo
blah foo blah foo
} // ERROR "invalid recursive type foo" }
...@@ -21,35 +21,7 @@ import _ "go/parser" ...@@ -21,35 +21,7 @@ import _ "go/parser"
//import "greek/αβ" //import "greek/αβ"
// Import paths must be strings. // Import paths must be strings.
import 42 // ERROR "import statement" import 42 // ERROR "missing import path; require quoted string"
import 'a' // ERROR "import statement" import 'a' // ERROR "missing import path; require quoted string"
import 3.14 // ERROR "import statement" import 3.14 // ERROR "missing import path; require quoted string"
import 0.25i // ERROR "import statement" import 0.25i // ERROR "missing import path; require quoted string"
// 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"
// 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 ...@@ -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. // In particular, at printint r must be live.
func f41(p, q *int) (r *int) { // ERROR "live at entry to f41: p q$" func f41(p, q *int) (r *int) { // ERROR "live at entry to f41: p q$"
r = p r = p
defer func() { defer func() { // ERROR "live at call to deferproc: q r$" "live at call to deferreturn: r$"
recover() 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$" printint(0) // ERROR "live at call to printint: q r$"
r = q r = q
return // ERROR "live at call to deferreturn: r$" return // ERROR "live at call to deferreturn: r$"
......
...@@ -67,9 +67,9 @@ func f4(e interface{}) { ...@@ -67,9 +67,9 @@ func f4(e interface{}) {
case struct { case struct {
i int "tag2" i int "tag2"
}: }:
case struct { case struct { // ERROR "duplicate case struct { i int .tag1. } in type switch"
i int "tag1" i int "tag1"
}: // ERROR "duplicate case struct { i int .tag1. } in type switch" }:
} }
} }
......
...@@ -26,10 +26,10 @@ func whatis(x interface{}) string { ...@@ -26,10 +26,10 @@ func whatis(x interface{}) string {
w() w()
}: }:
return "rw" return "rw"
case interface { // GCCGO_ERROR "duplicate" case interface { // ERROR "duplicate"
w() w()
r() r()
}: // GC_ERROR "duplicate" }:
return "wr" 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