summaryrefslogtreecommitdiff
path: root/giscanner/codegen.py
diff options
context:
space:
mode:
Diffstat (limited to 'giscanner/codegen.py')
-rw-r--r--giscanner/codegen.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/giscanner/codegen.py b/giscanner/codegen.py
index e9ed9415..e0eb182f 100644
--- a/giscanner/codegen.py
+++ b/giscanner/codegen.py
@@ -26,9 +26,21 @@ from . import ast
class CCodeGenerator(object):
- def __init__(self, namespace, out_h_filename, out_c_filename):
+ def __init__(self, namespace,
+ out_h_filename,
+ out_c_filename,
+ function_decoration=[],
+ include_first_header=[],
+ include_last_header=[],
+ include_first_src=[],
+ include_last_src=[]):
self.out_h_filename = out_h_filename
self.out_c_filename = out_c_filename
+ self.function_decoration = function_decoration
+ self.include_first_header = include_first_header
+ self.include_last_header = include_last_header
+ self.include_first_src = include_first_src
+ self.include_last_src = include_last_src
self._function_bodies = {}
self.namespace = namespace
@@ -50,6 +62,10 @@ class CCodeGenerator(object):
return param.type.ctype + suffix
def _write_prelude(self, out, func):
+ if self.function_decoration:
+ out.write("""
+%s""" % " ".join(self.function_decoration))
+
out.write("""
%s
%s (""" % (self._typecontainer_to_ctype(func.retval), func.symbol))
@@ -105,16 +121,31 @@ class CCodeGenerator(object):
warning = '/* GENERATED BY testcodegen.py; DO NOT EDIT */\n\n'
self.out_h.write(warning)
nsupper = self.namespace.name.upper()
+
+ for header in self.include_first_header:
+ self.out_h.write("""#include "%s"\n""" % header)
+
self.out_h.write("""
#ifndef __%s_H__
#define __%s_H__
#include <glib-object.h>
+
""" % (nsupper, nsupper))
+ for header in self.include_last_header:
+ self.out_h.write("""#include "%s"\n""" % header)
+
self.out_c.write(warning)
+
+ for header in self.include_first_src:
+ self.out_c.write("""#include "%s"\n""" % header)
+
self.out_c.write("""#include "%s"\n\n""" % (self.out_h_filename, ))
+ for header in self.include_last_src:
+ self.out_c.write("""#include "%s"\n""" % header)
+
def _codegen_end(self):
self.out_h.write("""#endif\n""")