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