[gobject-introspection/wip/transformer] [testcodegen] Separate void foo(void) and minor cleanup



commit cd250d753fa887ab4b0cfceeac1a799be60c1c28
Author: Colin Walters <walters verbum org>
Date:   Fri Jul 30 17:33:24 2010 -0400

    [testcodegen] Separate void foo(void) and minor cleanup
    
    A small refactoring with the thought that we'd reuse the Everything
    Python AST to generate JS, but skip that for now.

 giscanner/codegen.py     |    5 +++--
 giscanner/testcodegen.py |   16 ++++++++++++----
 2 files changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/giscanner/codegen.py b/giscanner/codegen.py
index b17026b..34d50eb 100644
--- a/giscanner/codegen.py
+++ b/giscanner/codegen.py
@@ -27,8 +27,6 @@ class CCodeGenerator(object):
     def __init__(self, namespace, out_h_filename, out_c_filename):
         self.out_h_filename = out_h_filename
         self.out_c_filename = out_c_filename
-        self.out_h = open(out_h_filename, 'w')
-        self.out_c = open(out_c_filename, 'w')
         self._function_bodies = {}
         self.namespace = namespace
 
@@ -123,6 +121,9 @@ class CCodeGenerator(object):
         self._function_bodies[node] = body
 
     def codegen(self):
+        self.out_h = open(self.out_h_filename, 'w')
+        self.out_c = open(self.out_c_filename, 'w')
+
         self._codegen_start()
 
         for node in self.namespace.itervalues():
diff --git a/giscanner/testcodegen.py b/giscanner/testcodegen.py
index a5aeb10..0bb8958 100644
--- a/giscanner/testcodegen.py
+++ b/giscanner/testcodegen.py
@@ -25,7 +25,9 @@ from .ast import *
 from .glibast import *
 from .codegen import CCodeGenerator
 
-INTROSPECTABLE_BASIC = filter(lambda x: x not in (TYPE_LONG_LONG, TYPE_LONG_ULONG, TYPE_LONG_DOUBLE), GIR_TYPES)
+INTROSPECTABLE_BASIC = filter(lambda x: x not in (TYPE_NONE, TYPE_ANY,
+                                                  TYPE_LONG_LONG, TYPE_LONG_ULONG,
+                                                  TYPE_LONG_DOUBLE), GIR_TYPES)
 
 DEFAULT_C_VALUES = {TYPE_ANY: 'NULL',
                     TYPE_STRING: '""',
@@ -34,8 +36,6 @@ DEFAULT_C_VALUES = {TYPE_ANY: 'NULL',
 
 def get_default_for_typeval(typeval):
     default = DEFAULT_C_VALUES.get(typeval)
-    if typeval is TYPE_NONE:
-        return ""
     if default:
         return default
     return "0"
@@ -49,11 +49,19 @@ def uscore_from_type(typeval):
         assert False, typeval
 
 class EverythingCodeGenerator(object):
+
     def __init__(self, out_h_filename, out_c_filename):
         self.namespace = Namespace('Everything', '1.0')
         self.gen = CCodeGenerator(self.namespace, out_h_filename, out_c_filename)
 
     def write(self):
+        
+        func = Function('nullfunc', Return(TYPE_NONE, transfer=PARAM_TRANSFER_NONE),
+                        [], False, self.gen.gen_symbol('nullfunc'))
+        self.namespace.append(func)
+        body = "  return;\n"
+        self.gen.set_function_body(func, body)
+
         # First pass, generate constant returns
         prefix = 'const return '
         for typeval in INTROSPECTABLE_BASIC:
@@ -96,7 +104,7 @@ class EverythingCodeGenerator(object):
             body.write("  return;\n")
             self.gen.set_function_body(func, body.getvalue())
 
-        # Passthrough one para
+        # Passthrough one parameter
         prefix = 'passthrough_one '
         for typeval in INTROSPECTABLE_BASIC:
             if typeval is TYPE_NONE:



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