예제 #1
0
 def test_variable(self):
     result = self.translate(
         model.VariableExp(model.Identifier("var_name"),
                           model.IntegerType()))
     self.assertIsInstance(result, code.SimpleVariable)
     self.assertIsInstance(result.id, code.Identifier)
     self.assertEqual(result.id.name, "var_name")
예제 #2
0
 def test_tupletype(self):
     result = self.translate(
         model.TupleType([model.IntegerType(),
                          model.FloatType()]))
     self.assertIsInstance(result, code.TupleType)
     self.assertIsInstance(result.types[0], code.IntegerType)
     self.assertIsInstance(result.types[1], code.FloatType)
예제 #3
0
 def test_assign_stmt(self):
     result = self.translate(
         model.AssignStmt(
             model.VariableExp(model.Identifier("var_name"),
                               model.IntegerType()),
             model.IntegerLiteralExp(456)))
     self.assertIsInstance(result, code.Assign)
     self.assertIsInstance(result.operand, code.VariableDecl)
     self.assertIsInstance(result.expression, code.IntegerLiteral)
예제 #4
0
 def test_filled_block_stmt(self):
     result = self.translate(
         model.BlockStmt([
             model.AssignStmt(
                 model.VariableExp(model.Identifier("var_name"),
                                   model.IntegerType()),
                 model.IntegerLiteralExp(456))
         ]))
     self.assertEqual(len(result), 1)
     self.assertIsInstance(result[0], code.Assign)
예제 #5
0
 def test_simple_types(self):
     self.assertIsInstance(self.translate(model.VoidType()), code.VoidType)
     self.assertIsInstance(self.translate(model.IntegerType()),
                           code.IntegerType)
     self.assertIsInstance(self.translate(model.FloatType()),
                           code.FloatType)
     self.assertIsInstance(self.translate(model.LongType()), code.LongType)
     self.assertIsInstance(self.translate(model.ByteType()), code.ByteType)
     self.assertIsInstance(self.translate(model.BooleanType()),
                           code.BooleanType)
예제 #6
0
 def test_function_with_params_and_body(self):
     result = self.translate(
         model.FunctionDecl(model.BlockStmt([
             model.AssignStmt(
                 model.VariableExp(model.Identifier("var_name"),
                                   model.IntegerType()),
                 model.IntegerLiteralExp(456))
         ]),
                            type=model.VoidType(),
                            parameters=[
                                model.Parameter(
                                    model.Identifier("var_name"),
                                    model.IntegerType())
                            ]))
     self.assertIsInstance(result, code.Function)
     self.assertIsInstance(result.type, code.VoidType)
     self.assertEqual(len(result), 1)
     self.assertEqual(len(result.params), 1)
     self.assertIsInstance(result.children[0], code.Assign)
     self.assertEqual(result.params[0].name, "var_name")
     self.assertIsInstance(result.params[0].type, code.IntegerType)
예제 #7
0
 def test_nested_manytypes(self):
     result = self.translate(
         model.ManyType(model.ManyType(model.IntegerType())))
     self.assertIsInstance(result, code.ManyType)
     self.assertIsInstance(result.type, code.ManyType)
     self.assertIsInstance(result.type.type, code.IntegerType)