[gobject-introspection] [scanner] Move a function from transformer to ast
- From: Johan Dahlin <johan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] [scanner] Move a function from transformer to ast
- Date: Fri, 3 Sep 2010 02:45:59 +0000 (UTC)
commit e9684fcc96c2de2ad1337e368cdb642cd6e58e4c
Author: Johan Dahlin <johan gnome org>
Date: Thu Sep 2 23:35:09 2010 -0300
[scanner] Move a function from transformer to ast
It doesn't use any internal state, so it can easily
be moved over to the type as a factory function
giscanner/ast.py | 13 ++++++++++++-
giscanner/gdumpparser.py | 12 ++++++------
giscanner/transformer.py | 10 ----------
3 files changed, 18 insertions(+), 17 deletions(-)
---
diff --git a/giscanner/ast.py b/giscanner/ast.py
index c819d02..5267aef 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 d88f2e3..65edf2a 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 a1f6193..4cb167c 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('*', '')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]