evaluateMethod converts a method expression to an SSA value.
(leftValue ssa.Value, left *expression.Expression, right *expression.Expression, expr *expression.Expression)
| 8 | |
| 9 | // evaluateMethod converts a method expression to an SSA value. |
| 10 | func (f *Function) evaluateMethod(leftValue ssa.Value, left *expression.Expression, right *expression.Expression, expr *expression.Expression) (ssa.Value, error) { |
| 11 | methodName := right.Token.StringFrom(f.File.Bytes) |
| 12 | leftUnwrapped := types.Unwrap(leftValue.Type()) |
| 13 | pointer, isPointer := leftUnwrapped.(*types.Pointer) |
| 14 | |
| 15 | if isPointer { |
| 16 | leftUnwrapped = pointer.To |
| 17 | } |
| 18 | |
| 19 | call := expr.Parent |
| 20 | call.Children = append(call.Children, nil) |
| 21 | copy(call.Children[2:], call.Children[1:]) |
| 22 | call.Children[1] = left |
| 23 | |
| 24 | pkg := f.File.Package |
| 25 | structure, isStructPointer := leftUnwrapped.(*types.Struct) |
| 26 | |
| 27 | if isStructPointer && structure.Package != "" { |
| 28 | pkg = structure.Package |
| 29 | } |
| 30 | |
| 31 | return f.evaluatePackageMember(f.Env.Packages[pkg], methodName, expr) |
| 32 | } |
no test coverage detected