MCPcopy
hub / github.com/KhronosGroup/Vulkan-Docs / buildEnumCDecl

Method buildEnumCDecl

scripts/generator.py:633–682  ·  view source on GitHub ↗

Generate the C declaration for an enum

(self, expand, groupinfo, groupName)

Source from the content-addressed store, hash-verified

631 exit(1)
632
633 def buildEnumCDecl(self, expand, groupinfo, groupName):
634 """Generate the C declaration for an enum"""
635 if self.genOpts is None:
636 raise MissingGeneratorOptionsError()
637 if self.genOpts.conventions is None:
638 raise MissingGeneratorOptionsConventionsError()
639
640 groupElem = groupinfo.elem
641
642 # Determine the required bit width for the enum group.
643 # 32 is the default, which generates C enum types for the values.
644 bitwidth = 32
645
646 # If the constFlagBits preference is set, 64 is the default for bitmasks
647 if self.genOpts.conventions.constFlagBits and groupElem.get('type') == 'bitmask':
648 bitwidth = 64
649
650 # Check for an explicitly defined bitwidth, which will override any defaults.
651 if groupElem.get('bitwidth'):
652 try:
653 bitwidth = int(groupElem.get('bitwidth'))
654 except ValueError as ve:
655 self.logMsg('error', 'Invalid value for bitwidth attribute (', groupElem.get('bitwidth'), ') for ', groupName, ' - must be an integer value\n')
656 exit(1)
657
658 usebitmask = False
659 usedefine = False
660
661 # Bitmask flags can be generated as either "static const uint{32,64}_t" values,
662 # or as 32-bit C enums. 64-bit types must use uint64_t values.
663 if groupElem.get('type') == 'bitmask':
664 if bitwidth > 32 or self.misracppstyle():
665 usebitmask = True
666 if self.misracstyle():
667 usedefine = True
668
669 if usedefine or usebitmask:
670 # Validate the bitwidth and generate values appropriately
671 if bitwidth > 64:
672 self.logMsg('error', 'Invalid value for bitwidth attribute (', groupElem.get('bitwidth'), ') for bitmask type ', groupName, ' - must be less than or equal to 64\n')
673 exit(1)
674 else:
675 return self.buildEnumCDecl_BitmaskOrDefine(groupinfo, groupName, bitwidth, usedefine)
676 else:
677 # Validate the bitwidth and generate values appropriately
678 if bitwidth > 32:
679 self.logMsg('error', 'Invalid value for bitwidth attribute (', groupElem.get('bitwidth'), ') for enum type ', groupName, ' - must be less than or equal to 32\n')
680 exit(1)
681 else:
682 return self.buildEnumCDecl_Enum(expand, groupinfo, groupName)
683
684 def buildEnumCDecl_BitmaskOrDefine(self, groupinfo, groupName, bitwidth, usedefine):
685 """Generate the C declaration for an "enum" that is actually a

Callers 2

genGroupMethod · 0.80
genGroupMethod · 0.80

Calls 8

logMsgMethod · 0.95
misracppstyleMethod · 0.95
misracstyleMethod · 0.95
buildEnumCDecl_EnumMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected