예제 #1
0
 def test_structured_type_tagging(self):
     section = Section("test")
     struct = code.StructuredType("something")
     struct.tag("struct_something")
     section.append(struct)
     section.select("struct_something").append(
         code.Property("prop1", code.FloatType()))
     self.assertEqualToSource(
         struct,
         "typedef struct something_t {\nfloat prop1;\n} something_t;")
예제 #2
0
    def test_struct_with_property(self):
        tree = code.StructuredType("my_struct").contains(
            code.Property("test1", code.ManyType(code.ByteType())),
            code.Property("test2", code.ManyType(code.IntegerType())))
        self.assertEqualToSource(
            tree, """
typedef struct my_struct_t {
char* test1;
int* test2;
} my_struct_t;""")
예제 #3
0
    def prepare(self):
        """
    Prepares the definition of the node type.
    """
        # this is a generator for the Nodes domain, let's get it ;-)
        self.domain = SemanticNodes()

        # we need a translator
        self.translator = Translator()

        node_type = code.StructuredType("nodes").tag("node_type_def")
        node_type.append(code.Comment("domain properties"),
                         code.Property("id", code.ByteType()),
                         code.Property("address", code.LongType()))

        # the node type
        module = self.generator.unit.append(structure.Module("node_t"))
        module.select("def").append(code.Import("moose/bool"))

        module.select("def").append(code.Comment("THE node type"),
                                    node_type).tag("node_t-start")

        # provide init_node to initialise module-specific properties
        module.select("dec").append(
            code.Import("node_t"),
            code.Function("init_node",
                          params=[
                              code.Parameter("node",
                                             type=code.ObjectType("node"))
                          ]).tag("init_node")  # filled when creating node_t
        )

        # TODO: remove this redundant header file
        module = self.generator.unit.append(structure.Module("nodes"))
        module.select("def").append(code.Import("includes"))

        # add more imports to includes
        anchor = self.generator.unit.select("includes").select("def").find(
            "foo-lib-start")
        code.Import("nodes").insert_before(anchor).tag("requires-tuples")
        code.Import("node_t").insert_before(anchor)
        code.Import("foo-lib/nodes").insert_before(anchor)
        code.Import("foo-lib/payload").insert_before(anchor)

        # initialiase nodes and add handling of receive packets
        self.generator.unit.find("init").append(
            code.FunctionCall("nodes_init"),
            code.FunctionCall("mesh_on_receive",
                              [code.SimpleVariable("payload_parser_parse")]))
예제 #4
0
 def test_append_property_to_structured_type(self):
     struct = code.StructuredType("something")
     struct.append(code.Property("prop1", code.FloatType()))
     self.assertEqualToSource(
         struct,
         "typedef struct something_t {\nfloat prop1;\n} something_t;")
예제 #5
0
 def test_empty_structured_type(self):
     struct = code.StructuredType("something")
     self.assertEqualToSource(
         struct, "typedef struct something_t {\n\n} something_t;")