-
Notifications
You must be signed in to change notification settings - Fork 1
/
py_return.go
67 lines (63 loc) · 1.73 KB
/
py_return.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
package filterpy
import (
"fmt"
"github.com/apigear-io/cli/pkg/gen/filters/common"
"github.com/apigear-io/cli/pkg/model"
)
func ToReturnString(schema *model.Schema, prefix string) (string, error) {
text := ""
switch schema.KindType {
case model.TypeString:
text = "str"
case model.TypeInt:
text = "int"
case model.TypeInt32:
text = "int32"
case model.TypeInt64:
text = "int64"
case model.TypeFloat:
text = "float"
case model.TypeFloat32:
text = "float32"
case model.TypeFloat64:
text = "float64"
case model.TypeBool:
text = "bool"
case model.TypeEnum:
e := schema.Module.LookupEnum(schema.Type)
if e == nil {
return "xxx", fmt.Errorf("enum %s not found", schema.Type)
}
ident := common.CamelTitleCase(e.Name)
text = fmt.Sprintf("%s%s", prefix, ident)
case model.TypeStruct:
s := schema.Module.LookupStruct(schema.Type)
if s == nil {
return "xxx", fmt.Errorf("ToReturnString struct %s not found", schema.Type)
}
ident := common.CamelTitleCase(s.Name)
text = fmt.Sprintf("%s%s", prefix, ident)
case model.TypeInterface:
i := schema.Module.LookupInterface(schema.Type)
if i == nil {
return "xxx", fmt.Errorf("ToReturnString interface %s not found", schema.Type)
}
ident := common.CamelTitleCase(i.Name)
text = fmt.Sprintf("%s%s", prefix, ident)
case model.TypeVoid:
text = "None"
default:
return "xxx", fmt.Errorf("unknown schema kind type: %s", schema.KindType)
}
if schema.IsArray {
text = fmt.Sprintf("list[%s]", text)
}
return text, nil
}
// cast value to TypedNode and deduct the cpp return type
func pyReturn(prefix string, node *model.TypedNode) (string, error) {
if node == nil {
return "xxx", fmt.Errorf("called with nil node")
}
return ToReturnString(&node.Schema, prefix)
}