genbindings/enums: handle enum values with comments

This commit is contained in:
mappu 2024-10-07 18:31:32 +13:00
parent 11d0eaf5f4
commit 8585fc05f4
1 changed files with 30 additions and 21 deletions

View File

@ -539,9 +539,15 @@ func processEnum(node map[string]interface{}, addNamePrefix string) (CppEnum, er
// This means one more than the last value
cee.EntryValue = fmt.Sprintf("%d", lastImplicitValue+1)
} else if len(ei1) == 1 {
} else if len(ei1) >= 1 {
ei1_0 := ei1[0].(map[string]interface{})
// There may be more than one RHS `inner` expression if one of them
// is a comment
// Iterate through each of the ei1 entries and see if any of them
// work for the purposes of enum constant value parsing
for _, ei1_0 := range ei1 {
ei1_0 := ei1_0.(map[string]interface{})
// Best case: .inner -> kind=ConstantExpr value=xx
// e.g. qabstractitemmodel
@ -570,6 +576,9 @@ func processEnum(node map[string]interface{}, addNamePrefix string) (CppEnum, er
}
}
// If we made it here, we did not hit any of the `goto afterParse` cases
}
afterParse:
if cee.EntryValue == "" {
return ret, fmt.Errorf("Complex enum %q entry %q", ret.EnumName, entryname)