def printf(fmt, *args): """ Makes a printf call. Args must be CtreeNodes. """ for arg in args: assert isinstance(arg, CtreeNode) return FunctionCall(SymbolRef("printf"), [String(fmt)] + list(args))
def visit_Str(self, node): return String(node.s)
def visit_GeneratedPathRef(self, node): self.count += 1 return String(os.path.join(self.compilation_dir, node.target.get_filename()))
def test_string_none(self): self.assertEqual(str(String()), '""')
def test_string_multi_three(self): self.assertEqual(str(String("foo", "bar", "baz")), '"foo" "bar" "baz"')
def test_string_multi_two(self): self.assertEqual(str(String("foo", "bar")), '"foo" "bar"')
def test_string_tab(self): self.assertEqual(str(String(r"\t")), r'"\t"')
def test_string_newline(self): self.assertEqual(str(String(r"\n")), r'"\n"')
def test_string_empty(self): self.assertEqual(str(String("")), '""')
def test_string_full(self): self.assertEqual(str(String("foo")), '"foo"')
def test_file_template_dotgen(self): from ctree.c.nodes import String path = os.path.join(*(fixtures.__path__ + ["templates", "printf.tmpl.c"])) tree = FileTemplate(path, {'fmt': String('Hello, world!')}) tree.to_dot()
def test_simple_file_template(self): from ctree.c.nodes import String path = os.path.join(*(fixtures.__path__ + ["templates", "printf.tmpl.c"])) tree = FileTemplate(path, {'fmt': String('Hello, world!')}) self._check(tree, 'printf("Hello, world!");')
def visit_SymbolRef(self, node): return String(node.name)