Source code for ctree.cpp.codegen

"""
Code generation for C preprocessing directives.
"""

from ctree.codegen import CodeGenVisitor


[docs]class CppCodeGen(CodeGenVisitor): """ Visitor to generate C preprocessor directives. """
[docs] def visit_CppInclude(self, node): if node.angled_brackets: return "#include <%s>" % node.target else: return '#include "%s"' % node.target
[docs] def visit_CppComment(self, node): return "// " + ("\n" + self._tab() + "// ").join( node.text.splitlines())
[docs] def visit_CppDefine(self, node): params = ", ".join(map(str, node.params)) return "#define %s(%s) (%s)" % (node.name, params, node.body)