def setUp(self): super(TestForwardDeclaration, self).setUp() name = type(self).__name__ src = Source(name.lower() + ".c") a = Structure("A") a.append_field(Pointer(a)("next")) b = Structure("B") b.append_field(Pointer(a)("next")) src.add_types([a, b]) src_content = """\ /* {} */ typedef struct A A; struct A {{ A *next; }}; typedef struct B {{ A *next; }} B; """.format(src.path) self.files = [(src, src_content)]
def setUp(self): super(TestCrossDeclaration, self).setUp() src = Source(type(self).__name__.lower() + ".c") a = Structure("A") b = Structure("B") b.append_field(Pointer(a)("ref")) a.append_field(Pointer(b)("ref")) src.add_types([a, b]) src_content = """\ /* {} */ typedef struct B B; typedef struct A {{ B *ref; }} A; struct B {{ A *ref; }}; """.format(src.path) self.files = [(src, src_content)]
def setUp(self): super(TestEnumerations, self).setUp() name = type(self).__name__ try: h = Header["enums.h"] except: h = Header("enums.h") h.add_type(Enumeration([("EXT", 1)])) src = Source(name.lower() + ".c").add_types([ Enumeration([("ONE", 1)]), Enumeration([("TWO", 2)], enum_name="A"), Enumeration([("THREE", 3)], typedef_name="B"), Enumeration([("FOUR", 4)], enum_name="C", typedef_name="D") ]) a = Type["int"]("a") b = Type["int"]("b") c = Type["A"]("c") d = Type["B"]("d") e = Type["D"]("e") src.add_types([ Function(name="main", body=BodyTree()(Declare(a, b), OpAssign(a, Type["EXT"]), OpAssign(b, Type["ONE"]), Declare(c), OpAssign(c, Type["TWO"]), Declare(d), OpAssign(d, Type["THREE"]), Declare(e), OpAssign(e, Type["FOUR"]))) ]) src_content = """\ /* {} */ #include "enums.h" enum A {{ TWO = 2 }}; typedef enum {{ THREE = 3 }} B; typedef enum C {{ FOUR = 4 }} D; enum {{ ONE = 1 }}; void main(void) {{ int a, b; a = EXT; b = ONE; enum A c; c = TWO; B d; d = THREE; D e; e = FOUR; }} """.format(src.path) self.files = [(src, src_content)]