gobject-introspection r199 - in trunk: . giscanner



Author: johan
Date: Mon Apr 21 18:56:23 2008
New Revision: 199
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=199&view=rev

Log:
2008-04-21  Johan Dahlin  <johan gnome org>

    * giscanner/gidlwriter.py:
    * giscanner/gobjecttreebuilder.py:
    * giscanner/treebuilder.py:
    Add constructors for object/boxed types.



Modified:
   trunk/ChangeLog
   trunk/giscanner/gidlwriter.py
   trunk/giscanner/gobjecttreebuilder.py
   trunk/giscanner/treebuilder.py

Modified: trunk/giscanner/gidlwriter.py
==============================================================================
--- trunk/giscanner/gidlwriter.py	(original)
+++ trunk/giscanner/gidlwriter.py	Mon Apr 21 18:56:23 2008
@@ -44,6 +44,9 @@
     def _write_method(self, method):
         self._write_function(method, tag_name='method')
 
+    def _write_constructor(self, method):
+        self._write_function(method, tag_name='constructor')
+
     def _write_return_type(self, return_):
         if not return_:
             return
@@ -85,6 +88,8 @@
         if isinstance(class_, GLibObject):
             attrs.append(('get-type', class_.get_type))
         with self.tagcontext('object', attrs):
+            for method in class_.constructors:
+                self._write_constructor(method)
             for method in class_.methods:
                 self._write_method(method)
 
@@ -101,5 +106,7 @@
         if isinstance(boxed, GLibBoxed):
             attrs.append(('get-type', boxed.get_type))
         with self.tagcontext('boxed', attrs):
+            for method in boxed.constructors:
+                self._write_constructor(method)
             for method in boxed.methods:
                 self._write_method(method)

Modified: trunk/giscanner/gobjecttreebuilder.py
==============================================================================
--- trunk/giscanner/gobjecttreebuilder.py	(original)
+++ trunk/giscanner/gobjecttreebuilder.py	Mon Apr 21 18:56:23 2008
@@ -63,6 +63,7 @@
 class GLibBoxed(Struct):
     def __init__(self, name, methods, get_type):
         Struct.__init__(self, name)
+        self.constructors = []
         self.methods = []
         self.get_type = get_type
 
@@ -129,6 +130,8 @@
     def _parse_function(self, func):
         if self._parse_get_type_function(func):
             return
+        elif self._parse_constructor(func):
+            return
         elif self._parse_method(func):
             return
 
@@ -181,6 +184,32 @@
         class_.methods.append(method)
         return True
 
+    def _parse_constructor(self, func):
+        # FIXME: This is hackish, we should preserve the pointer structures
+        #        here, so we can find pointers to objects and not just
+        #        pointers to anything
+        rtype = func.retval.type
+        if rtype.count('*') != 1:
+            return False
+
+        object_name = rtype.replace('*', '')
+        class_ = self._get_attribute(object_name)
+        if class_ is None or not isinstance(class_, (GLibObject, GLibBoxed)):
+            return False
+
+        # GtkButton -> gtk_button_, so we can figure out the constructor name
+        prefix = to_underscores(object_name).lower() + '_'
+        if not func.name.startswith(prefix):
+            return False
+
+        # Okay, the function is really a method
+        constructor = func
+
+        # Strip namespace and object prefix: gtk_button_set_text -> set_text
+        constructor.name = func.name[len(prefix):]
+        class_.constructors.append(constructor)
+        return True
+
     def _parse_struct(self, struct):
         if (struct.name.startswith('_') or
             struct.name.endswith('Iface') or

Modified: trunk/giscanner/treebuilder.py
==============================================================================
--- trunk/giscanner/treebuilder.py	(original)
+++ trunk/giscanner/treebuilder.py	Mon Apr 21 18:56:23 2008
@@ -65,6 +65,7 @@
         self.name = name
         self.parent = parent
         self.methods = methods
+        self.constructors = []
 
     def __repr__(self):
         return 'Class(%r, %r, %r)' % (



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]