mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2026-03-30 11:11:05 -04:00
scanner: extract validator function emission to helper function
This function will grow in the next commit.
Signed-off-by: Simon Ser <contact@emersion.fr>
(cherry picked from commit caaa308c0d)
This commit is contained in:
parent
a156431ea6
commit
2b8f9401ee
1 changed files with 33 additions and 26 deletions
|
|
@ -1378,6 +1378,37 @@ emit_event_wrappers(struct wl_list *message_list, struct interface *interface)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
emit_validator(struct interface *interface, struct enumeration *e)
|
||||||
|
{
|
||||||
|
struct entry *entry;
|
||||||
|
|
||||||
|
printf("/**\n"
|
||||||
|
" * @ingroup iface_%s\n"
|
||||||
|
" * Validate a %s %s value.\n"
|
||||||
|
" *\n"
|
||||||
|
" * @return true on success, false on error.\n"
|
||||||
|
" * @ref %s_%s\n"
|
||||||
|
" */\n"
|
||||||
|
"static inline bool\n"
|
||||||
|
"%s_%s_is_valid(uint32_t value, uint32_t version) {\n"
|
||||||
|
" switch (value) {\n",
|
||||||
|
interface->name, interface->name, e->name,
|
||||||
|
interface->name, e->name,
|
||||||
|
interface->name, e->name);
|
||||||
|
wl_list_for_each(entry, &e->entry_list, link) {
|
||||||
|
printf(" case %s%s_%s_%s:\n"
|
||||||
|
" return version >= %d;\n",
|
||||||
|
entry->value[0] == '-' ? "(uint32_t)" : "",
|
||||||
|
interface->uppercase_name, e->uppercase_name,
|
||||||
|
entry->uppercase_name, entry->since);
|
||||||
|
}
|
||||||
|
printf(" default:\n"
|
||||||
|
" return false;\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n");
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
emit_enumerations(struct interface *interface, bool with_validators)
|
emit_enumerations(struct interface *interface, bool with_validators)
|
||||||
{
|
{
|
||||||
|
|
@ -1439,32 +1470,8 @@ emit_enumerations(struct interface *interface, bool with_validators)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (with_validators) {
|
if (with_validators)
|
||||||
printf("/**\n"
|
emit_validator(interface, e);
|
||||||
" * @ingroup iface_%s\n"
|
|
||||||
" * Validate a %s %s value.\n"
|
|
||||||
" *\n"
|
|
||||||
" * @return true on success, false on error.\n"
|
|
||||||
" * @ref %s_%s\n"
|
|
||||||
" */\n"
|
|
||||||
"static inline bool\n"
|
|
||||||
"%s_%s_is_valid(uint32_t value, uint32_t version) {\n"
|
|
||||||
" switch (value) {\n",
|
|
||||||
interface->name, interface->name, e->name,
|
|
||||||
interface->name, e->name,
|
|
||||||
interface->name, e->name);
|
|
||||||
wl_list_for_each(entry, &e->entry_list, link) {
|
|
||||||
printf(" case %s%s_%s_%s:\n"
|
|
||||||
" return version >= %d;\n",
|
|
||||||
entry->value[0] == '-' ? "(uint32_t)" : "",
|
|
||||||
interface->uppercase_name, e->uppercase_name,
|
|
||||||
entry->uppercase_name, entry->since);
|
|
||||||
}
|
|
||||||
printf(" default:\n"
|
|
||||||
" return false;\n"
|
|
||||||
" }\n"
|
|
||||||
"}\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("#endif /* %s_%s_ENUM */\n\n",
|
printf("#endif /* %s_%s_ENUM */\n\n",
|
||||||
interface->uppercase_name, e->uppercase_name);
|
interface->uppercase_name, e->uppercase_name);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue