diff --git a/python/dune/perftool/file.py b/python/dune/perftool/file.py index 9403ff8e5878c354b3bed69311457d6421cf8055..d1b566595abb175dfbfa75867d94149ce235c4f1 100644 --- a/python/dune/perftool/file.py +++ b/python/dune/perftool/file.py @@ -1,13 +1,16 @@ """ Manages the generation of C++ header files """ +from cgen import Generable, Include + +from dune.perftool.generation import retrieve_cache_items + def generate_file(filename, tag, content, headerguard=True): - """ - Write a file from the generation cache: + """Write a file from the generation cache. Arguments: ---------- - filename : str + filename: str The filename to write the generated code to. tag: str The tag, that all entries related to this file in the cache have. @@ -16,7 +19,7 @@ def generate_file(filename, tag, content, headerguard=True): Keyword Arguments: ------------------ - headerguard : bool + headerguard: bool Whether a double inclusion protection header should be added to the file. The name of the macro is mangled from the absolute path. Defaults to True. """ @@ -26,7 +29,6 @@ def generate_file(filename, tag, content, headerguard=True): macro = filename.upper().replace("/", "_").replace(".", "_").replace("-", "_") f.write("#ifndef {0}\n#define {0}\n\n".format(macro)) - from dune.perftool.generation import retrieve_cache_items # Add pre include lines from the cache for define in retrieve_cache_items('{} and pre_include'.format(tag)): for line in define: @@ -36,14 +38,13 @@ def generate_file(filename, tag, content, headerguard=True): # Add the includes from the cache for inc in retrieve_cache_items('{} and include'.format(tag)): - from cgen import Include assert isinstance(inc, Include) for line in inc.generate(): f.write(line) f.write('\n') f.write('\n') - # Add post include lines from the cache + # Add post include lines direclty after includes for define in retrieve_cache_items('{} and post_include'.format(tag)): for line in define: f.write(line) @@ -51,12 +52,13 @@ def generate_file(filename, tag, content, headerguard=True): f.write('\n\n') + # Add main content for c in content: - from cgen import Generable assert isinstance(c, Generable) for line in c.generate(): f.write(line) f.write('\n\n') + # Close headerguard if headerguard: f.write("\n\n#endif //{}\n".format(macro))