From 2fe6cd6d5514bbf8bc0e31918fb15f4862678865 Mon Sep 17 00:00:00 2001
From: Stephan Seitz <stephan.seitz@fau.de>
Date: Mon, 5 Aug 2019 20:54:01 +0200
Subject: [PATCH] Implement astnodes {SourceCodeComment,EmptyLine}

---
 pystencils/astnodes.py                       | 47 +++++++++++++++++++-
 pystencils/backends/cbackend.py              |  6 +++
 pystencils_tests/test_source_code_comment.py | 38 ++++++++++++++++
 3 files changed, 89 insertions(+), 2 deletions(-)
 create mode 100644 pystencils_tests/test_source_code_comment.py

diff --git a/pystencils/astnodes.py b/pystencils/astnodes.py
index 38bb9883..d9867fed 100644
--- a/pystencils/astnodes.py
+++ b/pystencils/astnodes.py
@@ -718,5 +718,48 @@ class DestructuringBindingsForFieldClass(Node):
         return self.body.atoms(arg_type) | {s for s in self.symbols_defined if isinstance(s, arg_type)}
 
 
-def get_dummy_symbol(dtype='bool'):
-    return TypedSymbol('dummy%s' % uuid.uuid4().hex, create_type(dtype))
+class SourceCodeComment(Node):
+    def __init__(self, text):
+        self.text = text
+
+    @property
+    def args(self):
+        return []
+
+    @property
+    def symbols_defined(self):
+        return set()
+
+    @property
+    def undefined_symbols(self):
+        return set()
+
+    def __str__(self):
+        return "/* " + self.text + " */"
+
+    def __repr__(self):
+        return self.__str__()
+
+
+class EmptyLine(Node):
+
+    def __init__(self):
+        pass
+
+    @property
+    def args(self):
+        return []
+
+    @property
+    def symbols_defined(self):
+        return set()
+
+    @property
+    def undefined_symbols(self):
+        return set()
+
+    def __str__(self):
+        return ""
+
+    def __repr__(self):
+        return self.__str__()
diff --git a/pystencils/backends/cbackend.py b/pystencils/backends/cbackend.py
index 5616a724..4b077651 100644
--- a/pystencils/backends/cbackend.py
+++ b/pystencils/backends/cbackend.py
@@ -251,6 +251,12 @@ class CBackend:
     def _print_CustomCodeNode(self, node):
         return node.get_code(self._dialect, self._vector_instruction_set)
 
+    def _print_SourceCodeComment(self, node):
+        return "/* " + node.text + " */"
+
+    def _print_EmptyLine(self, node):
+        return ""
+
     def _print_Conditional(self, node):
         cond_type = get_type_of_expression(node.condition_expr)
         if isinstance(cond_type, VectorType):
diff --git a/pystencils_tests/test_source_code_comment.py b/pystencils_tests/test_source_code_comment.py
new file mode 100644
index 00000000..28b6768b
--- /dev/null
+++ b/pystencils_tests/test_source_code_comment.py
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright © 2019 Stephan Seitz <stephan.seitz@fau.de>
+#
+# Distributed under terms of the GPLv3 license.
+
+"""
+
+"""
+import pystencils
+import pystencils.astnodes
+
+
+def test_source_code_comment():
+
+    a, b = pystencils.fields('a,b: float[2D]')
+
+    assignments = pystencils.AssignmentCollection(
+        {a.center(): b[0, 2] + b[0, 0]}, {}
+    )
+
+    ast = pystencils.create_kernel(assignments, target='cpu')
+
+    ast.body.append(pystencils.astnodes.SourceCodeComment("Hallo"))
+    ast.body.append(pystencils.astnodes.EmptyLine())
+    ast.body.append(pystencils.astnodes.SourceCodeComment("World!"))
+    print(ast)
+    compiled = ast.compile()
+    assert compiled is not None
+    print(pystencils.show_code(ast))
+
+
+def main():
+    test_source_code_comment()
+
+
+if __name__ == '__main__':
+    main()
-- 
GitLab