From 4b9b6f0791ece8cf92f01abb68b034c3964ca640 Mon Sep 17 00:00:00 2001 From: mappu Date: Sat, 10 Aug 2024 13:21:30 +1200 Subject: [PATCH] genbindings: more aggressive skip for #include in header --- cmd/genbindings/clang2il.go | 9 +++++++++ cmd/genbindings/clangexec.go | 35 +++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/cmd/genbindings/clang2il.go b/cmd/genbindings/clang2il.go index 0baa9422..b3d0aabb 100644 --- a/cmd/genbindings/clang2il.go +++ b/cmd/genbindings/clang2il.go @@ -49,6 +49,15 @@ func parseHeader(inner []interface{}) (*CppParsedHeader, error) { case "StaticAssertDecl": // ignore + case "ClassTemplateDecl", "ClassTemplateSpecializationDecl", "ClassTemplatePartialSpecializationDecl": + // ignore + + case "FileScopeAsmDecl": + // ignore + + case "NamespaceDecl": + // ignore + default: return nil, fmt.Errorf("missing handling for clang ast node type %q", kind) } diff --git a/cmd/genbindings/clangexec.go b/cmd/genbindings/clangexec.go index 3a95d83c..aab423b9 100644 --- a/cmd/genbindings/clangexec.go +++ b/cmd/genbindings/clangexec.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "log" "os/exec" "sync" ) @@ -71,9 +70,12 @@ func clangStripUpToFile(stdout io.Reader, inputFilePath string) ([]interface{}, 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{}) if !ok { @@ -81,6 +83,7 @@ func clangStripUpToFile(stdout io.Reader, inputFilePath string) ([]interface{}, } if _, ok := entry["isImplicit"]; ok { + // Don't keep continue } @@ -97,6 +100,11 @@ func clangStripUpToFile(stdout io.Reader, inputFilePath string) ([]interface{}, if expansionloc, ok := loc["expansionLoc"].(map[string]interface{}); ok { if filename, ok := expansionloc["file"].(string); ok { 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") } - if match_filename == inputFilePath { - // Found the marker position - markerPosition = i - break + // log.Printf("# name=%v kind=%v filename=%q\n", entry["name"], entry["kind"], match_filename) + + if match_filename == "" { + // 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)) - - inner = inner[markerPosition:] - - return inner, nil + return ret, nil }