MCPcopy
hub / github.com/google/mangle / Struct

Function Struct

ast/ast.go:408–428  ·  view source on GitHub ↗

Struct constructs a struct constant. Parts can only be accessed in transforms. labels must be sorted .

(kvMap map[*Constant]*Constant)

Source from the content-addressed store, hash-verified

406// Struct constructs a struct constant. Parts can only be accessed in transforms.
407// labels must be sorted .
408func Struct(kvMap map[*Constant]*Constant) *Constant {
409 m := &StructNil
410 if len(kvMap) == 0 {
411 return m
412 }
413 labels := make([]*Constant, len(kvMap))
414 vals := make([]*Constant, len(kvMap))
415 i := 0
416 for k, v := range kvMap {
417 labels[i] = k
418 vals[i] = v
419 i++
420 }
421 index := make([]int, len(kvMap))
422 SortIndexInto(labels, index)
423 for _, i := range index {
424 next := StructCons(labels[i], vals[i], m)
425 m = &next
426 }
427 return m
428}
429
430// NameValue returns the name value of this constant, if it is of type name.
431func (c Constant) NameValue() (string, error) {

Callers 8

makeStructFunction · 0.92
JSONtoStructFunction · 0.92
ConvertValueFunction · 0.92
TestJSONtoStructFunction · 0.92
ProtoToStructFunction · 0.92
TestEvalApplyFnFunction · 0.92
EvalApplyFnFunction · 0.92
ast_test.goFile · 0.85

Calls 2

SortIndexIntoFunction · 0.85
StructConsFunction · 0.85

Tested by 3

makeStructFunction · 0.74
TestJSONtoStructFunction · 0.74
TestEvalApplyFnFunction · 0.74