mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: remove gratuituous copying of lexer token data
Rename yySymType to lexer; should eventually capture all lexer state. Embed lexer in parser and access lexer token data directly. Change-Id: I246194705d594f80426f3ba77d8580af9185daf7 Reviewed-on: https://go-review.googlesource.com/19759 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
5621b09dad
commit
11e51ed4bc
2 changed files with 21 additions and 27 deletions
|
|
@ -866,10 +866,15 @@ func isfrog(c int) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
type yySymType struct {
|
type lexer struct {
|
||||||
sym *Sym
|
// TODO(gri) move other lexer state here and out of global variables
|
||||||
val Val
|
// (source, current line number, etc.)
|
||||||
op Op
|
|
||||||
|
// current token
|
||||||
|
tok int32
|
||||||
|
sym_ *Sym // valid if tok == LNAME
|
||||||
|
val Val // valid if tok == LLITERAL
|
||||||
|
op Op // valid if tok == LASOP
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -920,7 +925,7 @@ const (
|
||||||
LRSH
|
LRSH
|
||||||
)
|
)
|
||||||
|
|
||||||
func _yylex(yylval *yySymType) int32 {
|
func (yylval *lexer) _yylex() int32 {
|
||||||
var c1 int
|
var c1 int
|
||||||
var op Op
|
var op Op
|
||||||
var escflag int
|
var escflag int
|
||||||
|
|
@ -1402,7 +1407,7 @@ talph:
|
||||||
if Debug['x'] != 0 {
|
if Debug['x'] != 0 {
|
||||||
fmt.Printf("lex: %s %s\n", s, lexname(int(s.Lexical)))
|
fmt.Printf("lex: %s %s\n", s, lexname(int(s.Lexical)))
|
||||||
}
|
}
|
||||||
yylval.sym = s
|
yylval.sym_ = s
|
||||||
return int32(s.Lexical)
|
return int32(s.Lexical)
|
||||||
|
|
||||||
ncu:
|
ncu:
|
||||||
|
|
@ -1828,16 +1833,16 @@ func pragcgo(text string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func yylex(yylval *yySymType) int32 {
|
func (l *lexer) next() {
|
||||||
lx := _yylex(yylval)
|
tok := l._yylex()
|
||||||
|
|
||||||
if curio.nlsemi && lx == EOF {
|
if curio.nlsemi && tok == EOF {
|
||||||
// Treat EOF as "end of line" for the purposes
|
// Treat EOF as "end of line" for the purposes
|
||||||
// of inserting a semicolon.
|
// of inserting a semicolon.
|
||||||
lx = ';'
|
tok = ';'
|
||||||
}
|
}
|
||||||
|
|
||||||
switch lx {
|
switch tok {
|
||||||
case LNAME,
|
case LNAME,
|
||||||
LLITERAL,
|
LLITERAL,
|
||||||
LBREAK,
|
LBREAK,
|
||||||
|
|
@ -1855,7 +1860,7 @@ func yylex(yylval *yySymType) int32 {
|
||||||
curio.nlsemi = false
|
curio.nlsemi = false
|
||||||
}
|
}
|
||||||
|
|
||||||
return lx
|
l.tok = tok
|
||||||
}
|
}
|
||||||
|
|
||||||
func getc() int {
|
func getc() int {
|
||||||
|
|
|
||||||
|
|
@ -42,21 +42,10 @@ func parse_file(bin *obj.Biobuf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type parser struct {
|
type parser struct {
|
||||||
tok int32 // next token (one-token look-ahead)
|
lexer
|
||||||
op Op // valid if tok == LASOP
|
fnest int // function nesting level (for error handling)
|
||||||
val Val // valid if tok == LLITERAL
|
xnest int // expression nesting level (for complit ambiguity resolution)
|
||||||
sym_ *Sym // valid if tok == LNAME
|
indent []byte // tracing support
|
||||||
fnest int // function nesting level (for error handling)
|
|
||||||
xnest int // expression nesting level (for complit ambiguity resolution)
|
|
||||||
yy yySymType // for temporary use by next
|
|
||||||
indent []byte // tracing support
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser) next() {
|
|
||||||
p.tok = yylex(&p.yy)
|
|
||||||
p.op = p.yy.op
|
|
||||||
p.val = p.yy.val
|
|
||||||
p.sym_ = p.yy.sym
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser) got(tok int32) bool {
|
func (p *parser) got(tok int32) bool {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue