MCPcopy Create free account
hub / github.com/akyoto/q / evaluateStruct

Method evaluateStruct

src/core/evaluateStruct.go:12–50  ·  view source on GitHub ↗

evaluateStruct converts a struct expression to an SSA value.

(expr *expression.Expression)

Source from the content-addressed store, hash-verified

10
11// evaluateStruct converts a struct expression to an SSA value.
12func (f *Function) evaluateStruct(expr *expression.Expression) (ssa.Value, error) {
13 if expr.Children[0].Token.Kind == token.Call && expr.Children[0].Children[0].Token.Kind == token.New {
14 return f.evaluateNewStruct(expr)
15 }
16
17 typ, err := f.Env.TypeFromToken(expr.Children[0].Token, f.File)
18
19 if err != nil {
20 return nil, err
21 }
22
23 structType, isStructType := typ.(*types.Struct)
24
25 if !isStructType {
26 return nil, errors.New(&NotDataStruct{TypeName: typ.Name()}, f.File, expr.Children[0].Source())
27 }
28
29 structure := &ssa.Struct{
30 Typ: structType,
31 Arguments: make(ssa.Arguments, len(structType.Fields)),
32 Source: expr.Source(),
33 }
34
35 for _, definition := range expr.Children[1:] {
36 if isTrailing(definition, expr.Children) {
37 continue
38 }
39
40 field, rightValue, err := f.extractField(structType, definition)
41
42 if err != nil {
43 return nil, err
44 }
45
46 structure.Arguments[field.Index] = rightValue
47 }
48
49 return structure, nil
50}

Callers 1

evaluateMethod · 0.95

Calls 7

evaluateNewStructMethod · 0.95
extractFieldMethod · 0.95
NewFunction · 0.92
isTrailingFunction · 0.85
TypeFromTokenMethod · 0.80
NameMethod · 0.65
SourceMethod · 0.45

Tested by

no test coverage detected