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
2 changes: 1 addition & 1 deletion cl/_testcpp/ctor_dtor/wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern "C" void _llcppg__ZN3barC1Ev(bar* this) {
this->bar();
}

extern "C" void _llcppg__ZN3barC1EPKc(bar* this, const char * a) {
extern "C" void _llcppg__ZN3barC1EPKc(bar* this, const char *a) {
this->bar(a);
}

Expand Down
4 changes: 4 additions & 0 deletions cl/_testpp/macro/in.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#define TRUE 1
#define FALSE 0

typedef char BOOL, *PBOOL;
6 changes: 6 additions & 0 deletions cl/_testpp/macro/out.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package foo

import "github.com/goplus/lib/c"

type BOOL = c.Char
type PBOOL = *c.Char
20 changes: 19 additions & 1 deletion cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,30 @@ func loadDecl(ctx *pkgCtx, scope *scopeCtx, decl clang.Cursor) {
case lc.CursorVarDecl:
// compileVarDecl(ctx, decl, global)
case lc.CursorTypedefDecl:
// TODO(xsw)
loadTypedef(ctx, decl)
case lc.CursorEnumDecl:
// compileEnum(ctx, decl, global)
default:
log.Panicln("compileDecl: unknown kind =", decl.Kind)
}
}

func loadTypedef(ctx *pkgCtx, decl clang.Cursor) {
ctx.compiles = append(ctx.compiles, func(ctx *pkgCtx) {
origName := clang.String(decl)
pkg := ctx.pkg
pkgTypes := pkg.Types
underlying := decl.TypedefDeclUnderlyingType()
if debugCompileDecl {
log.Println("typedef", origName, "-", clang.String(underlying))
}
tunder := toType(ctx, pkgTypes, underlying, flagIsTypedef)
name, rewritten := ctx.getPubName(origName, -1)
t := pkg.NewTypeDefs().AliasType(name, tunder)
if rewritten {
pkgTypes.Scope().Insert(types.NewTypeName(token.NoPos, pkgTypes, origName, t))
}
})
}

// -----------------------------------------------------------------------------
4 changes: 4 additions & 0 deletions cl/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,8 @@ func TestCpp(t *testing.T) {
testFromDir(t, "", "./_testcpp", cl.LanguageCXX)
}

func TestPreprocessor(t *testing.T) {
testFromDir(t, "", "./_testpp", cl.LanguageC)
}

// -----------------------------------------------------------------------------
6 changes: 3 additions & 3 deletions cl/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ func (p *pkgCtx) compile() {
}
}

func (p *pkgCtx) getPubName(fnName string, order int) (pubName string, rewritten bool) {
pubName = cPubName(fnName)
func (p *pkgCtx) getPubName(cName string, order int) (pubName string, rewritten bool) {
pubName = cPubName(cName)
if order >= 0 {
return pubName + "__" + strconv.FormatInt(int64(order), 36), true
}
rewritten = fnName != pubName
rewritten = cName != pubName
return
}

Expand Down
4 changes: 3 additions & 1 deletion cl/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ func writeParam(b *writerT, typ lc.Type, name string) {
return
}
b.WriteString(clang.String(typ))
b.WriteByte(' ')
if typ.Kind != lc.TypePointer {
b.WriteByte(' ')
}
b.WriteString(name)
}

Expand Down
Loading