summaryrefslogtreecommitdiff
path: root/giscanner/codegen.py
diff options
context:
space:
mode:
authorChun-wei Fan <fanchunwei@src.gnome.org>2014-09-03 11:22:35 +0800
committerChun-wei Fan <fanchunwei@src.gnome.org>2014-09-04 00:06:24 +0800
commitc112e9830f8af59275d6f590bbcb365c9968c1fc (patch)
tree7edf821a5fb472655a85888b14e5d0f25002a14e /giscanner/codegen.py
parent5143afb1e79f4a67f57499ca60f6df3a4682eb21 (diff)
downloadgobject-introspection-c112e9830f8af59275d6f590bbcb365c9968c1fc.tar.gz
giscanner: Add Optional Options for Codegen
This adds options to scannermain so that we can decorate functions with macros as needed, so that we can use compiler annotations for symbol export for example. Options are also added to include headers before or after the main include block at the top so that we can include headers as necessary in the generated sources and/or headers, so that we could for example grab definitions from those headers as needed, such as to grab definitions of macros used for symbol export. The testcodegen.py script has been updated as well to make use of this functionality, if needed. https://bugzilla.gnome.org/show_bug.cgi?id=732669
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""")