Commit cd7d7382 authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile/internal/gc: introduce type for decl contexts/storage classes

Change-Id: I956e27fa07f16060b8f41b986d991c36557f7c12
Reviewed-on: https://go-review.googlesource.com/16332Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent 8993f79e
...@@ -151,7 +151,7 @@ var vargen int ...@@ -151,7 +151,7 @@ var vargen int
var declare_typegen int var declare_typegen int
func declare(n *Node, ctxt uint8) { func declare(n *Node, ctxt Class) {
if ctxt == PDISCARD { if ctxt == PDISCARD {
return return
} }
...@@ -217,12 +217,12 @@ func declare(n *Node, ctxt uint8) { ...@@ -217,12 +217,12 @@ func declare(n *Node, ctxt uint8) {
s.Def = n s.Def = n
n.Name.Vargen = int32(gen) n.Name.Vargen = int32(gen)
n.Name.Funcdepth = Funcdepth n.Name.Funcdepth = Funcdepth
n.Class = uint8(ctxt) n.Class = ctxt
autoexport(n, ctxt) autoexport(n, ctxt)
} }
func addvar(n *Node, t *Type, ctxt uint8) { func addvar(n *Node, t *Type, ctxt Class) {
if n == nil || n.Sym == nil || (n.Op != ONAME && n.Op != ONONAME) || t == nil { if n == nil || n.Sym == nil || (n.Op != ONAME && n.Op != ONONAME) || t == nil {
Fatalf("addvar: n=%v t=%v nil", n, t) Fatalf("addvar: n=%v t=%v nil", n, t)
} }
......
...@@ -72,7 +72,7 @@ func exportedsym(sym *Sym) bool { ...@@ -72,7 +72,7 @@ func exportedsym(sym *Sym) bool {
return sym.Pkg == localpkg && exportname(sym.Name) return sym.Pkg == localpkg && exportname(sym.Name)
} }
func autoexport(n *Node, ctxt uint8) { func autoexport(n *Node, ctxt Class) {
if n == nil || n.Sym == nil { if n == nil || n.Sym == nil {
return return
} }
......
...@@ -333,19 +333,23 @@ const ( ...@@ -333,19 +333,23 @@ const (
Cboth = Crecv | Csend Cboth = Crecv | Csend
) )
// declaration context // The Class of a variable/function describes the "storage class"
// of a variable or function. During parsing, storage classes are
// called declaration contexts.
type Class uint8
const ( const (
Pxxx = uint8(iota) Pxxx Class = iota
PEXTERN // global variable PEXTERN // global variable
PAUTO // local variables PAUTO // local variables
PPARAM // input arguments PPARAM // input arguments
PPARAMOUT // output results PPARAMOUT // output results
PPARAMREF // closure variable reference PPARAMREF // closure variable reference
PFUNC // global function PFUNC // global function
PDISCARD // discard during parse of duplicate import PDISCARD // discard during parse of duplicate import
PHEAP = uint8(1 << 7) // an extra bit to identify an escaped variable PHEAP = 1 << 7 // an extra bit to identify an escaped variable
) )
const ( const (
...@@ -587,7 +591,7 @@ var importlist []*Node // imported functions and methods with inlinable bodies ...@@ -587,7 +591,7 @@ var importlist []*Node // imported functions and methods with inlinable bodies
var funcsyms []*Node var funcsyms []*Node
var dclcontext uint8 // PEXTERN/PAUTO var dclcontext Class // PEXTERN/PAUTO
var incannedimport int var incannedimport int
......
...@@ -818,7 +818,7 @@ func checkparam(fn *Node, p *obj.Prog, n *Node) { ...@@ -818,7 +818,7 @@ func checkparam(fn *Node, p *obj.Prog, n *Node) {
return return
} }
var a *Node var a *Node
var class uint8 var class Class
for l := fn.Func.Dcl; l != nil; l = l.Next { for l := fn.Func.Dcl; l != nil; l = l.Next {
a = l.N a = l.N
class = a.Class &^ PHEAP class = a.Class &^ PHEAP
......
...@@ -48,7 +48,7 @@ type Node struct { ...@@ -48,7 +48,7 @@ type Node struct {
Addable bool // addressable Addable bool // addressable
Etype uint8 // op for OASOP, etype for OTYPE, exclam for export, 6g saved reg Etype uint8 // op for OASOP, etype for OTYPE, exclam for export, 6g saved reg
Bounded bool // bounds check unnecessary Bounded bool // bounds check unnecessary
Class uint8 // PPARAM, PAUTO, PEXTERN, etc Class Class // PPARAM, PAUTO, PEXTERN, etc
Embedded uint8 // ODCLFIELD embedded type Embedded uint8 // ODCLFIELD embedded type
Colas bool // OAS resulting from := Colas bool // OAS resulting from :=
Diag uint8 // already printed error about this Diag uint8 // already printed error about this
......
...@@ -288,7 +288,7 @@ func walkstmt(np **Node) { ...@@ -288,7 +288,7 @@ func walkstmt(np **Node) {
// so that reorder3 can fix up conflicts // so that reorder3 can fix up conflicts
var rl *NodeList var rl *NodeList
var cl uint8 var cl Class
for ll := Curfn.Func.Dcl; ll != nil; ll = ll.Next { for ll := Curfn.Func.Dcl; ll != nil; ll = ll.Next {
cl = ll.N.Class &^ PHEAP cl = ll.N.Class &^ PHEAP
if cl == PAUTO { if cl == PAUTO {
......
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