If none are specified, then it's in an "unresolved" state. An
unresolved type can have two data sources; a "ctype" which comes
from a C type string, or a gtype_name (from g_type_name()).
-"""
+""" # '''
def __init__(self,
ctype=None,
else:
assert False
+ @classmethod
+ def create_from_gtype_name(cls, gtype_name):
+ """Parse a GType name (as from g_type_name()), and return a
+Type instance. Note that this function performs namespace lookup,
+in contrast to the other create_type() functions."""
+ # First, is it a fundamental?
+ fundamental = type_names.get(gtype_name)
+ if fundamental is not None:
+ return cls(target_fundamental=fundamental.target_fundamental)
+ return cls(gtype_name=gtype_name)
+
def get_giname(self):
assert self.target_giname is not None
return self.target_giname.split('.')[1]
self._introspect_signals(node, xmlnode)
for child in xmlnode.findall('prerequisite'):
name = child.attrib['name']
- prereq = self._transformer.create_type_from_gtype_name(name)
+ prereq = ast.Type.create_from_gtype_name(name)
node.prerequisites.append(prereq)
# GtkFileChooserEmbed is an example of a private interface, we
# just filter them out
def _introspect_implemented_interfaces(self, node, xmlnode):
gt_interfaces = []
for interface in xmlnode.findall('implements'):
- gitype = self._transformer.create_type_from_gtype_name(interface.attrib['name'])
+ gitype = ast.Type.create_from_gtype_name(interface.attrib['name'])
gt_interfaces.append(gitype)
node.interfaces = gt_interfaces
construct_only = (flags & G_PARAM_CONSTRUCT_ONLY) != 0
node.properties.append(ast.Property(
pspec.attrib['name'],
- self._transformer.create_type_from_gtype_name(ctype),
+ ast.Type.create_from_gtype_name(ctype),
readable, writable, construct, construct_only,
ctype,
))
def _introspect_signals(self, node, xmlnode):
for signal_info in xmlnode.findall('signal'):
rctype = signal_info.attrib['return']
- rtype = self._transformer.create_type_from_gtype_name(rctype)
+ rtype = ast.Type.create_from_gtype_name(rctype)
return_ = ast.Return(rtype)
parameters = []
for i, parameter in enumerate(signal_info.findall('param')):
else:
argname = 'p%s' % (i-1, )
pctype = parameter.attrib['type']
- ptype = self._transformer.create_type_from_gtype_name(pctype)
+ ptype = ast.Type.create_type_gtype_name(pctype)
param = ast.Parameter(argname, ptype)
param.transfer = ast.PARAM_TRANSFER_NONE
parameters.append(param)
def _parse_parents(self, xmlnode, node):
parents_str = xmlnode.attrib.get('parents', '')
if parents_str != '':
- parent_types = map(lambda s: self._transformer.create_type_from_gtype_name(s),
+ parent_types = map(lambda s: ast.Type.create_from_gtype_name(s),
parents_str.split(','))
else:
parent_types = []
typeval.ctype = None
return typeval
- def create_type_from_gtype_name(self, gtype_name):
- """Parse a GType name (as from g_type_name()), and return a
-Type instance. Note that this function performs namespace lookup,
-in contrast to the other create_type() functions."""
- # First, is it a fundamental?
- fundamental = ast.type_names.get(gtype_name)
- if fundamental is not None:
- return ast.Type(target_fundamental=fundamental.target_fundamental)
- return ast.Type(gtype_name=gtype_name)
-
def _resolve_type_from_ctype(self, typeval):
assert typeval.ctype is not None
pointer_stripped = typeval.ctype.replace('*', '')