mirror of
https://github.com/KhronosGroup/Vulkan-Utility-Libraries.git
synced 2025-05-15 01:08:39 +00:00
tests: Ensure vk_enum_string_helper.h is C compatible
Added ifdef checks for backcompat Intended to properly address these issue(s): - https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/3233 - https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/1211
This commit is contained in:
parent
d05c872b51
commit
02d552db0c
6 changed files with 505 additions and 427 deletions
|
@ -27,7 +27,9 @@ class EnumStringHelperOutputGenerator(BaseGenerator):
|
|||
|
||||
out.append('''
|
||||
#pragma once
|
||||
#ifdef __cplusplus
|
||||
#include <string>
|
||||
#endif
|
||||
#include <vulkan/vulkan.h>
|
||||
''')
|
||||
|
||||
|
@ -53,17 +55,33 @@ class EnumStringHelperOutputGenerator(BaseGenerator):
|
|||
# If there are no flags (empty bitmask) ignore
|
||||
for bitmask in [x for x in self.vk.bitmasks.values() if len(x.flags) > 0]:
|
||||
groupType = bitmask.name if bitmask.bitWidth == 32 else 'uint64_t'
|
||||
|
||||
# switch labels must be constant expressions. In C a const-qualified variable is not a constant expression.
|
||||
use_switch_statement = True
|
||||
if groupType == 'uint64_t':
|
||||
use_switch_statement = False
|
||||
|
||||
out.extend([f'#ifdef {bitmask.protect}\n'] if bitmask.protect else [])
|
||||
out.append(f'static inline const char* string_{bitmask.name}({groupType} input_value) {{\n')
|
||||
out.append(' switch (input_value) {\n')
|
||||
for flag in [x for x in bitmask.flags if not x.multiBit]:
|
||||
out.extend([f'#ifdef {flag.protect}\n'] if flag.protect else [])
|
||||
out.append(f' case {flag.name}:\n')
|
||||
out.append(f' return "{flag.name}";\n')
|
||||
out.extend([f'#endif //{flag.protect}\n'] if flag.protect else [])
|
||||
out.append(' default:\n')
|
||||
out.append(f' return "Unhandled {bitmask.name}";\n')
|
||||
out.append(' }\n')
|
||||
|
||||
if use_switch_statement:
|
||||
out.append(' switch (input_value) {\n')
|
||||
for flag in [x for x in bitmask.flags if not x.multiBit]:
|
||||
out.extend([f'#ifdef {flag.protect}\n'] if flag.protect else [])
|
||||
out.append(f' case {flag.name}:\n')
|
||||
out.append(f' return "{flag.name}";\n')
|
||||
out.extend([f'#endif //{flag.protect}\n'] if flag.protect else [])
|
||||
out.append(' default:\n')
|
||||
out.append(f' return "Unhandled {bitmask.name}";\n')
|
||||
out.append(' }\n')
|
||||
else:
|
||||
# We need to use if statements
|
||||
for flag in [x for x in bitmask.flags if not x.multiBit]:
|
||||
out.extend([f'#ifdef {flag.protect}\n'] if flag.protect else [])
|
||||
out.append(f' if (input_value == {flag.name}) return "{flag.name}";\n')
|
||||
out.extend([f'#endif //{flag.protect}\n'] if flag.protect else [])
|
||||
out.append(f' return "Unhandled {bitmask.name}";\n')
|
||||
|
||||
out.append('}\n')
|
||||
|
||||
mulitBitChecks = ''
|
||||
|
@ -71,6 +89,7 @@ class EnumStringHelperOutputGenerator(BaseGenerator):
|
|||
mulitBitChecks += f' if (input_value == {flag.name}) {{ return "{flag.name}"; }}\n'
|
||||
intSuffix = 'U' if bitmask.bitWidth == 32 else 'ULL'
|
||||
|
||||
out.append('\n#ifdef __cplusplus')
|
||||
out.append(f'''
|
||||
static inline std::string string_{bitmask.flagName}({bitmask.flagName} input_value) {{
|
||||
{mulitBitChecks} std::string ret;
|
||||
|
@ -87,6 +106,7 @@ static inline std::string string_{bitmask.flagName}({bitmask.flagName} input_val
|
|||
return ret;
|
||||
}}\n''')
|
||||
out.extend([f'#endif //{bitmask.protect}\n'] if bitmask.protect else [])
|
||||
out.append('#endif // __cplusplus\n')
|
||||
|
||||
out.append('// NOLINTEND') # Wrap for clang-tidy to ignore
|
||||
self.write("".join(out))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue