Skip to content

cl name refactor: use cName instead of origName - #890

Merged
xushiwei merged 10 commits into
goplus:mainfrom
xushiwei:q
Oct 1, 2026
Merged

xushiwei merged 10 commits into
goplus:mainfrom
xushiwei:q

Conversation

@xushiwei

@xushiwei xushiwei commented Oct 1, 2026

Copy link
Copy Markdown
Member

cName := full C/C++ name (eg. foo::bar::f)
origName := concat parts (eg. FooBarF)

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.61084% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.71%. Comparing base (c615738) to head (885bc24).
⚠️ Report is 31 commits behind head on main.

Files with missing lines Patch % Lines
cl/class.go 87.80% 5 Missing ⚠️
cl/compile.go 83.33% 3 Missing ⚠️
cl/var.go 77.77% 2 Missing ⚠️
cl/enum.go 94.11% 1 Missing ⚠️
cl/func.go 88.88% 1 Missing ⚠️
cl/name.go 98.36% 1 Missing ⚠️
cl/type.go 66.66% 1 Missing ⚠️
cl/vtable.go 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #890      +/-   ##
==========================================
+ Coverage   87.64%   87.71%   +0.06%     
==========================================
  Files          23       23              
  Lines        1951     1962      +11     
==========================================
+ Hits         1710     1721      +11     
  Misses        241      241              
Flag Coverage Δ
llgo-tests 87.71% <92.61%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@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 summary

This PR refactors naming to derive C/C++ full names (cName) directly from the AST cursor (new helpers cNameOf/cNS/cBaseName/cNameSplit/cNameWithNS/cTypeName) instead of threading an ns string through the load/compile paths, and adds an NSPrefix config option. The refactor is coherent and consistently applied, the NSPrefix wiring is complete end-to-end (config → gen → compile → ctx → name), and the cstyleToGo rewrite preserves prior behavior for the leading-underscore case.

Findings below are minor — a leftover dead function, a log-format typo, and doc comments that still describe the removed ns parameter. None are blocking. One robustness note (latent hang in cNameOf/cNS) is included for awareness.

Not blocking / verified correct: the inlined cstyleToGo leading-_ handling (old cPubName's _→X branch was unreachable from cstyleToGo since _ is a split char), the new rename[part] v != "" guard (a safe improvement), and the lastEndWithUpper separator logic. Performance of the new per-reference AST walks is negligible for a one-shot code generator.

Findings not placed inline

  • cl/name.go:273 — nameWithNS is now dead code. After this refactor its only remaining reference is its own definition; all former callers moved to the new cNameWithNS/cstyleToGo scheme. Note it behaves differently from the similarly-named cNameWithNS (nsName-based vs "::"-joined), so keeping both invites future misuse. Recommend deleting it.
  • tool/config.go:53 — NSIgnore doc is now stale. The struct tag comment still reads // namespaces (Go style names) to ignore, but isNSIgnored now matches against C/C++ names (loadNamespace computes cNameOf(namespace)). The parallel comment in cl/compile.go was correctly updated to "C/C++ namespaces"; this one was missed and now contradicts it. (Line not in the diff, so noted here.)
  • cl/name.go cNameOf/cNS — latent infinite loop on a null/invalid cursor. Both loops terminate only on Cursor_TranslationUnit; libclang's semantic parent of a null cursor is itself null (Cursor_InvalidFile), so an invalid cursor would loop forever. Current call sites always pass valid cursors, so this is defensive only — the rest of the codebase guards with IsNull() (e.g. cl/vtable.go, cl/class.go). Consider adding an if decl.IsNull() != 0 { break } guard.

Comment thread cl/typedef.go
underlying := decl.TypedefDeclUnderlyingType()
if debugCompileDecl {
log.Println("typedef", origName, "-", clang.String(underlying))
ctx.logf(decl, "typedef %ss: %s", cName, clang.String(underlying))

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.

Log format typo: "typedef %ss: %s" renders as e.g. typedef Foos: ... (double s). Every other log in this file uses "typedef %s: ..." (lines 31, 37, 51, 56). Should be "typedef %s: %s". Only emitted under debugCompileDecl.

Comment thread cl/enum.go
name := clang.String(decl)
origName := nameWithNS(name, ns)
anonymous := decl.IsAnonymous() != 0
func loadEnum(ctx *pkgCtx, decl clang.Cursor) {

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.

Stale doc comment above this signature still describes the removed ns parameter: "ns carries the enclosing namespace/class prefix (e.g. \"bar_\" or \"Shape_\") ... through getPubName". loadEnum no longer takes ns — it derives ns := cNS(decl) internally, which is a ::-joined C++ namespace (e.g. bar, Shape), not an underscore-suffixed Go prefix, and there is no getPubName. Please update the comment.

Comment thread cl/union.go
func loadUnion(ctx *pkgCtx, decl clang.Cursor, ns string) {
if decl.IsCursorDefinition() == 0 {
return
func loadUnion(ctx *pkgCtx, decl clang.Cursor) {

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.

Stale doc comment above this signature: "ns carries the enclosing prefix ... through getPubName like a struct's". loadUnion no longer takes an ns parameter (it now computes cName := cNameOf(decl)), and getPubName no longer exists. Please update.

Comment thread cl/var.go
// handled). Non-static class member variables are fields, not VarDecls, and are
// handled separately in loadClassMember.
func loadVar(ctx *pkgCtx, decl clang.Cursor, ns string) {
func loadVar(ctx *pkgCtx, decl clang.Cursor) {

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.

Stale doc comment above this signature: "The Go name is prefixed by ns, which encodes the enclosing namespaces and/or class". loadVar/compileVar no longer take ns; the name is now derived via cNameOf(decl). Please update the comment to match.

@xushiwei
xushiwei merged commit 3ae444f into goplus:main Oct 1, 2026
4 checks passed
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