-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue_funcCall.go
90 lines (72 loc) · 2.21 KB
/
value_funcCall.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package codegen
import "strings"
type funcCallValue struct {
alias string
isPtr bool
*callHelper
}
// FuncCall creates a new function call
func FuncCall(name string) *funcCallValue {
return newFuncCall("", name)
}
// QualFuncCall creates a new function call with a package alias
func QualFuncCall(alias, name string) *funcCallValue {
return newFuncCall(alias, name)
}
// Pointer dereferences the return value of the function
func (f *funcCallValue) Pointer() *funcCallValue {
f.isPtr = true
return f
}
// Args appeng argument for the function call
func (f *funcCallValue) Args(args ...Value) *funcCallValue {
f.args = args
return f
}
// Field appends a new field getter after the function call
func (f *funcCallValue) Field(fieldName string) *fieldValue {
return newField(f, fieldName)
}
// Call appends a new function call after the function call
func (f *funcCallValue) Call(funcName string) *callValue {
return newCallValue(f, funcName)
}
// Cast casts the function return value to the specified type
func (f *funcCallValue) Cast(typeName string) *castValue {
return newCastValue(f, "", typeName, false)
}
// CastPointer casts thefunction return value to a pointer of the specified type
func (f *funcCallValue) CastPointer(typeName string) *castValue {
return newCastValue(f, "", typeName, true)
}
// CastQual casts the function return value to the specified type with an alias
func (f *funcCallValue) CastQual(alias, typeName string) *castValue {
return newCastValue(f, alias, typeName, false)
}
// CastQualPointer casts thefunction return value to a pointer of the specified type with an alias
func (f *funcCallValue) CastQualPointer(alias, typeName string) *castValue {
return newCastValue(f, alias, typeName, true)
}
func newFuncCall(alias, name string) *funcCallValue {
return &funcCallValue{
alias: alias,
callHelper: newCallHelper(name, make([]Value, 0)),
}
}
func (f *funcCallValue) getCall() Value {
return f
}
func (f *funcCallValue) writeStmt(sb *strings.Builder) bool {
f.writeValue(sb)
return true
}
func (f *funcCallValue) writeValue(sb *strings.Builder) {
if f.isPtr {
sb.WriteByte('*')
}
writeAlias(sb, f.alias)
f.callHelper.wr(sb)
}
func (f *funcCallValue) isPointer() bool {
return f.isPtr
}