Struct constructs a struct constant. Parts can only be accessed in transforms. labels must be sorted .
(kvMap map[*Constant]*Constant)
| 406 | // Struct constructs a struct constant. Parts can only be accessed in transforms. |
| 407 | // labels must be sorted . |
| 408 | func 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. |
| 431 | func (c Constant) NameValue() (string, error) { |