diff --git a/cl/class.go b/cl/class.go index 87ccc4db5..6eb6a0450 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 } @@ -301,13 +300,13 @@ 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 // 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..588b99066 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, "loadDecl: unknown kind - %v", decl.Kind) } } diff --git a/cl/typedef.go b/cl/typedef.go index d6cca67ec..c0bab8da8 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: unsupported 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/_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 783fe365a..85aca27a0 100644 --- a/tool/gen_test.go +++ b/tool/gen_test.go @@ -292,3 +292,11 @@ 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") +} + +func TestLLVM_iterator_range(t *testing.T) { + testFromDir(t, "iterator_range", "./_testcpp", true, "adt") +}