Skip to content

Commit 2ff4639

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent 1177936 commit 2ff4639

File tree

3 files changed

+1139
-20
lines changed

3 files changed

+1139
-20
lines changed

src/cmd/compile/internal/gc/main.go

+8-18
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ var (
3030
goarch string
3131
goroot string
3232
buildid string
33+
34+
flag_newparser bool
3335
)
3436

3537
var (
@@ -189,6 +191,7 @@ func Main() {
189191
obj.Flagcount("live", "debug liveness analysis", &debuglive)
190192
obj.Flagcount("m", "print optimization decisions", &Debug['m'])
191193
flag.BoolVar(&flag_msan, "msan", false, "build code compatible with C/C++ memory sanitizer")
194+
flag.BoolVar(&flag_newparser, "newparser", false, "use new parser")
192195
flag.BoolVar(&nolocalimports, "nolocalimports", false, "reject local (relative) imports")
193196
flag.StringVar(&outfile, "o", "", "write output to `file`")
194197
flag.StringVar(&myimportpath, "p", "", "set expected package import `path`")
@@ -321,25 +324,14 @@ func Main() {
321324
}
322325

323326
linehistpush(infile)
324-
325-
f, err := os.Open(infile)
326-
if err != nil {
327-
fmt.Printf("open %s: %v\n", infile, err)
328-
errorexit()
329-
}
330-
bin := bufio.NewReader(f)
331-
332-
// Skip initial BOM if present.
333-
if r, _, _ := bin.ReadRune(); r != BOM {
334-
bin.UnreadRune()
335-
}
336-
337327
block = 1
338328
iota_ = -1000000
339-
340329
imported_unsafe = false
341-
342-
parse_file(bin)
330+
if flag_newparser {
331+
parseFile(infile)
332+
} else {
333+
oldParseFile(infile)
334+
}
343335
if nsyntaxerrors != 0 {
344336
errorexit()
345337
}
@@ -348,9 +340,7 @@ func Main() {
348340
// for the line history to work, and which then has to be corrected elsewhere,
349341
// just add a line here.
350342
lexlineno++
351-
352343
linehistpop()
353-
f.Close()
354344
}
355345
timings.Stop()
356346
timings.AddEvent(int64(lexlineno-lexlineno0), "lines")

0 commit comments

Comments
 (0)