mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
type strings through the reflection library.
R=rsc DELTA=187 (107 added, 28 deleted, 52 changed) OCL=18510 CL=18510
This commit is contained in:
parent
69e26bf28d
commit
a45f947c34
3 changed files with 146 additions and 67 deletions
|
|
@ -11,34 +11,8 @@ import (
|
|||
"reflect";
|
||||
)
|
||||
|
||||
|
||||
type Addr uint64 // TODO: where are ptrint/intptr etc?
|
||||
|
||||
export type Value interface {
|
||||
Kind() int;
|
||||
Type() Type;
|
||||
}
|
||||
|
||||
// Common fields and functionality for all values
|
||||
|
||||
type Common struct {
|
||||
kind int;
|
||||
typ Type;
|
||||
addr Addr;
|
||||
}
|
||||
|
||||
func (c *Common) Kind() int {
|
||||
return c.kind
|
||||
}
|
||||
|
||||
func (c *Common) Type() Type {
|
||||
return c.typ
|
||||
}
|
||||
|
||||
func NewValueAddr(typ Type, addr Addr) Value
|
||||
|
||||
type Creator *(typ Type, addr Addr) Value
|
||||
|
||||
// Conversion functions, implemented in assembler
|
||||
func AddrToPtrAddr(Addr) *Addr
|
||||
func AddrToPtrInt(Addr) *int
|
||||
|
|
@ -60,6 +34,39 @@ func AddrToPtrFloat80(Addr) *float80
|
|||
func AddrToPtrString(Addr) *string
|
||||
func AddrToPtrBool(Addr) *bool
|
||||
|
||||
export type Empty interface {} // TODO(r): Delete when no longer needed?
|
||||
|
||||
export type Value interface {
|
||||
Kind() int;
|
||||
Type() Type;
|
||||
Unreflect() Empty;
|
||||
}
|
||||
|
||||
// Common fields and functionality for all values
|
||||
|
||||
type Common struct {
|
||||
kind int;
|
||||
typ Type;
|
||||
addr Addr;
|
||||
}
|
||||
|
||||
func (c *Common) Kind() int {
|
||||
return c.kind
|
||||
}
|
||||
|
||||
func (c *Common) Type() Type {
|
||||
return c.typ
|
||||
}
|
||||
|
||||
func (c *Common) Unreflect() Empty {
|
||||
return sys.unreflect(*AddrToPtrAddr(c.addr), c.typ.String());
|
||||
}
|
||||
|
||||
func NewValueAddr(typ Type, addr Addr) Value
|
||||
|
||||
type Creator *(typ Type, addr Addr) Value
|
||||
|
||||
|
||||
// -- Missing
|
||||
|
||||
export type MissingValue interface {
|
||||
|
|
@ -743,8 +750,6 @@ export func NewInitValue(typ Type) Value {
|
|||
return NewValueAddr(typ, PtrUint8ToAddr(&data[0]));
|
||||
}
|
||||
|
||||
export type Empty interface {}
|
||||
|
||||
export func NewValue(e Empty) Value {
|
||||
value, typestring := sys.reflect(e);
|
||||
typ := ParseTypeString("", typestring);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue