Append int `help:"print information about append compilation"`
Checkptr int `help:"instrument unsafe pointer conversions\n0: instrumentation disabled\n1: conversions involving unsafe.Pointer are instrumented\n2: conversions to unsafe.Pointer force heap allocation" concurrent:"ok"`
Closure int `help:"print information about closure compilation"`
- DclStack int `help:"run internal dclstack check"`
Defer int `help:"print information about defer compilation"`
DisableNil int `help:"disable nil checks" concurrent:"ok"`
DumpPtrs int `help:"show Node pointers values in dump output"`
typecheck.Stmts(fn.Body)
ir.CurFunc = nil
- if base.Debug.DclStack != 0 {
- types.CheckDclstack()
- }
-
fn.SetNilCheckDisabled(true)
typecheck.Target.Decls = append(typecheck.Target.Decls, fn)
typecheck.Stmts(fn.Body)
ir.CurFunc = nil
- if base.Debug.DclStack != 0 {
- types.CheckDclstack()
- }
-
// Disable checknils while compiling this code.
// We are comparing a struct or an array,
// neither of which can be nil, and our comparisons
base.ErrorfAt(n.Pos(), "cannot declare main - must be func")
}
Target.Externs = append(Target.Externs, n)
+ s.Def = n
} else {
if ir.CurFunc == nil && ctxt == ir.PAUTO {
base.Pos = n.Pos()
if ir.CurFunc != nil && ctxt != ir.PFUNC && n.Op() == ir.ONAME {
ir.CurFunc.Dcl = append(ir.CurFunc.Dcl, n)
}
- types.Pushdcl(s)
n.Curfn = ir.CurFunc
}
n.SetFrameOffset(0)
}
- s.Def = n
n.Class = ctxt
if ctxt == ir.PFUNC {
n.Sym().SetFunc(true)
funcStack = append(funcStack, funcStackEnt{ir.CurFunc, DeclContext})
ir.CurFunc = fn
DeclContext = ir.PAUTO
-
- types.Markdcl()
}
// finish the body.
// returns in extern-declaration context.
func FinishFuncBody() {
// change the declaration context from auto to previous context
- types.Popdcl()
var e funcStackEnt
funcStack, e = funcStack[:len(funcStack)-1], funcStack[len(funcStack)-1]
ir.CurFunc, DeclContext = e.curfn, e.dclcontext
package types
-import (
- "cmd/compile/internal/base"
-)
-
-// Declaration stack & operations
-
-// A dsym stores a symbol's shadowed declaration so that it can be
-// restored once the block scope ends.
-type dsym struct {
- sym *Sym // sym == nil indicates stack mark
- def Object
-}
-
-// dclstack maintains a stack of shadowed symbol declarations so that
-// Popdcl can restore their declarations when a block scope ends.
-var dclstack []dsym
-
-// 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) {
- dclstack = append(dclstack, dsym{
- sym: s,
- def: s.Def,
- })
-}
-
-// Popdcl pops the innermost block scope and restores all symbol declarations
-// to their previous state.
-func Popdcl() {
- for i := len(dclstack); i > 0; i-- {
- d := &dclstack[i-1]
- s := d.sym
- if s == nil {
- // pop stack mark
- dclstack = dclstack[:i-1]
- return
- }
-
- s.Def = d.def
-
- // Clear dead pointer fields.
- d.sym = nil
- d.def = nil
- }
- base.Fatalf("popdcl: no stack mark")
-}
-
-// Markdcl records the start of a new block scope for declarations.
-func Markdcl() {
- dclstack = append(dclstack, dsym{
- sym: nil, // stack mark
- })
-}
-
-func isDclstackValid() bool {
- for _, d := range dclstack {
- if d.sym == nil {
- return false
- }
- }
- return true
-}
-
// PkgDef returns the definition associated with s at package scope.
-func (s *Sym) PkgDef() Object {
- return *s.pkgDefPtr()
-}
+func (s *Sym) PkgDef() Object { return s.Def }
// SetPkgDef sets the definition associated with s at package scope.
-func (s *Sym) SetPkgDef(n Object) {
- *s.pkgDefPtr() = n
-}
-
-func (s *Sym) pkgDefPtr() *Object {
- // Look for outermost saved declaration, which must be the
- // package scope definition, if present.
- for i := range dclstack {
- d := &dclstack[i]
- if s == d.sym {
- return &d.def
- }
- }
-
- // Otherwise, the declaration hasn't been shadowed within a
- // function scope.
- return &s.Def
-}
-
-func CheckDclstack() {
- if !isDclstackValid() {
- base.Fatalf("mark left on the dclstack")
- }
-}
+func (s *Sym) SetPkgDef(n Object) { s.Def = n }