MCPcopy Index your code
hub / github.com/KhronosGroup/Vulkan-Docs / genProtectDirective

Function genProtectDirective

scripts/generator.py:53–90  ·  view source on GitHub ↗

Generate protection preprocessor directive. Protection strings are the strings defining the OS/Platform/Graphics requirements for a given API element. When generating the language header files, we need to make sure the items specific to a graphics API or OS platform are properly wra

(protect_str)

Source from the content-addressed store, hash-verified

51
52
53def genProtectDirective(protect_str):
54 """Generate protection preprocessor directive.
55
56 Protection strings are the strings defining the OS/Platform/Graphics
57 requirements for a given API element. When generating the
58 language header files, we need to make sure the items specific to a
59 graphics API or OS platform are properly wrapped in #ifs.
60
61 Supports boolean expressions using the same syntax as 'depends':
62 - '+' for AND
63 - ',' for OR
64 - '()' for grouping
65
66 Examples:
67 'VK_A,VK_B' -> '#if defined(VK_A) || defined(VK_B)'
68 'VK_A+VK_B' -> '#if defined(VK_A) && defined(VK_B)'
69 '(VK_A+VK_B),VK_C' -> '#if (defined(VK_A) && defined(VK_B)) || defined(VK_C)'
70
71 - protect_str - string with boolean expression of defines, or single define
72
73 Returns a tuple of (opening_directive, closing_directive) strings."""
74 if not protect_str:
75 return ('', '')
76
77 # Check if this is a boolean expression (contains operators, parens, or negation)
78 if any(c in protect_str for c in [',', '+', '(', ')', '!']):
79 # Use the dependency parser to handle complex expressions
80 from parse_dependency import protectLanguageC
81 try:
82 protect_condition = protectLanguageC(protect_str)
83 return (f'#if {protect_condition}', '#endif')
84 except Exception:
85 # Fall back to simple #ifdef if parsing fails
86 # (Silently fall back since this is a utility function without logging)
87 return (f'#ifdef {protect_str}', '#endif')
88 else:
89 # Simple single identifier - use #ifdef for backward compatibility
90 return (f'#ifdef {protect_str}', '#endif')
91
92
93def regSortFeatures(orderedFeatureNames, features):

Callers 3

genProtectStringMethod · 0.90
buildEnumCDecl_EnumMethod · 0.85

Calls 1

protectLanguageCFunction · 0.90

Tested by

no test coverage detected