OLD | NEW |
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 reflect | 5 package reflect |
6 | 6 |
7 import ( | 7 import ( |
8 "runtime" | 8 "runtime" |
9 "unsafe" | 9 "unsafe" |
10 ) | 10 ) |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 func (v *Float64Value) Set(x float64) { | 179 func (v *Float64Value) Set(x float64) { |
180 if !v.canSet { | 180 if !v.canSet { |
181 panic(cannotSet) | 181 panic(cannotSet) |
182 } | 182 } |
183 *(*float64)(v.addr) = x | 183 *(*float64)(v.addr) = x |
184 } | 184 } |
185 | 185 |
186 // Set sets v to the value x. | 186 // Set sets v to the value x. |
187 func (v *Float64Value) SetValue(x Value) { v.Set(x.(*Float64Value).Get()) } | 187 func (v *Float64Value) SetValue(x Value) { v.Set(x.(*Float64Value).Get()) } |
188 | 188 |
| 189 //// ComplexValue represents a complex value. |
| 190 //type ComplexValue struct { |
| 191 // value |
| 192 //} |
| 193 // |
| 194 //// Get returns the underlying complex value. |
| 195 //func (v *ComplexValue) Get() complex { return *(*complex)(v.addr) } |
| 196 // |
| 197 //// Set sets v to the value x. |
| 198 //func (v *ComplexValue) Set(x complex) { |
| 199 // if !v.canSet { |
| 200 // panic(cannotSet) |
| 201 // } |
| 202 // *(*complex)(v.addr) = x |
| 203 //} |
| 204 // |
| 205 //// Set sets v to the value x. |
| 206 //func (v *ComplexValue) SetValue(x Value) { v.Set(x.(*ComplexValue).Get()) } |
| 207 // |
| 208 //// Complex64Value represents a complex64 value. |
| 209 //type Complex64Value struct { |
| 210 // value |
| 211 //} |
| 212 // |
| 213 //// Get returns the underlying complex64 value. |
| 214 //func (v *Complex64Value) Get() complex64 { return *(*complex64)(v.addr) } |
| 215 // |
| 216 //// Set sets v to the value x. |
| 217 //func (v *Complex64Value) Set(x complex64) { |
| 218 // if !v.canSet { |
| 219 // panic(cannotSet) |
| 220 // } |
| 221 // *(*complex64)(v.addr) = x |
| 222 //} |
| 223 // |
| 224 //// Set sets v to the value x. |
| 225 //func (v *Complex64Value) SetValue(x Value) { v.Set(x.(*Complex64Value).Get())
} |
| 226 // |
| 227 //// Complex128Value represents a complex128 value. |
| 228 //type Complex128Value struct { |
| 229 // value |
| 230 //} |
| 231 // |
| 232 //// Get returns the underlying complex128 value. |
| 233 //func (v *Complex128Value) Get() complex128 { return *(*complex128)(v.addr) } |
| 234 // |
| 235 //// Set sets v to the value x. |
| 236 //func (v *Complex128Value) Set(x complex128) { |
| 237 // if !v.canSet { |
| 238 // panic(cannotSet) |
| 239 // } |
| 240 // *(*complex128)(v.addr) = x |
| 241 //} |
| 242 // |
| 243 //// Set sets v to the value x. |
| 244 //func (v *Complex128Value) SetValue(x Value) { v.Set(x.(*Complex128Value).Get()
) } |
| 245 |
189 // IntValue represents an int value. | 246 // IntValue represents an int value. |
190 type IntValue struct { | 247 type IntValue struct { |
191 value | 248 value |
192 } | 249 } |
193 | 250 |
194 // Get returns the underlying int value. | 251 // Get returns the underlying int value. |
195 func (v *IntValue) Get() int { return *(*int)(v.addr) } | 252 func (v *IntValue) Get() int { return *(*int)(v.addr) } |
196 | 253 |
197 // Set sets v to the value x. | 254 // Set sets v to the value x. |
198 func (v *IntValue) Set(x int) { | 255 func (v *IntValue) Set(x int) { |
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 case *BoolType: | 1296 case *BoolType: |
1240 return (*BoolValue)(v) | 1297 return (*BoolValue)(v) |
1241 case *ChanType: | 1298 case *ChanType: |
1242 return (*ChanValue)(v) | 1299 return (*ChanValue)(v) |
1243 case *FloatType: | 1300 case *FloatType: |
1244 return (*FloatValue)(v) | 1301 return (*FloatValue)(v) |
1245 case *Float32Type: | 1302 case *Float32Type: |
1246 return (*Float32Value)(v) | 1303 return (*Float32Value)(v) |
1247 case *Float64Type: | 1304 case *Float64Type: |
1248 return (*Float64Value)(v) | 1305 return (*Float64Value)(v) |
| 1306 // case *ComplexType: |
| 1307 // return (*ComplexValue)(v) |
| 1308 // case *Complex64Type: |
| 1309 // return (*Complex64Value)(v) |
| 1310 // case *Complex128Type: |
| 1311 // return (*Complex128Value)(v) |
1249 case *IntType: | 1312 case *IntType: |
1250 return (*IntValue)(v) | 1313 return (*IntValue)(v) |
1251 case *Int8Type: | 1314 case *Int8Type: |
1252 return (*Int8Value)(v) | 1315 return (*Int8Value)(v) |
1253 case *Int16Type: | 1316 case *Int16Type: |
1254 return (*Int16Value)(v) | 1317 return (*Int16Value)(v) |
1255 case *Int32Type: | 1318 case *Int32Type: |
1256 return (*Int32Value)(v) | 1319 return (*Int32Value)(v) |
1257 case *Int64Type: | 1320 case *Int64Type: |
1258 return (*Int64Value)(v) | 1321 return (*Int64Value)(v) |
(...skipping 27 matching lines...) Expand all Loading... |
1286 panicln("newValue", typ.String()) | 1349 panicln("newValue", typ.String()) |
1287 } | 1350 } |
1288 | 1351 |
1289 // MakeZero returns a zero Value for the specified Type. | 1352 // MakeZero returns a zero Value for the specified Type. |
1290 func MakeZero(typ Type) Value { | 1353 func MakeZero(typ Type) Value { |
1291 if typ == nil { | 1354 if typ == nil { |
1292 return nil | 1355 return nil |
1293 } | 1356 } |
1294 return newValue(typ, addr(unsafe.New(typ)), true) | 1357 return newValue(typ, addr(unsafe.New(typ)), true) |
1295 } | 1358 } |
OLD | NEW |