Beispiel #1
0
 def process_array_files(self, array_file_list):
     for array_file in array_file_list:
         array_file = search_for_file("Array", array_file)
         array_model = XmlArrayParser.XmlArrayParser(array_file)
         # process any XML includes
         self.process_enum_files(array_model.get_include_enum_files())
         self.process_array_files(array_model.get_include_array_files())
         self.process_serializable_files(array_model.get_includes())
         array_type = array_model.get_namespace(
         ) + "::" + array_model.get_name()
         array_size = int(array_model.get_size())
         elem_type = array_model.get_type()
         elem_type_size = None
         if type(elem_type) == type(tuple()):
             elem_type_size = 4  # Fixme: can we put this in a constant somewhere?
         elif elem_type in self.size_dict.keys(
         ):  # See if it is a registered type
             elem_type_size = self.size_dict[elem_type]
         else:
             elem_type_size = self.get_type_size(elem_type,
                                                 1)  # Fixme: strings?
         if elem_type_size is None:
             print("Illegal type %s in array %s" % (elem_type, array_type))
             sys.exit(-1)
         self.add_type_size(array_type, elem_type_size * array_size)
Beispiel #2
0
    def check_for_arrays(self):
        array_file_list = self.__parsed_xml_dict[
            self.__comp_type].get_array_type_files()
        if array_file_list is not None:
            for array_file in array_file_list:
                array_file = search_for_file("Array", array_file)
                array_model = XmlArrayParser.XmlArrayParser(array_file)
                array_elem = etree.Element("array")

                array_name = array_model.get_namespace(
                ) + "::" + array_model.get_name()
                array_elem.attrib["name"] = array_name

                array_type = array_model.get_type()
                array_elem.attrib["type"] = array_type

                array_type_id = array_model.get_type_id()
                array_elem.attrib["type_id"] = array_type_id

                array_size = array_model.get_size()
                array_elem.attrib["size"] = array_size

                array_format = array_model.get_format()
                array_elem.attrib["format"] = array_format

                members_elem = etree.Element("defaults")
                for d_val in array_model.get_default():
                    member_elem = etree.Element("default")
                    member_elem.attrib["value"] = d_val
                    members_elem.append(member_elem)

                array_elem.append(members_elem)

                dup = False
                for arr in self.__array_list:
                    if arr.attrib["name"] == array_elem.attrib["name"]:
                        dup = True
                if not dup:
                    self.__array_list.append(array_elem)
Beispiel #3
0
def generate_array(xml_file):
    """
    Produce a *Ac.hpp, *Ac.cpp, and *.py files for serializable arrays.
    Return True if xml file was an array, otherwise return False and
    generate nothing.
    """
    xml = XmlParser.XmlParser(xml_file)
    if xml() == "array":
        #
        # Parse array xml here
        #
        array_xml = XmlArrayParser.XmlArrayParser(xml_file)
        name = array_xml.get_name()
        namespace = array_xml.get_namespace()
        arr_type = array_xml.get_type()
        arr_typeinfo = array_xml.get_typeinfo()
        arr_size = int(array_xml.get_size())
        format_string = array_xml.get_format()
        default_values = array_xml.get_default()
        type_id = array_xml.get_type_id()
        string_size = array_xml.get_string_size()
        if string_size:
            string_size = int(string_size)
        comment = array_xml.get_comment()
        include_headers = array_xml.get_include_header_files()
        import_serializables = array_xml.get_includes()
        import_enums = array_xml.get_include_enum_files()
        import_arrays = array_xml.get_include_array_files()
        include_path = array_xml.get_include_path()

        # Set up imports
        headers = []
        for h in include_headers:
            headers.append(h.replace("Ai.xml", "Ac.hpp"))

        serials = []
        for s in import_serializables:
            serials.append(s.replace("Ai.xml", "Ac.hpp"))

        enums = []
        for e in import_enums:
            enums.append(e.replace("Ai.xml", "Ac.hpp"))

        arrays = []
        for a in import_arrays:
            arrays.append(a.replace("Ai.xml", "Ac.hpp"))

        #
        # Generate the hpp file
        #
        fp = open_file(name, "hpp")
        c = array_hpp.array_hpp()
        write_template(
            fp,
            c,
            name,
            namespace,
            arr_type,
            arr_typeinfo,
            arr_size,
            format_string,
            default_values,
            type_id,
            string_size,
            include_path,
            comment,
            headers,
            serials,
            enums,
            arrays,
        )
        fp.close()
        #
        # Generate the cpp file
        #
        fp = open_file(name, "cpp")
        c = array_cpp.array_cpp()
        write_template(
            fp,
            c,
            name,
            namespace,
            arr_type,
            arr_typeinfo,
            arr_size,
            format_string,
            default_values,
            type_id,
            string_size,
            include_path,
            comment,
            headers,
            serials,
            enums,
            arrays,
        )
        fp.close()
        return True
    else:
        return False