mirror of
https://github.com/golang/go
synced 2024-09-05 07:54:46 +00:00
cmd/compile: move a lot of declarations outside of go.go
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>
This commit is contained in:
parent
cca4ddb497
commit
5ba797bd18
|
@ -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 {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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'
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue