Hi,

I used h2def.py this weekend and noticed it does not create
'is-constructor-of' entries in the generated code. I started browsing
the code and noticed this is a todo item. I solved it this way:
- a constructor function ends with '_new' and returns a pointer
- h2def converts the text before the _new to a class name and writes
  a constructor entry.

Here's the patch.

Regards,

Arjan



Index: pygtk/codegen/h2def.py
===================================================================
RCS file: /cvs/gnome/gnome-python/pygtk/codegen/h2def.py,v
retrieving revision 1.15
diff -u -r1.15 h2def.py
--- pygtk/codegen/h2def.py	2002/04/17 16:07:40	1.15
+++ pygtk/codegen/h2def.py	2002/05/01 09:43:28
@@ -296,6 +296,8 @@
         write_func(fp, func, ret, args)
 
 get_type_pat = re.compile(r'(const-)?([A-Za-z0-9]+)\*?\s+')
+pointer_pat = re.compile('.*\*$')
+func_new_pat = re.compile('(\w+)_new$')
 
 def write_func(fp, name, ret, args):
     if len(args) >= 1:
@@ -334,9 +336,23 @@
                 fp.write(')\n\n')
                 return
     # it is either a constructor or normal function
-    # FIXME: put in constructor check
     fp.write('(define-function ' + name + '\n')
-    # do in-module thingee
+
+    # Hmmm... Let's asume that a constructor function name
+    # ends with '_new' and it returns a pointer.
+    m = func_new_pat.match(name)
+    if pointer_pat.match(ret) and m:
+        cname = ''
+	for s in m.group(1).split ('_'):
+	    cname += s.title()
+	if cname != '':
+	    fp.write('  (is-constructor-of "' + cname + '")\n')
+    else:
+	# do in-module thingee
+	s = name.split('_')
+	if s:
+	    fp.write('  (in-module "' + s[0].title() + '")\n')
+
     fp.write('  (c-name "' + name + '")\n')
     if ret != 'void':
         fp.write('  (return-type "' + ret + '")\n')

Reply via email to