Esempio n. 1
0
def new_composed(self, ast, current_block):
    ast.set(nodes.BlockStmt([]))
    current_block.ref = ast
    parent = self.rule_nodes.parents
    if 'current_block' in parent:
        current_block.ref.types = parent['current_block'].ref.types.new_child()
    return True
Esempio n. 2
0
def new_blockstmt(self, ast, current_block):
    ast.set(nodes.BlockStmt([]))
    current_block.ref = ast
    parent = self.rule_nodes.parents
    if (('current_block' in parent
         and hasattr(parent['current_block'].ref, 'types'))):
        current_block.ref.types = parent['current_block'].ref.types.new_child()
    return True
Esempio n. 3
0
 def test_03_basicstmt(self):
     """Test cnorm statement nodes"""
     c = nodes.Binary(nodes.Raw('<'), [nodes.Id('a'), nodes.Literal('12')])
     thencond = nodes.ExprStmt(
         nodes.Binary(nodes.Raw('='),
                      [nodes.Id('b'), nodes.Literal('1')]))
     elsecond = nodes.ExprStmt(
         nodes.Binary(nodes.Raw('='),
                      [nodes.Id('c'), nodes.Literal('2')]))
     s = nodes.If(c, thencond, elsecond)
     self.assertEqual(
         str(s.to_c()),
         "if (a < 12)\n{tab}b = 1;\nelse\n{tab}c = 2;\n".format(tab=" " *
                                                                4),
         "Failed to convert to C")
     s = nodes.RootBlockStmt(
         [thencond,
          nodes.BlockStmt([thencond, elsecond]), elsecond])
     self.assertEqual(
         str(s.to_c()),
         "b = 1;\n{{\n{tab}b = 1;\n{tab}c = 2;\n}}\nc = 2;\n".format(
             tab=" " * 4), "Failed to convert to C")
     s = nodes.While(c, thencond)
     self.assertEqual(str(s.to_c()),
                      "while (a < 12)\n{tab}b = 1;\n".format(tab=" " * 4),
                      "Failed to convert to C")
     s = nodes.Do(c, thencond)
     self.assertEqual(
         str(s.to_c()),
         "do\n{tab}b = 1;\nwhile (a < 12);\n".format(tab=" " * 4),
         "Failed to convert to C")
     s = nodes.Return(c)
     self.assertEqual(str(s.to_c()), "return a < 12;\n",
                      "Failed to convert to C")
     s = nodes.Goto(c)
     self.assertEqual(str(s.to_c()), "goto a < 12;\n",
                      "Failed to convert to C")
     s = nodes.Case(c)
     self.assertEqual(str(s.to_c()), "case a < 12:\n",
                      "Failed to convert to C")
     s = nodes.Label("Cool")
     self.assertEqual(str(s.to_c()), "Cool:\n", "Failed to convert to C")
     s = nodes.Switch(c, thencond)
     self.assertEqual(str(s.to_c()),
                      "switch (a < 12)\n{tab}b = 1;\n".format(tab=" " * 4),
                      "Failed to convert to C")
     init = nodes.ExprStmt(
         nodes.Binary(nodes.Raw('='),
                      [nodes.Id('b'), nodes.Literal('0')]))
     cond = nodes.ExprStmt(c)
     inc = nodes.Binary(nodes.Raw('+='),
                        [nodes.Id('b'), nodes.Literal('1')])
     s = nodes.For(init, cond, inc, thencond)
     self.assertEqual(
         str(s.to_c()),
         "for (b = 0; a < 12; b += 1)\n{tab}b = 1;\n".format(tab=" " * 4),
         "Failed to convert to C")
Esempio n. 4
0
def new_member(self, ast, current_block):
    ast.set(nodes.BlockStmt([]))
    current_block.ref = ast
    parent = self.rule_nodes.parents
    if 'current_block' in parent:
        current_block.ref.types = parent['current_block'].ref.types.new_child()
    # if "name" == init
    # creer fonction new
    return True