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
14 changes: 6 additions & 8 deletions cl/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ func compileTemplateClass(ctx *pkgCtx, obj *templateObj, parent *scopeCtx) {
origName := obj.name
cls := obj.decl
if debugCompileDecl {
log.Println("template class", origName)
log.Println("template class", origName, "order:", obj.order())
}

pkg := ctx.pkg
pkgTypes := pkg.Types
feats := 0
tparams := newTemplateParams(ctx, pkgTypes, cls, &feats)
if feats&featIgnored != 0 {
log.Println("template class: unsupported template params, skipped -", origName)
if feats&featIgnored != 0 || obj.order() >= 0 {
ctx.logf(cls, "class %s: unsupported template params, skipped", clang.String(cls))
Comment thread
xushiwei marked this conversation as resolved.
return
}

Expand Down Expand Up @@ -149,10 +149,8 @@ func loadClass(ctx *pkgCtx, cls clang.Cursor, ns string, kind typeTag, parent *s
}

if cls.NumTemplateArguments() > 0 {
if debugCompileDecl {
log.Println("class", origName, "- with template arguments, skipped")
}
return // temporarily skip class with template arguments, e.g. Foo<int>
loadTemplateClass(ctx, cls, ns, parent)
return
}

var clsName string
Expand Down Expand Up @@ -360,7 +358,7 @@ func loadClassMember(ctx *pkgCtx, pkg *types.Package, this *classCtx, clsName st
// noop

default:
log.Panicln("loadClassMember: unknown kind =", decl.Kind)
ctx.panicf(decl, "loadClassMember: unknown kind = %v", decl.Kind)
}
}

Expand Down
28 changes: 15 additions & 13 deletions cl/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package cl

import (
"fmt"
"go/ast"
"go/token"
"go/types"
Expand Down Expand Up @@ -153,6 +154,16 @@ type pkgCtx struct {
keepDoc bool
}

func (p *pkgCtx) logf(decl clang.Cursor, format string, args ...any) {
pos := p.fset.Position(goNodePos(p, decl))
log.Printf("%s: %s", pos, fmt.Sprintf(format, args...))
}

func (p *pkgCtx) panicf(decl clang.Cursor, format string, args ...any) {
pos := p.fset.Position(goNodePos(p, decl))
log.Panicf("%s: %s", pos, fmt.Sprintf(format, args...))
}

const (
anonPrefix = "_llcppg_anon_"
)
Expand Down Expand Up @@ -530,6 +541,9 @@ func (p *scopeCtx) lookupType(name string) (types.Type, bool) {
}

func (p *scopeCtx) addTemplate(_ *pkgCtx, name string, decl clang.Cursor, isClass bool) (*templateObj, bool) {
if debugCompileDecl {
log.Println("==> addTemplate", name, "-", clang.DisplayName(decl))
}
// TODO(xsw): check if the class is already added
obj := &templateObj{
name: name,
Expand Down Expand Up @@ -585,23 +599,11 @@ func (p *scopeCtx) reorder() {
}

func funcUSR(decl clang.Cursor) string {
return clang.GoStringAndDispose(decl.USR())
return clang.USR(decl)
}

func funcDisplayName(decl clang.Cursor) string {
return clang.DisplayName(decl)
}

/*
func substObj(pkg *types.Package, scope *types.Scope, origName string, real types.Object) {
old := scope.Insert(gogen.NewSubst(0, pkg, origName, real))
if old != nil {
if t, ok := old.Type().(*gogen.TySubst); ok {
t.Real = real
} else {
log.Panicln(origName, "redefined")
}
}
}
*/
// -----------------------------------------------------------------------------
14 changes: 4 additions & 10 deletions cl/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func compileFuncOrMethod(ctx *pkgCtx, obj *funcObj, this *classCtx) {

manglingName := clang.Mangling(fn)
if manglingName == "" {
log.Println("func skipped: no mangling name for", origName)
ctx.logf(fn, "func %s: no mangled symbol, skipped", clang.String(fn))
return
}

Expand All @@ -91,24 +91,18 @@ func compileFuncOrMethod(ctx *pkgCtx, obj *funcObj, this *classCtx) {
params, variadic := newParams(ctx, pkgTypes, fn, &feats, scope)
results := toFuncResults(ctx, pkgTypes, fn.ResultType(), &feats, scope)
if feats&featIgnored != 0 {
if debugCompileDecl {
log.Println("func", origName, "- ignored")
}
ctx.logf(fn, "func %s: function with unsupported features, skipped", clang.String(fn))
return
}

if fn.IsFunctionInlined() != 0 {
if ctx.cflags == "" {
if debugCompileDecl {
log.Println("inline func", origName, "- skipped")
}
ctx.logf(fn, "func %s: inline function but no CFlags in config, skipped", clang.String(fn))
return
}
manglingName = wrapInlineFunc(ctx, manglingName, fn, this)
} else if _, ok := ctx.nameLookup(manglingName); !ok {
if debugCompileDecl {
log.Println("func", origName, "- skipped")
}
ctx.logf(fn, "func %s: symbol not found in lib files, skipped", clang.String(fn))
return
}

Expand Down
4 changes: 1 addition & 3 deletions cl/var.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ func compileVar(ctx *pkgCtx, decl clang.Cursor, ns string) {
origName := nameWithNS(clang.String(decl), ns)
manglingName := clang.Mangling(decl)
if _, ok := ctx.nameLookup(manglingName); !ok {
if debugCompileDecl {
log.Println("var", origName, "- skipped")
}
ctx.logf(decl, "var %s: symbol not found in lib files, skipped", clang.String(decl))
return
}

Expand Down
Loading
Loading