Generate protection string. Protection strings are the strings defining the OS/Platform/Graphics requirements for a given API command. When generating the language header files, we need to make sure the items specific to a graphics API or OS platform are properly wr
(self, protect_str)
| 378 | self.appendSection(section, body) |
| 379 | |
| 380 | def genProtectString(self, protect_str): |
| 381 | """Generate protection string. |
| 382 | |
| 383 | Protection strings are the strings defining the OS/Platform/Graphics |
| 384 | requirements for a given API command. When generating the |
| 385 | language header files, we need to make sure the items specific to a |
| 386 | graphics API or OS platform are properly wrapped in #ifs. |
| 387 | |
| 388 | Supports boolean expressions using the same syntax as 'depends': |
| 389 | - '+' for AND |
| 390 | - ',' for OR |
| 391 | - '()' for grouping |
| 392 | |
| 393 | Examples: |
| 394 | 'VK_A,VK_B' -> '#if defined(VK_A) || defined(VK_B)' |
| 395 | 'VK_A+VK_B' -> '#if defined(VK_A) && defined(VK_B)' |
| 396 | '(VK_A+VK_B),VK_C' -> '#if (defined(VK_A) && defined(VK_B)) || defined(VK_C)' |
| 397 | """ |
| 398 | if not protect_str: |
| 399 | return ('', '') |
| 400 | |
| 401 | # Use the common genProtectDirective function from generator.py |
| 402 | from generator import genProtectDirective |
| 403 | |
| 404 | try: |
| 405 | (protect_if, protect_end) = genProtectDirective(protect_str) |
| 406 | except Exception as e: |
| 407 | # Log warning and fall back to simple #ifdef if parsing fails |
| 408 | self.logMsg('warn', f'Failed to parse protect expression "{protect_str}": {e}') |
| 409 | protect_if = f'#ifdef {protect_str}' |
| 410 | protect_end = '#endif' |
| 411 | |
| 412 | # Add newlines and comments for the C generator |
| 413 | # Extract the condition from the protect_if for the comment |
| 414 | if protect_if.startswith('#if '): |
| 415 | # Complex expression - extract condition after '#if ' |
| 416 | condition = protect_if[4:].strip() |
| 417 | protect_if_str = f'{protect_if}\n' |
| 418 | protect_end_str = f'#endif // {condition}\n' |
| 419 | else: |
| 420 | # Simple #ifdef - use original protect_str in comment |
| 421 | protect_if_str = f'{protect_if}\n' |
| 422 | protect_end_str = f'#endif // {protect_str}\n' |
| 423 | |
| 424 | return (protect_if_str, protect_end_str) |
| 425 | |
| 426 | def typeMayAlias(self, typeName): |
| 427 | if not self.may_alias: |
no test coverage detected