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: extend struct annotation with default mode qualifier
Extend the !generate-accessors annotation so callers can set a
struct-level default for accessor generation:
struct foo { //!generate-accessors - both get+set (unchanged)
struct foo { //!generate-accessors:none - no accessors by default
struct foo { //!generate-accessors:readonly - getter only by default
struct foo { //!generate-accessors:writeonly - setter only by default
Add two new per-member annotations to complement the new struct-level
defaults when individual members need to override them:
//!accessors:writeonly - setter only for this member
//!accessors:readwrite - both getter and setter for this member
Internally, replace Member.is_const with explicit gen_getter/gen_setter
flags and add parse_struct_annotation() to extract the mode qualifier.
Update generate-accessors.md with the full annotation table.
Signed-off-by: Daniel Wagner <[email protected]>
Copy file name to clipboardExpand all lines: libnvme/tools/generator/generate-accessors.md
+54-19Lines changed: 54 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,22 +29,29 @@ Struct inclusion and member behaviour are controlled by **annotations written as
29
29
30
30
### Struct inclusion — `generate-accessors`
31
31
32
-
Place the annotation on the same line as the struct's opening brace to opt that struct in to code generation:
32
+
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:
69
+
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:
Members declared with the `const` qualifier are also automatically read-only.
73
80
81
+
### Write-only members — `accessors:writeonly`
82
+
83
+
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:
char *token; //!accessors:writeonly /* setter only override */
89
+
};
90
+
```
91
+
92
+
### Read-write members — `accessors:readwrite`
93
+
94
+
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
+
96
+
```c
97
+
struct nvme_ctrl { /*!generate-accessors:none*/
98
+
char *name; /* no accessors (struct default) */
99
+
char *model; //!accessors:readwrite /* both getter and setter */
100
+
char *firmware; //!accessors:readonly /* getter only */
3. **`const` members** — only a getter is generated, no setter.
300
+
3. **`const` members** — only a getter is generated, no setter (applies regardless of any annotation).
269
301
4. **`//!accessors:readonly`** — same effect as `const`: getter only.
270
-
5. **`//!accessors:none`** — member is completely ignored by the generator.
271
-
6. **`--prefix`** — prepended to every function name (e.g. `--prefix nvme_` turns `ctrl_set_name` into `nvme_ctrl_set_name`).
272
-
7. **Line length** — generated code is automatically wrapped to stay within the 80-column limit required by `checkpatch.pl`.
302
+
5. **`//!accessors:writeonly`** — setter only; getter is suppressed.
303
+
6. **`//!accessors:readwrite`** — both getter and setter; overrides a restrictive struct-level default.
304
+
7. **`//!accessors:none`** — member is completely ignored by the generator.
305
+
8. **Struct-level mode** — the qualifier on `generate-accessors` sets the default for every member in the struct; per-member annotations override the struct default.
306
+
9. **`--prefix`** — prepended to every function name (e.g. `--prefix nvme_` turns `ctrl_set_name` into `nvme_ctrl_set_name`).
307
+
10. **Line length** — generated code is automatically wrapped to stay within the 80-column limit required by `checkpatch.pl`.
0 commit comments