Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
ed2ac9b8
Commit
ed2ac9b8
authored
Jan 16, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
casify reflect.
R=rsc DELTA=513 (0 added, 2 deleted, 511 changed) OCL=22954 CL=22956
parent
aedfb397
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
357 additions
and
359 deletions
+357
-359
src/lib/reflect/all_test.go
src/lib/reflect/all_test.go
+4
-6
src/lib/reflect/tostring.go
src/lib/reflect/tostring.go
+10
-10
src/lib/reflect/type.go
src/lib/reflect/type.go
+169
-169
src/lib/reflect/value.go
src/lib/reflect/value.go
+174
-174
No files found.
src/lib/reflect/all_test.go
View file @
ed2ac9b8
...
...
@@ -87,8 +87,6 @@ func valuedump(s, t string) {
assert
(
reflect
.
ValueToString
(
v
),
t
);
}
export
type
empty
interface
{}
export
type
T
struct
{
a
int
;
b
float64
;
c
string
;
d
*
int
}
export
func
TestAll
(
tt
*
testing
.
T
)
{
// TODO(r): wrap up better
...
...
@@ -342,14 +340,14 @@ export func TestBigUnnamedStruct(t *testing.T) {
}
}
type
B
ig
struct
{
type
b
ig
struct
{
a
,
b
,
c
,
d
,
e
int64
}
export
func
TestBigStruct
(
t
*
testing
.
T
)
{
b
:=
B
ig
{
1
,
2
,
3
,
4
,
5
};
b
:=
b
ig
{
1
,
2
,
3
,
4
,
5
};
v
:=
NewValue
(
b
);
b1
:=
v
.
Interface
()
.
(
B
ig
);
b1
:=
v
.
Interface
()
.
(
b
ig
);
if
b1
.
a
!=
b
.
a
||
b1
.
b
!=
b
.
b
||
b1
.
c
!=
b
.
c
||
b1
.
d
!=
b
.
d
||
b1
.
e
!=
b
.
e
{
t
.
Errorf
(
"NewValue(%v).Interface().(
B
ig) = %v"
,
b
,
b1
);
t
.
Errorf
(
"NewValue(%v).Interface().(
b
ig) = %v"
,
b
,
b1
);
}
}
src/lib/reflect/tostring.go
View file @
ed2ac9b8
...
...
@@ -15,7 +15,7 @@ import (
export
func
TypeToString
(
typ
Type
,
expand
bool
)
string
export
func
ValueToString
(
val
Value
)
string
func
D
oubleQuote
(
s
string
)
string
{
func
d
oubleQuote
(
s
string
)
string
{
out
:=
"
\"
"
;
for
i
:=
0
;
i
<
len
(
s
);
i
++
{
c
:=
s
[
i
];
...
...
@@ -38,12 +38,12 @@ func DoubleQuote(s string) string {
return
out
;
}
type
H
asFields
interface
{
type
h
asFields
interface
{
Field
(
i
int
)
(
name
string
,
typ
Type
,
tag
string
,
offset
int
);
Len
()
int
;
}
func
TypeFieldsToString
(
t
H
asFields
,
sep
string
)
string
{
func
typeFieldsToString
(
t
h
asFields
,
sep
string
)
string
{
var
str
string
;
for
i
:=
0
;
i
<
t
.
Len
();
i
++
{
str1
,
typ
,
tag
,
offset
:=
t
.
Field
(
i
);
...
...
@@ -52,7 +52,7 @@ func TypeFieldsToString(t HasFields, sep string) string {
}
str1
+=
TypeToString
(
typ
,
false
);
if
tag
!=
""
{
str1
+=
" "
+
D
oubleQuote
(
tag
);
str1
+=
" "
+
d
oubleQuote
(
tag
);
}
if
i
<
t
.
Len
()
-
1
{
str1
+=
sep
+
" "
;
...
...
@@ -62,7 +62,7 @@ func TypeFieldsToString(t HasFields, sep string) string {
return
str
;
}
func
TypeToString
(
typ
Type
,
expand
bool
)
string
{
export
func
TypeToString
(
typ
Type
,
expand
bool
)
string
{
var
str
string
;
if
name
:=
typ
.
Name
();
!
expand
&&
name
!=
""
{
return
name
...
...
@@ -105,14 +105,14 @@ func TypeToString(typ Type, expand bool) string {
}
return
str
+
TypeToString
(
c
.
Elem
(),
false
);
case
StructKind
:
return
"struct{"
+
T
ypeFieldsToString
(
typ
,
";"
)
+
"}"
;
return
"struct{"
+
t
ypeFieldsToString
(
typ
,
";"
)
+
"}"
;
case
InterfaceKind
:
return
"interface{"
+
T
ypeFieldsToString
(
typ
,
";"
)
+
"}"
;
return
"interface{"
+
t
ypeFieldsToString
(
typ
,
";"
)
+
"}"
;
case
FuncKind
:
f
:=
typ
.
(
FuncType
);
str
=
"("
+
T
ypeFieldsToString
(
f
.
In
(),
","
)
+
")"
;
str
=
"("
+
t
ypeFieldsToString
(
f
.
In
(),
","
)
+
")"
;
if
f
.
Out
()
!=
nil
{
str
+=
"("
+
T
ypeFieldsToString
(
f
.
Out
(),
","
)
+
")"
;
str
+=
"("
+
t
ypeFieldsToString
(
f
.
Out
(),
","
)
+
")"
;
}
return
str
;
default
:
...
...
@@ -126,7 +126,7 @@ func integer(v int64) string {
return
strconv
.
Itoa64
(
v
);
}
func
ValueToString
(
val
Value
)
string
{
export
func
ValueToString
(
val
Value
)
string
{
var
str
string
;
typ
:=
val
.
Type
();
switch
(
val
.
Kind
())
{
...
...
src/lib/reflect/type.go
View file @
ed2ac9b8
...
...
@@ -48,8 +48,8 @@ export const (
var
ptrsize
int
var
interfacesize
int
var
M
issingString
=
"$missing$"
// syntactic name for undefined type names
var
D
otDotDotString
=
"..."
var
m
issingString
=
"$missing$"
// syntactic name for undefined type names
var
d
otDotDotString
=
"..."
export
type
Type
interface
{
Kind
()
int
;
...
...
@@ -90,50 +90,50 @@ func (c *commonType) Size() int {
// -- Basic
type
B
asicType
struct
{
type
b
asicType
struct
{
commonType
}
func
N
ewBasicType
(
name
string
,
kind
int
,
size
int
)
Type
{
return
&
B
asicType
{
commonType
{
kind
,
name
,
name
,
size
}
}
func
n
ewBasicType
(
name
string
,
kind
int
,
size
int
)
Type
{
return
&
b
asicType
{
commonType
{
kind
,
name
,
name
,
size
}
}
}
// Prebuilt basic types
export
var
(
Missing
=
NewBasicType
(
M
issingString
,
MissingKind
,
1
);
DotDotDot
=
NewBasicType
(
D
otDotDotString
,
DotDotDotKind
,
16
);
// TODO(r): size of interface?
Bool
=
N
ewBasicType
(
"bool"
,
BoolKind
,
1
);
// TODO: need to know how big a bool is
Int
=
N
ewBasicType
(
"int"
,
IntKind
,
4
);
// TODO: need to know how big an int is
Int8
=
N
ewBasicType
(
"int8"
,
Int8Kind
,
1
);
Int16
=
N
ewBasicType
(
"int16"
,
Int16Kind
,
2
);
Int32
=
N
ewBasicType
(
"int32"
,
Int32Kind
,
4
);
Int64
=
N
ewBasicType
(
"int64"
,
Int64Kind
,
8
);
Uint
=
N
ewBasicType
(
"uint"
,
UintKind
,
4
);
// TODO: need to know how big a uint is
Uint8
=
N
ewBasicType
(
"uint8"
,
Uint8Kind
,
1
);
Uint16
=
N
ewBasicType
(
"uint16"
,
Uint16Kind
,
2
);
Uint32
=
N
ewBasicType
(
"uint32"
,
Uint32Kind
,
4
);
Uint64
=
N
ewBasicType
(
"uint64"
,
Uint64Kind
,
8
);
Uintptr
=
N
ewBasicType
(
"uintptr"
,
UintptrKind
,
8
);
// TODO: need to know how big a uintptr is
Float
=
N
ewBasicType
(
"float"
,
FloatKind
,
4
);
// TODO: need to know how big a float is
Float32
=
N
ewBasicType
(
"float32"
,
Float32Kind
,
4
);
Float64
=
N
ewBasicType
(
"float64"
,
Float64Kind
,
8
);
Float80
=
N
ewBasicType
(
"float80"
,
Float80Kind
,
10
);
// TODO: strange size?
String
=
N
ewBasicType
(
"string"
,
StringKind
,
8
);
// implemented as a pointer
Missing
=
newBasicType
(
m
issingString
,
MissingKind
,
1
);
DotDotDot
=
newBasicType
(
d
otDotDotString
,
DotDotDotKind
,
16
);
// TODO(r): size of interface?
Bool
=
n
ewBasicType
(
"bool"
,
BoolKind
,
1
);
// TODO: need to know how big a bool is
Int
=
n
ewBasicType
(
"int"
,
IntKind
,
4
);
// TODO: need to know how big an int is
Int8
=
n
ewBasicType
(
"int8"
,
Int8Kind
,
1
);
Int16
=
n
ewBasicType
(
"int16"
,
Int16Kind
,
2
);
Int32
=
n
ewBasicType
(
"int32"
,
Int32Kind
,
4
);
Int64
=
n
ewBasicType
(
"int64"
,
Int64Kind
,
8
);
Uint
=
n
ewBasicType
(
"uint"
,
UintKind
,
4
);
// TODO: need to know how big a uint is
Uint8
=
n
ewBasicType
(
"uint8"
,
Uint8Kind
,
1
);
Uint16
=
n
ewBasicType
(
"uint16"
,
Uint16Kind
,
2
);
Uint32
=
n
ewBasicType
(
"uint32"
,
Uint32Kind
,
4
);
Uint64
=
n
ewBasicType
(
"uint64"
,
Uint64Kind
,
8
);
Uintptr
=
n
ewBasicType
(
"uintptr"
,
UintptrKind
,
8
);
// TODO: need to know how big a uintptr is
Float
=
n
ewBasicType
(
"float"
,
FloatKind
,
4
);
// TODO: need to know how big a float is
Float32
=
n
ewBasicType
(
"float32"
,
Float32Kind
,
4
);
Float64
=
n
ewBasicType
(
"float64"
,
Float64Kind
,
8
);
Float80
=
n
ewBasicType
(
"float80"
,
Float80Kind
,
10
);
// TODO: strange size?
String
=
n
ewBasicType
(
"string"
,
StringKind
,
8
);
// implemented as a pointer
)
// Stub types allow us to defer evaluating type names until needed.
// If the name is empty, the type must be non-nil.
type
S
tubType
struct
{
type
s
tubType
struct
{
name
string
;
typ
Type
;
}
func
NewStubType
(
name
string
,
typ
Type
)
*
S
tubType
{
return
&
S
tubType
{
name
,
typ
}
func
newStubType
(
name
string
,
typ
Type
)
*
s
tubType
{
return
&
s
tubType
{
name
,
typ
}
}
func
(
t
*
S
tubType
)
Get
()
Type
{
func
(
t
*
s
tubType
)
Get
()
Type
{
if
t
.
typ
==
nil
{
t
.
typ
=
ExpandType
(
t
.
name
)
}
...
...
@@ -146,16 +146,16 @@ export type PtrType interface {
Sub
()
Type
}
type
P
trTypeStruct
struct
{
type
p
trTypeStruct
struct
{
commonType
;
sub
*
S
tubType
;
sub
*
s
tubType
;
}
func
NewPtrTypeStruct
(
name
,
typestring
string
,
sub
*
StubType
)
*
P
trTypeStruct
{
return
&
P
trTypeStruct
{
commonType
{
PtrKind
,
typestring
,
name
,
ptrsize
},
sub
}
func
newPtrTypeStruct
(
name
,
typestring
string
,
sub
*
stubType
)
*
p
trTypeStruct
{
return
&
p
trTypeStruct
{
commonType
{
PtrKind
,
typestring
,
name
,
ptrsize
},
sub
}
}
func
(
t
*
P
trTypeStruct
)
Sub
()
Type
{
func
(
t
*
p
trTypeStruct
)
Sub
()
Type
{
return
t
.
sub
.
Get
()
}
...
...
@@ -167,34 +167,34 @@ export type ArrayType interface {
Elem
()
Type
;
}
type
A
rrayTypeStruct
struct
{
type
a
rrayTypeStruct
struct
{
commonType
;
elem
*
S
tubType
;
elem
*
s
tubType
;
open
bool
;
// otherwise fixed size
len
int
;
}
func
NewArrayTypeStruct
(
name
,
typestring
string
,
open
bool
,
len
int
,
elem
*
StubType
)
*
A
rrayTypeStruct
{
return
&
A
rrayTypeStruct
{
commonType
{
ArrayKind
,
typestring
,
name
,
0
},
elem
,
open
,
len
}
func
newArrayTypeStruct
(
name
,
typestring
string
,
open
bool
,
len
int
,
elem
*
stubType
)
*
a
rrayTypeStruct
{
return
&
a
rrayTypeStruct
{
commonType
{
ArrayKind
,
typestring
,
name
,
0
},
elem
,
open
,
len
}
}
func
(
t
*
A
rrayTypeStruct
)
Size
()
int
{
func
(
t
*
a
rrayTypeStruct
)
Size
()
int
{
if
t
.
open
{
return
ptrsize
*
2
// open arrays are 2-word headers
}
return
t
.
len
*
t
.
elem
.
Get
()
.
Size
();
}
func
(
t
*
A
rrayTypeStruct
)
Open
()
bool
{
func
(
t
*
a
rrayTypeStruct
)
Open
()
bool
{
return
t
.
open
}
func
(
t
*
A
rrayTypeStruct
)
Len
()
int
{
func
(
t
*
a
rrayTypeStruct
)
Len
()
int
{
// what about open array? TODO
return
t
.
len
}
func
(
t
*
A
rrayTypeStruct
)
Elem
()
Type
{
func
(
t
*
a
rrayTypeStruct
)
Elem
()
Type
{
return
t
.
elem
.
Get
()
}
...
...
@@ -205,21 +205,21 @@ export type MapType interface {
Elem
()
Type
;
}
type
M
apTypeStruct
struct
{
type
m
apTypeStruct
struct
{
commonType
;
key
*
S
tubType
;
elem
*
S
tubType
;
key
*
s
tubType
;
elem
*
s
tubType
;
}
func
NewMapTypeStruct
(
name
,
typestring
string
,
key
,
elem
*
StubType
)
*
M
apTypeStruct
{
return
&
M
apTypeStruct
{
commonType
{
MapKind
,
typestring
,
name
,
ptrsize
},
key
,
elem
}
func
newMapTypeStruct
(
name
,
typestring
string
,
key
,
elem
*
stubType
)
*
m
apTypeStruct
{
return
&
m
apTypeStruct
{
commonType
{
MapKind
,
typestring
,
name
,
ptrsize
},
key
,
elem
}
}
func
(
t
*
M
apTypeStruct
)
Key
()
Type
{
func
(
t
*
m
apTypeStruct
)
Key
()
Type
{
return
t
.
key
.
Get
()
}
func
(
t
*
M
apTypeStruct
)
Elem
()
Type
{
func
(
t
*
m
apTypeStruct
)
Elem
()
Type
{
return
t
.
elem
.
Get
()
}
...
...
@@ -236,21 +236,21 @@ export const ( // channel direction
BothDir
=
SendDir
|
RecvDir
;
)
type
C
hanTypeStruct
struct
{
type
c
hanTypeStruct
struct
{
commonType
;
elem
*
S
tubType
;
elem
*
s
tubType
;
dir
int
;
}
func
NewChanTypeStruct
(
name
,
typestring
string
,
dir
int
,
elem
*
StubType
)
*
C
hanTypeStruct
{
return
&
C
hanTypeStruct
{
commonType
{
ChanKind
,
typestring
,
name
,
ptrsize
},
elem
,
dir
}
func
newChanTypeStruct
(
name
,
typestring
string
,
dir
int
,
elem
*
stubType
)
*
c
hanTypeStruct
{
return
&
c
hanTypeStruct
{
commonType
{
ChanKind
,
typestring
,
name
,
ptrsize
},
elem
,
dir
}
}
func
(
t
*
C
hanTypeStruct
)
Dir
()
int
{
func
(
t
*
c
hanTypeStruct
)
Dir
()
int
{
return
t
.
dir
}
func
(
t
*
C
hanTypeStruct
)
Elem
()
Type
{
func
(
t
*
c
hanTypeStruct
)
Elem
()
Type
{
return
t
.
elem
.
Get
()
}
...
...
@@ -261,25 +261,25 @@ export type StructType interface {
Len
()
int
;
}
type
Field
struct
{
type
struct
Field
struct
{
name
string
;
typ
*
S
tubType
;
typ
*
s
tubType
;
tag
string
;
size
int
;
offset
int
;
}
type
S
tructTypeStruct
struct
{
type
s
tructTypeStruct
struct
{
commonType
;
field
[]
Field
;
field
[]
struct
Field
;
}
func
NewStructTypeStruct
(
name
,
typestring
string
,
field
[]
Field
)
*
S
tructTypeStruct
{
return
&
S
tructTypeStruct
{
commonType
{
StructKind
,
typestring
,
name
,
0
},
field
}
func
newStructTypeStruct
(
name
,
typestring
string
,
field
[]
structField
)
*
s
tructTypeStruct
{
return
&
s
tructTypeStruct
{
commonType
{
StructKind
,
typestring
,
name
,
0
},
field
}
}
// TODO: not portable; depends on 6g
func
(
t
*
S
tructTypeStruct
)
Size
()
int
{
func
(
t
*
s
tructTypeStruct
)
Size
()
int
{
if
t
.
size
>
0
{
return
t
.
size
}
...
...
@@ -303,14 +303,14 @@ func (t *StructTypeStruct) Size() int {
return
size
;
}
func
(
t
*
S
tructTypeStruct
)
Field
(
i
int
)
(
name
string
,
typ
Type
,
tag
string
,
offset
int
)
{
func
(
t
*
s
tructTypeStruct
)
Field
(
i
int
)
(
name
string
,
typ
Type
,
tag
string
,
offset
int
)
{
if
t
.
field
[
i
]
.
offset
==
0
{
t
.
Size
();
// will compute offsets
}
return
t
.
field
[
i
]
.
name
,
t
.
field
[
i
]
.
typ
.
Get
(),
t
.
field
[
i
]
.
tag
,
t
.
field
[
i
]
.
offset
}
func
(
t
*
S
tructTypeStruct
)
Len
()
int
{
func
(
t
*
s
tructTypeStruct
)
Len
()
int
{
return
len
(
t
.
field
)
}
...
...
@@ -321,24 +321,24 @@ export type InterfaceType interface {
Len
()
int
;
}
type
I
nterfaceTypeStruct
struct
{
type
i
nterfaceTypeStruct
struct
{
commonType
;
field
[]
Field
;
field
[]
struct
Field
;
}
func
NewInterfaceTypeStruct
(
name
,
typestring
string
,
field
[]
Field
)
*
I
nterfaceTypeStruct
{
return
&
I
nterfaceTypeStruct
{
commonType
{
InterfaceKind
,
typestring
,
name
,
interfacesize
},
field
}
func
newInterfaceTypeStruct
(
name
,
typestring
string
,
field
[]
structField
)
*
i
nterfaceTypeStruct
{
return
&
i
nterfaceTypeStruct
{
commonType
{
InterfaceKind
,
typestring
,
name
,
interfacesize
},
field
}
}
func
(
t
*
I
nterfaceTypeStruct
)
Field
(
i
int
)
(
name
string
,
typ
Type
,
tag
string
,
offset
int
)
{
func
(
t
*
i
nterfaceTypeStruct
)
Field
(
i
int
)
(
name
string
,
typ
Type
,
tag
string
,
offset
int
)
{
return
t
.
field
[
i
]
.
name
,
t
.
field
[
i
]
.
typ
.
Get
(),
""
,
0
}
func
(
t
*
I
nterfaceTypeStruct
)
Len
()
int
{
func
(
t
*
i
nterfaceTypeStruct
)
Len
()
int
{
return
len
(
t
.
field
)
}
var
NilInterface
=
NewInterfaceTypeStruct
(
"nil"
,
""
,
make
([]
Field
,
0
));
var
nilInterface
=
newInterfaceTypeStruct
(
"nil"
,
""
,
make
([]
struct
Field
,
0
));
// -- Func
...
...
@@ -347,26 +347,26 @@ export type FuncType interface {
Out
()
StructType
;
}
type
F
uncTypeStruct
struct
{
type
f
uncTypeStruct
struct
{
commonType
;
in
*
S
tructTypeStruct
;
out
*
S
tructTypeStruct
;
in
*
s
tructTypeStruct
;
out
*
s
tructTypeStruct
;
}
func
NewFuncTypeStruct
(
name
,
typestring
string
,
in
,
out
*
StructTypeStruct
)
*
F
uncTypeStruct
{
return
&
F
uncTypeStruct
{
commonType
{
FuncKind
,
typestring
,
name
,
0
},
in
,
out
}
func
newFuncTypeStruct
(
name
,
typestring
string
,
in
,
out
*
structTypeStruct
)
*
f
uncTypeStruct
{
return
&
f
uncTypeStruct
{
commonType
{
FuncKind
,
typestring
,
name
,
0
},
in
,
out
}
}
func
(
t
*
F
uncTypeStruct
)
Size
()
int
{
func
(
t
*
f
uncTypeStruct
)
Size
()
int
{
panic
(
"reflect.type: func.Size(): cannot happen"
);
return
0
}
func
(
t
*
F
uncTypeStruct
)
In
()
StructType
{
func
(
t
*
f
uncTypeStruct
)
In
()
StructType
{
return
t
.
in
}
func
(
t
*
F
uncTypeStruct
)
Out
()
StructType
{
func
(
t
*
f
uncTypeStruct
)
Out
()
StructType
{
if
t
.
out
==
nil
{
// nil.(StructType) != nil so make sure caller sees real nil
return
nil
}
...
...
@@ -380,20 +380,20 @@ var types map[string] Type
var
typestring
map
[
string
]
string
var
initialized
bool
=
false
// Map of basic types to prebuilt
S
tubTypes
var
basicstub
map
[
string
]
*
S
tubType
// Map of basic types to prebuilt
s
tubTypes
var
basicstub
map
[
string
]
*
s
tubType
var
MissingStub
*
S
tubType
;
var
DotDotDotStub
*
S
tubType
;
var
missingStub
*
s
tubType
;
var
dotDotDotStub
*
s
tubType
;
// The database stored in the maps is global; use locking to guarantee safety.
var
typestringlock
sync
.
Mutex
func
L
ock
()
{
func
l
ock
()
{
typestringlock
.
Lock
()
}
func
U
nlock
()
{
func
u
nlock
()
{
typestringlock
.
Unlock
()
}
...
...
@@ -401,15 +401,15 @@ func init() {
ptrsize
=
8
;
// TODO: compute this
interfacesize
=
2
*
ptrsize
;
// TODO: compute this
L
ock
();
// not necessary because of init ordering but be safe.
l
ock
();
// not necessary because of init ordering but be safe.
types
=
make
(
map
[
string
]
Type
);
typestring
=
make
(
map
[
string
]
string
);
basicstub
=
make
(
map
[
string
]
*
S
tubType
);
basicstub
=
make
(
map
[
string
]
*
s
tubType
);
// Basics go into types table
types
[
M
issingString
]
=
Missing
;
types
[
D
otDotDotString
]
=
DotDotDot
;
types
[
m
issingString
]
=
Missing
;
types
[
d
otDotDotString
]
=
DotDotDot
;
types
[
"int"
]
=
Int
;
types
[
"int8"
]
=
Int8
;
types
[
"int16"
]
=
Int16
;
...
...
@@ -429,29 +429,29 @@ func init() {
types
[
"bool"
]
=
Bool
;
// Basics get prebuilt stubs
MissingStub
=
NewStubType
(
M
issingString
,
Missing
);
DotDotDotStub
=
NewStubType
(
D
otDotDotString
,
DotDotDot
);
basicstub
[
MissingString
]
=
M
issingStub
;
basicstub
[
DotDotDotString
]
=
D
otDotDotStub
;
basicstub
[
"int"
]
=
N
ewStubType
(
"int"
,
Int
);
basicstub
[
"int8"
]
=
N
ewStubType
(
"int8"
,
Int8
);
basicstub
[
"int16"
]
=
N
ewStubType
(
"int16"
,
Int16
);
basicstub
[
"int32"
]
=
N
ewStubType
(
"int32"
,
Int32
);
basicstub
[
"int64"
]
=
N
ewStubType
(
"int64"
,
Int64
);
basicstub
[
"uint"
]
=
N
ewStubType
(
"uint"
,
Uint
);
basicstub
[
"uint8"
]
=
N
ewStubType
(
"uint8"
,
Uint8
);
basicstub
[
"uint16"
]
=
N
ewStubType
(
"uint16"
,
Uint16
);
basicstub
[
"uint32"
]
=
N
ewStubType
(
"uint32"
,
Uint32
);
basicstub
[
"uint64"
]
=
N
ewStubType
(
"uint64"
,
Uint64
);
basicstub
[
"uintptr"
]
=
N
ewStubType
(
"uintptr"
,
Uintptr
);
basicstub
[
"float"
]
=
N
ewStubType
(
"float"
,
Float
);
basicstub
[
"float32"
]
=
N
ewStubType
(
"float32"
,
Float32
);
basicstub
[
"float64"
]
=
N
ewStubType
(
"float64"
,
Float64
);
basicstub
[
"float80"
]
=
N
ewStubType
(
"float80"
,
Float80
);
basicstub
[
"string"
]
=
N
ewStubType
(
"string"
,
String
);
basicstub
[
"bool"
]
=
N
ewStubType
(
"bool"
,
Bool
);
U
nlock
();
missingStub
=
newStubType
(
m
issingString
,
Missing
);
dotDotDotStub
=
newStubType
(
d
otDotDotString
,
DotDotDot
);
basicstub
[
missingString
]
=
m
issingStub
;
basicstub
[
dotDotDotString
]
=
d
otDotDotStub
;
basicstub
[
"int"
]
=
n
ewStubType
(
"int"
,
Int
);
basicstub
[
"int8"
]
=
n
ewStubType
(
"int8"
,
Int8
);
basicstub
[
"int16"
]
=
n
ewStubType
(
"int16"
,
Int16
);
basicstub
[
"int32"
]
=
n
ewStubType
(
"int32"
,
Int32
);
basicstub
[
"int64"
]
=
n
ewStubType
(
"int64"
,
Int64
);
basicstub
[
"uint"
]
=
n
ewStubType
(
"uint"
,
Uint
);
basicstub
[
"uint8"
]
=
n
ewStubType
(
"uint8"
,
Uint8
);
basicstub
[
"uint16"
]
=
n
ewStubType
(
"uint16"
,
Uint16
);
basicstub
[
"uint32"
]
=
n
ewStubType
(
"uint32"
,
Uint32
);
basicstub
[
"uint64"
]
=
n
ewStubType
(
"uint64"
,
Uint64
);
basicstub
[
"uintptr"
]
=
n
ewStubType
(
"uintptr"
,
Uintptr
);
basicstub
[
"float"
]
=
n
ewStubType
(
"float"
,
Float
);
basicstub
[
"float32"
]
=
n
ewStubType
(
"float32"
,
Float32
);
basicstub
[
"float64"
]
=
n
ewStubType
(
"float64"
,
Float64
);
basicstub
[
"float80"
]
=
n
ewStubType
(
"float80"
,
Float80
);
basicstub
[
"string"
]
=
n
ewStubType
(
"string"
,
String
);
basicstub
[
"bool"
]
=
n
ewStubType
(
"bool"
,
Bool
);
u
nlock
();
}
/*
...
...
@@ -551,7 +551,7 @@ func unescape(s string, backslash bool) string {
}
// Simple parser for type strings
type
Parser
struct
{
type
type
Parser
struct
{
str
string
;
// string being parsed
token
string
;
// the token being parsed now
tokstart
int
;
// starting position of token
...
...
@@ -561,12 +561,12 @@ type Parser struct {
// Return typestring starting at position i. It will finish at the
// end of the previous token (before trailing white space).
func
(
p
*
Parser
)
TypeString
(
i
int
)
string
{
func
(
p
*
type
Parser
)
TypeString
(
i
int
)
string
{
return
p
.
str
[
i
:
p
.
prevend
];
}
// Load next token into p.token
func
(
p
*
Parser
)
Next
()
{
func
(
p
*
type
Parser
)
Next
()
{
p
.
prevend
=
p
.
index
;
token
:=
""
;
for
;
p
.
index
<
len
(
p
.
str
)
&&
p
.
str
[
p
.
index
]
==
' '
;
p
.
index
++
{
...
...
@@ -588,9 +588,9 @@ func (p *Parser) Next() {
}
fallthrough
;
// shouldn't happen but let the parser figure it out
case
c
==
'.'
:
if
p
.
index
<
len
(
p
.
str
)
+
2
&&
p
.
str
[
p
.
index
-
1
:
p
.
index
+
2
]
==
D
otDotDotString
{
if
p
.
index
<
len
(
p
.
str
)
+
2
&&
p
.
str
[
p
.
index
-
1
:
p
.
index
+
2
]
==
d
otDotDotString
{
p
.
index
+=
2
;
p
.
token
=
D
otDotDotString
;
p
.
token
=
d
otDotDotString
;
return
;
}
fallthrough
;
// shouldn't happen but let the parser figure it out
...
...
@@ -627,14 +627,14 @@ func (p *Parser) Next() {
p
.
token
=
p
.
str
[
start
:
p
.
index
];
}
func
(
p
*
Parser
)
Type
(
name
string
)
*
S
tubType
func
(
p
*
typeParser
)
Type
(
name
string
)
*
s
tubType
func
(
p
*
Parser
)
Array
(
name
string
,
tokstart
int
)
*
S
tubType
{
func
(
p
*
typeParser
)
Array
(
name
string
,
tokstart
int
)
*
s
tubType
{
size
:=
0
;
open
:=
true
;
if
p
.
token
!=
"]"
{
if
len
(
p
.
token
)
==
0
||
!
isdigit
(
p
.
token
[
0
])
{
return
M
issingStub
return
m
issingStub
}
// write our own (trivial and simpleminded) atoi to avoid dependency
size
=
0
;
...
...
@@ -645,46 +645,46 @@ func (p *Parser) Array(name string, tokstart int) *StubType {
open
=
false
;
}
if
p
.
token
!=
"]"
{
return
M
issingStub
return
m
issingStub
}
p
.
Next
();
elemtype
:=
p
.
Type
(
""
);
return
NewStubType
(
name
,
N
ewArrayTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
open
,
size
,
elemtype
));
return
newStubType
(
name
,
n
ewArrayTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
open
,
size
,
elemtype
));
}
func
(
p
*
Parser
)
Map
(
name
string
,
tokstart
int
)
*
S
tubType
{
func
(
p
*
typeParser
)
Map
(
name
string
,
tokstart
int
)
*
s
tubType
{
if
p
.
token
!=
"["
{
return
M
issingStub
return
m
issingStub
}
p
.
Next
();
keytype
:=
p
.
Type
(
""
);
if
p
.
token
!=
"]"
{
return
M
issingStub
return
m
issingStub
}
p
.
Next
();
elemtype
:=
p
.
Type
(
""
);
return
NewStubType
(
name
,
N
ewMapTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
keytype
,
elemtype
));
return
newStubType
(
name
,
n
ewMapTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
keytype
,
elemtype
));
}
func
(
p
*
Parser
)
Chan
(
name
string
,
tokstart
,
dir
int
)
*
S
tubType
{
func
(
p
*
typeParser
)
Chan
(
name
string
,
tokstart
,
dir
int
)
*
s
tubType
{
if
p
.
token
==
"<-"
{
if
dir
!=
BothDir
{
return
M
issingStub
return
m
issingStub
}
p
.
Next
();
dir
=
SendDir
;
}
elemtype
:=
p
.
Type
(
""
);
return
NewStubType
(
name
,
N
ewChanTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
dir
,
elemtype
));
return
newStubType
(
name
,
n
ewChanTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
dir
,
elemtype
));
}
// Parse array of fields for struct, interface, and func arguments
func
(
p
*
Parser
)
Fields
(
sep
,
term
string
)
[]
Field
{
a
:=
make
([]
Field
,
10
);
func
(
p
*
typeParser
)
Fields
(
sep
,
term
string
)
[]
struct
Field
{
a
:=
make
([]
struct
Field
,
10
);
nf
:=
0
;
for
p
.
token
!=
""
&&
p
.
token
!=
term
{
if
nf
==
len
(
a
)
{
a1
:=
make
([]
Field
,
2
*
nf
);
a1
:=
make
([]
struct
Field
,
2
*
nf
);
for
i
:=
0
;
i
<
nf
;
i
++
{
a1
[
i
]
=
a
[
i
];
}
...
...
@@ -711,59 +711,59 @@ func (p *Parser) Fields(sep, term string) []Field {
}
// A single type packaged as a field for a function return
func
(
p
*
Parser
)
OneField
()
[]
Field
{
a
:=
make
([]
Field
,
1
);
func
(
p
*
typeParser
)
OneField
()
[]
struct
Field
{
a
:=
make
([]
struct
Field
,
1
);
a
[
0
]
.
name
=
""
;
a
[
0
]
.
typ
=
p
.
Type
(
""
);
return
a
;
}
func
(
p
*
Parser
)
Struct
(
name
string
,
tokstart
int
)
*
S
tubType
{
func
(
p
*
typeParser
)
Struct
(
name
string
,
tokstart
int
)
*
s
tubType
{
f
:=
p
.
Fields
(
";"
,
"}"
);
if
p
.
token
!=
"}"
{
return
M
issingStub
;
return
m
issingStub
;
}
p
.
Next
();
return
NewStubType
(
name
,
N
ewStructTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
f
));
return
newStubType
(
name
,
n
ewStructTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
f
));
}
func
(
p
*
Parser
)
Interface
(
name
string
,
tokstart
int
)
*
S
tubType
{
func
(
p
*
typeParser
)
Interface
(
name
string
,
tokstart
int
)
*
s
tubType
{
f
:=
p
.
Fields
(
";"
,
"}"
);
if
p
.
token
!=
"}"
{
return
M
issingStub
;
return
m
issingStub
;
}
p
.
Next
();
return
NewStubType
(
name
,
N
ewInterfaceTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
f
));
return
newStubType
(
name
,
n
ewInterfaceTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
f
));
}
func
(
p
*
Parser
)
Func
(
name
string
,
tokstart
int
)
*
S
tubType
{
func
(
p
*
typeParser
)
Func
(
name
string
,
tokstart
int
)
*
s
tubType
{
// may be 1 or 2 parenthesized lists
f1
:=
N
ewStructTypeStruct
(
""
,
""
,
p
.
Fields
(
","
,
")"
));
f1
:=
n
ewStructTypeStruct
(
""
,
""
,
p
.
Fields
(
","
,
")"
));
if
p
.
token
!=
")"
{
return
M
issingStub
;
return
m
issingStub
;
}
p
.
Next
();
if
p
.
token
!=
"("
{
// 1 list: the in parameters are a list. Is there a single out parameter?
if
p
.
token
==
""
||
p
.
token
==
"}"
||
p
.
token
==
","
||
p
.
token
==
";"
{
return
NewStubType
(
name
,
N
ewFuncTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
f1
,
nil
));
return
newStubType
(
name
,
n
ewFuncTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
f1
,
nil
));
}
// A single out parameter.
f2
:=
N
ewStructTypeStruct
(
""
,
""
,
p
.
OneField
());
return
NewStubType
(
name
,
N
ewFuncTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
f1
,
f2
));
f2
:=
n
ewStructTypeStruct
(
""
,
""
,
p
.
OneField
());
return
newStubType
(
name
,
n
ewFuncTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
f1
,
f2
));
}
else
{
p
.
Next
();
}
f2
:=
N
ewStructTypeStruct
(
""
,
""
,
p
.
Fields
(
","
,
")"
));
f2
:=
n
ewStructTypeStruct
(
""
,
""
,
p
.
Fields
(
","
,
")"
));
if
p
.
token
!=
")"
{
return
M
issingStub
;
return
m
issingStub
;
}
p
.
Next
();
// 2 lists: the in and out parameters are present
return
NewStubType
(
name
,
N
ewFuncTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
f1
,
f2
));
return
newStubType
(
name
,
n
ewFuncTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
f1
,
f2
));
}
func
(
p
*
Parser
)
Type
(
name
string
)
*
S
tubType
{
func
(
p
*
typeParser
)
Type
(
name
string
)
*
s
tubType
{
dir
:=
BothDir
;
tokstart
:=
p
.
tokstart
;
switch
{
...
...
@@ -772,7 +772,7 @@ func (p *Parser) Type(name string) *StubType {
case
p
.
token
==
"*"
:
p
.
Next
();
sub
:=
p
.
Type
(
""
);
return
NewStubType
(
name
,
N
ewPtrTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
sub
));
return
newStubType
(
name
,
n
ewPtrTypeStruct
(
name
,
p
.
TypeString
(
tokstart
),
sub
));
case
p
.
token
==
"["
:
p
.
Next
();
return
p
.
Array
(
name
,
tokstart
);
...
...
@@ -783,7 +783,7 @@ func (p *Parser) Type(name string) *StubType {
p
.
Next
();
dir
=
RecvDir
;
if
p
.
token
!=
"chan"
{
return
M
issingStub
;
return
m
issingStub
;
}
fallthrough
;
case
p
.
token
==
"chan"
:
...
...
@@ -792,14 +792,14 @@ func (p *Parser) Type(name string) *StubType {
case
p
.
token
==
"struct"
:
p
.
Next
();
if
p
.
token
!=
"{"
{
return
M
issingStub
return
m
issingStub
}
p
.
Next
();
return
p
.
Struct
(
name
,
tokstart
);
case
p
.
token
==
"interface"
:
p
.
Next
();
if
p
.
token
!=
"{"
{
return
M
issingStub
return
m
issingStub
}
p
.
Next
();
return
p
.
Interface
(
name
,
tokstart
);
...
...
@@ -808,10 +808,10 @@ func (p *Parser) Type(name string) *StubType {
return
p
.
Func
(
name
,
tokstart
);
case
isdigit
(
p
.
token
[
0
])
:
p
.
Next
();
return
M
issingStub
;
return
m
issingStub
;
case
special
(
p
.
token
[
0
])
:
p
.
Next
();
return
M
issingStub
;
return
m
issingStub
;
}
// must be an identifier. is it basic? if so, we have a stub
if
s
,
ok
:=
basicstub
[
p
.
token
];
ok
{
...
...
@@ -819,7 +819,7 @@ func (p *Parser) Type(name string) *StubType {
if
name
!=
""
{
// Need to make a copy because we are renaming a basic type
b
:=
s
.
Get
();
s
=
NewStubType
(
name
,
N
ewBasicType
(
name
,
b
.
Kind
(),
b
.
Size
()));
s
=
newStubType
(
name
,
n
ewBasicType
(
name
,
b
.
Kind
(),
b
.
Size
()));
}
return
s
}
...
...
@@ -832,9 +832,9 @@ func (p *Parser) Type(name string) *StubType {
}
if
ndot
!=
1
{
p
.
Next
();
return
M
issingStub
;
return
m
issingStub
;
}
s
:=
N
ewStubType
(
p
.
token
,
nil
);
s
:=
n
ewStubType
(
p
.
token
,
nil
);
p
.
Next
();
return
s
;
}
...
...
@@ -842,16 +842,16 @@ func (p *Parser) Type(name string) *StubType {
export
func
ParseTypeString
(
name
,
typestring
string
)
Type
{
if
typestring
==
""
{
// If the typestring is empty, it represents (the type of) a nil interface value
return
N
ilInterface
return
n
ilInterface
}
p
:=
new
(
Parser
);
p
:=
new
(
type
Parser
);
p
.
str
=
typestring
;
p
.
Next
();
return
p
.
Type
(
name
)
.
Get
();
}
// Create typestring map from reflect.typestrings() data. Lock is held.
func
I
nitializeTypeStrings
()
{
func
i
nitializeTypeStrings
()
{
if
initialized
{
return
}
...
...
@@ -885,13 +885,13 @@ func InitializeTypeStrings() {
}
// Look up type string associated with name. Lock is held.
func
T
ypeNameToTypeString
(
name
string
)
string
{
func
t
ypeNameToTypeString
(
name
string
)
string
{
s
,
ok
:=
typestring
[
name
];
if
!
ok
{
I
nitializeTypeStrings
();
i
nitializeTypeStrings
();
s
,
ok
=
typestring
[
name
];
if
!
ok
{
s
=
M
issingString
;
s
=
m
issingString
;
typestring
[
name
]
=
s
;
}
}
...
...
@@ -899,16 +899,16 @@ func TypeNameToTypeString(name string) string {
}
// Type is known by name. Find (and create if necessary) its real type.
func
ExpandType
(
name
string
)
Type
{
L
ock
();
export
func
ExpandType
(
name
string
)
Type
{
l
ock
();
t
,
ok
:=
types
[
name
];
if
ok
{
U
nlock
();
u
nlock
();
return
t
}
types
[
name
]
=
Missing
;
// prevent recursion; will overwrite
t1
:=
ParseTypeString
(
name
,
T
ypeNameToTypeString
(
name
));
t1
:=
ParseTypeString
(
name
,
t
ypeNameToTypeString
(
name
));
types
[
name
]
=
t1
;
U
nlock
();
u
nlock
();
return
t1
;
}
src/lib/reflect/value.go
View file @
ed2ac9b8
...
...
@@ -12,9 +12,9 @@ import (
"unsafe"
;
)
type
Addr
unsafe
.
pointer
export
type
Addr
unsafe
.
pointer
func
E
qualType
(
a
,
b
Type
)
bool
{
func
e
qualType
(
a
,
b
Type
)
bool
{
return
a
.
String
()
==
b
.
String
()
}
...
...
@@ -58,9 +58,9 @@ func (c *commonValue) Interface() interface {} {
return
i
;
}
func
N
ewValueAddr
(
typ
Type
,
addr
Addr
)
Value
func
n
ewValueAddr
(
typ
Type
,
addr
Addr
)
Value
type
Creator
*
(
typ
Type
,
addr
Addr
)
Value
type
creatorFn
*
(
typ
Type
,
addr
Addr
)
Value
// -- Missing
...
...
@@ -71,12 +71,12 @@ export type MissingValue interface {
Addr
()
Addr
;
}
type
M
issingValueStruct
struct
{
type
m
issingValueStruct
struct
{
commonValue
}
func
M
issingCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
M
issingValueStruct
{
commonValue
{
MissingKind
,
typ
,
addr
}
}
func
m
issingCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
m
issingValueStruct
{
commonValue
{
MissingKind
,
typ
,
addr
}
}
}
// -- Int
...
...
@@ -88,19 +88,19 @@ export type IntValue interface {
Type
()
Type
;
}
type
I
ntValueStruct
struct
{
type
i
ntValueStruct
struct
{
commonValue
}
func
I
ntCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
I
ntValueStruct
{
commonValue
{
IntKind
,
typ
,
addr
}
}
func
i
ntCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
i
ntValueStruct
{
commonValue
{
IntKind
,
typ
,
addr
}
}
}
func
(
v
*
I
ntValueStruct
)
Get
()
int
{
func
(
v
*
i
ntValueStruct
)
Get
()
int
{
return
*
v
.
addr
.
(
*
int
)
}
func
(
v
*
I
ntValueStruct
)
Set
(
i
int
)
{
func
(
v
*
i
ntValueStruct
)
Set
(
i
int
)
{
*
v
.
addr
.
(
*
int
)
=
i
}
...
...
@@ -113,19 +113,19 @@ export type Int8Value interface {
Type
()
Type
;
}
type
I
nt8ValueStruct
struct
{
type
i
nt8ValueStruct
struct
{
commonValue
}
func
I
nt8Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
I
nt8ValueStruct
{
commonValue
{
Int8Kind
,
typ
,
addr
}
}
func
i
nt8Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
i
nt8ValueStruct
{
commonValue
{
Int8Kind
,
typ
,
addr
}
}
}
func
(
v
*
I
nt8ValueStruct
)
Get
()
int8
{
func
(
v
*
i
nt8ValueStruct
)
Get
()
int8
{
return
*
v
.
addr
.
(
*
int8
)
}
func
(
v
*
I
nt8ValueStruct
)
Set
(
i
int8
)
{
func
(
v
*
i
nt8ValueStruct
)
Set
(
i
int8
)
{
*
v
.
addr
.
(
*
int8
)
=
i
}
...
...
@@ -138,19 +138,19 @@ export type Int16Value interface {
Type
()
Type
;
}
type
I
nt16ValueStruct
struct
{
type
i
nt16ValueStruct
struct
{
commonValue
}
func
I
nt16Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
I
nt16ValueStruct
{
commonValue
{
Int16Kind
,
typ
,
addr
}
}
func
i
nt16Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
i
nt16ValueStruct
{
commonValue
{
Int16Kind
,
typ
,
addr
}
}
}
func
(
v
*
I
nt16ValueStruct
)
Get
()
int16
{
func
(
v
*
i
nt16ValueStruct
)
Get
()
int16
{
return
*
v
.
addr
.
(
*
int16
)
}
func
(
v
*
I
nt16ValueStruct
)
Set
(
i
int16
)
{
func
(
v
*
i
nt16ValueStruct
)
Set
(
i
int16
)
{
*
v
.
addr
.
(
*
int16
)
=
i
}
...
...
@@ -163,19 +163,19 @@ export type Int32Value interface {
Type
()
Type
;
}
type
I
nt32ValueStruct
struct
{
type
i
nt32ValueStruct
struct
{
commonValue
}
func
I
nt32Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
I
nt32ValueStruct
{
commonValue
{
Int32Kind
,
typ
,
addr
}
}
func
i
nt32Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
i
nt32ValueStruct
{
commonValue
{
Int32Kind
,
typ
,
addr
}
}
}
func
(
v
*
I
nt32ValueStruct
)
Get
()
int32
{
func
(
v
*
i
nt32ValueStruct
)
Get
()
int32
{
return
*
v
.
addr
.
(
*
int32
)
}
func
(
v
*
I
nt32ValueStruct
)
Set
(
i
int32
)
{
func
(
v
*
i
nt32ValueStruct
)
Set
(
i
int32
)
{
*
v
.
addr
.
(
*
int32
)
=
i
}
...
...
@@ -188,19 +188,19 @@ export type Int64Value interface {
Type
()
Type
;
}
type
I
nt64ValueStruct
struct
{
type
i
nt64ValueStruct
struct
{
commonValue
}
func
I
nt64Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
I
nt64ValueStruct
{
commonValue
{
Int64Kind
,
typ
,
addr
}
}
func
i
nt64Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
i
nt64ValueStruct
{
commonValue
{
Int64Kind
,
typ
,
addr
}
}
}
func
(
v
*
I
nt64ValueStruct
)
Get
()
int64
{
func
(
v
*
i
nt64ValueStruct
)
Get
()
int64
{
return
*
v
.
addr
.
(
*
int64
)
}
func
(
v
*
I
nt64ValueStruct
)
Set
(
i
int64
)
{
func
(
v
*
i
nt64ValueStruct
)
Set
(
i
int64
)
{
*
v
.
addr
.
(
*
int64
)
=
i
}
...
...
@@ -213,19 +213,19 @@ export type UintValue interface {
Type
()
Type
;
}
type
U
intValueStruct
struct
{
type
u
intValueStruct
struct
{
commonValue
}
func
U
intCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
U
intValueStruct
{
commonValue
{
UintKind
,
typ
,
addr
}
}
func
u
intCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
u
intValueStruct
{
commonValue
{
UintKind
,
typ
,
addr
}
}
}
func
(
v
*
U
intValueStruct
)
Get
()
uint
{
func
(
v
*
u
intValueStruct
)
Get
()
uint
{
return
*
v
.
addr
.
(
*
uint
)
}
func
(
v
*
U
intValueStruct
)
Set
(
i
uint
)
{
func
(
v
*
u
intValueStruct
)
Set
(
i
uint
)
{
*
v
.
addr
.
(
*
uint
)
=
i
}
...
...
@@ -238,19 +238,19 @@ export type Uint8Value interface {
Type
()
Type
;
}
type
U
int8ValueStruct
struct
{
type
u
int8ValueStruct
struct
{
commonValue
}
func
U
int8Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
U
int8ValueStruct
{
commonValue
{
Uint8Kind
,
typ
,
addr
}
}
func
u
int8Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
u
int8ValueStruct
{
commonValue
{
Uint8Kind
,
typ
,
addr
}
}
}
func
(
v
*
U
int8ValueStruct
)
Get
()
uint8
{
func
(
v
*
u
int8ValueStruct
)
Get
()
uint8
{
return
*
v
.
addr
.
(
*
uint8
)
}
func
(
v
*
U
int8ValueStruct
)
Set
(
i
uint8
)
{
func
(
v
*
u
int8ValueStruct
)
Set
(
i
uint8
)
{
*
v
.
addr
.
(
*
uint8
)
=
i
}
...
...
@@ -263,19 +263,19 @@ export type Uint16Value interface {
Type
()
Type
;
}
type
U
int16ValueStruct
struct
{
type
u
int16ValueStruct
struct
{
commonValue
}
func
U
int16Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
U
int16ValueStruct
{
commonValue
{
Uint16Kind
,
typ
,
addr
}
}
func
u
int16Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
u
int16ValueStruct
{
commonValue
{
Uint16Kind
,
typ
,
addr
}
}
}
func
(
v
*
U
int16ValueStruct
)
Get
()
uint16
{
func
(
v
*
u
int16ValueStruct
)
Get
()
uint16
{
return
*
v
.
addr
.
(
*
uint16
)
}
func
(
v
*
U
int16ValueStruct
)
Set
(
i
uint16
)
{
func
(
v
*
u
int16ValueStruct
)
Set
(
i
uint16
)
{
*
v
.
addr
.
(
*
uint16
)
=
i
}
...
...
@@ -288,19 +288,19 @@ export type Uint32Value interface {
Type
()
Type
;
}
type
U
int32ValueStruct
struct
{
type
u
int32ValueStruct
struct
{
commonValue
}
func
U
int32Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
U
int32ValueStruct
{
commonValue
{
Uint32Kind
,
typ
,
addr
}
}
func
u
int32Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
u
int32ValueStruct
{
commonValue
{
Uint32Kind
,
typ
,
addr
}
}
}
func
(
v
*
U
int32ValueStruct
)
Get
()
uint32
{
func
(
v
*
u
int32ValueStruct
)
Get
()
uint32
{
return
*
v
.
addr
.
(
*
uint32
)
}
func
(
v
*
U
int32ValueStruct
)
Set
(
i
uint32
)
{
func
(
v
*
u
int32ValueStruct
)
Set
(
i
uint32
)
{
*
v
.
addr
.
(
*
uint32
)
=
i
}
...
...
@@ -313,19 +313,19 @@ export type Uint64Value interface {
Type
()
Type
;
}
type
U
int64ValueStruct
struct
{
type
u
int64ValueStruct
struct
{
commonValue
}
func
U
int64Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
U
int64ValueStruct
{
commonValue
{
Uint64Kind
,
typ
,
addr
}
}
func
u
int64Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
u
int64ValueStruct
{
commonValue
{
Uint64Kind
,
typ
,
addr
}
}
}
func
(
v
*
U
int64ValueStruct
)
Get
()
uint64
{
func
(
v
*
u
int64ValueStruct
)
Get
()
uint64
{
return
*
v
.
addr
.
(
*
uint64
)
}
func
(
v
*
U
int64ValueStruct
)
Set
(
i
uint64
)
{
func
(
v
*
u
int64ValueStruct
)
Set
(
i
uint64
)
{
*
v
.
addr
.
(
*
uint64
)
=
i
}
...
...
@@ -338,19 +338,19 @@ export type UintptrValue interface {
Type
()
Type
;
}
type
U
intptrValueStruct
struct
{
type
u
intptrValueStruct
struct
{
commonValue
}
func
U
intptrCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
U
intptrValueStruct
{
commonValue
{
UintptrKind
,
typ
,
addr
}
}
func
u
intptrCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
u
intptrValueStruct
{
commonValue
{
UintptrKind
,
typ
,
addr
}
}
}
func
(
v
*
U
intptrValueStruct
)
Get
()
uintptr
{
func
(
v
*
u
intptrValueStruct
)
Get
()
uintptr
{
return
*
v
.
addr
.
(
*
uintptr
)
}
func
(
v
*
U
intptrValueStruct
)
Set
(
i
uintptr
)
{
func
(
v
*
u
intptrValueStruct
)
Set
(
i
uintptr
)
{
*
v
.
addr
.
(
*
uintptr
)
=
i
}
...
...
@@ -363,19 +363,19 @@ export type FloatValue interface {
Type
()
Type
;
}
type
F
loatValueStruct
struct
{
type
f
loatValueStruct
struct
{
commonValue
}
func
F
loatCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
F
loatValueStruct
{
commonValue
{
FloatKind
,
typ
,
addr
}
}
func
f
loatCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
f
loatValueStruct
{
commonValue
{
FloatKind
,
typ
,
addr
}
}
}
func
(
v
*
F
loatValueStruct
)
Get
()
float
{
func
(
v
*
f
loatValueStruct
)
Get
()
float
{
return
*
v
.
addr
.
(
*
float
)
}
func
(
v
*
F
loatValueStruct
)
Set
(
f
float
)
{
func
(
v
*
f
loatValueStruct
)
Set
(
f
float
)
{
*
v
.
addr
.
(
*
float
)
=
f
}
...
...
@@ -388,19 +388,19 @@ export type Float32Value interface {
Type
()
Type
;
}
type
F
loat32ValueStruct
struct
{
type
f
loat32ValueStruct
struct
{
commonValue
}
func
F
loat32Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
F
loat32ValueStruct
{
commonValue
{
Float32Kind
,
typ
,
addr
}
}
func
f
loat32Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
f
loat32ValueStruct
{
commonValue
{
Float32Kind
,
typ
,
addr
}
}
}
func
(
v
*
F
loat32ValueStruct
)
Get
()
float32
{
func
(
v
*
f
loat32ValueStruct
)
Get
()
float32
{
return
*
v
.
addr
.
(
*
float32
)
}
func
(
v
*
F
loat32ValueStruct
)
Set
(
f
float32
)
{
func
(
v
*
f
loat32ValueStruct
)
Set
(
f
float32
)
{
*
v
.
addr
.
(
*
float32
)
=
f
}
...
...
@@ -413,19 +413,19 @@ export type Float64Value interface {
Type
()
Type
;
}
type
F
loat64ValueStruct
struct
{
type
f
loat64ValueStruct
struct
{
commonValue
}
func
F
loat64Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
F
loat64ValueStruct
{
commonValue
{
Float64Kind
,
typ
,
addr
}
}
func
f
loat64Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
f
loat64ValueStruct
{
commonValue
{
Float64Kind
,
typ
,
addr
}
}
}
func
(
v
*
F
loat64ValueStruct
)
Get
()
float64
{
func
(
v
*
f
loat64ValueStruct
)
Get
()
float64
{
return
*
v
.
addr
.
(
*
float64
)
}
func
(
v
*
F
loat64ValueStruct
)
Set
(
f
float64
)
{
func
(
v
*
f
loat64ValueStruct
)
Set
(
f
float64
)
{
*
v
.
addr
.
(
*
float64
)
=
f
}
...
...
@@ -438,12 +438,12 @@ export type Float80Value interface {
Type
()
Type
;
}
type
F
loat80ValueStruct
struct
{
type
f
loat80ValueStruct
struct
{
commonValue
}
func
F
loat80Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
F
loat80ValueStruct
{
commonValue
{
Float80Kind
,
typ
,
addr
}
}
func
f
loat80Creator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
f
loat80ValueStruct
{
commonValue
{
Float80Kind
,
typ
,
addr
}
}
}
/*
...
...
@@ -466,19 +466,19 @@ export type StringValue interface {
Type
()
Type
;
}
type
S
tringValueStruct
struct
{
type
s
tringValueStruct
struct
{
commonValue
}
func
S
tringCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
S
tringValueStruct
{
commonValue
{
StringKind
,
typ
,
addr
}
}
func
s
tringCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
s
tringValueStruct
{
commonValue
{
StringKind
,
typ
,
addr
}
}
}
func
(
v
*
S
tringValueStruct
)
Get
()
string
{
func
(
v
*
s
tringValueStruct
)
Get
()
string
{
return
*
v
.
addr
.
(
*
string
)
}
func
(
v
*
S
tringValueStruct
)
Set
(
s
string
)
{
func
(
v
*
s
tringValueStruct
)
Set
(
s
string
)
{
*
v
.
addr
.
(
*
string
)
=
s
}
...
...
@@ -491,19 +491,19 @@ export type BoolValue interface {
Type
()
Type
;
}
type
B
oolValueStruct
struct
{
type
b
oolValueStruct
struct
{
commonValue
}
func
B
oolCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
B
oolValueStruct
{
commonValue
{
BoolKind
,
typ
,
addr
}
}
func
b
oolCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
b
oolValueStruct
{
commonValue
{
BoolKind
,
typ
,
addr
}
}
}
func
(
v
*
B
oolValueStruct
)
Get
()
bool
{
func
(
v
*
b
oolValueStruct
)
Get
()
bool
{
return
*
v
.
addr
.
(
*
bool
)
}
func
(
v
*
B
oolValueStruct
)
Set
(
b
bool
)
{
func
(
v
*
b
oolValueStruct
)
Set
(
b
bool
)
{
*
v
.
addr
.
(
*
bool
)
=
b
}
...
...
@@ -517,30 +517,30 @@ export type PtrValue interface {
SetSub
(
Value
);
}
type
P
trValueStruct
struct
{
type
p
trValueStruct
struct
{
commonValue
}
func
(
v
*
P
trValueStruct
)
Get
()
Addr
{
func
(
v
*
p
trValueStruct
)
Get
()
Addr
{
return
*
v
.
addr
.
(
*
Addr
)
}
func
(
v
*
P
trValueStruct
)
Sub
()
Value
{
return
N
ewValueAddr
(
v
.
typ
.
(
PtrType
)
.
Sub
(),
v
.
Get
());
func
(
v
*
p
trValueStruct
)
Sub
()
Value
{
return
n
ewValueAddr
(
v
.
typ
.
(
PtrType
)
.
Sub
(),
v
.
Get
());
}
func
(
v
*
P
trValueStruct
)
SetSub
(
subv
Value
)
{
func
(
v
*
p
trValueStruct
)
SetSub
(
subv
Value
)
{
a
:=
v
.
typ
.
(
PtrType
)
.
Sub
();
b
:=
subv
.
Type
();
if
!
E
qualType
(
a
,
b
)
{
if
!
e
qualType
(
a
,
b
)
{
panicln
(
"reflect: incompatible types in PtrValue.SetSub:"
,
a
.
String
(),
b
.
String
());
}
*
v
.
addr
.
(
*
Addr
)
=
subv
.
Addr
();
}
func
P
trCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
P
trValueStruct
{
commonValue
{
PtrKind
,
typ
,
addr
}
};
func
p
trCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
p
trValueStruct
{
commonValue
{
PtrKind
,
typ
,
addr
}
};
}
// -- Array
...
...
@@ -563,84 +563,84 @@ export type ArrayValue interface {
uint32 cap;
};
*/
type
R
untimeArray
struct
{
type
r
untimeArray
struct
{
data
Addr
;
len
uint32
;
cap
uint32
;
}
type
O
penArrayValueStruct
struct
{
type
o
penArrayValueStruct
struct
{
commonValue
;
elemtype
Type
;
elemsize
int
;
array
*
R
untimeArray
;
array
*
r
untimeArray
;
}
func
(
v
*
O
penArrayValueStruct
)
Open
()
bool
{
func
(
v
*
o
penArrayValueStruct
)
Open
()
bool
{
return
true
}
func
(
v
*
O
penArrayValueStruct
)
Len
()
int
{
func
(
v
*
o
penArrayValueStruct
)
Len
()
int
{
return
int
(
v
.
array
.
len
);
}
func
(
v
*
O
penArrayValueStruct
)
Cap
()
int
{
func
(
v
*
o
penArrayValueStruct
)
Cap
()
int
{
return
int
(
v
.
array
.
cap
);
}
func
(
v
*
O
penArrayValueStruct
)
SetLen
(
len
int
)
{
func
(
v
*
o
penArrayValueStruct
)
SetLen
(
len
int
)
{
if
len
>
v
.
Cap
()
{
panicln
(
"reflect: OpenArrayValueStruct.SetLen"
,
len
,
v
.
Cap
());
}
v
.
array
.
len
=
uint32
(
len
);
}
func
(
v
*
O
penArrayValueStruct
)
Elem
(
i
int
)
Value
{
func
(
v
*
o
penArrayValueStruct
)
Elem
(
i
int
)
Value
{
data_uint
:=
uintptr
(
v
.
array
.
data
)
+
uintptr
(
i
*
v
.
elemsize
);
return
N
ewValueAddr
(
v
.
elemtype
,
Addr
(
data_uint
));
return
n
ewValueAddr
(
v
.
elemtype
,
Addr
(
data_uint
));
}
type
F
ixedArrayValueStruct
struct
{
type
f
ixedArrayValueStruct
struct
{
commonValue
;
elemtype
Type
;
elemsize
int
;
len
int
;
}
func
(
v
*
F
ixedArrayValueStruct
)
Open
()
bool
{
func
(
v
*
f
ixedArrayValueStruct
)
Open
()
bool
{
return
false
}
func
(
v
*
F
ixedArrayValueStruct
)
Len
()
int
{
func
(
v
*
f
ixedArrayValueStruct
)
Len
()
int
{
return
v
.
len
}
func
(
v
*
F
ixedArrayValueStruct
)
Cap
()
int
{
func
(
v
*
f
ixedArrayValueStruct
)
Cap
()
int
{
return
v
.
len
}
func
(
v
*
F
ixedArrayValueStruct
)
SetLen
(
len
int
)
{
func
(
v
*
f
ixedArrayValueStruct
)
SetLen
(
len
int
)
{
}
func
(
v
*
F
ixedArrayValueStruct
)
Elem
(
i
int
)
Value
{
func
(
v
*
f
ixedArrayValueStruct
)
Elem
(
i
int
)
Value
{
data_uint
:=
uintptr
(
v
.
addr
)
+
uintptr
(
i
*
v
.
elemsize
);
return
N
ewValueAddr
(
v
.
elemtype
,
Addr
(
data_uint
));
return
n
ewValueAddr
(
v
.
elemtype
,
Addr
(
data_uint
));
return
nil
}
func
A
rrayCreator
(
typ
Type
,
addr
Addr
)
Value
{
func
a
rrayCreator
(
typ
Type
,
addr
Addr
)
Value
{
arraytype
:=
typ
.
(
ArrayType
);
if
arraytype
.
Open
()
{
v
:=
new
(
O
penArrayValueStruct
);
v
:=
new
(
o
penArrayValueStruct
);
v
.
kind
=
ArrayKind
;
v
.
addr
=
addr
;
v
.
typ
=
typ
;
v
.
elemtype
=
arraytype
.
Elem
();
v
.
elemsize
=
v
.
elemtype
.
Size
();
v
.
array
=
addr
.
(
*
R
untimeArray
);
v
.
array
=
addr
.
(
*
r
untimeArray
);
return
v
;
}
v
:=
new
(
F
ixedArrayValueStruct
);
v
:=
new
(
f
ixedArrayValueStruct
);
v
.
kind
=
ArrayKind
;
v
.
addr
=
addr
;
v
.
typ
=
typ
;
...
...
@@ -659,19 +659,19 @@ export type MapValue interface {
Elem
(
key
Value
)
Value
;
}
type
M
apValueStruct
struct
{
type
m
apValueStruct
struct
{
commonValue
}
func
M
apCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
M
apValueStruct
{
commonValue
{
MapKind
,
typ
,
addr
}
}
func
m
apCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
m
apValueStruct
{
commonValue
{
MapKind
,
typ
,
addr
}
}
}
func
(
v
*
M
apValueStruct
)
Len
()
int
{
func
(
v
*
m
apValueStruct
)
Len
()
int
{
return
0
// TODO: probably want this to be dynamic
}
func
(
v
*
M
apValueStruct
)
Elem
(
key
Value
)
Value
{
func
(
v
*
m
apValueStruct
)
Elem
(
key
Value
)
Value
{
panic
(
"map value element"
);
return
nil
}
...
...
@@ -683,12 +683,12 @@ export type ChanValue interface {
Type
()
Type
;
}
type
C
hanValueStruct
struct
{
type
c
hanValueStruct
struct
{
commonValue
}
func
C
hanCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
C
hanValueStruct
{
commonValue
{
ChanKind
,
typ
,
addr
}
}
func
c
hanCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
c
hanValueStruct
{
commonValue
{
ChanKind
,
typ
,
addr
}
}
}
// -- Struct
...
...
@@ -700,27 +700,27 @@ export type StructValue interface {
Field
(
i
int
)
Value
;
}
type
S
tructValueStruct
struct
{
type
s
tructValueStruct
struct
{
commonValue
;
field
[]
Value
;
}
func
(
v
*
S
tructValueStruct
)
Len
()
int
{
func
(
v
*
s
tructValueStruct
)
Len
()
int
{
return
len
(
v
.
field
)
}
func
(
v
*
S
tructValueStruct
)
Field
(
i
int
)
Value
{
func
(
v
*
s
tructValueStruct
)
Field
(
i
int
)
Value
{
return
v
.
field
[
i
]
}
func
S
tructCreator
(
typ
Type
,
addr
Addr
)
Value
{
func
s
tructCreator
(
typ
Type
,
addr
Addr
)
Value
{
t
:=
typ
.
(
StructType
);
nfield
:=
t
.
Len
();
v
:=
&
S
tructValueStruct
{
commonValue
{
StructKind
,
typ
,
addr
},
make
([]
Value
,
nfield
)
};
v
:=
&
s
tructValueStruct
{
commonValue
{
StructKind
,
typ
,
addr
},
make
([]
Value
,
nfield
)
};
for
i
:=
0
;
i
<
nfield
;
i
++
{
name
,
ftype
,
str
,
offset
:=
t
.
Field
(
i
);
addr_uint
:=
uintptr
(
addr
)
+
uintptr
(
offset
);
v
.
field
[
i
]
=
N
ewValueAddr
(
ftype
,
Addr
(
addr_uint
));
v
.
field
[
i
]
=
n
ewValueAddr
(
ftype
,
Addr
(
addr_uint
));
}
v
.
typ
=
typ
;
return
v
;
...
...
@@ -734,16 +734,16 @@ export type InterfaceValue interface {
Get
()
interface
{};
}
type
I
nterfaceValueStruct
struct
{
type
i
nterfaceValueStruct
struct
{
commonValue
}
func
(
v
*
I
nterfaceValueStruct
)
Get
()
interface
{}
{
func
(
v
*
i
nterfaceValueStruct
)
Get
()
interface
{}
{
return
*
v
.
addr
.
(
*
interface
{})
}
func
I
nterfaceCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
I
nterfaceValueStruct
{
commonValue
{
InterfaceKind
,
typ
,
addr
}
}
func
i
nterfaceCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
i
nterfaceValueStruct
{
commonValue
{
InterfaceKind
,
typ
,
addr
}
}
}
// -- Func
...
...
@@ -753,45 +753,45 @@ export type FuncValue interface {
Type
()
Type
;
}
type
F
uncValueStruct
struct
{
type
f
uncValueStruct
struct
{
commonValue
}
func
F
uncCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
F
uncValueStruct
{
commonValue
{
FuncKind
,
typ
,
addr
}
}
}
var
creator
=
map
[
int
]
Creator
{
MissingKind
:
&
M
issingCreator
,
IntKind
:
&
I
ntCreator
,
Int8Kind
:
&
I
nt8Creator
,
Int16Kind
:
&
I
nt16Creator
,
Int32Kind
:
&
I
nt32Creator
,
Int64Kind
:
&
I
nt64Creator
,
UintKind
:
&
U
intCreator
,
Uint8Kind
:
&
U
int8Creator
,
Uint16Kind
:
&
U
int16Creator
,
Uint32Kind
:
&
U
int32Creator
,
Uint64Kind
:
&
U
int64Creator
,
UintptrKind
:
&
U
intptrCreator
,
FloatKind
:
&
F
loatCreator
,
Float32Kind
:
&
F
loat32Creator
,
Float64Kind
:
&
F
loat64Creator
,
Float80Kind
:
&
F
loat80Creator
,
StringKind
:
&
S
tringCreator
,
BoolKind
:
&
B
oolCreator
,
PtrKind
:
&
P
trCreator
,
ArrayKind
:
&
A
rrayCreator
,
MapKind
:
&
M
apCreator
,
ChanKind
:
&
C
hanCreator
,
StructKind
:
&
S
tructCreator
,
InterfaceKind
:
&
I
nterfaceCreator
,
FuncKind
:
&
F
uncCreator
,
func
f
uncCreator
(
typ
Type
,
addr
Addr
)
Value
{
return
&
f
uncValueStruct
{
commonValue
{
FuncKind
,
typ
,
addr
}
}
}
var
creator
=
map
[
int
]
creatorFn
{
MissingKind
:
&
m
issingCreator
,
IntKind
:
&
i
ntCreator
,
Int8Kind
:
&
i
nt8Creator
,
Int16Kind
:
&
i
nt16Creator
,
Int32Kind
:
&
i
nt32Creator
,
Int64Kind
:
&
i
nt64Creator
,
UintKind
:
&
u
intCreator
,
Uint8Kind
:
&
u
int8Creator
,
Uint16Kind
:
&
u
int16Creator
,
Uint32Kind
:
&
u
int32Creator
,
Uint64Kind
:
&
u
int64Creator
,
UintptrKind
:
&
u
intptrCreator
,
FloatKind
:
&
f
loatCreator
,
Float32Kind
:
&
f
loat32Creator
,
Float64Kind
:
&
f
loat64Creator
,
Float80Kind
:
&
f
loat80Creator
,
StringKind
:
&
s
tringCreator
,
BoolKind
:
&
b
oolCreator
,
PtrKind
:
&
p
trCreator
,
ArrayKind
:
&
a
rrayCreator
,
MapKind
:
&
m
apCreator
,
ChanKind
:
&
c
hanCreator
,
StructKind
:
&
s
tructCreator
,
InterfaceKind
:
&
i
nterfaceCreator
,
FuncKind
:
&
f
uncCreator
,
}
var
typecache
=
make
(
map
[
string
]
Type
);
func
N
ewValueAddr
(
typ
Type
,
addr
Addr
)
Value
{
func
n
ewValueAddr
(
typ
Type
,
addr
Addr
)
Value
{
c
,
ok
:=
creator
[
typ
.
Kind
()];
if
!
ok
{
panicln
(
"no creator for type"
,
typ
.
Kind
());
...
...
@@ -814,7 +814,7 @@ export func NewInitValue(typ Type) Value {
size
=
1
;
}
data
:=
make
([]
uint8
,
size
);
return
N
ewValueAddr
(
typ
,
Addr
(
&
data
[
0
]));
return
n
ewValueAddr
(
typ
,
Addr
(
&
data
[
0
]));
}
/*
...
...
@@ -830,7 +830,7 @@ export func NewOpenArrayValue(typ ArrayType, len, cap int) ArrayValue {
return
nil
}
array
:=
new
(
R
untimeArray
);
array
:=
new
(
r
untimeArray
);
size
:=
typ
.
Elem
()
.
Size
()
*
cap
;
if
size
==
0
{
size
=
1
;
...
...
@@ -840,7 +840,7 @@ export func NewOpenArrayValue(typ ArrayType, len, cap int) ArrayValue {
array
.
len
=
uint32
(
len
);
array
.
cap
=
uint32
(
cap
);
return
N
ewValueAddr
(
typ
,
Addr
(
array
));
return
n
ewValueAddr
(
typ
,
Addr
(
array
));
}
export
func
CopyArray
(
dst
ArrayValue
,
src
ArrayValue
,
n
int
)
{
...
...
@@ -849,7 +849,7 @@ export func CopyArray(dst ArrayValue, src ArrayValue, n int) {
}
dt
:=
dst
.
Type
()
.
(
ArrayType
)
.
Elem
();
st
:=
src
.
Type
()
.
(
ArrayType
)
.
Elem
();
if
!
E
qualType
(
dt
,
st
)
{
if
!
e
qualType
(
dt
,
st
)
{
panicln
(
"reflect: incompatible types in CopyArray:"
,
dt
.
String
(),
st
.
String
());
}
...
...
@@ -885,12 +885,12 @@ export func NewValue(e interface {}) Value {
if
indir
{
// Content of interface is a pointer.
return
N
ewValueAddr
(
typ
,
value
.
(
uintptr
)
.
(
Addr
));
return
n
ewValueAddr
(
typ
,
value
.
(
uintptr
)
.
(
Addr
));
}
// Content of interface is a value;
// need a permanent copy to take its address.
ap
:=
new
(
uint64
);
*
ap
=
value
;
return
N
ewValueAddr
(
typ
,
ap
.
(
Addr
));
return
n
ewValueAddr
(
typ
,
ap
.
(
Addr
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment