go/pointer/testdata/funcreflect.go
Alan Donovan 3371b79a96 go.tools/pointer: reflect, part 2: channels.
(reflect.Value).Send
        (reflect.Value).TrySend
        (reflect.Value).Recv
        (reflect.Value).TryRecv
        (reflect.Type).ChanOf
        (reflect.Type).In
        (reflect.Type).Out
        reflect.Indirect
        reflect.MakeChan

Also:
- specialize genInvoke when the receiver is a reflect.Type under the
  assumption that there's only one possible concrete type.  This
  makes all reflect.Type operations context-sensitive since the calls
  are no longer dynamic.
- Rename all variables to match the actual parameter names used in
  the reflect API.
- Add pointer.Config.Reflection flag
  (exposed in oracle as --reflect, default false) to enable reflection.
  It currently adds about 20% running time.  I'll make it true after
  the presolver is implemented.
- Simplified worklist datatype and solver main loop slightly
  (~10% speed improvement).
- Use addLabel() utility to add a label to a PTS.

(Working on my 3 yr old 2x2GHz+4GB Mac vs 8x4GHz+24GB workstation,
one really notices the cost of pointer analysis.
Note to self: time to implement presolver.)

R=crawshaw
CC=golang-dev
https://golang.org/cl/13242062
2013-09-23 16:13:01 -04:00

45 lines
1.3 KiB
Go

// +build ignore
package main
import "reflect"
var zero, a, b int
// func f(p *int) *int {
// print(p) // #@pointsto
// return &b
// }
// func g(p *bool) {
// }
// func reflectValueCall() {
// rvf := reflect.ValueOf(f)
// res := rvf.Call([]reflect.Value{reflect.ValueOf(&a)})
// print(res[0].Interface()) // #@types
// print(res[0].Interface().(*int)) // #@pointsto
// }
// #@calls main.reflectValueCall -> main.f
func reflectTypeInOut() {
var f func(float64, bool) (string, int)
// TODO(adonovan): when the In/Out argument is a valid index constant,
// only include a single type in the result. Needs some work.
print(reflect.Zero(reflect.TypeOf(f).In(0)).Interface()) // @types float64 | bool
print(reflect.Zero(reflect.TypeOf(f).In(1)).Interface()) // @types float64 | bool
print(reflect.Zero(reflect.TypeOf(f).In(-1)).Interface()) // @types float64 | bool
print(reflect.Zero(reflect.TypeOf(f).In(zero)).Interface()) // @types float64 | bool
print(reflect.Zero(reflect.TypeOf(f).Out(0)).Interface()) // @types string | int
print(reflect.Zero(reflect.TypeOf(f).Out(1)).Interface()) // @types string | int
print(reflect.Zero(reflect.TypeOf(f).Out(2)).Interface()) // @types string | int
print(reflect.Zero(reflect.TypeOf(3).Out(0)).Interface()) // @types
}
func main() {
//reflectValueCall()
reflectTypeInOut()
}