Skip to content

Commit

Permalink
feat(cpp): add support for imported modules
Browse files Browse the repository at this point in the history
  • Loading branch information
w4bremer committed Jul 9, 2024
1 parent fe9966b commit 6d5f1a5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
13 changes: 11 additions & 2 deletions pkg/gen/filters/filtercpp/cpp_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package filtercpp
import (
"fmt"

"github.com/apigear-io/cli/pkg/gen/filters/common"
"github.com/apigear-io/cli/pkg/model"
)

Expand Down Expand Up @@ -32,13 +33,21 @@ func ToDefaultString(prefix string, schema *model.Schema) (string, error) {
text = fmt.Sprintf("%s%s()", prefix, xe.Name)
case model.TypeEnum:
e := schema.LookupEnum(schema.Import, schema.Type)
NameSpace := ""
if schema.Import != "" {
NameSpace = fmt.Sprintf("%s::%s::", common.CamelTitleCase(schema.System().Name), common.CamelTitleCase(schema.Import))
}
if e != nil {
text = fmt.Sprintf("%sEnum::%s", e.Name, e.Members[0].Name)
text = fmt.Sprintf("%s%sEnum::%s", NameSpace, e.Name, e.Members[0].Name)
}
case model.TypeStruct:
s := schema.LookupStruct(schema.Import, schema.Type)
NameSpace := ""
if schema.Import != "" {
NameSpace = fmt.Sprintf("%s::%s::", common.CamelTitleCase(schema.System().Name), common.CamelTitleCase(schema.Import))
}
if s != nil {
text = fmt.Sprintf("%s()", s.Name)
text = fmt.Sprintf("%s%s()", NameSpace, s.Name)
}
case model.TypeInterface:
i := schema.LookupInterface(schema.Import, schema.Type)
Expand Down
19 changes: 16 additions & 3 deletions pkg/gen/filters/filtercpp/cpp_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package filtercpp
import (
"fmt"

"github.com/apigear-io/cli/pkg/gen/filters/common"
"github.com/apigear-io/cli/pkg/model"
)

Expand Down Expand Up @@ -40,18 +41,30 @@ func ToParamString(prefix string, schema *model.Schema, name string) (string, er
return fmt.Sprintf("const %s%s& %s", prefix, xe.Name, name), nil
case model.TypeEnum:
e := schema.LookupEnum(schema.Import, schema.Type)
NameSpace := ""
if schema.Import != "" {
NameSpace = fmt.Sprintf("%s::%s::", common.CamelTitleCase(schema.System().Name), common.CamelTitleCase(schema.Import))
}
if e != nil {
return fmt.Sprintf("%sEnum %s", e.Name, name), nil
return fmt.Sprintf("%s%sEnum %s", NameSpace, e.Name, name), nil
}
case model.TypeStruct:
s := schema.LookupStruct(schema.Import, schema.Type)
NameSpace := ""
if schema.Import != "" {
NameSpace = fmt.Sprintf("%s::%s::", common.CamelTitleCase(schema.System().Name), common.CamelTitleCase(schema.Import))
}
if s != nil {
return fmt.Sprintf("const %s& %s", s.Name, name), nil
return fmt.Sprintf("const %s%s& %s", NameSpace, s.Name, name), nil
}
case model.TypeInterface:
i := schema.LookupInterface(schema.Import, schema.Type)
NameSpace := ""
if schema.Import != "" {
NameSpace = fmt.Sprintf("%s::%s::", common.CamelTitleCase(schema.System().Name), common.CamelTitleCase(schema.Import))
}
if i != nil {
return fmt.Sprintf("%s* %s", i.Name, name), nil
return fmt.Sprintf("%s%s* %s", NameSpace, i.Name, name), nil
}
}
return "xxx", fmt.Errorf("cppParam: unknown schema %s", schema.Dump())
Expand Down
10 changes: 10 additions & 0 deletions pkg/gen/filters/filtercpp/cpp_return.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package filtercpp
import (
"fmt"

"github.com/apigear-io/cli/pkg/gen/filters/common"
"github.com/apigear-io/cli/pkg/model"
)

Expand Down Expand Up @@ -35,16 +36,25 @@ func ToReturnString(prefix string, schema *model.Schema) (string, error) {
text = fmt.Sprintf("%s%s", prefix, xe.Name)
case model.TypeEnum:
e := schema.LookupEnum(schema.Import, schema.Type)
if schema.Import != "" {
prefix = fmt.Sprintf("%s::%s::", common.CamelTitleCase(schema.System().Name), common.CamelTitleCase(schema.Import))
}
if e != nil {
text = fmt.Sprintf("%s%sEnum", prefix, e.Name)
}
case model.TypeStruct:
s := schema.LookupStruct(schema.Import, schema.Type)
if schema.Import != "" {
prefix = fmt.Sprintf("%s::%s::", common.CamelTitleCase(schema.System().Name), common.CamelTitleCase(schema.Import))
}
if s != nil {
text = fmt.Sprintf("%s%s", prefix, s.Name)
}
case model.TypeInterface:
i := schema.LookupInterface(schema.Import, schema.Type)
if schema.Import != "" {
prefix = fmt.Sprintf("%s::%s::", common.CamelTitleCase(schema.System().Name), common.CamelTitleCase(schema.Import))
}
if i != nil {
text = fmt.Sprintf("%s%s*", prefix, i.Name)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/gen/filters/filtercpp/cpp_type_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package filtercpp
import (
"fmt"

"github.com/apigear-io/cli/pkg/gen/filters/common"
"github.com/apigear-io/cli/pkg/model"
)

Expand Down Expand Up @@ -36,6 +37,9 @@ func ToTypeRefString(prefix string, schema *model.Schema) (string, error) {
case "bool":
text = "bool"
default:
if schema.Import != "" {
prefix = fmt.Sprintf("%s::%s::", common.CamelTitleCase(schema.System().Name), common.CamelTitleCase(schema.Import))
}
e := schema.LookupEnum(schema.Import, schema.Type)
if e != nil {
text = fmt.Sprintf("%s%sEnum", prefix, e.Name)
Expand Down

0 comments on commit 6d5f1a5

Please sign in to comment.