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: 5 additions & 0 deletions cl/_testcpp/ctor_dtor/in.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"LLGoPackage": "link: -L/path/foo -lfoo",
"CFlags": "-I/path/foo/include",
"WrapFileHeader": "#include <foo.h>\n"
}
13 changes: 11 additions & 2 deletions cl/_testcpp/ctor_dtor/in.h
Original file line number Diff line number Diff line change
@@ -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() {
}
19 changes: 17 additions & 2 deletions cl/_testcpp/ctor_dtor/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
Expand All @@ -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() {
}
13 changes: 13 additions & 0 deletions cl/_testcpp/ctor_dtor/wrap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <foo.h>

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();
}
3 changes: 3 additions & 0 deletions cl/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cl/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading