Commit 0625fc8e authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: clean up getlinepragma

Passes toolstash -cmp.

Change-Id: Ia497b51c74a9c760a873e1ed690e4408fd0fe596
Reviewed-on: https://go-review.googlesource.com/19844Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 9c269e6a
...@@ -1569,10 +1569,8 @@ func more(pp *string) bool { ...@@ -1569,10 +1569,8 @@ func more(pp *string) bool {
// as a discontinuity in sequential line numbers. // as a discontinuity in sequential line numbers.
// the next line of input comes from parse.y:15 // the next line of input comes from parse.y:15
func (l *lexer) getlinepragma() rune { func (l *lexer) getlinepragma() rune {
var cmd, verb, name string
c := l.getr() c := l.getr()
if c == 'g' { if c == 'g' { // check for //go: directive
cp := &lexbuf cp := &lexbuf
cp.Reset() cp.Reset()
cp.WriteByte('g') // already read cp.WriteByte('g') // already read
...@@ -1594,77 +1592,55 @@ func (l *lexer) getlinepragma() rune { ...@@ -1594,77 +1592,55 @@ func (l *lexer) getlinepragma() rune {
pragcgo(text) pragcgo(text)
} }
cmd = text verb := text
verb = cmd if i := strings.Index(text, " "); i >= 0 {
if i := strings.Index(verb, " "); i >= 0 {
verb = verb[:i] verb = verb[:i]
} }
if verb == "go:linkname" { switch verb {
case "go:linkname":
if !imported_unsafe { if !imported_unsafe {
Yyerror("//go:linkname only allowed in Go files that import \"unsafe\"") Yyerror("//go:linkname only allowed in Go files that import \"unsafe\"")
} }
f := strings.Fields(cmd) f := strings.Fields(text)
if len(f) != 3 { if len(f) != 3 {
Yyerror("usage: //go:linkname localname linkname") Yyerror("usage: //go:linkname localname linkname")
return c break
} }
Lookup(f[1]).Linkname = f[2] Lookup(f[1]).Linkname = f[2]
return c case "go:nointerface":
} if obj.Fieldtrack_enabled != 0 {
if verb == "go:nointerface" && obj.Fieldtrack_enabled != 0 {
nointerface = true nointerface = true
return c
} }
case "go:noescape":
if verb == "go:noescape" {
noescape = true noescape = true
return c case "go:norace":
}
if verb == "go:norace" {
norace = true norace = true
return c case "go:nosplit":
}
if verb == "go:nosplit" {
nosplit = true nosplit = true
return c case "go:noinline":
}
if verb == "go:noinline" {
noinline = true noinline = true
return c case "go:systemstack":
}
if verb == "go:systemstack" {
if compiling_runtime == 0 { if compiling_runtime == 0 {
Yyerror("//go:systemstack only allowed in runtime") Yyerror("//go:systemstack only allowed in runtime")
} }
systemstack = true systemstack = true
return c case "go:nowritebarrier":
}
if verb == "go:nowritebarrier" {
if compiling_runtime == 0 { if compiling_runtime == 0 {
Yyerror("//go:nowritebarrier only allowed in runtime") Yyerror("//go:nowritebarrier only allowed in runtime")
} }
nowritebarrier = true nowritebarrier = true
return c case "go:nowritebarrierrec":
}
if verb == "go:nowritebarrierrec" {
if compiling_runtime == 0 { if compiling_runtime == 0 {
Yyerror("//go:nowritebarrierrec only allowed in runtime") Yyerror("//go:nowritebarrierrec only allowed in runtime")
} }
nowritebarrierrec = true nowritebarrierrec = true
nowritebarrier = true // Implies nowritebarrier nowritebarrier = true // Implies nowritebarrier
return c
} }
return c return c
} }
// check for //line directive
if c != 'l' { if c != 'l' {
return c return c
} }
...@@ -1694,34 +1670,25 @@ func (l *lexer) getlinepragma() rune { ...@@ -1694,34 +1670,25 @@ func (l *lexer) getlinepragma() rune {
} }
cp.WriteByte(byte(c)) cp.WriteByte(byte(c))
} }
cp = nil cp = nil
if linep == 0 { if linep == 0 {
return c return c
} }
text := strings.TrimSuffix(lexbuf.String(), "\r") text := strings.TrimSuffix(lexbuf.String(), "\r")
n := 0 n, err := strconv.Atoi(text[linep:])
for _, c := range text[linep:] { if err != nil {
if c < '0' || c > '9' { return c // todo: make this an error instead? it is almost certainly a bug.
goto out
} }
n = n*10 + int(c) - '0'
if n > 1e8 { if n > 1e8 {
Yyerror("line number out of range") Yyerror("line number out of range")
errorexit() errorexit()
} }
}
if n <= 0 { if n <= 0 {
return c return c
} }
name = text[:linep-1] linehistupdate(text[:linep-1], n)
linehistupdate(name, n)
return c
out:
return c return c
} }
......
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