Skip to content

Commit

Permalink
cmd/compile/internal/gc: introduce type for decl contexts/storage cla…
Browse files Browse the repository at this point in the history
…sses

Change-Id: I956e27fa07f16060b8f41b986d991c36557f7c12
Reviewed-on: https://go-review.googlesource.com/16332
Reviewed-by: Keith Randall <[email protected]>
  • Loading branch information
griesemer committed Oct 26, 2015
1 parent 8993f79 commit cd7d738
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/cmd/compile/internal/gc/dcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ var vargen int

var declare_typegen int

func declare(n *Node, ctxt uint8) {
func declare(n *Node, ctxt Class) {
if ctxt == PDISCARD {
return
}
Expand Down Expand Up @@ -217,12 +217,12 @@ func declare(n *Node, ctxt uint8) {
s.Def = n
n.Name.Vargen = int32(gen)
n.Name.Funcdepth = Funcdepth
n.Class = uint8(ctxt)
n.Class = 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 {
Fatalf("addvar: n=%v t=%v nil", n, t)
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func exportedsym(sym *Sym) bool {
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 {
return
}
Expand Down
24 changes: 14 additions & 10 deletions src/cmd/compile/internal/gc/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,19 +333,23 @@ const (
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 (
Pxxx = uint8(iota)
PEXTERN // global variable
PAUTO // local variables
PPARAM // input arguments
PPARAMOUT // output results
PPARAMREF // closure variable reference
PFUNC // global function
Pxxx Class = iota
PEXTERN // global variable
PAUTO // local variables
PPARAM // input arguments
PPARAMOUT // output results
PPARAMREF // closure variable reference
PFUNC // global function

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 (
Expand Down Expand Up @@ -587,7 +591,7 @@ var importlist []*Node // imported functions and methods with inlinable bodies

var funcsyms []*Node

var dclcontext uint8 // PEXTERN/PAUTO
var dclcontext Class // PEXTERN/PAUTO

var incannedimport int

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/plive.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ func checkparam(fn *Node, p *obj.Prog, n *Node) {
return
}
var a *Node
var class uint8
var class Class
for l := fn.Func.Dcl; l != nil; l = l.Next {
a = l.N
class = a.Class &^ PHEAP
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Node struct {
Addable bool // addressable
Etype uint8 // op for OASOP, etype for OTYPE, exclam for export, 6g saved reg
Bounded bool // bounds check unnecessary
Class uint8 // PPARAM, PAUTO, PEXTERN, etc
Class Class // PPARAM, PAUTO, PEXTERN, etc
Embedded uint8 // ODCLFIELD embedded type
Colas bool // OAS resulting from :=
Diag uint8 // already printed error about this
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func walkstmt(np **Node) {
// so that reorder3 can fix up conflicts
var rl *NodeList

var cl uint8
var cl Class
for ll := Curfn.Func.Dcl; ll != nil; ll = ll.Next {
cl = ll.N.Class &^ PHEAP
if cl == PAUTO {
Expand Down

0 comments on commit cd7d738

Please sign in to comment.