Insert creates a copy of the struct or array v with the field/element at changed to val.
(at ValueIndexOrName, val *Value)
| 202 | // Insert creates a copy of the struct or array v with the field/element at |
| 203 | // changed to val. |
| 204 | func (v *Value) Insert(at ValueIndexOrName, val *Value) *Value { |
| 205 | switch ty := v.ty.(type) { |
| 206 | case *Struct: |
| 207 | f, idx := field(ty, at) |
| 208 | assertTypesEqual(f.Type, val.Type()) |
| 209 | return v.b.val(ty, v.b.llvm.CreateInsertValue(v.llvm, val.llvm, idx, "")).SetName(v.Name()) |
| 210 | case *Array: |
| 211 | idx, ok := at.(int) |
| 212 | if !ok { |
| 213 | fail("Insert parameter at must be int for arrays values. Got %T", at) |
| 214 | } |
| 215 | assertTypesEqual(ty.Element, val.Type()) |
| 216 | return v.b.val(ty, v.b.llvm.CreateInsertValue(v.llvm, val.llvm, idx, "")).SetName(v.Name()) |
| 217 | default: |
| 218 | fail("Attempted to insert on non-struct and non-array type %v", v.ty.TypeName()) |
| 219 | return nil |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | // Extract returns the field at extracted from the struct or array v. |
| 224 | func (v *Value) Extract(at IndexOrName) *Value { |