]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: introduce type for decl contexts/storage classes
authorRobert Griesemer <gri@golang.org>
Mon, 26 Oct 2015 21:57:36 +0000 (14:57 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 26 Oct 2015 22:18:42 +0000 (22:18 +0000)
Change-Id: I956e27fa07f16060b8f41b986d991c36557f7c12
Reviewed-on: https://go-review.googlesource.com/16332
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/export.go
src/cmd/compile/internal/gc/go.go
src/cmd/compile/internal/gc/plive.go
src/cmd/compile/internal/gc/syntax.go
src/cmd/compile/internal/gc/walk.go

index 0d508daeb1c7b908e7678b487b6ca660b126f7d5..a3179c9d181f4803b5cc82e3bda78df04b7dc780 100644 (file)
@@ -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
        }
@@ -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)
        }
index f69fa9069920850f67bdc4f8243ac9f93dde963b..a7a8522ecdd3b0a3b050b1e9f00e76f543dcf3c3 100644 (file)
@@ -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
        }
index 9b91b57c3418a76a9cd437cdebafc48a07277a7d..550f332d07a5f693b04e5aa2bf93edc9f01404ae 100644 (file)
@@ -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 (
@@ -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
 
index 4d7f0f72a907579fb22e513c04cb04ced368ad17..c671c3bf3e2f4ca05c25e0a370af7013d5ce9aaf 100644 (file)
@@ -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
index dd185f18f571da098beafb5bdec42f88c8dc1700..c94d727488eda1143f031ff14dc4c045b1a7563a 100644 (file)
@@ -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
index 43398a3d3174c066cb90b5447f9723ba479e3afc..875b7aba13437e283bf0cc5aa53abdc063881e32 100644 (file)
@@ -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 {