Commit 2ff46394 authored by Matthew Dempsky's avatar Matthew Dempsky

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: default avatarRobert Griesemer <gri@golang.org>
parent 11779362
...@@ -30,6 +30,8 @@ var ( ...@@ -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() { ...@@ -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() { ...@@ -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() { ...@@ -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")
......
This diff is collapsed.
...@@ -15,14 +15,27 @@ package gc ...@@ -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()
} }
......
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