-
Notifications
You must be signed in to change notification settings - Fork 11
cl: loadNamespace #726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cl: loadNamespace #726
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| namespace bar { | ||
| namespace detail { | ||
| unsigned f(int a); | ||
| void f(); | ||
| } | ||
| } | ||
|
|
||
| namespace bar { | ||
| class base | ||
| { | ||
| public: | ||
| ~base(); | ||
| }; | ||
|
|
||
| typedef char boolean; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package foo | ||
|
|
||
| import ( | ||
| "github.com/goplus/lib/c" | ||
| _ "unsafe" | ||
| ) | ||
|
|
||
| const XGoPackage = true | ||
|
|
||
| //go:linkname Bar_detail_f__1 C._ZN3bar6detail1fEi | ||
| func Bar_detail_f__1(a c.Int) c.Uint | ||
|
|
||
| //go:linkname Bar_detail_f__0 C._ZN3bar6detail1fEv | ||
| func Bar_detail_f__0() | ||
|
|
||
| type Bar_base struct { | ||
| } | ||
|
|
||
| // llgo:link (*Bar_base).XGo_Dtor C._ZN3bar4baseD1Ev | ||
| func (this *Bar_base) XGo_Dtor() { | ||
| } | ||
|
|
||
| type Bar_boolean = c.Char |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,10 +95,6 @@ type Config struct { | |
|
|
||
| // ----------------------------------------------------------------------------- | ||
|
|
||
| const ( | ||
| headerGoFile = "llcppg.i.go" | ||
| ) | ||
|
|
||
| // NewPackage loads a translation unit and generates a Go package with the given package | ||
| // path, name and configuration. | ||
| func NewPackage(pkgPath, pkgName string, conf *Config, tu clang.TranslationUnit, files ...string) (ret Package, err error) { | ||
|
|
@@ -114,7 +110,7 @@ func NewPackage(pkgPath, pkgName string, conf *Config, tu clang.TranslationUnit, | |
| NewBuiltin: nil, | ||
| NodeInterpreter: interp, | ||
| CanImplicitCast: nil, | ||
| DefaultGoFile: headerGoFile, | ||
| DefaultGoFile: "", | ||
| } | ||
| pkg := gogen.NewPackage(pkgPath, pkgName, confGox) | ||
| pkg.SetRedeclarable(true) | ||
|
|
@@ -165,13 +161,13 @@ func loadFiles(ctx *pkgCtx) { | |
| return clang.Continue | ||
| } | ||
| } | ||
| loadDecl(ctx, scope, decl) | ||
| loadDecl(ctx, scope, decl, "") | ||
| return clang.Continue | ||
| }) | ||
| scope.reorder() | ||
| } | ||
|
|
||
| func loadDecl(ctx *pkgCtx, scope *scopeCtx, decl clang.Cursor) { | ||
| func loadDecl(ctx *pkgCtx, scope *scopeCtx, decl clang.Cursor, ns string) { | ||
| /* if global { | ||
| ctx.logFile(decl) | ||
| if decl.IsImplicit || ctx.inDepPkg { | ||
|
|
@@ -180,25 +176,35 @@ func loadDecl(ctx *pkgCtx, scope *scopeCtx, decl clang.Cursor) { | |
| } */ | ||
| switch decl.Kind { | ||
| case lc.CursorFunctionDecl: | ||
| loadGlobalFunc(ctx, scope, decl) | ||
| loadGlobalFunc(ctx, scope, decl, ns) | ||
| case lc.CursorClassDecl, lc.CursorStructDecl: | ||
| defaultInPublic := decl.Kind == lc.CursorStructDecl | ||
| loadClass(ctx, decl, defaultInPublic) | ||
| loadClass(ctx, decl, ns, defaultInPublic) | ||
| case lc.CursorCXXMethod, lc.CursorConstructor, lc.CursorDestructor: | ||
| loadOutsideMethod(ctx, decl) | ||
| case lc.CursorTypedefDecl: | ||
| loadTypedef(ctx, decl) | ||
| loadTypedef(ctx, decl, ns) | ||
| case lc.CursorEnumDecl: | ||
| // compileEnum(ctx, decl, global) | ||
| case lc.CursorMacroDefinition: | ||
| loadMacro(ctx, decl) | ||
| case lc.CursorNamespace: | ||
| loadNamespace(ctx, scope, decl, ns) | ||
| case lc.CursorVarDecl: | ||
| // compileVarDecl(ctx, decl, global) | ||
| default: | ||
| log.Panicln("compileDecl: unknown kind =", decl.Kind) | ||
| } | ||
| } | ||
|
|
||
| func loadNamespace(ctx *pkgCtx, scope *scopeCtx, namespace clang.Cursor, ns string) { | ||
|
xushiwei marked this conversation as resolved.
|
||
| ns = ns + clang.String(namespace) + "_" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Namespace prefix separator is non-injective; distinct C++ names can collide
|
||
| clang.VisitChildren(namespace, func(decl, parent clang.Cursor) clang.ChildVisitResult { | ||
| loadDecl(ctx, scope, decl, ns) | ||
| return clang.Continue | ||
| }) | ||
| } | ||
|
|
||
| func loadMacro(ctx *pkgCtx, decl clang.Cursor) { | ||
| if decl.IsMacroFunctionLike() != 0 { | ||
| return | ||
|
|
@@ -225,9 +231,9 @@ func loadMacro(ctx *pkgCtx, decl clang.Cursor) { | |
| }) | ||
| } | ||
|
|
||
| func loadTypedef(ctx *pkgCtx, decl clang.Cursor) { | ||
| func loadTypedef(ctx *pkgCtx, decl clang.Cursor, ns string) { | ||
| ctx.compiles = append(ctx.compiles, func(ctx *pkgCtx) { | ||
| origName := clang.String(decl) | ||
| origName := ns + clang.String(decl) | ||
| pkg := ctx.pkg | ||
| pkgTypes := pkg.Types | ||
| underlying := decl.TypedefDeclUnderlyingType() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.