mirror of https://github.com/golang/go.git
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
This commit is contained in:
parent
55b9234023
commit
29cfbcfef4
|
|
@ -29,6 +29,8 @@ var (
|
|||
goarch string
|
||||
goroot string
|
||||
buildid string
|
||||
|
||||
flag_newparser bool
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -182,6 +184,7 @@ func Main() {
|
|||
obj.Flagcount("live", "debug liveness analysis", &debuglive)
|
||||
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_newparser, "newparser", false, "use new parser")
|
||||
flag.BoolVar(&newexport, "newexport", true, "use new export format") // TODO(gri) remove eventually (issue 15323)
|
||||
flag.BoolVar(&nolocalimports, "nolocalimports", false, "reject local (relative) imports")
|
||||
flag.StringVar(&outfile, "o", "", "write output to `file`")
|
||||
|
|
@ -311,25 +314,14 @@ func Main() {
|
|||
}
|
||||
|
||||
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
|
||||
iota_ = -1000000
|
||||
|
||||
imported_unsafe = false
|
||||
|
||||
parse_file(bin)
|
||||
if flag_newparser {
|
||||
parseFile(infile)
|
||||
} else {
|
||||
oldParseFile(infile)
|
||||
}
|
||||
if nsyntaxerrors != 0 {
|
||||
errorexit()
|
||||
}
|
||||
|
|
@ -338,9 +330,7 @@ func Main() {
|
|||
// for the line history to work, and which then has to be corrected elsewhere,
|
||||
// just add a line here.
|
||||
lexlineno++
|
||||
|
||||
linehistpop()
|
||||
f.Close()
|
||||
}
|
||||
|
||||
testdclstack()
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -15,6 +15,7 @@ package gc
|
|||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
|
@ -26,8 +27,20 @@ func parse_import(bin *bufio.Reader, indent []byte) {
|
|||
newparser(bin, indent).import_package()
|
||||
}
|
||||
|
||||
// parse_file parses a single Go source file.
|
||||
func parse_file(bin *bufio.Reader) {
|
||||
// oldParseFile parses a single Go source file.
|
||||
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()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue