Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions cl/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
}
}

Expand Down
17 changes: 10 additions & 7 deletions cl/typedef.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions tool/_testcpp/llvm-22.1.8-support/ADL/out.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package ADL

const LLGoPackage = "link: -L$(llvm-config --libdir) -lLLVM; -lLLVM"
9 changes: 9 additions & 0 deletions tool/_testcpp/llvm-22.1.8-support/iterator_range/out.go
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions tool/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Loading