def Check(kind): if kind.spec in checked: return True checked.add(kind.spec) if mojom.IsNullableKind(kind): return False elif mojom.IsStructKind(kind): if kind.native_only: return False if (self._IsTypemappedKind(kind) and not self.typemap[self._GetFullMojomNameForKind(kind)]["hashable"]): return False return all(Check(field.kind) for field in kind.fields) elif mojom.IsEnumKind(kind): return not self._IsTypemappedKind(kind) or self.typemap[ self._GetFullMojomNameForKind(kind)]["hashable"] elif mojom.IsUnionKind(kind): return all(Check(field.kind) for field in kind.fields) elif mojom.IsAnyHandleKind(kind): return False elif mojom.IsAnyInterfaceKind(kind): return False # TODO(crbug.com/735301): Arrays and maps could be made hashable. We just # don't have a use case yet. elif mojom.IsArrayKind(kind): return False elif mojom.IsMapKind(kind): return False else: return True
def Check(kind): if kind.spec in checked: return True checked.add(kind.spec) if mojom.IsNullableKind(kind): return False elif mojom.IsStructKind(kind): if (IsTypemappedKind(kind) and not _current_typemap[ GetFullMojomNameForKind(kind)]["hashable"]): return False return all(Check(field.kind) for field in kind.fields) elif mojom.IsEnumKind(kind): return not IsTypemappedKind(kind) or _current_typemap[ GetFullMojomNameForKind(kind)]["hashable"] elif mojom.IsUnionKind(kind): return all(Check(field.kind) for field in kind.fields) elif mojom.IsAnyHandleKind(kind): return False elif mojom.IsAnyInterfaceKind(kind): return False # TODO(tibell): Arrays and maps could be made hashable. We just don't have a # use case yet. elif mojom.IsArrayKind(kind): return False elif mojom.IsMapKind(kind): return False else: return True
def _GetObjCUnionNullReturnValue(self, kind): typemap = MojoTypemapForKind(kind) if mojom.IsEnumKind(kind): return 'static_cast<%s>(0)' % typemap.ObjCWrappedType() elif mojom.IsObjectKind(kind) or mojom.IsAnyInterfaceKind(kind): return 'nil' else: return '0'
def _CollectReferencedKinds(module, all_defined_kinds): """ Takes a {mojom.Module} object and a list of all defined kinds within that module, and enumerates the complete dict of user-defined mojom types (as {mojom.Kind} objects) referenced by the module's own defined kinds (i.e. as types of struct or union or interface parameters. The returned dict is keyed by kind spec. """ def extract_referenced_user_kinds(kind): if mojom.IsArrayKind(kind): return extract_referenced_user_kinds(kind.kind) if mojom.IsMapKind(kind): return (extract_referenced_user_kinds(kind.key_kind) + extract_referenced_user_kinds(kind.value_kind)) if mojom.IsInterfaceRequestKind(kind) or mojom.IsAssociatedKind(kind): return [kind.kind] if mojom.IsStructKind(kind): return [kind] if (mojom.IsInterfaceKind(kind) or mojom.IsEnumKind(kind) or mojom.IsUnionKind(kind)): return [kind] return [] def sanitize_kind(kind): """Removes nullability from a kind""" if kind.spec.startswith('?'): return _Kind(module.kinds, kind.spec[1:], (module.mojom_namespace, '')) return kind referenced_user_kinds = {} for defined_kind in all_defined_kinds: if mojom.IsStructKind(defined_kind) or mojom.IsUnionKind(defined_kind): for field in defined_kind.fields: for referenced_kind in extract_referenced_user_kinds( field.kind): sanitized_kind = sanitize_kind(referenced_kind) referenced_user_kinds[sanitized_kind.spec] = sanitized_kind # Also scan for references in parameter lists for interface in module.interfaces: for method in interface.methods: for param in itertools.chain(method.parameters or [], method.response_parameters or []): if (mojom.IsStructKind(param.kind) or mojom.IsUnionKind(param.kind) or mojom.IsEnumKind(param.kind) or mojom.IsAnyInterfaceKind(param.kind)): for referenced_kind in extract_referenced_user_kinds( param.kind): sanitized_kind = sanitize_kind(referenced_kind) referenced_user_kinds[ sanitized_kind.spec] = sanitized_kind return referenced_user_kinds
def assertDependencyIsStable(dependency): if (mojom.IsEnumKind(dependency) or mojom.IsStructKind(dependency) or mojom.IsUnionKind(dependency) or mojom.IsInterfaceKind(dependency)): if not dependency.stable: raise Exception( '%s is marked [Stable] but cannot be stable because it depends on ' '%s, which is not marked [Stable].' % (kind.mojom_name, dependency.mojom_name)) elif mojom.IsArrayKind(dependency) or mojom.IsAnyInterfaceKind(dependency): assertDependencyIsStable(dependency.kind) elif mojom.IsMapKind(dependency): assertDependencyIsStable(dependency.key_kind) assertDependencyIsStable(dependency.value_kind)
def _JavaScriptEncodeSnippet(self, kind): if (kind in mojom.PRIMITIVES or mojom.IsUnionKind(kind) or mojom.IsAnyInterfaceKind(kind)): return "encodeStruct(%s, " % self._CodecType(kind) if mojom.IsUnionKind(kind): return "encodeStruct(%s, " % self._JavaScriptType(kind) if mojom.IsStructKind(kind): return "encodeStructPointer(%s, " % self._JavaScriptType(kind) if mojom.IsMapKind(kind): return "encodeMapPointer(%s, %s, " % (self._ElementCodecType( kind.key_kind), self._ElementCodecType(kind.value_kind)) if mojom.IsArrayKind(kind) and mojom.IsBoolKind(kind.kind): return "encodeArrayPointer(codec.PackedBool, " if mojom.IsArrayKind(kind): return "encodeArrayPointer(%s, " % self._CodecType(kind.kind) if mojom.IsEnumKind(kind): return self._JavaScriptEncodeSnippet(mojom.INT32) raise Exception("No encode snippet for %s" % kind)
def JavaScriptDecodeSnippet(kind): if (kind in mojom.PRIMITIVES or mojom.IsUnionKind(kind) or mojom.IsAnyInterfaceKind(kind)): return "decodeStruct(%s)" % CodecType(kind) if mojom.IsStructKind(kind): return "decodeStructPointer(%s)" % JavaScriptType(kind) if mojom.IsMapKind(kind): return "decodeMapPointer(%s, %s)" % \ (ElementCodecType(kind.key_kind), ElementCodecType(kind.value_kind)) if mojom.IsArrayKind(kind) and mojom.IsBoolKind(kind.kind): return "decodeArrayPointer(codec.PackedBool)" if mojom.IsArrayKind(kind): return "decodeArrayPointer(%s)" % CodecType(kind.kind) if mojom.IsUnionKind(kind): return "decodeUnion(%s)" % CodecType(kind) if mojom.IsEnumKind(kind): return JavaScriptDecodeSnippet(mojom.INT32) raise Exception("No decode snippet for %s" % kind)