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

Method enumToValue

scripts/generator.py:434–531  ·  view source on GitHub ↗

Parse and convert an ` ` tag into a value. - elem - Element - needsNum - generate a numeric representation of the element value - bitwidth - size of the numeric representation in bits (32 or 64) - forceSuffix - if True, always use a 'U' / 'ULL' suffix on

(self, elem, needsNum, bitwidth = 32,
                    forceSuffix = False, parent_for_alias_dereference=None)

Source from the content-addressed store, hash-verified

432 f"*** FATAL ERROR in Generator.logMsg: unknown level:{level}")
433
434 def enumToValue(self, elem, needsNum, bitwidth = 32,
435 forceSuffix = False, parent_for_alias_dereference=None):
436 """Parse and convert an `<enum>` tag into a value.
437
438 - elem - <enum> Element
439 - needsNum - generate a numeric representation of the element value
440 - bitwidth - size of the numeric representation in bits (32 or 64)
441 - forceSuffix - if True, always use a 'U' / 'ULL' suffix on integers
442 - parent_for_alias_dereference - if not None, an Element containing
443 the parent of elem, used to look for elements this is an alias of
444
445 Returns a list:
446
447 - first element - integer representation of the value, or None
448 if needsNum is False. The value must be a legal number
449 if needsNum is True.
450 - second element - string representation of the value
451
452 There are several possible representations of values.
453
454 - A 'value' attribute simply contains the value.
455 - A 'bitpos' attribute defines a value by specifying the bit
456 position which is set in that value.
457 - An 'offset','extbase','extends' triplet specifies a value
458 as an offset to a base value defined by the specified
459 'extbase' extension name, which is then cast to the
460 typename specified by 'extends'. This requires probing
461 the registry database, and imbeds knowledge of the
462 API extension enum scheme in this function.
463 - An 'alias' attribute contains the name of another enum
464 which this is an alias of. The other enum must be
465 declared first when emitting this enum."""
466 if self.genOpts is None:
467 raise MissingGeneratorOptionsError()
468 if self.genOpts.conventions is None:
469 raise MissingGeneratorOptionsConventionsError()
470
471 name = elem.get('name')
472 numVal = None
473 if 'value' in elem.keys():
474 value = elem.get('value')
475 # print('About to translate value =', value, 'type =', type(value))
476 if needsNum:
477 numVal = int(value, 0)
478 # If there is a non-integer, numeric 'type' attribute (e.g. 'u' or
479 # 'ull'), append it to the string value.
480 # t = enuminfo.elem.get('type')
481 # if t is not None and t != '' and t != 'i' and t != 's':
482 # value += enuminfo.type
483 if forceSuffix:
484 if bitwidth == 64:
485 value = f"{value}ULL"
486 else:
487 value = f"{value}U"
488 self.logMsg('diag', 'Enum', name, '-> value [', numVal, ',', value, ']')
489 return [numVal, value]
490 if 'bitpos' in elem.keys():
491 value = elem.get('bitpos')

Callers 6

checkDuplicateEnumsMethod · 0.95
buildEnumCDecl_EnumMethod · 0.95
buildConstantCDeclMethod · 0.95
genEnumTableMethod · 0.80
genGroupMethod · 0.80

Calls 5

logMsgMethod · 0.95
keysMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected