Skip to content

Commit

Permalink
clang2il.go: Check for desugared types (support clang-19+)
Browse files Browse the repository at this point in the history
* Closes #116
  • Loading branch information
rcalixte committed Jan 3, 2025
1 parent 16bb62a commit e0572bf
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions cmd/genbindings/clang2il.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,15 @@ func processTypedef(node map[string]interface{}, addNamePrefix string) (CppTyped
}

if typ, ok := node["type"].(map[string]interface{}); ok {
if qualType, ok := typ["qualType"].(string); ok {
// Try desugaredQualType first
var qualType string
if desugared, ok := typ["desugaredQualType"].(string); ok {
qualType = desugared
} else if qt, ok := typ["qualType"].(string); ok {
qualType = qt
}

if qualType != "" {
return CppTypedef{
Alias: addNamePrefix + nodename,
UnderlyingType: parseSingleTypeString(qualType),
Expand Down Expand Up @@ -264,7 +272,13 @@ func processClassType(node map[string]interface{}, addNamePrefix string) (CppCla
}

if typ, ok := base["type"].(map[string]interface{}); ok {
if qualType, ok := typ["qualType"].(string); ok {
var qualType string
if desugared, ok := typ["desugaredQualType"].(string); ok {
qualType = desugared
} else if qt, ok := typ["qualType"].(string); ok {
qualType = qt
}
if qualType != "" {
ret.DirectInherits = append(ret.DirectInherits, qualType)
}
}
Expand Down Expand Up @@ -511,8 +525,14 @@ func processEnum(node map[string]interface{}, addNamePrefix string) (CppEnum, er
// Underlying type
ret.UnderlyingType = parseSingleTypeString("int")
if nodefut, ok := node["fixedUnderlyingType"].(map[string]interface{}); ok {
if nodequal, ok := nodefut["qualType"].(string); ok {
ret.UnderlyingType = parseSingleTypeString(nodequal)
var qualType string
if desugared, ok := nodefut["desugaredQualType"].(string); ok {
qualType = desugared
} else if qt, ok := nodefut["qualType"].(string); ok {
qualType = qt
}
if qualType != "" {
ret.UnderlyingType = parseSingleTypeString(qualType)
}
}

Expand Down Expand Up @@ -649,18 +669,20 @@ nextEnumEntry:

// parseMethod parses a Clang method into our CppMethod intermediate format.
func parseMethod(node map[string]interface{}, mm *CppMethod) error {

if typobj, ok := node["type"].(map[string]interface{}); ok {
if qualType, ok := typobj["qualType"].(string); ok {
// The qualType is the whole type of the method, including its parameter types
// If anything here is too complicated, skip the whole method
var qualType string
if desugared, ok := typobj["desugaredQualType"].(string); ok {
qualType = desugared
} else if qt, ok := typobj["qualType"].(string); ok {
qualType = qt
}

var err error = nil
if qualType != "" {
var err error
mm.ReturnType, mm.Parameters, mm.IsConst, err = parseTypeString(qualType)
if err != nil {
return err
}

}
}

Expand Down Expand Up @@ -690,6 +712,14 @@ func parseMethod(node map[string]interface{}, mm *CppMethod) error {
parmName, _ := methodObj["name"].(string) // n.b. may be unnamed
if parmName == "" {

// Get the precise parameter type if available
if typ, ok := methodObj["type"].(map[string]interface{}); ok {
if desugared, ok := typ["desugaredQualType"].(string); ok {
// Update the parameter type with the more precise desugared version
mm.Parameters[paramCounter].ParameterType = desugared
}
}

// Generate a default parameter name
// Super nice autogen names if this is a Q_PROPERTY setter:
if len(mm.Parameters) == 1 && strings.HasPrefix(mm.MethodName, "set") {
Expand Down

0 comments on commit e0572bf

Please sign in to comment.