You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
generate-accessors: switch annotations to // comment style
Replace the /*!annotation*/ block-comment style with // line comments
throughout. The canonical form is '// !token' (one space between // and
!). The parser accepts any amount of whitespace between // and !, so
'//!token', '// !token', and '//\t!token' are all equivalent. This
makes the annotation resilient to contributor variation.
Update all annotated structs in private.h and private-fabrics.h, and
update the documentation and helper scripts accordingly. The generated
accessors.{h,c} and accessors-fabrics.{h,c} are unchanged.
Signed-off-by: Martin Belanger <[email protected]>
Struct inclusion and member behaviour are controlled by **annotations written as comments directly in the header file**. Both `/* */` (block) and `//` (line) comment styles are supported for every annotation.
28
+
Struct inclusion and member behaviour are controlled by **annotations written as
29
+
`//` comments directly in the header file**. The canonical form is `// !token`
30
+
(one space between `//` and `!`). The parser also accepts `//!token` and
31
+
`//\t!token` — any amount of whitespace between `//` and `!` is treated
32
+
identically, making the annotation resilient to contributor variation.
29
33
30
34
### Struct inclusion — `generate-accessors`
31
35
32
36
Place the annotation on the same line as the struct's opening brace to opt that struct in to code generation. An optional mode qualifier sets the **default behaviour for all members** of that struct:
Place the annotation on a member's declaration line to generate only a getter (no setter). This has the same effect as declaring the member `const`, but without changing the type in the struct. Also useful to override a `generate-accessors:writeonly` struct default for individual members:
70
74
71
75
```c
72
-
struct nvme_ctrl { /*!generate-accessors*/
76
+
struct nvme_ctrl { // !generate-accessors
73
77
char *name;
74
-
char *firmware; //!accessors:readonly
75
-
char *model; /*!accessors:readonly*/
78
+
char *firmware; //!accessors:readonly
79
+
char *model; // !accessors:readonly
76
80
};
77
81
```
78
82
@@ -83,9 +87,9 @@ Members declared with the `const` qualifier are also automatically read-only.
83
87
Place the annotation on a member's declaration line to generate only a setter (no getter). Useful to override a `generate-accessors:readonly` struct default for individual members:
Place the annotation on a member's declaration line to generate both a getter and a setter, overriding a restrictive struct-level default (`none`, `readonly`, or `writeonly`):
95
99
96
100
```c
97
-
struct nvme_ctrl { /*!generate-accessors:none*/
101
+
struct nvme_ctrl { // !generate-accessors:none
98
102
char *name; /* no accessors (struct default) */
99
-
char *model; //!accessors:readwrite /* both getter and setter */
100
-
char *firmware; //!accessors:readonly /* getter only */
103
+
char *model; //!accessors:readwrite /* both getter and setter */
104
+
char *firmware; //!accessors:readonly /* getter only */
@@ -258,7 +262,7 @@ const char *car_get_vin(const struct car *p);
258
262
#endif/* _ACCESSORS_H_ */
259
263
```
260
264
261
-
> **Note:** The `secret` member is absent because of `//!accessors:none` — excluded members leave no trace in the output. The `role` member has only a getter because of `//!accessors:readonly`. The `id` and `vin` members have only getters because they are declared `const`.
265
+
> **Note:** The `secret` member is absent because of `//!accessors:none` — excluded members leave no trace in the output. The `role` member has only a getter because of `//!accessors:readonly`. The `id` and `vin` members have only getters because they are declared `const`.
262
266
263
267
### Generated `accessors.c`
264
268
@@ -361,7 +365,7 @@ LIBNVME_ACCESSORS_3 {
361
365
};
362
366
```
363
367
364
-
> **Note:** Only symbols for members that have accessors generated appear in the linker script. The `secret` member (excluded via `//!accessors:none`) and the write-only `token` example would have no getter entry. The version node name `LIBNVME_ACCESSORS_3` is hardcoded in the generator.
368
+
> **Note:** Only symbols for members that have accessors generated appear in the linker script. The `secret` member (excluded via `//!accessors:none`) and the write-only `token` example would have no getter entry. The version node name `LIBNVME_ACCESSORS_3` is hardcoded in the generator.
365
369
366
370
------
367
371
@@ -379,10 +383,10 @@ LIBNVME_ACCESSORS_3 {
379
383
2. **String arrays** (`char **`) — setters deep-copy NULL-terminated arrays (each element and the container).
4. **`const` members** — only a getter is generated, no setter (applies regardless of any annotation).
382
-
5. **`//!accessors:readonly`** — same effect as `const`: getter only.
383
-
6. **`//!accessors:writeonly`** — setter only; getter is suppressed.
384
-
7. **`//!accessors:readwrite`** — both getter and setter; overrides a restrictive struct-level default.
385
-
8. **`//!accessors:none`** — member is completely ignored by the generator.
386
+
5. **`//!accessors:readonly`** — same effect as `const`: getter only.
387
+
6. **`//!accessors:writeonly`** — setter only; getter is suppressed.
388
+
7. **`//!accessors:readwrite`** — both getter and setter; overrides a restrictive struct-level default.
389
+
8. **`//!accessors:none`** — member is completely ignored by the generator.
386
390
9. **Struct-level mode** — the qualifier on `generate-accessors` sets the default for every member in the struct; per-member annotations override the struct default.
387
391
10. **`--prefix`** — prepended to every function name (e.g. `--prefix nvme_` turns `ctrl_set_name` into `nvme_ctrl_set_name`).
388
392
11. **Line length** — generated code is automatically wrapped to stay within the 80-column limit required by `checkpatch.pl`.
0 commit comments