From 8edfcbb1628dc62425822aaa50b2e1face1001f9 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Wed, 30 Sep 2026 08:07:00 +0800 Subject: [PATCH 1/2] cl loadTypedef: ignore Cursor_TypeAliasTemplateDecl --- cl/class.go | 3 +-- cl/compile.go | 8 ++++---- cl/typedef.go | 17 ++++++++++------- tool/_testcpp/llvm-22.1.8-support/ADL/out.go | 3 +++ tool/gen_test.go | 4 ++++ 5 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 tool/_testcpp/llvm-22.1.8-support/ADL/out.go diff --git a/cl/class.go b/cl/class.go index 87ccc4db5..e97a26542 100644 --- a/cl/class.go +++ b/cl/class.go @@ -91,7 +91,6 @@ func newTemplateParams(ctx *pkgCtx, pkg *types.Package, cls clang.Cursor, feats ret = append(ret, types.NewTypeParam(objName, ctx.any())) case lc.Cursor_NonTypeTemplateParameter, lc.Cursor_TemplateTemplateParameter: *feats |= featIgnored - log.Println("unsupported template parameter:", clang.String(decl)) default: return clang.Break } @@ -307,7 +306,7 @@ func loadClassMember(ctx *pkgCtx, pkg *types.Package, this *classCtx, clsName st // prefixed by the enclosing class name (the class name acts like a // namespace), e.g. Bar_iterator. if isPublic(decl) { - loadTypedef(ctx, decl, clsName) + loadTypedef(ctx, decl, clsName, this.scope()) } case lc.Cursor_CXXBaseSpecifier: diff --git a/cl/compile.go b/cl/compile.go index 9fe2ff280..ddac99147 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -293,8 +293,8 @@ func loadDecl(ctx *pkgCtx, scope *scopeCtx, decl clang.Cursor, ns string) { loadClass(ctx, decl, ns, decl.Kind, nil) case lc.Cursor_CXXMethod, lc.Cursor_Constructor, lc.Cursor_Destructor: loadOutsideMethod(ctx, decl) - case lc.Cursor_TypedefDecl, lc.Cursor_TypeAliasDecl: - loadTypedef(ctx, decl, ns) + case lc.Cursor_TypedefDecl, lc.Cursor_TypeAliasDecl, lc.Cursor_TypeAliasTemplateDecl: + loadTypedef(ctx, decl, ns, nil) case lc.Cursor_EnumDecl: loadEnum(ctx, decl, ns) case lc.Cursor_MacroDefinition: @@ -307,14 +307,14 @@ func loadDecl(ctx *pkgCtx, scope *scopeCtx, decl clang.Cursor, ns string) { loadVar(ctx, decl, ns) case lc.Cursor_UnionDecl: loadUnion(ctx, decl, ns) - case lc.Cursor_MacroExpansion, lc.Cursor_StaticAssert: + case lc.Cursor_MacroExpansion, lc.Cursor_StaticAssert, lc.Cursor_UsingDeclaration: // noop case lc.Cursor_FunctionTemplate: // TODO(xsw): ignore for now case lc.Cursor_ClassTemplate, lc.Cursor_ClassTemplatePartialSpecialization: loadTemplateClass(ctx, decl, ns, nil) default: - log.Panicln("compileDecl: unknown kind =", decl.Kind) + ctx.panicf(decl, "compileDecl: unknown kind - %v", decl.Kind) } } diff --git a/cl/typedef.go b/cl/typedef.go index d6cca67ec..982f299ed 100644 --- a/cl/typedef.go +++ b/cl/typedef.go @@ -21,11 +21,12 @@ import ( "log" "github.com/goplus/llcppg/clang" + lc "github.com/llarhub/clang-c" ) // ----------------------------------------------------------------------------- -func loadTypedef(ctx *pkgCtx, decl clang.Cursor, ns string) { +func loadTypedef(ctx *pkgCtx, decl clang.Cursor, ns string, scope *scopeCtx) { cName := clang.String(decl.Type()) if ctx.isTypeIgnored(cName) { if debugCompileDecl { @@ -35,21 +36,23 @@ func loadTypedef(ctx *pkgCtx, decl clang.Cursor, ns string) { return } + origName := nameWithNS(clang.String(decl), ns) + if decl.Kind == lc.Cursor_TypeAliasTemplateDecl { + ctx.logf(decl, "typedef %s: template type alias, skipped", origName) + return + } + pkg := ctx.pkg pkgTypes := pkg.Types - - origName := nameWithNS(clang.String(decl), ns) underlying := decl.TypedefDeclUnderlyingType() if debugCompileDecl { log.Println("typedef", origName, "-", clang.String(underlying)) } feats := 0 - tunder := toTypeEx(ctx, pkgTypes, underlying, flagIsTypeDef, &feats, nil) + tunder := toTypeEx(ctx, pkgTypes, underlying, flagIsTypeDef, &feats, scope) if feats&featIgnored != 0 { - if debugCompileDecl { - log.Println("typedef", cName, "- ignored") - } + ctx.logf(decl, "typedef %s: unsupport underlying type, skipped", origName) ctx.types[cName] = typeObj{nil, featIgnored} // ignored return } diff --git a/tool/_testcpp/llvm-22.1.8-support/ADL/out.go b/tool/_testcpp/llvm-22.1.8-support/ADL/out.go new file mode 100644 index 000000000..994b6bc86 --- /dev/null +++ b/tool/_testcpp/llvm-22.1.8-support/ADL/out.go @@ -0,0 +1,3 @@ +package ADL + +const LLGoPackage = "link: -L$(llvm-config --libdir) -lLLVM; -lLLVM" diff --git a/tool/gen_test.go b/tool/gen_test.go index 783fe365a..2fe6197d6 100644 --- a/tool/gen_test.go +++ b/tool/gen_test.go @@ -292,3 +292,7 @@ func TestLLVM_DenseMapInfo(t *testing.T) { func TestLLVM_String(t *testing.T) { testFromDir(t, "StringRef", "./_testcpp", true, "adt") } + +func TestLLVM_ADL(t *testing.T) { + testFromDir(t, "ADL", "./_testcpp", true, "adt") +} From 2313eefaa2989dcb0be59fe490721f2135745c3c Mon Sep 17 00:00:00 2001 From: xushiwei Date: Wed, 30 Sep 2026 08:19:22 +0800 Subject: [PATCH 2/2] tool test: TestLLVM_iterator_range --- cl/class.go | 2 +- cl/compile.go | 2 +- cl/typedef.go | 2 +- tool/_testcpp/llvm-22.1.8-support/iterator_range/out.go | 9 +++++++++ tool/gen_test.go | 4 ++++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cl/class.go b/cl/class.go index e97a26542..6eb6a0450 100644 --- a/cl/class.go +++ b/cl/class.go @@ -300,7 +300,7 @@ func loadClassMember(ctx *pkgCtx, pkg *types.Package, this *classCtx, clsName st loadEnum(ctx, decl, clsName) } - case lc.Cursor_TypedefDecl, lc.Cursor_TypeAliasDecl: + case lc.Cursor_TypedefDecl, lc.Cursor_TypeAliasDecl, lc.Cursor_TypeAliasTemplateDecl: // A typedef nested in a class acts like one nested in a namespace: it // only affects naming, so it is emitted as a package-level type alias // prefixed by the enclosing class name (the class name acts like a diff --git a/cl/compile.go b/cl/compile.go index ddac99147..588b99066 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -314,7 +314,7 @@ func loadDecl(ctx *pkgCtx, scope *scopeCtx, decl clang.Cursor, ns string) { case lc.Cursor_ClassTemplate, lc.Cursor_ClassTemplatePartialSpecialization: loadTemplateClass(ctx, decl, ns, nil) default: - ctx.panicf(decl, "compileDecl: unknown kind - %v", decl.Kind) + ctx.panicf(decl, "loadDecl: unknown kind - %v", decl.Kind) } } diff --git a/cl/typedef.go b/cl/typedef.go index 982f299ed..c0bab8da8 100644 --- a/cl/typedef.go +++ b/cl/typedef.go @@ -52,7 +52,7 @@ func loadTypedef(ctx *pkgCtx, decl clang.Cursor, ns string, scope *scopeCtx) { feats := 0 tunder := toTypeEx(ctx, pkgTypes, underlying, flagIsTypeDef, &feats, scope) if feats&featIgnored != 0 { - ctx.logf(decl, "typedef %s: unsupport underlying type, skipped", origName) + ctx.logf(decl, "typedef %s: unsupported underlying type, skipped", origName) ctx.types[cName] = typeObj{nil, featIgnored} // ignored return } diff --git a/tool/_testcpp/llvm-22.1.8-support/iterator_range/out.go b/tool/_testcpp/llvm-22.1.8-support/iterator_range/out.go index 60edcfb74..e3f355d99 100644 --- a/tool/_testcpp/llvm-22.1.8-support/iterator_range/out.go +++ b/tool/_testcpp/llvm-22.1.8-support/iterator_range/out.go @@ -1,3 +1,12 @@ package iterator_range const LLGoPackage = "link: -L$(llvm-config --libdir) -lLLVM; -lLLVM" + +// A range adaptor for a pair of iterators. +// +// This just wraps two iterators into a range-compatible interface. Nothing +// fancy at all. +type IteratorRange[IteratorT any] struct { + beginIterator IteratorT + endIterator IteratorT +} diff --git a/tool/gen_test.go b/tool/gen_test.go index 2fe6197d6..85aca27a0 100644 --- a/tool/gen_test.go +++ b/tool/gen_test.go @@ -296,3 +296,7 @@ func TestLLVM_String(t *testing.T) { func TestLLVM_ADL(t *testing.T) { testFromDir(t, "ADL", "./_testcpp", true, "adt") } + +func TestLLVM_iterator_range(t *testing.T) { + testFromDir(t, "iterator_range", "./_testcpp", true, "adt") +}