Skip to content

Commit 2467df6

Browse files
committed
docs(design):named fntype for nest anonymous field
1 parent 0fbca18 commit 2467df6

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

doc/en/dev/llcppg.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Due to the characteristics of LLGo, an anonymous function type cannot be directl
9999

100100
For anonymous function pointer types, llgo will build a public function type for them and reference it,and ensure that the anonymous type is unique, the naming rule for the corresponding type will be:
101101
```
102-
LLGO_<namespace>_<typename>_<fieldname>
102+
LLGO_<namespaces>_<typename>_<nested_field_typename>_<fieldname>
103103
```
104104

105105
```c
@@ -120,6 +120,51 @@ type Hooks struct {
120120
}
121121
```
122122

123+
with namespace
124+
125+
```c
126+
namespace A {
127+
struct Hooks {
128+
void *(*malloc_fn)(size_t sz);
129+
void (*free_fn)(void *ptr);
130+
} Hooks;
131+
}
132+
```
133+
```go
134+
// llgo:type C
135+
type LLGO_A_Hooks_MallocFn func(c.SizeT) c.Pointer
136+
// llgo:type C
137+
type LLGO_A_Hooks_FreeFn func(c.Pointer)
138+
139+
type Hooks struct {
140+
MallocFn LLGO_A_Hooks_MallocFn
141+
FreeFn LLGO_A_Hooks_FreeFn
142+
}
143+
```
144+
with nested struct's function pointer
145+
```c
146+
struct Foo {
147+
struct {
148+
void *(*malloc_fn)(size_t sz);
149+
void (*free_fn)(void *ptr);
150+
} Hooks;
151+
};
152+
```
153+
```go
154+
// llgo:type C
155+
type LLGO_Foo_Hooks_MallocFn func(c.SizeT) c.Pointer
156+
157+
// llgo:type C
158+
type LLGO_Foo_Hooks_FreeFn func(c.Pointer)
159+
160+
type Foo struct {
161+
Hooks struct {
162+
MallocFn LLGO_Foo_Hooks_MallocFn
163+
FreeFn LLGO_Foo_Hooks_FreeFn
164+
}
165+
}
166+
```
167+
123168
##### Array
124169

125170
Arrays in C are mapped differently depending on their context - function parameters versus struct fields.

0 commit comments

Comments
 (0)