summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--giscanner/ast.py13
-rw-r--r--giscanner/gdumpparser.py12
-rw-r--r--giscanner/transformer.py10
3 files changed, 18 insertions, 17 deletions
diff --git a/giscanner/ast.py b/giscanner/ast.py
index c819d024..5267aef9 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -30,7 +30,7 @@ class Type(object):
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,
@@ -79,6 +79,17 @@ from a C type string, or a gtype_name (from g_type_name()).
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]
diff --git a/giscanner/gdumpparser.py b/giscanner/gdumpparser.py
index d88f2e33..65edf2a0 100644
--- a/giscanner/gdumpparser.py
+++ b/giscanner/gdumpparser.py
@@ -307,7 +307,7 @@ blob containing data gleaned from GObject's primitive introspection."""
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
@@ -327,7 +327,7 @@ blob containing data gleaned from GObject's primitive introspection."""
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
@@ -341,7 +341,7 @@ blob containing data gleaned from GObject's primitive introspection."""
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,
))
@@ -350,7 +350,7 @@ blob containing data gleaned from GObject's primitive introspection."""
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')):
@@ -359,7 +359,7 @@ blob containing data gleaned from GObject's primitive introspection."""
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)
@@ -370,7 +370,7 @@ blob containing data gleaned from GObject's primitive introspection."""
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 = []
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index a1f6193b..4cb167cc 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -730,16 +730,6 @@ Note that type resolution may not succeed."""
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('*', '')