From 7a132ba4df38473423a2e1c0d212df2134bebc77 Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Mon, 29 Nov 2021 22:16:33 -0700 Subject: vulkaninfo: Use enum names in switches Replace numeric values with the textual version, this makes it easier to read the code and verify that it is correct. --- scripts/vulkaninfo_generator.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/vulkaninfo_generator.py b/scripts/vulkaninfo_generator.py index 44eb238a..50bfcfb0 100644 --- a/scripts/vulkaninfo_generator.py +++ b/scripts/vulkaninfo_generator.py @@ -408,7 +408,7 @@ def PrintEnumToString(enum, gen): out += f"std::string {enum.name}String({enum.name} value) {{\n" out += f" switch (value) {{\n" for v in enum.options: - out += f" case ({str(v.value)}): return \"{v.name[3:]}\";\n" + out += f" case ({v.name}): return \"{v.name[3:]}\";\n" out += f" default: return std::string(\"UNKNOWN_{enum.name}_value\") + std::to_string(value);\n" out += f" }}\n}}\n" out += AddGuardFooter(GetExtension(enum.name, gen)) @@ -434,8 +434,7 @@ def PrintGetFlagStrings(name, bitmask): out += f" std::vector strings;\n" out += f" if (value == 0) {{ strings.push_back(\"None\"); return strings; }}\n" for v in bitmask.options: - val = v.value if isinstance(v.value, str) else str(hex(v.value)) - out += f" if ({val} & value) strings.push_back(\"{str(v.name[3:])}\");\n" + out += f" if ({v.name} & value) strings.push_back(\"{str(v.name[3:])}\");\n" out += f" return strings;\n}}\n" return out @@ -482,7 +481,7 @@ def PrintBitMaskToString(bitmask, name, gen): out += f" std::string out;\n" out += f" bool is_first = true;\n" for v in bitmask.options: - out += f" if ({str(v.value)} & value) {{\n" + out += f" if ({v.name} & value) {{\n" out += f" if (is_first) {{ is_first = false; }} else {{ out += \" | \"; }}\n" out += f" out += \"{str(v.name).strip('VK_').strip('_BIT')}\";\n" out += f" }}\n" -- cgit v1.2.3