mirror of
https://github.com/golang/go.git
synced 2025-11-10 13:41:05 +00:00
cmd/compile/internal/gc: use new AST parser
Introduce a new noder type to transform package syntax's AST into gc's Node tree. Hidden behind a new -newparser flag. Change-Id: Id0e862ef6196c41533876afc4ec289e21d422d18 Reviewed-on: https://go-review.googlesource.com/27198 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
117793624b
commit
2ff463948c
3 changed files with 1139 additions and 20 deletions
|
|
@ -30,6 +30,8 @@ var (
|
||||||
goarch string
|
goarch string
|
||||||
goroot string
|
goroot string
|
||||||
buildid string
|
buildid string
|
||||||
|
|
||||||
|
flag_newparser bool
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -189,6 +191,7 @@ func Main() {
|
||||||
obj.Flagcount("live", "debug liveness analysis", &debuglive)
|
obj.Flagcount("live", "debug liveness analysis", &debuglive)
|
||||||
obj.Flagcount("m", "print optimization decisions", &Debug['m'])
|
obj.Flagcount("m", "print optimization decisions", &Debug['m'])
|
||||||
flag.BoolVar(&flag_msan, "msan", false, "build code compatible with C/C++ memory sanitizer")
|
flag.BoolVar(&flag_msan, "msan", false, "build code compatible with C/C++ memory sanitizer")
|
||||||
|
flag.BoolVar(&flag_newparser, "newparser", false, "use new parser")
|
||||||
flag.BoolVar(&nolocalimports, "nolocalimports", false, "reject local (relative) imports")
|
flag.BoolVar(&nolocalimports, "nolocalimports", false, "reject local (relative) imports")
|
||||||
flag.StringVar(&outfile, "o", "", "write output to `file`")
|
flag.StringVar(&outfile, "o", "", "write output to `file`")
|
||||||
flag.StringVar(&myimportpath, "p", "", "set expected package import `path`")
|
flag.StringVar(&myimportpath, "p", "", "set expected package import `path`")
|
||||||
|
|
@ -321,25 +324,14 @@ func Main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
linehistpush(infile)
|
linehistpush(infile)
|
||||||
|
|
||||||
f, err := os.Open(infile)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("open %s: %v\n", infile, err)
|
|
||||||
errorexit()
|
|
||||||
}
|
|
||||||
bin := bufio.NewReader(f)
|
|
||||||
|
|
||||||
// Skip initial BOM if present.
|
|
||||||
if r, _, _ := bin.ReadRune(); r != BOM {
|
|
||||||
bin.UnreadRune()
|
|
||||||
}
|
|
||||||
|
|
||||||
block = 1
|
block = 1
|
||||||
iota_ = -1000000
|
iota_ = -1000000
|
||||||
|
|
||||||
imported_unsafe = false
|
imported_unsafe = false
|
||||||
|
if flag_newparser {
|
||||||
parse_file(bin)
|
parseFile(infile)
|
||||||
|
} else {
|
||||||
|
oldParseFile(infile)
|
||||||
|
}
|
||||||
if nsyntaxerrors != 0 {
|
if nsyntaxerrors != 0 {
|
||||||
errorexit()
|
errorexit()
|
||||||
}
|
}
|
||||||
|
|
@ -348,9 +340,7 @@ func Main() {
|
||||||
// for the line history to work, and which then has to be corrected elsewhere,
|
// for the line history to work, and which then has to be corrected elsewhere,
|
||||||
// just add a line here.
|
// just add a line here.
|
||||||
lexlineno++
|
lexlineno++
|
||||||
|
|
||||||
linehistpop()
|
linehistpop()
|
||||||
f.Close()
|
|
||||||
}
|
}
|
||||||
timings.Stop()
|
timings.Stop()
|
||||||
timings.AddEvent(int64(lexlineno-lexlineno0), "lines")
|
timings.AddEvent(int64(lexlineno-lexlineno0), "lines")
|
||||||
|
|
|
||||||
1116
src/cmd/compile/internal/gc/noder.go
Normal file
1116
src/cmd/compile/internal/gc/noder.go
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -15,14 +15,27 @@ package gc
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const trace = false // if set, parse tracing can be enabled with -x
|
const trace = false // if set, parse tracing can be enabled with -x
|
||||||
|
|
||||||
// parse_file parses a single Go source file.
|
// oldParseFile parses a single Go source file.
|
||||||
func parse_file(bin *bufio.Reader) {
|
func oldParseFile(infile string) {
|
||||||
|
f, err := os.Open(infile)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("open %s: %v\n", infile, err)
|
||||||
|
errorexit()
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
bin := bufio.NewReader(f)
|
||||||
|
|
||||||
|
// Skip initial BOM if present.
|
||||||
|
if r, _, _ := bin.ReadRune(); r != BOM {
|
||||||
|
bin.UnreadRune()
|
||||||
|
}
|
||||||
newparser(bin, nil).file()
|
newparser(bin, nil).file()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue