mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-10-31 22:25:25 -04:00
scanner: fix validator for bitfields
Bitfields are valid if the value only contains bits inside of the supported entries for the given version. Signed-off-by: Simon Ser <contact@emersion.fr>
This commit is contained in:
parent
caaa308c0d
commit
c669d99259
2 changed files with 73 additions and 70 deletions
|
|
@ -1391,22 +1391,35 @@ emit_validator(struct interface *interface, struct enumeration *e)
|
|||
" * @ref %s_%s\n"
|
||||
" */\n"
|
||||
"static inline bool\n"
|
||||
"%s_%s_is_valid(uint32_t value, uint32_t version) {\n"
|
||||
" switch (value) {\n",
|
||||
"%s_%s_is_valid(uint32_t value, uint32_t version) {\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);
|
||||
|
||||
if (e->bitfield) {
|
||||
printf(" uint32_t valid = 0;\n");
|
||||
wl_list_for_each(entry, &e->entry_list, link) {
|
||||
printf(" if (version >= %d)\n"
|
||||
" valid |= %s_%s_%s;\n",
|
||||
entry->since,
|
||||
interface->uppercase_name, e->uppercase_name,
|
||||
entry->uppercase_name);
|
||||
}
|
||||
printf(" return (value & ~valid) == 0;\n");
|
||||
} else {
|
||||
printf(" switch (value) {\n");
|
||||
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");
|
||||
}
|
||||
printf(" default:\n"
|
||||
" return false;\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
printf("}\n");
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue