Example #1
0
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))
Example #2
0
 def visit_Str(self, node):
     return String(node.s)
Example #3
0
 def visit_GeneratedPathRef(self, node):
     self.count += 1
     return String(os.path.join(self.compilation_dir, node.target.get_filename()))
Example #4
0
 def test_string_none(self):
     self.assertEqual(str(String()), '""')
Example #5
0
 def test_string_multi_three(self):
     self.assertEqual(str(String("foo", "bar", "baz")), '"foo" "bar" "baz"')
Example #6
0
 def test_string_multi_two(self):
     self.assertEqual(str(String("foo", "bar")), '"foo" "bar"')
Example #7
0
 def test_string_tab(self):
     self.assertEqual(str(String(r"\t")), r'"\t"')
Example #8
0
 def test_string_newline(self):
     self.assertEqual(str(String(r"\n")), r'"\n"')
Example #9
0
 def test_string_empty(self):
     self.assertEqual(str(String("")), '""')
Example #10
0
 def test_string_full(self):
     self.assertEqual(str(String("foo")), '"foo"')
Example #11
0
 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()
Example #12
0
 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!");')
Example #13
0
 def visit_SymbolRef(self, node):
     return String(node.name)