Index: mojo/public/tools/bindings/pylib/mojom/generate/module.py |
diff --git a/mojo/public/tools/bindings/pylib/mojom/generate/module.py b/mojo/public/tools/bindings/pylib/mojom/generate/module.py |
index 4297afbc6c8f14a7711a8244607631d3a0a9c984..b3e8e754d51ed9e37c7f46aea791b795cec029df 100644 |
--- a/mojo/public/tools/bindings/pylib/mojom/generate/module.py |
+++ b/mojo/public/tools/bindings/pylib/mojom/generate/module.py |
@@ -460,6 +460,40 @@ class Module(object): |
self.unions.append(union) |
return union |
+def GetMojomTypeName(kind): |
+ """Get the mojom type's name from its kind.""" |
+ # Note: InterfaceRequest's should use the Interface inside them. |
+ if IsInterfaceRequestKind(kind): |
+ return kind.kind.name |
+ elif hasattr(kind, 'name'): |
+ return kind.name |
+ else: |
+ # These kinds (e.g., simple kinds, maps, and arrays) lack names. |
+ raise Exception('Unexpected kind: %s' % kind) |
+ |
+def GetPackageName(kind): |
+ """Get the package name from the given kind's module.""" |
+ return kind.module.name.split('.')[0] |
+ |
+def GetMojomTypeIdentifier(kind): |
+ """Get the mojom type's unique identifier from the kind's package and name.""" |
+ # Note: InterfaceRequest's should use the Interface inside them. |
+ if hasattr(kind, 'module'): |
+ package = GetPackageName(kind) |
+ elif IsInterfaceRequestKind(kind): |
+ package = GetPackageName(kind.kind) |
+ else: |
+ # These kinds (e.g., simple kinds and fields) lack identifiers. |
+ raise Exception('Unexpected kind: %s' % kind) |
+ return "%s_%s__" % (package, GetMojomTypeName(kind)) |
+ |
+ |
+# Returns a string of the form package.path.TypeName - the full identifier |
+# for an element. |
+def GetMojomTypeFullIdentifier(kind, exported=True): |
+ """Get the Full Identifier for a Mojom Type. Format: package.path.TypeName""" |
+ return '%s.%s' % (kind.module.namespace, GetMojomTypeName(kind)) |
+ |
def IsBoolKind(kind): |
return kind.spec == BOOL.spec |
@@ -469,6 +503,10 @@ def IsFloatKind(kind): |
return kind.spec == FLOAT.spec |
+def IsDoubleKind(kind): |
+ return kind.spec == DOUBLE.spec |
+ |
+ |
def IsIntegralKind(kind): |
return (kind.spec == BOOL.spec or |
kind.spec == INT8.spec or |
@@ -480,6 +518,11 @@ def IsIntegralKind(kind): |
kind.spec == UINT32.spec or |
kind.spec == UINT64.spec) |
+def IsNumericalKind(kind): |
+ return (IsBoolKind(kind) or |
+ IsFloatKind(kind) or |
+ IsDoubleKind(kind) or |
+ IsIntegralKind(kind)) |
def IsStringKind(kind): |
return kind.spec == STRING.spec or kind.spec == NULLABLE_STRING.spec |