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

Unified Diff: third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_go_generator.py

Issue 1157843002: Update mojo sdk to rev 1dc8a9a5db73d3718d99917fadf31f5fb2ebad4f (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
Index: third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_go_generator.py
diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_go_generator.py b/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_go_generator.py
index 1df4eb5d1a410e9726362acdfbd32b2a7a8deedd..e20e9e4f6b4ac69e95823bf9621c230bec48c707 100644
--- a/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_go_generator.py
+++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_go_generator.py
@@ -60,8 +60,12 @@ _kind_infos = {
_imports = {}
def GetBitSize(kind):
+ if isinstance(kind, (mojom.Union)):
+ return 128
if isinstance(kind, (mojom.Array, mojom.Map, mojom.Struct, mojom.Interface)):
return 64
+ if mojom.IsUnionKind(kind):
+ return 2*64
if isinstance(kind, (mojom.InterfaceRequest)):
kind = mojom.MSGPIPE
if isinstance(kind, mojom.Enum):
@@ -78,7 +82,7 @@ def GetGoType(kind, nullable = True):
# Returns go type corresponding to provided kind. Ignores nullability of
# top-level kind.
def GetNonNullableGoType(kind):
- if mojom.IsStructKind(kind):
+ if mojom.IsStructKind(kind) or mojom.IsUnionKind(kind):
return '%s' % GetFullName(kind)
if mojom.IsArrayKind(kind):
if kind.length:
@@ -140,7 +144,8 @@ def GetNameForNestedElement(element):
return GetFullName(element)
def GetNameForElement(element, exported=True):
- if (mojom.IsInterfaceKind(element) or mojom.IsStructKind(element)):
+ if (mojom.IsInterfaceKind(element) or mojom.IsStructKind(element)
+ or mojom.IsUnionKind(element)):
return GetFullName(element, exported)
if isinstance(element, (mojom.EnumField,
mojom.Field,
@@ -228,6 +233,7 @@ def AddImport(module, element):
name += '_'
_imports[path] = name
+
class Generator(generator.Generator):
go_filters = {
'array': lambda kind: mojom.Array(kind),
@@ -246,6 +252,7 @@ class Generator(generator.Generator):
'is_nullable': mojom.IsNullableKind,
'is_pointer': mojom.IsObjectKind,
'is_struct': mojom.IsStructKind,
+ 'is_union': mojom.IsUnionKind,
'name': GetNameForElement,
'tab_indent': lambda s, size = 1: ('\n' + '\t' * size).join(s.splitlines())
}
@@ -257,6 +264,7 @@ class Generator(generator.Generator):
'interfaces': self.GetInterfaces(),
'package': GetPackageName(self.module),
'structs': self.GetStructs(),
+ 'unions': self.GetUnions(),
}
@UseJinja('go_templates/source.tmpl', filters=go_filters)
@@ -299,6 +307,10 @@ class Generator(generator.Generator):
if len(all_structs) > 0:
_imports['sort'] = 'sort'
+ for union in self.module.unions:
+ for field in union.fields:
+ AddImport(self.module, field.kind)
+
for struct in all_structs:
for field in struct.fields:
AddImport(self.module, field.kind)

Powered by Google App Engine
This is Rietveld 408576698