shared/verbs: add _SCOPE variants of the verb macros
In some of the large programs, verbs are defined as non-static functions. To support this cases, add variants of the VERB macros that take an explicit scope parameter. The existing macros then call those new macros with scope=static. The variant without static is the exception, so the macros are "optimized" toward the static helpers. I also considered allowing VERB macros to be used in different files, i.e. in different compilation units. This would actually work without too many changes, except for one caveat: the order in the array would be unspecified, so we'd need to somehow order the verbs appropriately. This most likely means that the verbs would need to be annotated with a number. But that doesn't seem attractive at all: we'd need to coordinate changes in different files. So just listing the verbs in one file seems like least bad option.
This commit is contained in:
+14
-6
@@ -39,19 +39,27 @@ typedef struct {
|
||||
.help = h, \
|
||||
}
|
||||
|
||||
#define VERB_FULL(d, v, a, amin, amax, f, dat, h) \
|
||||
/* Forward-define function d. scope specifies the scope, e.g. static. */
|
||||
#define VERB_SCOPE_FULL(scope, d, v, a, amin, amax, f, dat, h) \
|
||||
DISABLE_WARNING_REDUNDANT_DECLS \
|
||||
static int d(int, char**, uintptr_t, void*); \
|
||||
scope int d(int, char**, uintptr_t, void*); \
|
||||
REENABLE_WARNING \
|
||||
_VERB_DATA(d, v, a, amin, amax, f, dat, h)
|
||||
/* The same as VERB_SCOPE_FULL with scope hardwired to 'static'. */
|
||||
#define VERB_FULL(d, v, a, amin, amax, f, dat, h) \
|
||||
VERB_SCOPE_FULL(static, d, v, a, amin, amax, f, dat, h)
|
||||
|
||||
/* The same as VERB_FULL, but without the data argument */
|
||||
/* The same as VERB_SCOPE_FULL/VERB_FULL, but without the data argument. */
|
||||
#define VERB_SCOPE(scope, d, v, a, amin, amax, f, h) \
|
||||
VERB_SCOPE_FULL(scope, d, v, a, amin, amax, f, /* dat= */ 0, h)
|
||||
#define VERB(d, v, a, amin, amax, f, h) \
|
||||
VERB_FULL(d, v, a, amin, amax, f, /* dat= */ 0, h)
|
||||
VERB_SCOPE(static, d, v, a, amin, amax, f, h)
|
||||
|
||||
/* Simplified VERB for parameters that take no argument */
|
||||
/* Simplified VERB_SCOPE/VERB for verbs that take no argument. */
|
||||
#define VERB_SCOPE_NOARG(scope, d, v, h) \
|
||||
VERB_SCOPE(scope, d, v, /* a= */ NULL, /* amin= */ VERB_ANY, /* amax= */ 1, /* f= */ 0, h)
|
||||
#define VERB_NOARG(d, v, h) \
|
||||
VERB(d, v, /* a= */ NULL, /* amin= */ VERB_ANY, /* amax= */ 1, /* f= */ 0, h)
|
||||
VERB_SCOPE_NOARG(static, d, v, h)
|
||||
|
||||
/* Magic entry in the table (which will not be returned) that designates the start of the group <gr>.
|
||||
* The macro works as a separator between groups and must be between other VERB* stanzas. */
|
||||
|
||||
Reference in New Issue
Block a user