Exemplo n.º 1
0
 def get_members_with_name(self, name):
     res = []
     for x in InheritanceType.getTypes():
         for y in self.attributes[x] + self.methods[x]:
             if y.name == name:
                 res.append(y)
     return res
Exemplo n.º 2
0
def __check_visibility_type(line, inheritance_type):
    for inherit_id in InheritanceType.getTupleOfTypes():
        if inherit_id[1] in line:
            line = line.replace(inherit_id[1], "")
            inheritance_type = inherit_id[0]
            break
    return line, inheritance_type
Exemplo n.º 3
0
    def __solve_using_statement(self, attribute):
        cls = self.get_parent_class(attribute.inheritance_class_id)
        if not cls:
            raise BaseClsException("Given parent class " +
                                   attribute.inheritance_class_id +
                                   " was not found")

        parent_attr, access_modifier = cls.get_attribute(attribute.name)

        # remove the old reference from list, default location is private
        self.attributes[InheritanceType.private] = list(
            filter(lambda x: attribute.name != x.name,
                   self.attributes[InheritanceType.private]))

        # now copy all useful info into subclass parameter
        attribute.type = parent_attr.type
        attribute.is_static = parent_attr.is_static
        attribute.inherit_from = parent_attr.inherit_from

        # now remove all other mambers with the same name
        for x in InheritanceType.getTypes():
            self.attributes[x] = list(
                filter(lambda x: attribute.name != x.name, self.attributes[x]))
            self.methods[x] = list(
                filter(lambda x: attribute.name != x.name, self.methods[x]))

        self.attributes[access_modifier].append(attribute)
Exemplo n.º 4
0
def parse_inheritance_type(cls):
    inherit_type = None
    if " " in cls:
        tmp = cls.split(" ")
        inherit_type = InheritanceType.getTypeFromString(tmp[0])
        cls = tmp[1]
    else:
        inherit_type = InheritanceType.private

    return inherit_type, cls
Exemplo n.º 5
0
 def check_conflicts(self):
     for x in InheritanceType.getTypes():
         for y in self.attributes[x] + self.methods[x]:
             others = self.get_members_with_name(y.name)
             if len(others) != 1:
                 methods = list(
                     filter(lambda x: isinstance(x, Method), others))
                 for method in methods:
                     if not method.is_virtual:
                         raise BaseClsException(
                             "Inheritance conflict with member " + y.name)
Exemplo n.º 6
0
    def check_pure_virtual_methods(self):
        for access_modifier in InheritanceType.getTypes():
            for y in self.methods[access_modifier]:
                if y.is_pure_virtual:
                    members_with_same_name = self.get_members_with_name(y.name)
                    methods_with_same_name = list(
                        filter(lambda x: isinstance(x, Method),
                               members_with_same_name))
                    if len(methods_with_same_name) >= 2:

                        # get rid of those inherited pure virtual methods
                        for method in methods_with_same_name:
                            if not method.is_pure_virtual and method.type == y.type:
                                # if the method is virtual, but not pure virtual and has the same return type, than we found implementation of pure virtual method, so the class may no longer be abstract
                                self.__remove_pure_virtual_method(
                                    method.name, access_modifier)
                                self.check_abstract_x_concrete()
Exemplo n.º 7
0
    def show_details(self, output=None, root=None, indent_size=4):

        elem = self.__prepare_class_header()
        if self.inherit:
            inherit_elem = etree.Element("inheritance")
            for cls in self.inherit:
                cls_elem = etree.Element("from")
                cls_elem.attrib["name"] = cls[1]
                cls_elem.attrib["privacy"] = InheritanceType.getStringForType(
                    cls[0])
                inherit_elem.append(cls_elem)
            elem.append(inherit_elem)

        for type, str_repr in ((x, InheritanceType.getStringForType(x))
                               for x in InheritanceType.getTypes()):

            inner_elem = etree.Element(str_repr)
            not_empty = False

            for i in (self.attributes, "attributes"), (self.methods,
                                                       "methods"):

                if i[0][type]:
                    if not not_empty:
                        not_empty = True

                    tmp = etree.Element(i[1])
                    inner_elem.append(tmp)
                    for attr in i[0][type]:
                        a = etree.Element(i[1][:-1])
                        a.attrib["name"] = attr.name
                        a.attrib["type"] = attr.type
                        a.attrib[
                            "scope"] = "class" if attr.is_static else "instance"
                        if attr.inheritance_class_id:
                            a.append(
                                etree.Element(
                                    "from",
                                    {"name": attr.inheritance_class_id}))
                        elif attr.inherit_from:
                            a.append(
                                etree.Element("from",
                                              {"name": attr.inherit_from}))
                        if i[1] == "methods":
                            if attr.is_virtual:
                                virtual_elem = etree.Element(
                                    "virtual", {
                                        "pure":
                                        "yes" if attr.is_pure_virtual else "no"
                                    })
                                a.append(virtual_elem)

                            arguments = etree.Element("arguments")
                            if attr.params:
                                for param in attr.params:
                                    param_element = etree.Element(
                                        "argument", {
                                            "name": param[1],
                                            "type": param[0]
                                        })
                                    arguments.append(param_element)
                            a.append(arguments)

                        tmp.append(a)

            if not_empty:
                elem.append(inner_elem)

        # attrs, methods = self.get_inherited_members()

        if root == None:
            return prepare_xml_from_elem_tree(elem,
                                              indent_size,
                                              True,
                                              output=output)
        else:
            root.append(elem)