]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: move a lot of declarations outside of go.go
authorMatthew Dempsky <mdempsky@google.com>
Tue, 5 Apr 2016 21:20:04 +0000 (14:20 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 5 Apr 2016 21:38:15 +0000 (21:38 +0000)
go.go is currently a grab bag of various unrelated type and variable
declarations. Move a bunch of them into other more relevant source
files.

There are still more that can be moved, but these were the low hanging
fruit with obvious homes.

No code/comment changes. Just shuffling stuff around.

Change-Id: I43dbe1a5b8b707709c1a3a034c693d38b8465063
Reviewed-on: https://go-review.googlesource.com/21561
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/go.go
src/cmd/compile/internal/gc/lex.go
src/cmd/compile/internal/gc/popt.go
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/type.go
src/cmd/compile/internal/gc/typecheck.go

index 5c9a67c8b50263b047f66efda020281d8eac5f60..c7fb4d97e5089b055518e5d376c4986246a8d228 100644 (file)
@@ -10,6 +10,59 @@ import (
        "strings"
 )
 
+// Ctype describes the constant kind of an "ideal" (untyped) constant.
+type Ctype int8
+
+const (
+       CTxxx Ctype = iota
+
+       CTINT
+       CTRUNE
+       CTFLT
+       CTCPLX
+       CTSTR
+       CTBOOL
+       CTNIL
+)
+
+type Val struct {
+       // U contains one of:
+       // bool     bool when n.ValCtype() == CTBOOL
+       // *Mpint   int when n.ValCtype() == CTINT, rune when n.ValCtype() == CTRUNE
+       // *Mpflt   float when n.ValCtype() == CTFLT
+       // *Mpcplx  pair of floats when n.ValCtype() == CTCPLX
+       // string   string when n.ValCtype() == CTSTR
+       // *Nilval  when n.ValCtype() == CTNIL
+       U interface{}
+}
+
+func (v Val) Ctype() Ctype {
+       switch x := v.U.(type) {
+       default:
+               Fatalf("unexpected Ctype for %T", v.U)
+               panic("not reached")
+       case nil:
+               return 0
+       case *NilVal:
+               return CTNIL
+       case bool:
+               return CTBOOL
+       case *Mpint:
+               if x.Rune {
+                       return CTRUNE
+               }
+               return CTINT
+       case *Mpflt:
+               return CTFLT
+       case *Mpcplx:
+               return CTCPLX
+       case string:
+               return CTSTR
+       }
+}
+
+type NilVal struct{}
+
 // IntLiteral returns the Node's literal value as an integer.
 func (n *Node) IntLiteral() (x int64, ok bool) {
        switch {
index 8553e2f1e82203946a4e00cc316d04ecc58efbda..fb81545a46769973c72952d2ae2a99d541ee4570 100644 (file)
@@ -26,6 +26,12 @@ func dflag() bool {
        return true
 }
 
+var externdcl []*Node
+
+var blockgen int32 // max block number
+
+var block int32 // current block number
+
 // dclstack maintains a stack of shadowed symbol declarations so that
 // popdcl can restore their declarations when a block scope ends.
 // The stack is maintained as a linked list, using Sym's Link field.
index f4b3dc9326948c7b74bcb43f92d3bebbaf147737..4cb985b1be8ebc3bb1e4f39b676a706669a308fd 100644 (file)
@@ -5,7 +5,6 @@
 package gc
 
 import (
-       "bytes"
        "cmd/compile/internal/ssa"
        "cmd/internal/obj"
 )
@@ -16,44 +15,6 @@ const (
        MaxStackVarSize = 10 * 1024 * 1024
 )
 
-type Val struct {
-       // U contains one of:
-       // bool     bool when n.ValCtype() == CTBOOL
-       // *Mpint   int when n.ValCtype() == CTINT, rune when n.ValCtype() == CTRUNE
-       // *Mpflt   float when n.ValCtype() == CTFLT
-       // *Mpcplx  pair of floats when n.ValCtype() == CTCPLX
-       // string   string when n.ValCtype() == CTSTR
-       // *Nilval  when n.ValCtype() == CTNIL
-       U interface{}
-}
-
-type NilVal struct{}
-
-func (v Val) Ctype() Ctype {
-       switch x := v.U.(type) {
-       default:
-               Fatalf("unexpected Ctype for %T", v.U)
-               panic("not reached")
-       case nil:
-               return 0
-       case *NilVal:
-               return CTNIL
-       case bool:
-               return CTBOOL
-       case *Mpint:
-               if x.Rune {
-                       return CTRUNE
-               }
-               return CTINT
-       case *Mpflt:
-               return CTFLT
-       case *Mpcplx:
-               return CTCPLX
-       case string:
-               return CTSTR
-       }
-}
-
 type Pkg struct {
        Name     string // package name, e.g. "sys"
        Path     string // string literal used in import statement, e.g. "runtime/internal/sys"
@@ -119,35 +80,6 @@ const (
        SymAlgGen
 )
 
-// Ctype describes the constant kind of an "ideal" (untyped) constant.
-type Ctype int8
-
-const (
-       CTxxx Ctype = iota
-
-       CTINT
-       CTRUNE
-       CTFLT
-       CTCPLX
-       CTSTR
-       CTBOOL
-       CTNIL
-)
-
-// ChanDir is whether a channel can send, receive, or both.
-type ChanDir uint8
-
-func (c ChanDir) CanRecv() bool { return c&Crecv != 0 }
-func (c ChanDir) CanSend() bool { return c&Csend != 0 }
-
-const (
-       // types of channel
-       // must match ../../../../reflect/type.go:/ChanDir
-       Crecv ChanDir = 1 << 0
-       Csend ChanDir = 1 << 1
-       Cboth ChanDir = Crecv | Csend
-)
-
 // The Class of a variable/function describes the "storage class"
 // of a variable or function. During parsing, storage classes are
 // called declaration contexts.
@@ -167,30 +99,6 @@ const (
        PHEAP = 1 << 7 // an extra bit to identify an escaped variable
 )
 
-const (
-       Etop      = 1 << 1 // evaluated at statement level
-       Erv       = 1 << 2 // evaluated in value context
-       Etype     = 1 << 3
-       Ecall     = 1 << 4  // call-only expressions are ok
-       Efnstruct = 1 << 5  // multivalue function returns are ok
-       Eiota     = 1 << 6  // iota is ok
-       Easgn     = 1 << 7  // assigning to expression
-       Eindir    = 1 << 8  // indirecting through expression
-       Eaddr     = 1 << 9  // taking address of expression
-       Eproc     = 1 << 10 // inside a go statement
-       Ecomplit  = 1 << 11 // type in composite literal
-)
-
-type Sig struct {
-       name   string
-       pkg    *Pkg
-       isym   *Sym
-       tsym   *Sym
-       type_  *Type
-       mtype  *Type
-       offset int32
-}
-
 // note this is the runtime representation
 // of the compilers arrays.
 //
@@ -218,13 +126,6 @@ var sizeof_Array int // runtime sizeof(Array)
 // } String;
 var sizeof_String int // runtime sizeof(String)
 
-// lexlineno is the line number _after_ the most recently read rune.
-// In particular, it's advanced (or rewound) as newlines are read (or unread).
-var lexlineno int32
-
-// lineno is the line number at the start of the most recently lexed token.
-var lineno int32
-
 var pragcgobuf string
 
 var infile string
@@ -245,10 +146,6 @@ var safemode int
 
 var nolocalimports int
 
-var lexbuf bytes.Buffer
-var strbuf bytes.Buffer
-var litbuf string // LLITERAL value for use in syntax error messages
-
 var Debug [256]int
 
 var debugstr string
@@ -324,8 +221,6 @@ var maxfltval [NTYPE]*Mpflt
 
 var xtop []*Node
 
-var externdcl []*Node
-
 var exportlist []*Node
 
 var importlist []*Node // imported functions and methods with inlinable bodies
@@ -350,10 +245,6 @@ var Stksize int64 // stack size for current frame
 
 var stkptrsize int64 // prefix of stack containing pointers
 
-var blockgen int32 // max block number
-
-var block int32 // current block number
-
 var hasdefer bool // flag that curfn has defer statement
 
 var Curfn *Node
@@ -410,34 +301,6 @@ var nodfp *Node
 
 var Disable_checknil int
 
-type Flow struct {
-       Prog   *obj.Prog // actual instruction
-       P1     *Flow     // predecessors of this instruction: p1,
-       P2     *Flow     // and then p2 linked though p2link.
-       P2link *Flow
-       S1     *Flow // successors of this instruction (at most two: s1 and s2).
-       S2     *Flow
-       Link   *Flow // next instruction in function code
-
-       Active int32 // usable by client
-
-       Id     int32  // sequence number in flow graph
-       Rpo    int32  // reverse post ordering
-       Loop   uint16 // x5 for every loop
-       Refset bool   // diagnostic generated
-
-       Data interface{} // for use by client
-}
-
-type Graph struct {
-       Start *Flow
-       Num   int
-
-       // After calling flowrpo, rpo lists the flow nodes in reverse postorder,
-       // and each non-dead Flow node f has g->rpo[f->rpo] == f.
-       Rpo []*Flow
-}
-
 // interface to back end
 
 const (
index 6f1331ca8982f904e095861435b614222aa7e161..2dbbd9276bf9a4a6b8b7f42c184965b5fa96e6fd 100644 (file)
@@ -6,6 +6,7 @@ package gc
 
 import (
        "bufio"
+       "bytes"
        "cmd/internal/obj"
        "fmt"
        "io"
@@ -20,6 +21,17 @@ const (
        BOM = 0xFEFF
 )
 
+// lexlineno is the line number _after_ the most recently read rune.
+// In particular, it's advanced (or rewound) as newlines are read (or unread).
+var lexlineno int32
+
+// lineno is the line number at the start of the most recently lexed token.
+var lineno int32
+
+var lexbuf bytes.Buffer
+var strbuf bytes.Buffer
+var litbuf string // LLITERAL value for use in syntax error messages
+
 func isSpace(c rune) bool {
        return c == ' ' || c == '\t' || c == '\n' || c == '\r'
 }
index 41f8ba9fccc83e3579648ddf1434fa8610ecbba1..001a715f7b7aa13d8ed7bb5b251bb330a5c1ab93 100644 (file)
@@ -235,6 +235,34 @@ func fixjmp(firstp *obj.Prog) {
 // for every f.Data field, for use by the client.
 // If newData is nil, f.Data will be nil.
 
+type Graph struct {
+       Start *Flow
+       Num   int
+
+       // After calling flowrpo, rpo lists the flow nodes in reverse postorder,
+       // and each non-dead Flow node f has g->rpo[f->rpo] == f.
+       Rpo []*Flow
+}
+
+type Flow struct {
+       Prog   *obj.Prog // actual instruction
+       P1     *Flow     // predecessors of this instruction: p1,
+       P2     *Flow     // and then p2 linked though p2link.
+       P2link *Flow
+       S1     *Flow // successors of this instruction (at most two: s1 and s2).
+       S2     *Flow
+       Link   *Flow // next instruction in function code
+
+       Active int32 // usable by client
+
+       Id     int32  // sequence number in flow graph
+       Rpo    int32  // reverse post ordering
+       Loop   uint16 // x5 for every loop
+       Refset bool   // diagnostic generated
+
+       Data interface{} // for use by client
+}
+
 var flowmark int
 
 // MaxFlowProg is the maximum size program (counted in instructions)
index 11bcd4cdc6de0f8084de8ae1926502f8ae6a6b5e..c069b35787476454d29aeb77da92ad7f2d8607ac 100644 (file)
@@ -22,6 +22,16 @@ type itabEntry struct {
 var signatlist []*Node
 var itabs []itabEntry
 
+type Sig struct {
+       name   string
+       pkg    *Pkg
+       isym   *Sym
+       tsym   *Sym
+       type_  *Type
+       mtype  *Type
+       offset int32
+}
+
 // byMethodNameAndPackagePath sorts method signatures by name, then package path.
 type byMethodNameAndPackagePath []*Sig
 
index b89c5dbf22f0f20de1686739b3908ab2cdb22f8d..05e30df2715b30ed002a5e3bdeb1fc18f634921c 100644 (file)
@@ -75,6 +75,20 @@ const (
        dddBound   = -100 // arrays declared as [...]T start life with Bound=dddBound
 )
 
+// ChanDir is whether a channel can send, receive, or both.
+type ChanDir uint8
+
+func (c ChanDir) CanRecv() bool { return c&Crecv != 0 }
+func (c ChanDir) CanSend() bool { return c&Csend != 0 }
+
+const (
+       // types of channel
+       // must match ../../../../reflect/type.go:/ChanDir
+       Crecv ChanDir = 1 << 0
+       Csend ChanDir = 1 << 1
+       Cboth ChanDir = Crecv | Csend
+)
+
 // Types stores pointers to predeclared named types.
 //
 // It also stores pointers to several special types:
index 688936e926818bc41ce26e7bf8d0efe7398521cf..d21552d180bde02889e600c922b8cd301af85ef1 100644 (file)
@@ -11,6 +11,20 @@ import (
        "strings"
 )
 
+const (
+       Etop      = 1 << 1 // evaluated at statement level
+       Erv       = 1 << 2 // evaluated in value context
+       Etype     = 1 << 3
+       Ecall     = 1 << 4  // call-only expressions are ok
+       Efnstruct = 1 << 5  // multivalue function returns are ok
+       Eiota     = 1 << 6  // iota is ok
+       Easgn     = 1 << 7  // assigning to expression
+       Eindir    = 1 << 8  // indirecting through expression
+       Eaddr     = 1 << 9  // taking address of expression
+       Eproc     = 1 << 10 // inside a go statement
+       Ecomplit  = 1 << 11 // type in composite literal
+)
+
 // type check the whole tree of an expression.
 // calculates expression types.
 // evaluates compile time constants.