MCPcopy Create free account
hub / github.com/google/gapid / Insert

Method Insert

core/codegen/value.go:204–221  ·  view source on GitHub ↗

Insert creates a copy of the struct or array v with the field/element at changed to val.

(at ValueIndexOrName, val *Value)

Source from the content-addressed store, hash-verified

202// Insert creates a copy of the struct or array v with the field/element at
203// changed to val.
204func (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.
224func (v *Value) Extract(at IndexOrName) *Value {

Callers

nothing calls this directly

Calls 8

NameMethod · 0.95
assertTypesEqualFunction · 0.85
SetNameMethod · 0.80
fieldFunction · 0.70
failFunction · 0.70
TypeMethod · 0.65
TypeNameMethod · 0.65
valMethod · 0.45

Tested by

no test coverage detected