Skip to content

cl: toFuncType (testcase: _testmockc/type) - #708

Merged
xushiwei merged 2 commits into
goplus:devfrom
xushiwei:q
Sep 13, 2026
Merged

cl: toFuncType (testcase: _testmockc/type)#708
xushiwei merged 2 commits into
goplus:devfrom
xushiwei:q

Conversation

@xushiwei

Copy link
Copy Markdown
Member

No description provided.

@xushiwei
xushiwei merged commit ffa835d into goplus:dev Sep 13, 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 Summary

Clean, well-scoped refactor. getPubName now returns (pubName, rewritten) instead of mutating through a pointer, toType/newParam/newVariadicParam take an explicit *types.Package, and new helpers toFuncType/toFuncParams/toFuncResults add function-pointer parameter support. The _testmockc/type fixture covers both the callback-parameter path and the void-return / no-arg path. Build passes.

No correctness or security issues introduced by this diff. Two minor notes are inline; a couple of non-blocking observations below.

Non-blocking observations

  • Minor optional perf: toFuncParams (cl/type_and_var.go) and newParams (cl/compile.go) grow params from a nil slice via append, though the count is known up front. make([]*types.Var, 0, n) would avoid reallocations. Trivial; compile-time path only.
  • Out of scope (pre-existing): cPubName (cl/blockctx.go:109) and manglingName[1:] (cl/compile.go:192) index position 0/1 without a length check and would panic on an empty name. Not touched by this PR, flagged only for awareness.

Comment thread cl/type_and_var.go
for i := range n {
item := fn.ArgType(c.Uint(i))
tyParam := toType(ctx, pkg, item, flagIsParam)
nameParam := "_llcppg_param" + strconv.Itoa(int(i)+1)

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.

toFuncParams unconditionally names each parameter _llcppg_param<N> and never consults the declared C argument name or applies avoidKeyword. This diverges from newParam (cl/compile.go:217-230), which adopts the real C name when present. For a function-pointer prototype that carries argument names (e.g. int (*cmp)(const void* lhs, const void* rhs)), those names are silently dropped. If dropping them is intentional (proto types often have none), a short comment would help; otherwise consider sharing naming logic with newParam.

Comment thread cl/type_and_var.go
pointee := toType(ctx, typ.PointeeType(), flags)
elem := typ.PointeeType()
if elem.Kind == lc.TypeFunctionProto {
return toFuncType(ctx, pkg, elem)

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.

The pointer branch forwards flags recursively (line 78), but the function-proto branch drops flags when calling toFuncType, and toFuncParams then hardcodes flagIsParam. Harmless today since flags is unused in the reachable branches, but the asymmetry could surprise if downstream logic ever keys off flagRetType/flagIsStructField inside a function pointer.

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