diff --git a/cl/_testcpp/ctor_dtor/in.cfg b/cl/_testcpp/ctor_dtor/in.cfg new file mode 100644 index 00000000..86a2677a --- /dev/null +++ b/cl/_testcpp/ctor_dtor/in.cfg @@ -0,0 +1,5 @@ +{ + "LLGoPackage": "link: -L/path/foo -lfoo", + "CFlags": "-I/path/foo/include", + "WrapFileHeader": "#include \n" +} diff --git a/cl/_testcpp/ctor_dtor/in.h b/cl/_testcpp/ctor_dtor/in.h index b1055b16..896dc26a 100644 --- a/cl/_testcpp/ctor_dtor/in.h +++ b/cl/_testcpp/ctor_dtor/in.h @@ -1,7 +1,16 @@ -class bar +class base { +public: + ~base(); +}; + +class bar : public base { public: bar(int a); bar(); - ~bar(); + bar(const char* a) {} + ~bar() {} }; + +inline bar::bar() { +} diff --git a/cl/_testcpp/ctor_dtor/out.go b/cl/_testcpp/ctor_dtor/out.go index ae1be811..2c095389 100644 --- a/cl/_testcpp/ctor_dtor/out.go +++ b/cl/_testcpp/ctor_dtor/out.go @@ -3,6 +3,17 @@ package foo import "github.com/goplus/lib/c" const XGoPackage = true +const ( + LLGoPackage = "link: -L/path/foo -lfoo" + LLGoFiles = "-I/path/foo/include: _wrap/llcppg.cpp" +) + +type Base struct { +} + +// llgo:link (*Base).XGo_Dtor C._ZN4baseD1Ev +func (this *Base) XGo_Dtor() { +} type Bar struct { } @@ -11,10 +22,14 @@ type Bar struct { func (this *Bar) XGo_Ctor__1(a c.Int) { } -// llgo:link (*Bar).XGo_Ctor__0 C._ZN3barC1Ev +// llgo:link (*Bar).XGo_Ctor__0 C._llcppg__ZN3barC1Ev func (this *Bar) XGo_Ctor__0() { } -// llgo:link (*Bar).XGo_Dtor C._ZN3barD1Ev +// llgo:link (*Bar).XGo_Ctor__2 C._llcppg__ZN3barC1EPKc +func (this *Bar) XGo_Ctor__2(a *c.Char) { +} + +// llgo:link (*Bar).XGo_Dtor C._llcppg__ZN3barD1Ev func (this *Bar) XGo_Dtor() { } diff --git a/cl/_testcpp/ctor_dtor/wrap.cpp b/cl/_testcpp/ctor_dtor/wrap.cpp new file mode 100644 index 00000000..afa477e9 --- /dev/null +++ b/cl/_testcpp/ctor_dtor/wrap.cpp @@ -0,0 +1,13 @@ +#include + +void _llcppg__ZN3barC1Ev(bar* this) { + this->bar(); +} + +void _llcppg__ZN3barC1EPKc(bar* this, const char * a) { + this->bar(a); +} + +void _llcppg__ZN3barD1Ev(bar* this) { + this->~bar(); +} diff --git a/cl/class.go b/cl/class.go index cd59409a..f384bbc5 100644 --- a/cl/class.go +++ b/cl/class.go @@ -119,6 +119,9 @@ func loadClassMember(ctx *pkgCtx, pkg *types.Package, cls *classCtx, decl clang. case lc.CursorCXXAccessSpecifier: cls.inPublic = decl.CXXAccessSpecifier() == lc.CXXPublic + case lc.CursorCXXBaseSpecifier: + // noop + default: log.Panicln("loadClassMember: unknown kind =", decl.Kind) } diff --git a/cl/compile.go b/cl/compile.go index c3ca0409..3703351b 100644 --- a/cl/compile.go +++ b/cl/compile.go @@ -181,7 +181,7 @@ func loadDecl(ctx *pkgCtx, scope *scopeCtx, decl clang.Cursor) { case lc.CursorClassDecl, lc.CursorStructDecl: defaultInPublic := decl.Kind == lc.CursorStructDecl loadClass(ctx, decl, defaultInPublic) - case lc.CursorCXXMethod: + case lc.CursorCXXMethod, lc.CursorConstructor, lc.CursorDestructor: loadOutsideMethod(ctx, decl) case lc.CursorVarDecl: // compileVarDecl(ctx, decl, global) diff --git a/cl/compile_test.go b/cl/compile_test.go index 61517198..971ad36f 100644 --- a/cl/compile_test.go +++ b/cl/compile_test.go @@ -52,7 +52,7 @@ func testGenGo(t *testing.T, pkg *gogen.Package, dir string, exp any) { if err != nil { t.Fatal("gogen.WriteTo failed:", err) } - testDiff(t, dir, "/out.txt", &b, exp) + testDiff(t, dir, "/out.go.txt", &b, exp) } func testFromDir(t *testing.T, sel, relDir string, lang cl.Language) {