lineno = autogeneratedPos // less confusing than end of input
dclcontext = PEXTERN
- types.Markdcl(lineno)
+ types.Markdcl()
// func sym(p *T, h uintptr) uintptr
tfn := nod(OTFUNC, nil, nil)
lineno = autogeneratedPos // less confusing than end of input
dclcontext = PEXTERN
- types.Markdcl(lineno)
+ types.Markdcl()
// func sym(p, q *T) bool
tfn := nod(OTFUNC, nil, nil)
return nodl(p.pos(), op, p.expr(), nil)
case OIF:
- types.Markdcl(lineno)
+ types.Markdcl()
n := nodl(p.pos(), OIF, nil, nil)
n.Ninit.Set(p.stmtList())
n.Left = p.expr()
return n
case OFOR:
- types.Markdcl(lineno)
+ types.Markdcl()
n := nodl(p.pos(), OFOR, nil, nil)
n.Ninit.Set(p.stmtList())
n.Left, n.Right = p.exprsOrNil()
return n
case ORANGE:
- types.Markdcl(lineno)
+ types.Markdcl()
n := nodl(p.pos(), ORANGE, nil, nil)
n.List.Set(p.stmtList())
n.Right = p.expr()
return n
case OSELECT, OSWITCH:
- types.Markdcl(lineno)
+ types.Markdcl()
n := nodl(p.pos(), op, nil, nil)
n.Ninit.Set(p.stmtList())
n.Left, _ = p.exprsOrNil()
// unreachable - mapped to OXCASE case below by exporter
case OXCASE:
- types.Markdcl(lineno)
+ types.Markdcl()
n := nodl(p.pos(), OXCASE, nil, nil)
n.Xoffset = int64(types.Block)
n.List.Set(p.exprList())
vargen++
gen = vargen
}
- types.Pushdcl(s, lineno)
+ types.Pushdcl(s)
n.Name.Curfn = Curfn
}
// start the function.
// called before funcargs; undone at end of funcbody.
func funcstart(n *Node) {
- types.Markdcl(lineno)
+ types.Markdcl()
funcstack = append(funcstack, Curfn)
funcdepth++
Curfn = n
}
func (p *noder) blockStmt(stmt *syntax.BlockStmt) []*Node {
- types.Markdcl(lineno)
+ types.Markdcl()
nodes := p.stmts(stmt.List)
types.Popdcl()
return nodes
}
func (p *noder) ifStmt(stmt *syntax.IfStmt) *Node {
- types.Markdcl(lineno)
+ types.Markdcl()
n := p.nod(stmt, OIF, nil, nil)
if stmt.Init != nil {
n.Ninit.Set1(p.stmt(stmt.Init))
}
func (p *noder) forStmt(stmt *syntax.ForStmt) *Node {
- types.Markdcl(lineno)
+ types.Markdcl()
var n *Node
if r, ok := stmt.Init.(*syntax.RangeClause); ok {
if stmt.Cond != nil || stmt.Post != nil {
}
func (p *noder) switchStmt(stmt *syntax.SwitchStmt) *Node {
- types.Markdcl(lineno)
+ types.Markdcl()
n := p.nod(stmt, OSWITCH, nil, nil)
if stmt.Init != nil {
n.Ninit.Set1(p.stmt(stmt.Init))
var nodes []*Node
for _, clause := range clauses {
p.lineno(clause)
- types.Markdcl(lineno)
+ types.Markdcl()
n := p.nod(clause, OXCASE, nil, nil)
if clause.Cases != nil {
n.List.Set(p.exprList(clause.Cases))
var nodes []*Node
for _, clause := range clauses {
p.lineno(clause)
- types.Markdcl(lineno)
+ types.Markdcl()
n := p.nod(clause, OXCASE, nil, nil)
if clause.Comm != nil {
n.List.Set1(p.stmt(clause.Comm))
lineno = autogeneratedPos
dclcontext = PEXTERN
- types.Markdcl(lineno)
+ types.Markdcl()
this := namedfield(".this", rcvr)
this.Left.Name.Param.Ntype = this.Right
package types
-import "cmd/internal/src"
-
// Declaration stack & operations
var blockgen int32 = 1 // max block number
var Block int32 // current block number
// dclstack maintains a stack of shadowed symbol declarations so that
-// popdcl can restore their declarations when a block scope ends.
+// Popdcl can restore their declarations when a block scope ends.
//
// The Syms on this stack are not "real" Syms as they don't actually
// represent object names. Sym is just a convenient type for saving shadowed
a.Name = b.Name
a.Def = b.Def
a.Block = b.Block
- a.Lastlineno = b.Lastlineno
}
-func push(pos src.XPos) *Sym {
+func push() *Sym {
d := new(Sym)
- d.Lastlineno = pos
dclstack = append(dclstack, d)
return d
}
// Pushdcl pushes the current declaration for symbol s (if any) so that
// it can be shadowed by a new declaration within a nested block scope.
-func Pushdcl(s *Sym, pos src.XPos) {
- d := push(pos)
- dcopy(d, s)
+func Pushdcl(s *Sym) {
+ dcopy(push(), s)
}
// Popdcl pops the innermost block scope and restores all symbol declarations
// to their previous state.
func Popdcl() {
- i := len(dclstack)
- for ; i > 0; i-- {
+ for i := len(dclstack); i > 0; i-- {
d := dclstack[i-1]
if d.Name == "" {
- break
+ // pop stack mark
+ Block = d.Block
+ dclstack = dclstack[:i-1]
+ return
}
- s := d.Pkg.Lookup(d.Name)
- lno := s.Lastlineno
- dcopy(s, d)
- d.Lastlineno = lno
- }
-
- if i == 0 {
- Fatalf("popdcl: no mark")
+ dcopy(d.Pkg.Lookup(d.Name), d)
}
-
- Block = dclstack[i-1].Block
- dclstack = dclstack[:i-1] // pop mark
+ Fatalf("popdcl: no stack mark")
}
// Markdcl records the start of a new block scope for declarations.
-func Markdcl(lineno src.XPos) {
- d := push(lineno)
- d.Name = "" // used as stack mark
- d.Block = Block
-
+func Markdcl() {
+ push().Block = Block // stack mark (Name == "")
blockgen++
Block = blockgen
}
// allows using Sym pointer equality to test for Go identifier uniqueness when
// handling selector expressions.
type Sym struct {
- Importdef *Pkg // where imported definition was found
- Linkname string // link name
+ Importdef *Pkg // where imported definition was found
+ Linkname string // link name
+ Lastlineno src.XPos // last declaration for diagnostic
// saved and restored by dcopy
- Pkg *Pkg
- Name string // object name
- Def *Node // definition: ONAME OTYPE OPACK or OLITERAL
- Lastlineno src.XPos // last declaration for diagnostic
- Block int32 // blocknumber to catch redeclaration
+ Pkg *Pkg
+ Name string // object name
+ Def *Node // definition: ONAME OTYPE OPACK or OLITERAL
+ Block int32 // blocknumber to catch redeclaration
flags bitset8
Label *Node // corresponding label (ephemeral)