]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: relocate a bunch of Type-related code
authorMatthew Dempsky <mdempsky@google.com>
Tue, 8 Mar 2016 22:31:22 +0000 (14:31 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 8 Mar 2016 22:58:01 +0000 (22:58 +0000)
Some cleaned up documentation, but no code changes.

Change-Id: I145398bb6d118c626ab3873ef75dbb64ebc286e9
Reviewed-on: https://go-review.googlesource.com/20404
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/bexport.go
src/cmd/compile/internal/gc/go.go
src/cmd/compile/internal/gc/lex.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/type.go

index ba5b8479a3d2969a849d44a51696a7bf2028e0af..36486e14f0d85b9b4497946493fe07c33911d912 100644 (file)
@@ -1250,13 +1250,6 @@ func untype(ctype Ctype) *Type {
        return nil
 }
 
-var (
-       idealint     = typ(TIDEAL)
-       idealrune    = typ(TIDEAL)
-       idealfloat   = typ(TIDEAL)
-       idealcomplex = typ(TIDEAL)
-)
-
 var predecl []*Type // initialized lazily
 
 func predeclared() []*Type {
index 397e278813dee4f44f50f354dd756989d3bd3af4..b5d3f3ec63e6e2f05b7a6217f863a63953fd6327 100644 (file)
@@ -85,69 +85,6 @@ type Sym struct {
        Fsym       *Sym // funcsym
 }
 
-type Type struct {
-       Etype       EType
-       Nointerface bool
-       Noalg       bool
-       Chan        uint8
-       Trecur      uint8 // to detect loops
-       Printed     bool
-       Embedded    uint8 // TFIELD embedded type
-       Funarg      bool  // on TSTRUCT and TFIELD
-       Copyany     bool
-       Local       bool // created in this file
-       Deferwidth  bool
-       Broke       bool // broken type definition.
-       Isddd       bool // TFIELD is ... argument
-       Align       uint8
-       Haspointers uint8 // 0 unknown, 1 no, 2 yes
-
-       Nod    *Node // canonical OTYPE node
-       Orig   *Type // original type (type literal or predefined type)
-       Lineno int32
-
-       // TFUNC
-       Thistuple int
-       Outtuple  int
-       Intuple   int
-       Outnamed  bool
-
-       Method  *Type
-       Xmethod *Type
-
-       Sym    *Sym
-       Vargen int32 // unique name for OTYPE/ONAME
-
-       Nname  *Node
-       Argwid int64
-
-       // most nodes
-       Type  *Type // actual type for TFIELD, element type for TARRAY, TCHAN, TMAP, TPTRxx
-       Width int64 // offset in TFIELD, width in all others
-
-       // TFIELD
-       Down  *Type   // next struct field, also key type in TMAP
-       Outer *Type   // outer struct
-       Note  *string // literal string annotation
-
-       // TARRAY
-       Bound int64 // negative is slice
-
-       // TMAP
-       Bucket *Type // internal type representing a hash bucket
-       Hmap   *Type // internal type representing a Hmap (map header object)
-       Hiter  *Type // internal type representing hash iterator state
-       Map    *Type // link from the above 3 internal types back to the map type.
-
-       Maplineno   int32 // first use of TFORW as map key
-       Embedlineno int32 // first use of TFORW as embedded type
-
-       // for TFORW, where to copy the eventual value to
-       Copyto []*Node
-
-       Lastfn *Node // for usefield
-}
-
 type Label struct {
        Sym  *Sym
        Def  *Node
@@ -189,66 +126,6 @@ const (
 
 var dclstack *Sym
 
-type Iter struct {
-       Done  int
-       Tfunc *Type
-       T     *Type
-}
-
-type EType uint8
-
-const (
-       Txxx = iota
-
-       TINT8
-       TUINT8
-       TINT16
-       TUINT16
-       TINT32
-       TUINT32
-       TINT64
-       TUINT64
-       TINT
-       TUINT
-       TUINTPTR
-
-       TCOMPLEX64
-       TCOMPLEX128
-
-       TFLOAT32
-       TFLOAT64
-
-       TBOOL
-
-       TPTR32
-       TPTR64
-
-       TFUNC
-       TARRAY
-       T_old_DARRAY // Doesn't seem to be used in existing code. Used now for Isddd export (see bexport.go). TODO(gri) rename.
-       TSTRUCT
-       TCHAN
-       TMAP
-       TINTER
-       TFORW
-       TFIELD
-       TANY
-       TSTRING
-       TUNSAFEPTR
-
-       // pseudo-types for literals
-       TIDEAL
-       TNIL
-       TBLANK
-
-       // pseudo-type for frame layout
-       TFUNCARGS
-       TCHANARGS
-       TINTERMETH
-
-       NTYPE
-)
-
 // Ctype describes the constant kind of an "ideal" (untyped) constant.
 type Ctype int8
 
@@ -437,18 +314,6 @@ var localimport string
 
 var asmhdr string
 
-var Types [NTYPE]*Type
-
-var idealstring *Type
-
-var idealbool *Type
-
-var bytetype *Type
-
-var runetype *Type
-
-var errortype *Type
-
 var Simtype [NTYPE]EType
 
 var (
index 3a7807e37c048310448375b1f3b5586324f54409..92614060cc3d4496c4e1e5596b5a86224b8635ab 100644 (file)
@@ -2135,13 +2135,7 @@ func lexinit() {
                s2.Def.Etype = EType(s.op)
        }
 
-       // logically, the type of a string literal.
-       // types[TSTRING] is the named type string
-       // (the type of x in var x string or var x = "hello").
-       // this is the ideal form
-       // (the type of x in const x = "hello").
        idealstring = typ(TSTRING)
-
        idealbool = typ(TBOOL)
 
        s := Pkglookup("true", builtinpkg)
index 6b85b3a3754804669e4d04f4f90167aa1ddab818..5eba2523bf17088a9cc7070eada20da8008bb451 100644 (file)
@@ -1462,128 +1462,6 @@ func badtype(op Op, tl *Type, tr *Type) {
        Yyerror("illegal types for operand: %v%s", Oconv(op, 0), s)
 }
 
-// iterator to walk a structure declaration
-func Structfirst(s *Iter, nn **Type) *Type {
-       var t *Type
-
-       n := *nn
-       if n == nil {
-               goto bad
-       }
-
-       switch n.Etype {
-       default:
-               goto bad
-
-       case TSTRUCT, TINTER, TFUNC:
-               break
-       }
-
-       t = n.Type
-       if t == nil {
-               return nil
-       }
-
-       if t.Etype != TFIELD {
-               Fatalf("structfirst: not field %v", t)
-       }
-
-       s.T = t
-       return t
-
-bad:
-       Fatalf("structfirst: not struct %v", n)
-
-       return nil
-}
-
-func structnext(s *Iter) *Type {
-       n := s.T
-       t := n.Down
-       if t == nil {
-               return nil
-       }
-
-       if t.Etype != TFIELD {
-               Fatalf("structnext: not struct %v", n)
-
-               return nil
-       }
-
-       s.T = t
-       return t
-}
-
-// iterator to this and inargs in a function
-func funcfirst(s *Iter, t *Type) *Type {
-       var fp *Type
-
-       if t == nil {
-               goto bad
-       }
-
-       if t.Etype != TFUNC {
-               goto bad
-       }
-
-       s.Tfunc = t
-       s.Done = 0
-       fp = Structfirst(s, getthis(t))
-       if fp == nil {
-               s.Done = 1
-               fp = Structfirst(s, getinarg(t))
-       }
-
-       return fp
-
-bad:
-       Fatalf("funcfirst: not func %v", t)
-       return nil
-}
-
-func funcnext(s *Iter) *Type {
-       fp := structnext(s)
-       if fp == nil && s.Done == 0 {
-               s.Done = 1
-               fp = Structfirst(s, getinarg(s.Tfunc))
-       }
-
-       return fp
-}
-
-func getthis(t *Type) **Type {
-       if t.Etype != TFUNC {
-               Fatalf("getthis: not a func %v", t)
-       }
-       return &t.Type
-}
-
-func Getoutarg(t *Type) **Type {
-       if t.Etype != TFUNC {
-               Fatalf("getoutarg: not a func %v", t)
-       }
-       return &t.Type.Down
-}
-
-func getinarg(t *Type) **Type {
-       if t.Etype != TFUNC {
-               Fatalf("getinarg: not a func %v", t)
-       }
-       return &t.Type.Down.Down
-}
-
-func getthisx(t *Type) *Type {
-       return *getthis(t)
-}
-
-func getoutargx(t *Type) *Type {
-       return *Getoutarg(t)
-}
-
-func getinargx(t *Type) *Type {
-       return *getinarg(t)
-}
-
 // Brcom returns !(op).
 // For example, Brcom(==) is !=.
 func Brcom(op Op) Op {
index f9ee816377bef2131899b527efb6608623f08419..095f81482552f2abf1a8129c17d05658840cf7ef 100644 (file)
@@ -14,6 +14,286 @@ import (
        "fmt"
 )
 
+// EType describes a kind of type.
+type EType uint8
+
+const (
+       Txxx = iota
+
+       TINT8
+       TUINT8
+       TINT16
+       TUINT16
+       TINT32
+       TUINT32
+       TINT64
+       TUINT64
+       TINT
+       TUINT
+       TUINTPTR
+
+       TCOMPLEX64
+       TCOMPLEX128
+
+       TFLOAT32
+       TFLOAT64
+
+       TBOOL
+
+       TPTR32
+       TPTR64
+
+       TFUNC
+       TARRAY
+       T_old_DARRAY // Doesn't seem to be used in existing code. Used now for Isddd export (see bexport.go). TODO(gri) rename.
+       TSTRUCT
+       TCHAN
+       TMAP
+       TINTER
+       TFORW
+       TFIELD
+       TANY
+       TSTRING
+       TUNSAFEPTR
+
+       // pseudo-types for literals
+       TIDEAL
+       TNIL
+       TBLANK
+
+       // pseudo-type for frame layout
+       TFUNCARGS
+       TCHANARGS
+       TINTERMETH
+
+       NTYPE
+)
+
+// Types stores pointers to predeclared named types.
+//
+// It also stores pointers to several special types:
+//   - Types[TANY] is the placeholder "any" type recognized by substArgTypes.
+//   - Types[TBLANK] represents the blank variable's type.
+//   - Types[TIDEAL] represents untyped numeric constants.
+//   - Types[TNIL] represents the predeclared "nil" value's type.
+//   - Types[TUNSAFEPTR] is package unsafe's Pointer type.
+var Types [NTYPE]*Type
+
+var (
+       // Predeclared alias types. Kept separate for better error messages.
+       bytetype *Type
+       runetype *Type
+
+       // Predeclared error interface type.
+       errortype *Type
+
+       // Types to represent untyped string and boolean constants.
+       idealstring *Type
+       idealbool   *Type
+
+       // Types to represent untyped numeric constants.
+       // Note: Currently these are only used within the binary export
+       // data format. The rest of the compiler only uses Types[TIDEAL].
+       idealint     = typ(TIDEAL)
+       idealrune    = typ(TIDEAL)
+       idealfloat   = typ(TIDEAL)
+       idealcomplex = typ(TIDEAL)
+)
+
+// A Type represents a Go type.
+type Type struct {
+       Etype       EType
+       Nointerface bool
+       Noalg       bool
+       Chan        uint8
+       Trecur      uint8 // to detect loops
+       Printed     bool
+       Embedded    uint8 // TFIELD embedded type
+       Funarg      bool  // on TSTRUCT and TFIELD
+       Copyany     bool
+       Local       bool // created in this file
+       Deferwidth  bool
+       Broke       bool // broken type definition.
+       Isddd       bool // TFIELD is ... argument
+       Align       uint8
+       Haspointers uint8 // 0 unknown, 1 no, 2 yes
+
+       Nod    *Node // canonical OTYPE node
+       Orig   *Type // original type (type literal or predefined type)
+       Lineno int32
+
+       // TFUNC
+       Thistuple int
+       Outtuple  int
+       Intuple   int
+       Outnamed  bool
+
+       Method  *Type
+       Xmethod *Type
+
+       Sym    *Sym
+       Vargen int32 // unique name for OTYPE/ONAME
+
+       Nname  *Node
+       Argwid int64
+
+       // most nodes
+       Type  *Type // actual type for TFIELD, element type for TARRAY, TCHAN, TMAP, TPTRxx
+       Width int64 // offset in TFIELD, width in all others
+
+       // TFIELD
+       Down  *Type   // next struct field, also key type in TMAP
+       Outer *Type   // outer struct
+       Note  *string // literal string annotation
+
+       // TARRAY
+       Bound int64 // negative is slice
+
+       // TMAP
+       Bucket *Type // internal type representing a hash bucket
+       Hmap   *Type // internal type representing a Hmap (map header object)
+       Hiter  *Type // internal type representing hash iterator state
+       Map    *Type // link from the above 3 internal types back to the map type.
+
+       Maplineno   int32 // first use of TFORW as map key
+       Embedlineno int32 // first use of TFORW as embedded type
+
+       // for TFORW, where to copy the eventual value to
+       Copyto []*Node
+
+       Lastfn *Node // for usefield
+}
+
+// Iter provides an abstraction for iterating across struct fields
+// and function parameters.
+type Iter struct {
+       Done  int
+       Tfunc *Type
+       T     *Type
+}
+
+// iterator to walk a structure declaration
+func Structfirst(s *Iter, nn **Type) *Type {
+       var t *Type
+
+       n := *nn
+       if n == nil {
+               goto bad
+       }
+
+       switch n.Etype {
+       default:
+               goto bad
+
+       case TSTRUCT, TINTER, TFUNC:
+               break
+       }
+
+       t = n.Type
+       if t == nil {
+               return nil
+       }
+
+       if t.Etype != TFIELD {
+               Fatalf("structfirst: not field %v", t)
+       }
+
+       s.T = t
+       return t
+
+bad:
+       Fatalf("structfirst: not struct %v", n)
+
+       return nil
+}
+
+func structnext(s *Iter) *Type {
+       n := s.T
+       t := n.Down
+       if t == nil {
+               return nil
+       }
+
+       if t.Etype != TFIELD {
+               Fatalf("structnext: not struct %v", n)
+
+               return nil
+       }
+
+       s.T = t
+       return t
+}
+
+// iterator to this and inargs in a function
+func funcfirst(s *Iter, t *Type) *Type {
+       var fp *Type
+
+       if t == nil {
+               goto bad
+       }
+
+       if t.Etype != TFUNC {
+               goto bad
+       }
+
+       s.Tfunc = t
+       s.Done = 0
+       fp = Structfirst(s, getthis(t))
+       if fp == nil {
+               s.Done = 1
+               fp = Structfirst(s, getinarg(t))
+       }
+
+       return fp
+
+bad:
+       Fatalf("funcfirst: not func %v", t)
+       return nil
+}
+
+func funcnext(s *Iter) *Type {
+       fp := structnext(s)
+       if fp == nil && s.Done == 0 {
+               s.Done = 1
+               fp = Structfirst(s, getinarg(s.Tfunc))
+       }
+
+       return fp
+}
+
+func getthis(t *Type) **Type {
+       if t.Etype != TFUNC {
+               Fatalf("getthis: not a func %v", t)
+       }
+       return &t.Type
+}
+
+func Getoutarg(t *Type) **Type {
+       if t.Etype != TFUNC {
+               Fatalf("getoutarg: not a func %v", t)
+       }
+       return &t.Type.Down
+}
+
+func getinarg(t *Type) **Type {
+       if t.Etype != TFUNC {
+               Fatalf("getinarg: not a func %v", t)
+       }
+       return &t.Type.Down.Down
+}
+
+func getthisx(t *Type) *Type {
+       return *getthis(t)
+}
+
+func getoutargx(t *Type) *Type {
+       return *Getoutarg(t)
+}
+
+func getinargx(t *Type) *Type {
+       return *getinarg(t)
+}
+
 func (t *Type) Size() int64 {
        dowidth(t)
        return t.Width