Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(825)

Unified Diff: mojo/public/tools/bindings/pylib/mojom/generate/module.py

Issue 1539673003: Generate Mojom Types in Dart (Take 2) (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Merge with master Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/tools/bindings/generators/mojom_go_generator.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « mojo/public/tools/bindings/generators/mojom_go_generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698