original_docstring: Generate the C declaration for an enumerated type
docstring: Generate the C declaration for an enumerated type
docstring_tokens: Generate the C declaration for an enumerated type
code: def buildEnumCDecl_Enum(self, expand, groupinfo, groupName):
          """Generate the C declaration for an enumerated type"""
          groupElem = groupinfo.elem
  
          # Break the group name into prefix and suffix portions for range
          # enum generation
          expandName = re.sub(r'([0-9]+|[a-z_])([A-Z0-9])', r'\1_\2', groupName).upper()
          expandPrefix = expandName
          expandSuffix = ''
          expandSuffixMatch = re.search(r'[A-Z][A-Z]+$', groupName)
          if expandSuffixMatch:
              expandSuffix = '_' + expandSuffixMatch.group()
              # Strip off the suffix from the prefix
              expandPrefix = expandName.rsplit(expandSuffix, 1)[0]
  
          # Prefix
          body = ["typedef enum %s {" % groupName]
  
          # @@ Should use the type="bitmask" attribute instead
          isEnum = ('FLAG_BITS' not in expandPrefix)
  
          # Allowable range for a C enum - which is that of a signed 32-bit integer
          maxValidValue = 2**(32 - 1) - 1
          minValidValue = (maxValidValue * -1) - 1
  
  
          # Get a list of nested 'enum' tags.
          enums = groupElem.findall('enum')
  
          # Check for and report duplicates, and return a list with them
          # removed.
          enums = self.checkDuplicateEnums(enums)
  
          # Loop over the nested 'enum' tags. Keep track of the minimum and
          # maximum numeric values, if they can be determined; but only for
          # core API enumerants, not extension enumerants. This is inferred
          # by looking for 'extends' attributes.
          minName = None
  
          # Accumulate non-numeric enumerant values separately and append
          # them following the numeric values, to allow for aliases.
          # NOTE: this doesn't do a topological sort yet, so aliases of
          # aliases can still get in the wrong order.
          aliasText = []
  
          for elem in enums:
              # Convert the value to an integer and use that to track min/max.
              # Values of form -(number) are accepted but nothing more complex.
              # Should catch exceptions here for more complex constructs. Not yet.
              (numVal, strVal) = self.enumToValue(elem, True)
              name = elem.get('name')
  
              # Extension enumerants are only included if they are required
              if self.isEnumRequired(elem):
                  decl = ''
  
                  protect = elem.get('protect')
                  if protect is not None:
                      decl += '#ifdef {}\n'.format(protect)
  
                  # Indent requirements comment, if there is one
                  requirements = self.genRequirements(name, mustBeFound = False)
                  if requirements != '':
                      requirements = '  ' + requirements
                  decl += requirements
                  decl += '    {} = {},'.format(name, strVal)
  
                  if protect is not None:
                      decl += '\n#endif'
  
                  if numVal is not None:
                      body.append(decl)
                  else:
                      aliasText.append(decl)
  
              # Range check for the enum value
              if numVal is not None and (numVal > maxValidValue or numVal < minValidValue):
                  self.logMsg('error', 'Allowable range for C enum types is [', minValidValue, ',', maxValidValue, '], but', name, 'has a value outside of this (', strVal, ')\n')
                  exit(1)
  
              # Don't track min/max for non-numbers (numVal is None)
              if isEnum and numVal is not None and elem.get('extends') is None:
                  if minName is None:
                      minName = maxName = name
                      minValue = maxValue = numVal
                  elif numVal < minValue:
                      minName = name
                      minValue = numVal
                  elif numVal > maxValue:
                      maxName = name
                      maxValue = numVal
  
          # Now append the non-numeric enumerant values
          body.extend(aliasText)
  
          # Generate min/max value tokens - legacy use case.
          if isEnum and expand:
              body.extend(("    {}_BEGIN_RANGE{} = {},".format(expandPrefix, expandSuffix, minName),
                           "    {}_END_RANGE{} = {},".format(
                               expandPrefix, expandSuffix, maxName),
                           "    {}_RANGE_SIZE{} = ({} - {} + 1),".format(expandPrefix, expandSuffix, maxName, minName)))
  
          # Generate a range-padding value to ensure the enum is 32 bits, but
          # only in code generators, so it doesn't appear in documentation
          if (self.genOpts.codeGenerator or
              self.conventions.generate_max_enum_in_docs):
              body.append("    {}_MAX_ENUM{} = 0x7FFFFFFF".format(
                  expandPrefix, expandSuffix))
  
          # Postfix
          body.append("} %s;" % groupName)
  
          # Determine appropriate section for this declaration
          if groupElem.get('type') == 'bitmask':
              section = 'bitmask'
          else:
              section = 'group'
  
          return (section, '\n'.join(body))
