[scanner] Move a function from transformer to ast
authorJohan Dahlin <johan@gnome.org>
Fri, 3 Sep 2010 02:35:09 +0000 (23:35 -0300)
committerJohan Dahlin <johan@gnome.org>
Fri, 3 Sep 2010 02:45:33 +0000 (23:45 -0300)
It doesn't use any internal state, so it can easily
be moved over to the type as a factory function

giscanner/ast.py
giscanner/gdumpparser.py
giscanner/transformer.py

index c819d024dbe64043734ad1c5ad403fe942c86f80..5267aef96d8f8860c4b25d63ceec58dc27f6e1e1 100644 (file)
@@ -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]
index d88f2e33bcd7d790e253dd3b016a65223cb5f94c..65edf2a0b0d9234fab7ac967c394598808ec1b1c 100644 (file)
@@ -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 = []
index a1f6193b376069191f5270147d2749f5ac9fd5b3..4cb167cc2f5da4e3f14bc6b332ce9aced50ee7ef 100644 (file)
@@ -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('*', '')