mojo/public/tools/mojom/mojom/generate/translate.py
def _ResolveNumericEnumValues(enum):
  """
  Given a reference to a mojom.Enum, resolves and assigns the numeric value of
  each field, and also computes the min_value and max_value of the enum.
  """

  # map of <mojom_name> -> integral value
  prev_value = -1
  min_value = None
  max_value = None
  for field in enum.fields:
    # This enum value is +1 the previous enum value (e.g: BEGIN).
    if field.value is None:
      prev_value += 1

    # Integral value (e.g: BEGIN = -0x1).
    elif _IsStrOrUnicode(field.value):
      prev_value = int(field.value, 0)

    # Reference to a previous enum value (e.g: INIT = BEGIN).
    elif isinstance(field.value, mojom.EnumValue):
      prev_value = field.value.field.numeric_value
    elif isinstance(field.value, mojom.ConstantValue):
      constant = field.value.constant
      kind = constant.kind
      if not mojom.IsIntegralKind(kind) or mojom.IsBoolKind(kind):
        raise ValueError('Enum values must be integers. %s is not an integer.' %
                         constant.mojom_name)
      prev_value = int(constant.value, 0)
    else:
      raise Exception('Unresolved enum value for %s' % field.value.GetSpec())

    #resolved_enum_values[field.mojom_name] = prev_value
    field.numeric_value = prev_value
    if min_value is None or prev_value < min_value:
      min_value = prev_value
    if max_value is None or prev_value > max_value:
      max_value = prev_value

  enum.min_value = min_value
  enum.max_value = max_value

  Given a reference to a mojom.Enum, resolves and assigns the numeric value of
  each field, and also computes the min_value and max_value of the enum.
  
Given a reference to a mojom.Enum, resolves and assigns the numeric value of
each field, and also computes the min_value and max_value of the enum.
Given a reference to a mojom . Enum resolves and assigns the numeric value of each field and also computes the min_value and max_value of the enum .
def _ResolveNumericEnumValues(enum):
  prev_value = -1
  min_value = None
  max_value = None
  for field in enum.fields:
    if field.value is None:
      prev_value += 1
    elif _IsStrOrUnicode(field.value):
      prev_value = int(field.value, 0)
    elif isinstance(field.value, mojom.EnumValue):
      prev_value = field.value.field.numeric_value
    elif isinstance(field.value, mojom.ConstantValue):
      constant = field.value.constant
      kind = constant.kind
      if not mojom.IsIntegralKind(kind) or mojom.IsBoolKind(kind):
        raise ValueError('Enum values must be integers. %s is not an integer.' %
                         constant.mojom_name)
      prev_value = int(constant.value, 0)
    else:
      raise Exception('Unresolved enum value for %s' % field.value.GetSpec())
    field.numeric_value = prev_value
    if min_value is None or prev_value < min_value:
      min_value = prev_value
    if max_value is None or prev_value > max_value:
      max_value = prev_value
  enum.min_value = min_value
  enum.max_value = max_value
def _ResolveNumericEnumValues ( enum ) : prev_value = - 1 min_value = None max_value = None for field in enum . fields : if field . value is None : prev_value += 1 elif _IsStrOrUnicode ( field . value ) : prev_value = int ( field . value , 0 ) elif isinstance ( field . value , mojom . EnumValue ) : prev_value = field . value . field . numeric_value elif isinstance ( field . value , mojom . ConstantValue ) : constant = field . value . constant kind = constant . kind if not mojom . IsIntegralKind ( kind ) or mojom . IsBoolKind ( kind ) : raise ValueError ( 'Enum values must be integers. %s is not an integer.' % constant . mojom_name ) prev_value = int ( constant . value , 0 ) else : raise Exception ( 'Unresolved enum value for %s' % field . value . GetSpec ( ) ) field . numeric_value = prev_value if min_value is None or prev_value < min_value : min_value = prev_value if max_value is None or prev_value > max_value : max_value = prev_value enum . min_value = min_value enum . max_value = max_value
Given a reference to a mojom.Enum, resolves and assigns the numeric value of
each field, and also computes the min_value and max_value of the enum.
Given a reference to a mojom . Enum resolves and assigns the numeric value of each field and also computes the min_value and max_value of the enum .
"""
  Given a reference to a mojom.Enum, resolves and assigns the numeric value of
  each field, and also computes the min_value and max_value of the enum.
  """ # map of <mojom_name> -> integral value # This enum value is +1 the previous enum value (e.g: BEGIN). # Integral value (e.g: BEGIN = -0x1). # Reference to a previous enum value (e.g: INIT = BEGIN). #resolved_enum_values[field.mojom_name] = prev_value
enum