code_tokens: def buildEnumCDecl_Enum ( self , expand , groupinfo , groupName ) : groupElem = groupinfo . elem expandName = re . sub ( r'([0-9]+|[a-z_])([A-Z0-9])' , r'\1_\2' , groupName ) . upper ( ) expandPrefix = expandName expandSuffix = '' expandSuffixMatch = re . search ( r'[A-Z][A-Z]+$' , groupName ) if expandSuffixMatch : expandSuffix = '_' + expandSuffixMatch . group ( ) expandPrefix = expandName . rsplit ( expandSuffix , 1 ) [ 0 ] body = [ "typedef enum %s {" % groupName ] isEnum = ( 'FLAG_BITS' not in expandPrefix ) maxValidValue = 2 ** ( 32 - 1 ) - 1 minValidValue = ( maxValidValue * - 1 ) - 1 enums = groupElem . findall ( 'enum' ) enums = self . checkDuplicateEnums ( enums ) minName = None aliasText = [ ] for elem in enums : ( numVal , strVal ) = self . enumToValue ( elem , True ) name = elem . get ( 'name' ) if self . isEnumRequired ( elem ) : decl = '' protect = elem . get ( 'protect' ) if protect is not None : decl += '#ifdef {}\n' . format ( protect ) requirements = self . genRequirements ( name , mustBeFound = False ) if requirements != '' : requirements = '  ' + requirements decl += requirements decl += '    {} = {},' . format ( name , strVal ) if protect is not None : decl += '\n#endif' if numVal is not None : body . append ( decl ) else : aliasText . append ( decl ) if numVal is not None and ( numVal > maxValidValue or numVal < minValidValue ) : self . logMsg ( 'error' , 'Allowable range for C enum types is [' , minValidValue , ',' , maxValidValue , '], but' , name , 'has a value outside of this (' , strVal , ')\n' ) exit ( 1 ) if isEnum and numVal is not None and elem . get ( 'extends' ) is None : if minName is None : minName = maxName = name minValue = maxValue = numVal elif numVal < minValue : minName = name minValue = numVal elif numVal > maxValue : maxName = name maxValue = numVal body . extend ( aliasText ) if isEnum and expand : body . extend ( ( "    {}_BEGIN_RANGE{} = {}," . format ( expandPrefix , expandSuffix , minName ) , "    {}_END_RANGE{} = {}," . format ( expandPrefix , expandSuffix , maxName ) , "    {}_RANGE_SIZE{} = ({} - {} + 1)," . format ( expandPrefix , expandSuffix , maxName , minName ) ) ) if ( self . genOpts . codeGenerator or self . conventions . generate_max_enum_in_docs ) : body . append ( "    {}_MAX_ENUM{} = 0x7FFFFFFF" . format ( expandPrefix , expandSuffix ) ) body . append ( "} %s;" % groupName ) if groupElem . get ( 'type' ) == 'bitmask' : section = 'bitmask' else : section = 'group' return ( section , '\n' . join ( body ) )
short_docstring: Generate the C declaration for an enumerated type
short_docstring_tokens: Generate the C declaration for an enumerated type
comment: """Generate the C declaration for an enumerated type"""$SEP$# Break the group name into prefix and suffix portions for range$SEP$# enum generation$SEP$# Strip off the suffix from the prefix$SEP$# Prefix$SEP$# @@ Should use the type="bitmask" attribute instead$SEP$# Allowable range for a C enum - which is that of a signed 32-bit integer$SEP$# Get a list of nested 'enum' tags.$SEP$# Check for and report duplicates, and return a list with them$SEP$# removed.$SEP$# Loop over the nested 'enum' tags. Keep track of the minimum and$SEP$# maximum numeric values, if they can be determined; but only for$SEP$# core API enumerants, not extension enumerants. This is inferred$SEP$# by looking for 'extends' attributes.$SEP$# Accumulate non-numeric enumerant values separately and append$SEP$# them following the numeric values, to allow for aliases.$SEP$# NOTE: this doesn't do a topological sort yet, so aliases of$SEP$# aliases can still get in the wrong order.$SEP$# Convert the value to an integer and use that to track min/max.$SEP$# Values of form -(number) are accepted but nothing more complex.$SEP$# Should catch exceptions here for more complex constructs. Not yet.$SEP$# Extension enumerants are only included if they are required$SEP$# Indent requirements comment, if there is one$SEP$# Range check for the enum value$SEP$# Don't track min/max for non-numbers (numVal is None)$SEP$# Now append the non-numeric enumerant values$SEP$# Generate min/max value tokens - legacy use case.$SEP$# Generate a range-padding value to ensure the enum is 32 bits, but$SEP$# only in code generators, so it doesn't appear in documentation$SEP$# Postfix$SEP$# Determine appropriate section for this declaration