Skip to content

cmd: llcppdump - #696

Merged
xushiwei merged 1 commit into
goplus:devfrom
xushiwei:q
Sep 6, 2026
Merged

cmd: llcppdump#696
xushiwei merged 1 commit into
goplus:devfrom
xushiwei:q

Conversation

@xushiwei

@xushiwei xushiwei commented Sep 6, 2026

Copy link
Copy Markdown
Member

No description provided.

@xushiwei
xushiwei merged commit 99a109f into goplus:dev Sep 6, 2026
2 checks passed

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Add VisitChildren / Cursor wrapper API

This is a clean, idiomatic addition to the high-level clang wrapper package. The new TranslationUnit.Cursor() method, the Cursor / ChildVisitResult type aliases, the Break / Continue / Recurse constants, and VisitChildren all match the existing conventions of the file.

Confirmed correct:

  • The closure plumbing in VisitChildren is correct and memory-safe: c.ClosureData(fn) boxes the Go func into a stable pointer passed as ClientData, and the C-ABI trampoline unboxes it via c.GoClosure[...] with the matching generic type and (cur, parent) order. Since clang_visitChildren is synchronous and fn stays reachable for the whole call, there is no GC/use-after-free window.
  • The Break/Continue/Recurse constants correctly alias the underlying clang.ChildVisit_* values.
  • The go.mod bump to lib v0.5.2 is consistent with the use of the GoClosure/ClosureData helpers.

The pure-Go go build relocation failures for C symbols are expected for this LLGo binding project and are not a defect of this PR.

Findings below are minor / non-blocking.

Comment thread cmd/llcppdump/cppdump.go
idx := clang.CreateIndex(0, 0)
defer idx.Dispose()

u := idx.ParseTranslationUnit(0, "")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Demo parses an empty filename, so it never exercises the new API

idx.ParseTranslationUnit(0, "") passes a non-NULL pointer to an empty C string with no command-line args. libclang treats a NULL source_filename as "the file is given in the args", but an empty-but-non-NULL string instead asks libclang to open a file literally named "", which fails and returns a NULL translation unit. As a result u.Cursor() yields a null cursor and dump() visits nothing, so this demo doesn't actually demonstrate VisitChildren.

Consider parsing a real source file (or taking a path from os.Args) and checking the returned unit before traversing. Since dump's visitor also just returns clang.Continue, printing something per node (e.g. cursor kind/spelling) would make it a meaningful "dump" demo.

Comment thread clang/clang.go

/**
* CreateIndex provides a shared context for creating translation units.
* Provides a shared context for creating translation units.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] CreateIndex doc comment no longer starts with the identifier name

Changing CreateIndex provides a shared context... to Provides a shared context... means the doc comment for the exported CreateIndex function no longer begins with the identifier name, so go doc CreateIndex renders "Provides a shared context..." and loses the Go doc convention.

Note this is a style tradeoff: the rest of this file uses doxygen /** */ blocks copied from the clang headers that also don't start with the identifier name, so this change is arguably making CreateIndex consistent with the surrounding style. Non-blocking — flag only if Go-doc conformance is preferred over header-comment fidelity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant