Skip to content

Commit

Permalink
goyacc: don't import "unsafe" if not used (#13008)
Browse files Browse the repository at this point in the history
* don't import unsafe if not used

Signed-off-by: Josh Humphries <[email protected]>

* make codegen

Signed-off-by: Josh Humphries <[email protected]>

* Apply suggestion from linter: use fmt.Fprint, no fmt.Fprintf

Signed-off-by: Joshua Humphries <[email protected]>

---------

Signed-off-by: Josh Humphries <[email protected]>
Signed-off-by: Joshua Humphries <[email protected]>
  • Loading branch information
jhump authored May 4, 2023
1 parent d552338 commit 1f203c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
21 changes: 15 additions & 6 deletions go/vt/sqlparser/goyacc/goyacc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,9 @@ func emitcode(code []rune, lineno int) {
if !writtenImports && isPackageClause(line) {
fmt.Fprintln(ftable, `import (`)
fmt.Fprintln(ftable, `__yyfmt__ "fmt"`)
fmt.Fprintln(ftable, `__yyunsafe__ "unsafe"`)
if allowFastAppend {
fmt.Fprintln(ftable, `__yyunsafe__ "unsafe"`)
}
fmt.Fprintln(ftable, `)`)
if !lflag {
fmt.Fprintf(ftable, "//line %v:%v\n\t\t", infile, lineno+i)
Expand Down Expand Up @@ -3047,9 +3049,14 @@ func others() {
ch = getrune(finput)
}

if allowFastAppend {
fastAppendHelper := strings.Replace(fastAppendHelperText, "$$", prefix, -1)
fmt.Fprint(ftable, fastAppendHelper)
}

// copy yaccpar
if !lflag {
fmt.Fprintf(ftable, "\n//line yaccpar:1\n")
fmt.Fprint(ftable, "\n//line yaccpar:1\n")
}

parts := strings.SplitN(yaccpar, prefix+"run()", 2)
Expand Down Expand Up @@ -3344,17 +3351,19 @@ func gofmt() {
os.WriteFile(oflag, src, 0666)
}

var yaccpar string // will be processed version of yaccpartext: s/$$/prefix/g
var yaccpartext = `
/* parser for yacc output */
const fastAppendHelperText = `
func $$Iaddr(v any) __yyunsafe__.Pointer {
type h struct {
t __yyunsafe__.Pointer
p __yyunsafe__.Pointer
}
return (*h)(__yyunsafe__.Pointer(&v)).p
}
`

var yaccpar string // will be processed version of yaccpartext: s/$$/prefix/g
const yaccpartext = `
/* parser for yacc output */
var (
$$Debug = 0
Expand Down
8 changes: 4 additions & 4 deletions go/vt/sqlparser/sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1f203c6

Please sign in to comment.