Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(714)

Delta Between Two Patch Sets: src/pkg/exp/eval/bridge.go

Issue 4301043: update tree for reflect changes (Closed)
Left Patch Set: Created 13 years ago
Right Patch Set: diff -r f692a5e90f6f https://go.googlecode.com/hg/ Created 13 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/exp/datafmt/datafmt.go ('k') | src/pkg/exp/ogle/process.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package eval 5 package eval
6 6
7 import ( 7 import (
8 "log" 8 "log"
9 "go/token" 9 "go/token"
10 "reflect" 10 "reflect"
(...skipping 16 matching lines...) Expand all
27 } 27 }
28 28
29 var nt *NamedType 29 var nt *NamedType
30 if t.Name() != "" { 30 if t.Name() != "" {
31 name := t.PkgPath() + "·" + t.Name() 31 name := t.PkgPath() + "·" + t.Name()
32 nt = &NamedType{token.NoPos, name, nil, true, make(map[string]Me thod)} 32 nt = &NamedType{token.NoPos, name, nil, true, make(map[string]Me thod)}
33 evalTypes[t] = nt 33 evalTypes[t] = nt
34 } 34 }
35 35
36 var et Type 36 var et Type
37 » switch t := t.(type) { 37 » switch t.Kind() {
38 » case *reflect.BoolType: 38 » case reflect.Bool:
39 et = BoolType 39 et = BoolType
40 » case *reflect.FloatType: 40 » case reflect.Float32, reflect.Float64:
41 switch t.Kind() { 41 switch t.Kind() {
42 case reflect.Float32: 42 case reflect.Float32:
43 et = Float32Type 43 et = Float32Type
44 case reflect.Float64: 44 case reflect.Float64:
45 et = Float64Type 45 et = Float64Type
46 } 46 }
47 » case *reflect.IntType: 47 » case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.In t64:
48 switch t.Kind() { 48 switch t.Kind() {
49 case reflect.Int16: 49 case reflect.Int16:
50 et = Int16Type 50 et = Int16Type
51 case reflect.Int32: 51 case reflect.Int32:
52 et = Int32Type 52 et = Int32Type
53 case reflect.Int64: 53 case reflect.Int64:
54 et = Int64Type 54 et = Int64Type
55 case reflect.Int8: 55 case reflect.Int8:
56 et = Int8Type 56 et = Int8Type
57 case reflect.Int: 57 case reflect.Int:
58 et = IntType 58 et = IntType
59 } 59 }
60 » case *reflect.UintType: 60 » case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflec t.Uint64, reflect.Uintptr:
61 switch t.Kind() { 61 switch t.Kind() {
62 case reflect.Uint16: 62 case reflect.Uint16:
63 et = Uint16Type 63 et = Uint16Type
64 case reflect.Uint32: 64 case reflect.Uint32:
65 et = Uint32Type 65 et = Uint32Type
66 case reflect.Uint64: 66 case reflect.Uint64:
67 et = Uint64Type 67 et = Uint64Type
68 case reflect.Uint8: 68 case reflect.Uint8:
69 et = Uint8Type 69 et = Uint8Type
70 case reflect.Uint: 70 case reflect.Uint:
71 et = UintType 71 et = UintType
72 case reflect.Uintptr: 72 case reflect.Uintptr:
73 et = UintptrType 73 et = UintptrType
74 } 74 }
75 » case *reflect.StringType: 75 » case reflect.String:
76 et = StringType 76 et = StringType
77 » case *reflect.ArrayType: 77 » case reflect.Array:
78 et = NewArrayType(int64(t.Len()), TypeFromNative(t.Elem())) 78 et = NewArrayType(int64(t.Len()), TypeFromNative(t.Elem()))
79 » case *reflect.ChanType: 79 » case reflect.Chan:
80 log.Panicf("%T not implemented", t) 80 log.Panicf("%T not implemented", t)
81 » case *reflect.FuncType: 81 » case reflect.Func:
82 nin := t.NumIn() 82 nin := t.NumIn()
83 // Variadic functions have DotDotDotType at the end 83 // Variadic functions have DotDotDotType at the end
84 variadic := t.DotDotDot() 84 variadic := t.DotDotDot()
85 if variadic { 85 if variadic {
86 nin-- 86 nin--
87 } 87 }
88 in := make([]Type, nin) 88 in := make([]Type, nin)
89 for i := range in { 89 for i := range in {
90 in[i] = TypeFromNative(t.In(i)) 90 in[i] = TypeFromNative(t.In(i))
91 } 91 }
92 out := make([]Type, t.NumOut()) 92 out := make([]Type, t.NumOut())
93 for i := range out { 93 for i := range out {
94 out[i] = TypeFromNative(t.Out(i)) 94 out[i] = TypeFromNative(t.Out(i))
95 } 95 }
96 et = NewFuncType(in, variadic, out) 96 et = NewFuncType(in, variadic, out)
97 » case *reflect.InterfaceType: 97 » case reflect.Interface:
98 log.Panicf("%T not implemented", t) 98 log.Panicf("%T not implemented", t)
99 » case *reflect.MapType: 99 » case reflect.Map:
100 log.Panicf("%T not implemented", t) 100 log.Panicf("%T not implemented", t)
101 » case *reflect.PtrType: 101 » case reflect.Ptr:
102 et = NewPtrType(TypeFromNative(t.Elem())) 102 et = NewPtrType(TypeFromNative(t.Elem()))
103 » case *reflect.SliceType: 103 » case reflect.Slice:
104 et = NewSliceType(TypeFromNative(t.Elem())) 104 et = NewSliceType(TypeFromNative(t.Elem()))
105 » case *reflect.StructType: 105 » case reflect.Struct:
106 n := t.NumField() 106 n := t.NumField()
107 fields := make([]StructField, n) 107 fields := make([]StructField, n)
108 for i := 0; i < n; i++ { 108 for i := 0; i < n; i++ {
109 sf := t.Field(i) 109 sf := t.Field(i)
110 // TODO(austin) What to do about private fields? 110 // TODO(austin) What to do about private fields?
111 fields[i].Name = sf.Name 111 fields[i].Name = sf.Name
112 fields[i].Type = TypeFromNative(sf.Type) 112 fields[i].Type = TypeFromNative(sf.Type)
113 fields[i].Anonymous = sf.Anonymous 113 fields[i].Anonymous = sf.Anonymous
114 } 114 }
115 et = NewStructType(fields) 115 et = NewStructType(fields)
116 » case *reflect.UnsafePointerType: 116 » case reflect.UnsafePointer:
117 log.Panicf("%T not implemented", t) 117 log.Panicf("%T not implemented", t)
118 default: 118 default:
119 log.Panicf("unexpected reflect.Type: %T", t) 119 log.Panicf("unexpected reflect.Type: %T", t)
120 } 120 }
121 121
122 if nt != nil { 122 if nt != nil {
123 if _, ok := et.(*NamedType); !ok { 123 if _, ok := et.(*NamedType); !ok {
124 nt.Complete(et) 124 nt.Complete(et)
125 et = nt 125 et = nt
126 } 126 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 } 160 }
161 161
162 // FuncFromNativeTyped is like FuncFromNative, but constructs the 162 // FuncFromNativeTyped is like FuncFromNative, but constructs the
163 // function type from a function pointer using reflection. Typically, 163 // function type from a function pointer using reflection. Typically,
164 // the type will be given as a nil pointer to a function with the 164 // the type will be given as a nil pointer to a function with the
165 // desired signature. 165 // desired signature.
166 func FuncFromNativeTyped(fn func(*Thread, []Value, []Value), t interface{}) (*Fu ncType, FuncValue) { 166 func FuncFromNativeTyped(fn func(*Thread, []Value, []Value), t interface{}) (*Fu ncType, FuncValue) {
167 ft := TypeOfNative(t).(*FuncType) 167 ft := TypeOfNative(t).(*FuncType)
168 return ft, FuncFromNative(fn, ft) 168 return ft, FuncFromNative(fn, ft)
169 } 169 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b