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

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

Issue 2864753002: Mojo code generator: simplify how imported types and values are handled. (Closed)
Patch Set: . Created 3 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: 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 8fa4e442690436dc6b04a426de2c5dc045e0a932..fd346e2f6efd32a1f83ce797ea64faca095549a4 100644
--- a/mojo/public/tools/bindings/pylib/mojom/generate/module.py
+++ b/mojo/public/tools/bindings/pylib/mojom/generate/module.py
@@ -82,11 +82,13 @@ class Kind(object):
Attributes:
spec: A string uniquely identifying the type. May be None.
+ module: {Module} The defining module. Set to None for built-in types.
parent_kind: The enclosing type. For example, a struct defined
inside an interface has that interface as its parent. May be None.
"""
- def __init__(self, spec=None):
+ def __init__(self, spec=None, module=None):
self.spec = spec
+ self.module = module
self.parent_kind = None
def Repr(self, as_ref=True):
@@ -106,10 +108,9 @@ class ReferenceKind(Kind):
Attributes:
is_nullable: True if the type is nullable.
"""
-
- def __init__(self, spec=None, is_nullable=False):
+ def __init__(self, spec=None, is_nullable=False, module=None):
assert spec is None or is_nullable == spec.startswith('?')
- Kind.__init__(self, spec)
+ Kind.__init__(self, spec, module)
self.is_nullable = is_nullable
self.shared_definition = {}
@@ -138,6 +139,8 @@ class ReferenceKind(Kind):
if self.spec is not None:
nullable_kind.spec = '?' + self.spec
nullable_kind.is_nullable = True
+ nullable_kind.parent_kind = self.parent_kind
+ nullable_kind.module = self.module
return nullable_kind
@@ -224,13 +227,11 @@ ATTRIBUTE_SYNC = 'Sync'
class NamedValue(object):
def __init__(self, module, parent_kind, name):
self.module = module
- self.namespace = module.namespace
self.parent_kind = parent_kind
self.name = name
- self.imported_from = None
def GetSpec(self):
- return (self.namespace + '.' +
+ return (self.module.namespace + '.' +
(self.parent_kind and (self.parent_kind.name + '.') or "") +
self.name)
@@ -252,7 +253,7 @@ class EnumValue(NamedValue):
self.enum = enum
def GetSpec(self):
- return (self.namespace + '.' +
+ return (self.module.namespace + '.' +
(self.parent_kind and (self.parent_kind.name + '.') or "") +
self.enum.name + '.' + self.name)
@@ -300,9 +301,6 @@ class Struct(ReferenceKind):
name: {str} The name of the struct type.
native_only: {bool} Does the struct have a body (i.e. any fields) or is it
purely a native struct.
- module: {Module} The defining module.
- imported_from: {dict} Information about where this union was
- imported from.
fields: {List[StructField]} The members of the struct.
attributes: {dict} Additional information about the struct, such as
if it's a native struct.
@@ -310,8 +308,6 @@ class Struct(ReferenceKind):
ReferenceKind.AddSharedProperty('name')
ReferenceKind.AddSharedProperty('native_only')
- ReferenceKind.AddSharedProperty('module')
- ReferenceKind.AddSharedProperty('imported_from')
ReferenceKind.AddSharedProperty('fields')
ReferenceKind.AddSharedProperty('attributes')
@@ -320,22 +316,19 @@ class Struct(ReferenceKind):
spec = 'x:' + name
else:
spec = None
- ReferenceKind.__init__(self, spec)
+ ReferenceKind.__init__(self, spec, False, module)
self.name = name
self.native_only = False
- self.module = module
- self.imported_from = None
self.fields = []
self.attributes = attributes
def Repr(self, as_ref=True):
if as_ref:
- return '<%s name=%r imported_from=%s>' % (
+ return '<%s name=%r module=%s>' % (
self.__class__.__name__, self.name,
- Repr(self.imported_from, as_ref=True))
+ Repr(self.module, as_ref=True))
else:
- return GenericRepr(self, {'name': False, 'fields': False,
- 'imported_from': True})
+ return GenericRepr(self, {'name': False, 'fields': False, 'module': True})
def AddField(self, name, kind, ordinal=None, default=None, attributes=None):
field = StructField(name, kind, ordinal, default, attributes)
@@ -348,17 +341,12 @@ class Union(ReferenceKind):
Attributes:
name: {str} The name of the union type.
- module: {Module} The defining module.
- imported_from: {dict} Information about where this union was
- imported from.
fields: {List[UnionField]} The members of the union.
attributes: {dict} Additional information about the union, such as
which Java class name to use to represent it in the generated
bindings.
"""
ReferenceKind.AddSharedProperty('name')
- ReferenceKind.AddSharedProperty('module')
- ReferenceKind.AddSharedProperty('imported_from')
ReferenceKind.AddSharedProperty('fields')
ReferenceKind.AddSharedProperty('attributes')
@@ -367,10 +355,8 @@ class Union(ReferenceKind):
spec = 'x:' + name
else:
spec = None
- ReferenceKind.__init__(self, spec)
+ ReferenceKind.__init__(self, spec, False, module)
self.name = name
- self.module = module
- self.imported_from = None
self.fields = []
self.attributes = attributes
@@ -551,9 +537,7 @@ class Method(object):
class Interface(ReferenceKind):
- ReferenceKind.AddSharedProperty('module')
ReferenceKind.AddSharedProperty('name')
- ReferenceKind.AddSharedProperty('imported_from')
ReferenceKind.AddSharedProperty('methods')
ReferenceKind.AddSharedProperty('attributes')
@@ -562,10 +546,8 @@ class Interface(ReferenceKind):
spec = 'x:' + name
else:
spec = None
- ReferenceKind.__init__(self, spec)
- self.module = module
+ ReferenceKind.__init__(self, spec, False, module)
self.name = name
- self.imported_from = None
self.methods = []
self.attributes = attributes
@@ -618,15 +600,13 @@ class EnumField(object):
class Enum(Kind):
def __init__(self, name=None, module=None, attributes=None):
- self.module = module
self.name = name
self.native_only = False
- self.imported_from = None
if name is not None:
spec = 'x:' + name
else:
spec = None
- Kind.__init__(self, spec)
+ Kind.__init__(self, spec, module)
self.fields = []
self.attributes = attributes

Powered by Google App Engine
This is Rietveld 408576698