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
a733f0bc
Commit
a733f0bc
authored
Jun 29, 2011
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exp/template: use MethodByName, add to build.
R=rsc, adg, r CC=golang-dev
https://golang.org/cl/4641081
parent
22484e22
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
12 deletions
+5
-12
src/pkg/Makefile
src/pkg/Makefile
+1
-0
src/pkg/exp/template/exec.go
src/pkg/exp/template/exec.go
+4
-12
No files found.
src/pkg/Makefile
View file @
a733f0bc
...
...
@@ -82,6 +82,7 @@ DIRS=\
exp/gui
\
exp/gui/x11
\
exp/regexp/syntax
\
exp/template
\
expvar
\
flag
\
fmt
\
...
...
src/pkg/exp/template/exec.go
View file @
a733f0bc
...
...
@@ -134,10 +134,7 @@ func (s *state) evalFieldNode(data reflect.Value, field *fieldNode, args []node,
}
func
(
s
*
state
)
evalField
(
data
reflect
.
Value
,
fieldName
string
)
reflect
.
Value
{
for
{
if
data
.
Kind
()
!=
reflect
.
Ptr
{
break
}
for
data
.
Kind
()
==
reflect
.
Ptr
{
data
=
reflect
.
Indirect
(
data
)
}
switch
data
.
Kind
()
{
...
...
@@ -162,12 +159,8 @@ func (s *state) evalMethodOrField(data reflect.Value, fieldName string, args []n
ptr
,
data
=
data
,
reflect
.
Indirect
(
data
)
}
// Is it a method? We use the pointer because it has value methods too.
// TODO: reflect.Type could use a MethodByName.
for
i
:=
0
;
i
<
ptr
.
Type
()
.
NumMethod
();
i
++
{
method
:=
ptr
.
Type
()
.
Method
(
i
)
if
method
.
Name
==
fieldName
{
return
s
.
evalMethod
(
ptr
,
i
,
args
,
final
)
}
if
method
,
ok
:=
ptr
.
Type
()
.
MethodByName
(
fieldName
);
ok
{
return
s
.
evalMethod
(
ptr
,
method
,
args
,
final
)
}
if
len
(
args
)
>
1
||
final
.
IsValid
()
{
s
.
errorf
(
"%s is not a method but has arguments"
,
fieldName
)
...
...
@@ -185,8 +178,7 @@ var (
osErrorType
=
reflect
.
TypeOf
(
new
(
os
.
Error
))
.
Elem
()
)
func
(
s
*
state
)
evalMethod
(
v
reflect
.
Value
,
i
int
,
args
[]
node
,
final
reflect
.
Value
)
reflect
.
Value
{
method
:=
v
.
Type
()
.
Method
(
i
)
func
(
s
*
state
)
evalMethod
(
v
reflect
.
Value
,
method
reflect
.
Method
,
args
[]
node
,
final
reflect
.
Value
)
reflect
.
Value
{
typ
:=
method
.
Type
fun
:=
method
.
Func
numIn
:=
len
(
args
)
...
...
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