genbindings/clang: handle FullComment in enum declarations

This commit is contained in:
mappu 2024-10-14 19:27:57 +13:00
parent b6aa72f62f
commit 6a01cc2d86

View File

@ -525,7 +525,7 @@ nextEnumEntry:
} }
kind, ok := entry["kind"].(string) kind, ok := entry["kind"].(string)
if kind == "DeprecatedAttr" { if kind == "DeprecatedAttr" || kind == "FullComment" {
continue nextEnumEntry // skip continue nextEnumEntry // skip
} else if kind == "EnumConstantDecl" { } else if kind == "EnumConstantDecl" {
// allow // allow
@ -545,24 +545,32 @@ nextEnumEntry:
// Try to find the enum value // Try to find the enum value
ei1, ok := entry["inner"].([]interface{}) ei1, ok := entry["inner"].([]interface{})
if !ok || len(ei1) == 0 { if !ok {
// Enum case without definition e.g. QCalendar::Gregorian // No inner value on the enum = autoincrement
// This means one more than the last value // Fall through as if a blank ei1, this will be handled
cee.EntryValue = fmt.Sprintf("%d", lastImplicitValue+1) }
} else if len(ei1) >= 1 {
// There may be more than one RHS `inner` expression if one of them // There may be more than one RHS `inner` expression if one of them
// is a comment // is a comment
// Iterate through each of the ei1 entries and see if any of them // Iterate through each of the ei1 entries and see if any of them
// work for the purposes of enum constant value parsing // work for the purposes of enum constant value parsing
foundValidInner := false
for _, ei1_0 := range ei1 { for _, ei1_0 := range ei1 {
ei1_0 := ei1_0.(map[string]interface{}) ei1_0 := ei1_0.(map[string]interface{})
ei1Kind, ok := ei1_0["kind"].(string)
if !ok {
panic("inner with no kind (1)")
}
if ei1Kind == "FullComment" {
continue
}
foundValidInner = true
// Best case: .inner -> kind=ConstantExpr value=xx // Best case: .inner -> kind=ConstantExpr value=xx
// e.g. qabstractitemmodel // e.g. qabstractitemmodel
if ei1Kind, ok := ei1_0["kind"].(string); ok && ei1Kind == "ConstantExpr" { if ei1Kind == "ConstantExpr" {
log.Printf("Got ConstantExpr OK") log.Printf("Got ConstantExpr OK")
if ei1Value, ok := ei1_0["value"].(string); ok { if ei1Value, ok := ei1_0["value"].(string); ok {
cee.EntryValue = ei1Value cee.EntryValue = ei1Value
@ -572,7 +580,7 @@ nextEnumEntry:
// Best case: .inner -> kind=ImplicitCastExpr .inner -> kind=ConstantExpr value=xx // Best case: .inner -> kind=ImplicitCastExpr .inner -> kind=ConstantExpr value=xx
// e.g. QCalendar (when there is a int typecast) // e.g. QCalendar (when there is a int typecast)
if ei1Kind, ok := ei1_0["kind"].(string); ok && ei1Kind == "ImplicitCastExpr" { if ei1Kind == "ImplicitCastExpr" {
log.Printf("Got ImplicitCastExpr OK") log.Printf("Got ImplicitCastExpr OK")
if ei2, ok := ei1_0["inner"].([]interface{}); ok && len(ei2) > 0 { if ei2, ok := ei1_0["inner"].([]interface{}); ok && len(ei2) > 0 {
ei2_0 := ei2[0].(map[string]interface{}) ei2_0 := ei2[0].(map[string]interface{})
@ -586,15 +594,20 @@ nextEnumEntry:
} }
} }
if ei1Kind, ok := ei1_0["kind"].(string); ok && ei1Kind == "DeprecatedAttr" { if ei1Kind == "DeprecatedAttr" {
log.Printf("Enum entry %q is deprecated, skipping", ret.EnumName+"::"+entryname) log.Printf("Enum entry %q is deprecated, skipping", ret.EnumName+"::"+entryname)
continue nextEnumEntry continue nextEnumEntry
} }
} }
// If we made it here, we did not hit any of the `goto afterParse` cases
// If we made it here, we did not hit any of the `goto afterParse` cases
if !foundValidInner {
// Enum case without definition e.g. QCalendar::Gregorian
// This means one more than the last value
cee.EntryValue = fmt.Sprintf("%d", lastImplicitValue+1)
} }
afterParse: afterParse:
if cee.EntryValue == "" { if cee.EntryValue == "" {
return ret, fmt.Errorf("Complex enum %q entry %q", ret.EnumName, entryname) return ret, fmt.Errorf("Complex enum %q entry %q", ret.EnumName, entryname)