Beispiel #1
0
 def test_cast_to_parent(self):
     """ Testing for a simple cast where the field is in the struct """
     void_ptr = mtypes.MyriadScalar("self",
                                    mtypes.MVoid,
                                    True,
                                    quals=["const"])
     double_val = mtypes.MyriadScalar("val", mtypes.MDouble)
     myriad_class = mtypes.MyriadStructType(
         "MyriadClass", OrderedDict({
             0: void_ptr,
             1: double_val
         }))
     self.assertEqual("(struct MyriadClass*)",
                      mtypes.cast_to_parent(myriad_class, "val"))
Beispiel #2
0
 def test_qual_scalar(self):
     """ Testing qualified scalar creation """
     void_ptr = mtypes.MyriadScalar("self",
                                    mtypes.MVoid,
                                    True,
                                    quals=["const"])
     self.assertEqual("const void *self", void_ptr.stringify_decl())
Beispiel #3
0
 def test_cast_to_parent_nested(self):
     """ Testing for a cast with 1 level of recursion """
     void_ptr = mtypes.MyriadScalar("self",
                                    mtypes.MVoid,
                                    True,
                                    quals=["const"])
     double_val = mtypes.MyriadScalar("val", mtypes.MDouble)
     myriad_class = mtypes.MyriadStructType("MyriadClass",
                                            OrderedDict({0: void_ptr}))
     class_m = myriad_class("_", quals=["const"])
     toplevel_struct = mtypes.MyriadStructType(
         "toplevel", OrderedDict({
             0: class_m,
             1: double_val
         }))
     self.assertEqual("(struct MyriadClass*)",
                      mtypes.cast_to_parent(toplevel_struct, "self"))
Beispiel #4
0
 def test_void_ret_function(self):
     """ Testing for functions with void return types """
     void_ptr = mtypes.MyriadScalar("self",
                                    mtypes.MVoid,
                                    True,
                                    quals=["const"])
     myriad_dtor = mtypes.MyriadFunction("dtor", OrderedDict({0: void_ptr}))
     self.assertEqual("void dtor(const void *self)",
                      myriad_dtor.stringify_decl())
Beispiel #5
0
 def test_struct_nesting(self):
     """ Testing basic struct nesting """
     void_ptr = mtypes.MyriadScalar("self",
                                    mtypes.MVoid,
                                    True,
                                    quals=["const"])
     double_val = mtypes.MyriadScalar("val", mtypes.MDouble)
     myriad_class = mtypes.MyriadStructType("MyriadClass",
                                            OrderedDict({0: void_ptr}))
     class_m = myriad_class("class_m", quals=["const"])
     toplevel_struct = mtypes.MyriadStructType(
         "toplevel", OrderedDict({
             0: class_m,
             1: double_val
         }))
     expected_result = \
         "struct toplevel { const struct MyriadClass class_m; double val; }"
     str_result = toplevel_struct.stringify_decl().replace('\n', ' ')
     self.assertEqual(trim_spaces(expected_result), trim_spaces(str_result))
Beispiel #6
0
 def test_function_typedef(self):
     """ Testing function typedef generation """
     void_ptr = mtypes.MyriadScalar("self",
                                    mtypes.MVoid,
                                    True,
                                    quals=["const"])
     dtor = mtypes.MyriadFunction("dtor", OrderedDict({0: void_ptr}))
     dtor.gen_typedef()
     self.assertEqual("typedef void (*dtor_t)(const void *self)",
                      dtor.stringify_typedef())
Beispiel #7
0
 def test_array_full(self):
     """ Testing arrays with qualifiers, storage specifies, and dim IDs """
     my_arr = mtypes.MyriadScalar(ident="my_arr",
                                  base_type=mtypes.MDouble,
                                  ptr=False,
                                  quals=["const"],
                                  storage=["static"],
                                  arr_id="SIMUL_LEN")
     self.assertEqual("static const double my_arr[SIMUL_LEN]",
                      my_arr.stringify_decl())
Beispiel #8
0
 def test_struct_qual(self):
     """ Testing making a struct having a qualifier """
     void_ptr = mtypes.MyriadScalar("self",
                                    mtypes.MVoid,
                                    True,
                                    quals=["const"])
     myriad_class = mtypes.MyriadStructType("MyriadClass",
                                            OrderedDict({0: void_ptr}))
     class_m = myriad_class("class_m", quals=["const"])
     self.assertEqual("const struct MyriadClass class_m",
                      class_m.stringify_decl())
Beispiel #9
0
 def test_struct_ptr(self):
     """ Testing having a struct pointer variable """
     void_ptr = mtypes.MyriadScalar("self",
                                    mtypes.MVoid,
                                    True,
                                    quals=["const"])
     myriad_class = mtypes.MyriadStructType("MyriadClass",
                                            OrderedDict({0: void_ptr}))
     class_2 = myriad_class("class_2", ptr=True)
     self.assertEqual(trim_spaces("struct MyriadClass *class_2"),
                      trim_spaces(class_2.stringify_decl()))
Beispiel #10
0
 def test_single_member_struct(self):
     """ Testing having a struct with single member """
     void_ptr = mtypes.MyriadScalar("self",
                                    mtypes.MVoid,
                                    True,
                                    quals=["const"])
     myriad_class = mtypes.MyriadStructType("MyriadClass",
                                            OrderedDict({0: void_ptr}))
     str1 = myriad_class.stringify_decl().replace('\n', ' ')
     str2 = "struct MyriadClass {   const void *self; }"
     self.assertEqual(trim_spaces(str1), trim_spaces(str2))
Beispiel #11
0
 def test_create_delegator(self):
     """ Testing if creating delegators works """
     # Create scalars and function
     args_list = OrderedDict()
     args_list["self"] = myriad_types.MyriadScalar("_self",
                                                   myriad_types.MVoid,
                                                   ptr=True)
     args_list["mechanism"] = myriad_types.MyriadScalar("mechanism",
                                                        myriad_types.MVoid,
                                                        ptr=True)
     instance_fxn = myriad_types.MyriadFunction(
         "add_mech", args_list,
         myriad_types.MyriadScalar("_", myriad_types.MInt), ["static"])
     # Generate delegator
     classname = "Compartment"
     result_fxn = myriad_metaclass.create_delegator(instance_fxn, classname)
     # Compare result strings
     expected_result = """
     int64_t add_mech(void *_self, void *mechanism)
     {
     return add_mech_vtable[((struct MyriadObject*) obj)->class_id](self, mechanism);
     }
     """
     self.assertTrimStrEquals(str(result_fxn), expected_result)
Beispiel #12
0
 def test_create_super_delegator(self):
     """ Testing if creating super delegator functions works """
     void_ptr = myriad_types.MyriadScalar("self",
                                          myriad_types.MVoid,
                                          True,
                                          quals=["const"])
     myriad_dtor = myriad_types.MyriadFunction("dtor",
                                               OrderedDict({0: void_ptr}))
     classname = "Compartment"
     super_delg = myriad_metaclass.create_super_delegator(
         myriad_dtor, classname)
     # Compare result strings
     expected_result = """
     void super_dtor(const int64_t _class, const void *self)
     {
     dtor_vtable[_class](self);
     return;
     }
     """
     self.assertTrimStrEquals(str(super_delg), expected_result)