Skip to content

Conversation

@luoliwoshang
Copy link
Member

@luoliwoshang luoliwoshang commented Jun 10, 2025

design for #448


To work around LLGo's inability to use anonymous function types directly in struct fields, llcppg automatically generates a corresponding named function type. This generated type is intentionally made unexported (private) to mirror C/C++ semantics, where anonymous function types are not externally accessible. Crucially, even though the type itself is private, this does not affect the ability to assign a compatible function to the field during normal use in Go. All such function types follow the specific naming convention:

llgo_<namespaces>_<typename>_<nested_field_typename>_<fieldname>

@codecov
Copy link

codecov bot commented Jun 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.38%. Comparing base (4580427) to head (5edc2b9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #449   +/-   ##
=======================================
  Coverage   84.38%   84.38%           
=======================================
  Files          27       27           
  Lines        2728     2728           
=======================================
  Hits         2302     2302           
  Misses        385      385           
  Partials       41       41           

☔ View full report in Codecov by Sentry.
📢 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.

@luoliwoshang luoliwoshang force-pushed the doc/en/fnptr branch 3 times, most recently from 6855c85 to ff94ed7 Compare June 10, 2025 12:23
Comment on lines 97 to 100
LLGo cannot use anonymous function types directly as field types. To preserve type information, llcppg automatically generates named function types and references them in the field and following this naming convention:
```
LLGO_<namespaces>_<typename>_<nested_field_typename>_<fieldname>
```
Copy link
Member Author

Choose a reason for hiding this comment

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

Based on our discussion in the meeting: In C, an anonymous function's type is not accessible from the outside. To follow this same rule in Go, we'll make the auto-generated type unexported, which still allows the field to be assigned correctly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 545cb07

To work around LLGo's inability to use anonymous function types directly in struct fields, llcppg automatically generates a corresponding named function type. This generated type is intentionally made unexported (private) to mirror C/C++ semantics, where anonymous function types are not externally accessible. Crucially, even though the type itself is private, this does not affect the ability to assign a compatible function to the field during normal use in Go. All such function types follow the specific naming convention:

```
llgo_<namespaces>_<typename>_<nested_field_typename>_<fieldname>
Copy link
Contributor

Choose a reason for hiding this comment

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

Although the design llgo_<namespaces>_<typename>_<nested_field_typename>_<fieldname> improves code readability to some extent, it compromises the original data structure. This is because the original code features a function pointer within a nested struct.

Copy link
Member Author

Choose a reason for hiding this comment

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

in llgo, when you refer a func type which is comment with llgo:type C,it is actual a pointer in data structure

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants