From ec0fe9e40d6b3dbd56c607fac50f17495b9ce193 Mon Sep 17 00:00:00 2001 From: Dominic Kempf <dominic.kempf@iwr.uni-heidelberg.de> Date: Fri, 15 Jan 2016 14:49:13 +0100 Subject: [PATCH] Add my cgen extensions --- python/dune/perftool/cgen/__init__.py | 22 ++++++++++++++++++++++ python/dune/perftool/cgen/clazz.py | 17 +++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 python/dune/perftool/cgen/__init__.py create mode 100644 python/dune/perftool/cgen/clazz.py diff --git a/python/dune/perftool/cgen/__init__.py b/python/dune/perftool/cgen/__init__.py new file mode 100644 index 00000000..de571020 --- /dev/null +++ b/python/dune/perftool/cgen/__init__.py @@ -0,0 +1,22 @@ +from __future__ import absolute_import + +from cgen import * + +from dune.perftool.cgen.clazz import Class + + +class Namespace(PrivateNamespace): + """ + A namespace Generable that is provided the name of the namespace. + Normally, you would revert the inheritance here, but I do not want + to interfere with cgen and for some reason it does not provide + explicitly named namespace. + """ + def __init__(self, *args, **kwargs): + name = kwargs.pop("name") + PrivateNamespace.__init__(self, *args, **kwargs) + + self.name = name + + def get_namespace_name(self): + return self.name \ No newline at end of file diff --git a/python/dune/perftool/cgen/clazz.py b/python/dune/perftool/cgen/clazz.py new file mode 100644 index 00000000..6b3b7157 --- /dev/null +++ b/python/dune/perftool/cgen/clazz.py @@ -0,0 +1,17 @@ +from cgen import Generable + +class Class(Generable): + """ Generator for a templated class """ + def __init__(self, name, public_methods = [], tparams=[], constructors=[]): + self.name = name + self.public_methods = public_methods + self.tparams = tparams + + assert isinstance(name, str) + + from cgen import FunctionBody + for m in self.methods: + assert isinstance(n, FunctionBody) + + def generate(self): + yield "class {}".format(self.name) \ No newline at end of file -- GitLab