genbindings: more aggressive skip for #include in header

This commit is contained in:
mappu 2024-08-10 13:21:30 +12:00
parent 911f4e378a
commit 4b9b6f0791
2 changed files with 32 additions and 12 deletions

View File

@ -49,6 +49,15 @@ func parseHeader(inner []interface{}) (*CppParsedHeader, error) {
case "StaticAssertDecl": case "StaticAssertDecl":
// ignore // ignore
case "ClassTemplateDecl", "ClassTemplateSpecializationDecl", "ClassTemplatePartialSpecializationDecl":
// ignore
case "FileScopeAsmDecl":
// ignore
case "NamespaceDecl":
// ignore
default: default:
return nil, fmt.Errorf("missing handling for clang ast node type %q", kind) return nil, fmt.Errorf("missing handling for clang ast node type %q", kind)
} }

View File

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"log"
"os/exec" "os/exec"
"sync" "sync"
) )
@ -71,9 +70,12 @@ func clangStripUpToFile(stdout io.Reader, inputFilePath string) ([]interface{},
return nil, errors.New("no inner") return nil, errors.New("no inner")
} }
var markerPosition int = -1 // This can't be done by matching the first position only, since it's possible
// that there are more #include<>s further down the file
for i, entry := range inner { ret := make([]interface{}, 0, len(inner))
for _, entry := range inner {
entry, ok := entry.(map[string]interface{}) entry, ok := entry.(map[string]interface{})
if !ok { if !ok {
@ -81,6 +83,7 @@ func clangStripUpToFile(stdout io.Reader, inputFilePath string) ([]interface{},
} }
if _, ok := entry["isImplicit"]; ok { if _, ok := entry["isImplicit"]; ok {
// Don't keep
continue continue
} }
@ -97,6 +100,11 @@ func clangStripUpToFile(stdout io.Reader, inputFilePath string) ([]interface{},
if expansionloc, ok := loc["expansionLoc"].(map[string]interface{}); ok { if expansionloc, ok := loc["expansionLoc"].(map[string]interface{}); ok {
if filename, ok := expansionloc["file"].(string); ok { if filename, ok := expansionloc["file"].(string); ok {
match_filename = filename match_filename = filename
} else if includedFrom, ok := expansionloc["includedFrom"].(map[string]interface{}); ok {
if filename, ok := includedFrom["file"].(string); ok {
match_filename = filename
}
} }
} }
} }
@ -104,16 +112,19 @@ func clangStripUpToFile(stdout io.Reader, inputFilePath string) ([]interface{},
return nil, errors.New("no loc") return nil, errors.New("no loc")
} }
if match_filename == inputFilePath { // log.Printf("# name=%v kind=%v filename=%q\n", entry["name"], entry["kind"], match_filename)
// Found the marker position
markerPosition = i if match_filename == "" {
break // Keep
ret = append(ret, entry)
} else if match_filename != inputFilePath {
// Skip this
} else {
// Keep this
// ret = append(ret, entry)
} }
} }
log.Printf("found first instance of same file at inner entry %d/%d", markerPosition, len(inner)) return ret, nil
inner = inner[markerPosition:]
return inner, nil
} }