Binary file not shown.
@@ -50,8 +50,6 @@ type Type struct {
|
|||||||
PtrToThis TypeOff // type for pointer to this type, may be zero
|
PtrToThis TypeOff // type for pointer to this type, may be zero
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Type) Kind() Kind { return Kind(t.Kind_ & KindMask) }
|
|
||||||
|
|
||||||
// A Kind represents the specific kind of type that a Type represents.
|
// A Kind represents the specific kind of type that a Type represents.
|
||||||
// The zero Kind is not a valid kind.
|
// The zero Kind is not a valid kind.
|
||||||
type Kind uint
|
type Kind uint
|
||||||
@@ -86,12 +84,14 @@ const (
|
|||||||
UnsafePointer
|
UnsafePointer
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
const (
|
const (
|
||||||
// TODO (khr, drchase) why aren't these in TFlag? Investigate, fix if possible.
|
// TODO (khr, drchase) why aren't these in TFlag? Investigate, fix if possible.
|
||||||
KindDirectIface = 1 << 5
|
KindDirectIface = 1 << 5
|
||||||
KindGCProg = 1 << 6 // Type.gc points to GC program
|
KindGCProg = 1 << 6 // Type.gc points to GC program
|
||||||
KindMask = (1 << 5) - 1
|
KindMask = (1 << 5) - 1
|
||||||
)
|
)
|
||||||
|
*/
|
||||||
|
|
||||||
// TFlag is used by a Type to signal what extra type information is
|
// TFlag is used by a Type to signal what extra type information is
|
||||||
// available in the memory directly following the Type value.
|
// available in the memory directly following the Type value.
|
||||||
@@ -207,6 +207,10 @@ type StructField struct {
|
|||||||
Offset uintptr // byte offset of field
|
Offset uintptr // byte offset of field
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *StructField) Embedded() bool {
|
||||||
|
return f.Name.IsEmbedded()
|
||||||
|
}
|
||||||
|
|
||||||
type StructType struct {
|
type StructType struct {
|
||||||
Type
|
Type
|
||||||
PkgPath Name
|
PkgPath Name
|
||||||
@@ -225,6 +229,16 @@ type Imethod struct {
|
|||||||
Typ TypeOff // .(*FuncType) underneath
|
Typ TypeOff // .(*FuncType) underneath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Type) Kind() Kind { return Kind(t.Kind_) }
|
||||||
|
|
||||||
|
// Size returns the size of data with type t.
|
||||||
|
func (t *Type) Size() uintptr { return t.Size_ }
|
||||||
|
|
||||||
|
// Align returns the alignment of data with type t.
|
||||||
|
func (t *Type) Align() int { return int(t.Align_) }
|
||||||
|
|
||||||
|
func (t *Type) FieldAlign() int { return int(t.FieldAlign_) }
|
||||||
|
|
||||||
func (t *Type) Common() *Type {
|
func (t *Type) Common() *Type {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -78,9 +78,36 @@ var (
|
|||||||
func basicType(kind abi.Kind) *Type {
|
func basicType(kind abi.Kind) *Type {
|
||||||
return &Type{
|
return &Type{
|
||||||
Size_: sizeBasicTypes[kind],
|
Size_: sizeBasicTypes[kind],
|
||||||
Hash: uint32(kind),
|
Hash: uint32(kind), // TODO(xsw): hash
|
||||||
Kind_: uint8(kind),
|
Kind_: uint8(kind),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// StructField returns a struct field.
|
||||||
|
func StructField(name string, typ *Type, off uintptr, tag string, exported, embedded bool) abi.StructField {
|
||||||
|
n := abi.NewName(name, tag, exported, embedded)
|
||||||
|
return abi.StructField{
|
||||||
|
Name: n,
|
||||||
|
Typ: typ,
|
||||||
|
Offset: off,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Struct returns a struct type.
|
||||||
|
func Struct(size uintptr, pkgPath string, fields ...abi.StructField) *Type {
|
||||||
|
npkg := abi.NewName(pkgPath, "", false, false)
|
||||||
|
ret := &abi.StructType{
|
||||||
|
Type: Type{
|
||||||
|
Size_: size,
|
||||||
|
Hash: uint32(abi.Struct), // TODO(xsw): hash
|
||||||
|
Kind_: uint8(abi.Struct),
|
||||||
|
},
|
||||||
|
PkgPath: npkg,
|
||||||
|
Fields: fields,
|
||||||
|
}
|
||||||
|
return &ret.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user