Skip to content

Commit

Permalink
rename structNames -> typedefsNames
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Nov 14, 2024
1 parent 8a407fd commit 23b2637
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/codegen/arguments_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ for i, %[1]sV := range %[1]sArg {
}

_, shouldSkipRefTypedef := context.preset.SkipTypedefs[pureType]
if context.structNames[pureType] || (isRefTypedef && !shouldSkipRefTypedef) {
if context.typedefsNames[pureType] || (isRefTypedef && !shouldSkipRefTypedef) {
srcPkg := context.flags.packageName
if isRefTypedef {
srcPkg = context.flags.refPackageName
Expand Down
2 changes: 1 addition & 1 deletion cmd/codegen/gengo.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func IsCallbackTypedef(s string) bool {
}

func IsStructName(name CIdentifier, ctx *Context) bool {
_, ok := ctx.structNames[name]
_, ok := ctx.typedefsNames[name]
return ok
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/codegen/gengo_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func GenerateGoFuncs(
) error {
generator := &goFuncsGenerator{
prefix: context.prefix,
structNames: context.structNames,
typedefsNames: context.typedefsNames,
enumNames: context.enumNames,
refTypedefs: context.refTypedefs,
context: context,
Expand Down Expand Up @@ -101,7 +101,7 @@ func GenerateGoFuncs(
// goFuncsGenerator is an internal state of GO funcs' generator
type goFuncsGenerator struct {
prefix string
structNames map[CIdentifier]bool
typedefsNames map[CIdentifier]bool
enumNames map[CIdentifier]bool
refTypedefs map[CIdentifier]bool

Expand Down Expand Up @@ -150,9 +150,9 @@ func (g *goFuncsGenerator) GenerateFunction(f FuncDef, args []GoIdentifier, argW
} else {
returnTypeType = returnTypeVoid
}
} else if HasSuffix(f.Ret, "*") && (g.structNames[TrimSuffix(f.Ret, "*")] || g.structNames[TrimSuffix(TrimPrefix(f.Ret, "const "), "*")]) {
} else if HasSuffix(f.Ret, "*") && (g.typedefsNames[TrimSuffix(f.Ret, "*")] || g.typedefsNames[TrimSuffix(TrimPrefix(f.Ret, "const "), "*")]) {
returnTypeType = returnTypeStructPtr
} else if f.StructGetter && g.structNames[f.Ret] {
} else if f.StructGetter && g.typedefsNames[f.Ret] {
returnTypeType = returnTypeStruct
} else if f.Constructor {
returnTypeType = returnTypeConstructor
Expand Down Expand Up @@ -366,7 +366,7 @@ func (g *goFuncsGenerator) generateFuncArgs(f FuncDef) (args []GoIdentifier, arg
decl, wrapper, err := getArgWrapper(
&a,
i == 0 && f.StructSetter,
f.StructGetter && g.structNames[a.Type],
f.StructGetter && g.typedefsNames[a.Type],
g.context,
)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions cmd/codegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
)

// this cextracts enums and structs names from json file.
func getEnumAndStructNames(enumJsonBytes []byte, context *Context) (enumNames []EnumIdentifier, structNames []CIdentifier, err error) {
func getEnumAndStructNames(enumJsonBytes []byte, context *Context) (enumNames []EnumIdentifier, typedefsNames []CIdentifier, err error) {
enums, err := getEnumDefs(enumJsonBytes)
if err != nil {
return nil, nil, fmt.Errorf("cannot get enum definitions: %w", err)
Expand All @@ -34,7 +34,7 @@ func getEnumAndStructNames(enumJsonBytes []byte, context *Context) (enumNames []

for _, s := range structs {
if shouldSkipStruct := context.preset.SkipStructs[s.Name]; !shouldSkipStruct {
structNames = append(structNames, s.Name)
typedefsNames = append(typedefsNames, s.Name)
}
}

Expand Down Expand Up @@ -126,9 +126,9 @@ type Context struct {
typedefs *Typedefs

// ghese fields are filled by parser while it generates code.
funcNames map[CIdentifier]bool // funcs are filled by gencpp
enumNames map[CIdentifier]bool
structNames map[CIdentifier]bool
funcNames map[CIdentifier]bool // funcs are filled by gencpp
enumNames map[CIdentifier]bool
typedefsNames map[CIdentifier]bool

// contains helper C functions to get/set struct fields
// of array types
Expand Down Expand Up @@ -189,7 +189,7 @@ func parseJson(jsonData *jsonData) (*Context, error) {
}

_, structs, err := getEnumAndStructNames(jsonData.structAndEnums, result)
result.structNames = SliceToMap(structs)
result.typedefsNames = SliceToMap(structs)
if err != nil {
return nil, fmt.Errorf("cannot get reference struct and enums names: %w", err)
}
Expand Down Expand Up @@ -245,7 +245,7 @@ func main() {
log.Panic(err)
}

context.structNames = SliceToMap(callbacks)
context.typedefsNames = SliceToMap(callbacks)

// 1.3. Generate C wrapper
validFuncs, err := generateCppWrapper(flags.prefix, flags.include, context.funcs, context)
Expand Down
4 changes: 2 additions & 2 deletions cmd/codegen/return_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func getReturnWrapper(
_, isEnum := context.enumNames[pureType]
_, isRefEnum := context.refEnumNames[pureType]
_, shouldSkipRefTypedef := context.preset.SkipTypedefs[pureType]
_, isStruct := context.structNames[pureType]
_, isStruct := context.typedefsNames[pureType]
isStruct = isStruct || ((isRefStruct || (isRefTypedef && !IsEnum(pureType, context.refEnumNames))) && !shouldSkipRefTypedef)
w, known := returnWrapperMap[t]
// check if is array (match regex)
Expand All @@ -102,7 +102,7 @@ func getReturnWrapper(
switch {
case known:
return w, nil
// case (context.structNames[t] || context.refStructNames[t]) && !shouldSkipStruct(t):
// case (context.typedefsNames[t] || context.refStructNames[t]) && !shouldSkipStruct(t):
case !isPointer && isStruct && !shouldSkipStruct:
return returnWrapper{
returnType: prefixGoPackage(pureType.renameGoIdentifier(context), srcPackage, context),
Expand Down

0 comments on commit 23b2637

Please sign in to comment.