Example #1
0
    def ConstantValueFromKey(self, constant_key):
        """Takes a key into graph.resolved_constants referring to a
    mojom declared_constant and returns a module.ConstantValue referring to the
    module equivalent constant.

    Args:
      constant_key: {str} the constant key referring to a constant.

    Returns:
      {module.ConstantValue} translated.
    """
        if constant_key in self._value_cache:
            return self._value_cache[constant_key]

        const_value = module.ConstantValue()
        self._value_cache[constant_key] = const_value

        const = self.ConstantFromKey(constant_key)
        const_value.constant = const
        const_value.name = const.name
        const_value.parent_kind = const.parent_kind
        self.PopulateModuleOrImportedFrom(
            const_value, self._graph.resolved_constants[constant_key])
        const_value.namespace = const_value.module.namespace
        return const_value
Example #2
0
def ConstantFromData(module, data, parent_kind):
    constant = mojom.Constant()
    constant.name = data['name']
    if parent_kind:
        scope = (module.namespace, parent_kind.name)
    else:
        scope = (module.namespace, )
    # TODO(mpcomplete): maybe we should only support POD kinds.
    constant.kind = KindFromData(module.kinds, data['kind'], scope)
    constant.value = FixupExpression(module, data.get('value'), scope, None)

    value = mojom.ConstantValue(module, parent_kind, constant)
    module.values[value.GetSpec()] = value
    return constant
Example #3
0
  def ConstantValueFromValueKey(self, value_key):
    """Takes a value key into graph.resolved_values referring to a declared
    constant and returns the module equivalent.

    Args:
      value_key: {str} the value key referring to the value to be returned.

    Returns:
      {module.ConstantValue} translated.
    """
    const_value = module.ConstantValue()
    self._value_cache[value_key] = const_value

    const = self.ConstantFromValueKey(value_key)
    const_value.constant = const
    const_value.name = const.name
    const_value.parent_kind = const.parent_kind
    self.PopulateModuleOrImportedFrom(const_value,
        self._graph.resolved_values[value_key].declared_constant)
    const_value.namespace = const_value.module.namespace
    return const_value
Example #4
0
def _Constant(module, parsed_const, parent_kind):
    """
  Args:
    module: {mojom.Module} Module currently being constructed.
    parsed_const: {ast.Const} Parsed constant.

  Returns:
    {mojom.Constant} AST constant.
  """
    constant = mojom.Constant()
    constant.mojom_name = parsed_const.mojom_name
    if parent_kind:
        scope = (module.mojom_namespace, parent_kind.mojom_name)
    else:
        scope = (module.mojom_namespace, )
    # TODO(mpcomplete): maybe we should only support POD kinds.
    constant.kind = _Kind(module.kinds, _MapKind(parsed_const.typename), scope)
    constant.parent_kind = parent_kind
    constant.value = _FixupExpression(module, parsed_const.value, scope, None)

    value = mojom.ConstantValue(module, parent_kind, constant)
    module.values[value.GetSpec()] = value
    return constant