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 = _LookupValue(module, parent_kind, constant.kind, parsed_const.value) # Iteratively resolve this constant reference to a concrete value while isinstance(constant.value, mojom.ConstantValue): constant.value = constant.value.constant.value value = mojom.ConstantValue(module, parent_kind, constant) module.values[value.GetSpec()] = value return constant
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