Esempio n. 1
0
    def process(self, root, file_id, context, allows_protected, namer):
        count0 = len(self.values)
        se_count0 = len(self.scoped_enums)

        q = ".//Enumeration[@file='%s'][@context='%s']" % (file_id, context)

        for enum in root.findall(q):
            access = Access.access_type(enum)
            if access == Access.PRIVATE:
                continue

            if access == Access.PROTECTED and not allows_protected:
                continue

            ns_prefix = Util.context_of(enum, root)
            if ns_prefix:
                ns_prefix += "::"

            if enum.attrib.get("scoped") == "1":
                se = ScopedEnum(enum.attrib["name"],
                                ns_prefix + enum.attrib["name"])

                for v in enum.findall("EnumValue"):
                    name = v.attrib["name"]
                    cppv = "%s::%s" % (se.full_name, name)
                    se.values[namer.to_python(name)] = cppv

                self.scoped_enums[se.name] = se
            else:
                for v in enum.findall("EnumValue"):
                    name = v.attrib["name"]
                    self.values[namer.to_python(name)] = ns_prefix + name

        return len(self.values) > count0 or len(self.scoped_enums) > se_count0
Esempio n. 2
0
    def _fields(self):
        for fnode in self.root.findall("Field[@context='%s']" % self.node.attrib["id"]):
            access_type = Access.access_type(fnode)

            if access_type == Access.PRIVATE:
                continue

            if access_type == Access.PROTECTED and not self.allows_subclassing():
                continue

            name = fnode.attrib["name"]

            # union
            if not name:
                continue

            if self.blacklist.field(self.full_name, name):
                full_name = self.full_name + "::" + name
                Session.ignored_fields.add(full_name)
                continue

            t = Types.get_type_by_id(fnode.attrib["type"], self.root)
            f = Argument.Argument(t, name)
            self.fields.append(f)

            if access_type == Access.PROTECTED:
                self.protected_nonvirtual_members.add("using %s::%s;" % (
                    self.full_name, f.raw_name
                ))
Esempio n. 3
0
    def _constructors(self):
        # If no copy constructor defined, the class is not copyable,
        # which is ensured by Clang's semantic checking
        # TODO: public copy assignment operator
        copy_ctor_args_sig = "(const %s &)" % self.full_name
        copy_ctor_args_sig_no_const = "(%s &)" % self.full_name
        has_public_copy_ctor = False

        for ctor in self.root.findall("Constructor[@context='%s']" % self.node.attrib["id"]):
            access = Access.access_type(ctor)

            if (ctor.attrib["demangled"].endswith(copy_ctor_args_sig) or
                ctor.attrib["demangled"].endswith(copy_ctor_args_sig_no_const)):
                # It is meaningless to copy an object whose class defines a proctected
                # copy constructor in the API code we are dealing with
                if access == Access.PUBLIC:
                    has_public_copy_ctor = True

            if access != Access.PRIVATE:
                if not self.blacklist.method(ctor.attrib["demangled"]):
                    self._constructor(ctor)

                    if access == Access.PROTECTED:
                        self.has_protected_ctor = True
                else:
                    Session.ignored_methods.add(ctor.attrib["demangled"])

        if len(self.ctors) == 0:
            self.no_accessible_canonical_ctors = True

        self.has_public_copy_ctor = has_public_copy_ctor
Esempio n. 4
0
    def _constructors(self):
        # If no copy constructor defined, the class is not copyable,
        # which is ensured by Clang's semantic checking
        # TODO: public copy assignment operator
        copy_ctor_args_sig = "(const %s &)" % self.full_name
        copy_ctor_args_sig_no_const = "(%s &)" % self.full_name
        has_public_copy_ctor = False

        for ctor in self.root.findall("Constructor[@context='%s']" %
                                      self.node.attrib["id"]):
            access = Access.access_type(ctor)

            if (ctor.attrib["demangled"].endswith(copy_ctor_args_sig)
                    or ctor.attrib["demangled"].endswith(
                        copy_ctor_args_sig_no_const)):
                # It is meaningless to copy an object whose class defines a proctected
                # copy constructor in the API code we are dealing with
                if access == Access.PUBLIC:
                    has_public_copy_ctor = True

            if access != Access.PRIVATE:
                if not self.blacklist.method(ctor.attrib["demangled"]):
                    self._constructor(ctor)

                    if access == Access.PROTECTED:
                        self.has_protected_ctor = True
                else:
                    Session.ignored_methods.add(ctor.attrib["demangled"])

        if len(self.ctors) == 0:
            self.no_accessible_canonical_ctors = True

        self.has_public_copy_ctor = has_public_copy_ctor
Esempio n. 5
0
    def _fields(self):
        for fnode in self.root.findall("Field[@context='%s']" %
                                       self.node.attrib["id"]):
            access_type = Access.access_type(fnode)

            if access_type == Access.PRIVATE:
                continue

            if access_type == Access.PROTECTED and not self.allows_subclassing(
            ):
                continue

            name = fnode.attrib["name"]

            # union
            if not name:
                continue

            if self.blacklist.field(self.full_name, name):
                full_name = self.full_name + "::" + name
                Session.ignored_fields.add(full_name)
                continue

            t = Types.get_type_by_id(fnode.attrib["type"], self.root)
            f = Argument.Argument(t, name)
            self.fields.append(f)

            if access_type == Access.PROTECTED:
                self.protected_nonvirtual_members.add(
                    "using %s::%s;" % (self.full_name, f.raw_name))
Esempio n. 6
0
    def process(self, root, file_id, context, allows_protected, namer):
        count0 = len(self.values)
        se_count0 = len(self.scoped_enums)

        q = ".//Enumeration[@file='%s'][@context='%s']" % (file_id, context)

        for enum in root.findall(q):
            access = Access.access_type(enum)
            if access == Access.PRIVATE:
                continue

            if access == Access.PROTECTED and not allows_protected:
                continue

            ns_prefix = Util.context_of(enum, root)
            if ns_prefix:
                ns_prefix += "::"

            if enum.attrib.get("scoped") == "1":
                se = ScopedEnum(enum.attrib["name"], ns_prefix + enum.attrib["name"])

                for v in enum.findall("EnumValue"):
                    name = v.attrib["name"]
                    cppv = "%s::%s" % (se.full_name, name)
                    se.values[namer.to_python(name)] = cppv

                self.scoped_enums[se.name] = se
            else:
                for v in enum.findall("EnumValue"):
                    name = v.attrib["name"]
                    self.values[namer.to_python(name)] = ns_prefix + name

        return len(self.values) > count0 or len(self.scoped_enums) > se_count0
Esempio n. 7
0
    def __init__(self, root, node, free_function):
        self.name = node.attrib["name"]
        self.raw_sig = node.attrib["demangled"]

        self.free_function = free_function
        if not free_function:
            self.access = Access.access_type(node)
            self.virtual = node.attrib.get("virtual") == "1"
            self.final = node.attrib.get("final") == "1"
            self.pure_virtual = node.attrib.get("pure_virtual") == "1"
            self.static = node.attrib.get("static") == "1"

        self.args = TupleAndKeywords.TupleAndKeywords()
        for arg_node in node.findall("Argument"):
            self.args.add_parameter(Argument.from_xml(root, arg_node))

        self.returns = Types.get_type_by_id(node.attrib["returns"], root)
Esempio n. 8
0
    def __init__(self, root, node, free_function):
        self.name = node.attrib["name"]
        self.raw_sig = node.attrib["demangled"]

        self.free_function = free_function
        if not free_function:
            self.access = Access.access_type(node)
            self.virtual = node.attrib.get("virtual") == "1"
            self.final = node.attrib.get("final") == "1"
            self.pure_virtual = node.attrib.get("pure_virtual") == "1"
            self.static = node.attrib.get("static") == "1"

        self.args = TupleAndKeywords.TupleAndKeywords()
        for arg_node in node.findall("Argument"):
            self.args.add_parameter(Argument.from_xml(root, arg_node))

        self.returns = Types.get_type_by_id(node.attrib["returns"], root)
Esempio n. 9
0
    def _filter(root, mnode, allows_subclassing, blacklist):
        # always collect pure virtual functions
        if mnode.attrib.get("pure_virtual") == "1":
            return False

        if blacklist.method(mnode.attrib["demangled"]):
            Session.ignored_methods.add(mnode.attrib["demangled"])
            return True

        if MethodJar._filter_by_return_type(mnode, blacklist, root, Session.ignored_methods):
            return True

        maccess = Access.access_type(mnode)
        if not allows_subclassing and maccess != Access.PUBLIC:
            return True

        # private non-pure-virtuals will be handled later
        if maccess != Access.PRIVATE or mnode.attrib.get("virtual", None) == "1":
            return False

        # filter all the other
        return True
Esempio n. 10
0
    def _do_process_classes(self, context_id):
        for decl_type in ("Class", "Struct"):
            xpath = ".//%s[@file='%s'][@context='%s']" % (
                decl_type, self.current_file_id(), context_id
            )

            for cls_node in self.root.findall(xpath):
                full_name = cls_node.attrib["demangled"]

                if self.blacklist.klass(full_name):
                    Session.ignored_classes.add(full_name)
                    continue

                if full_name in self.blacklist.dummy_classes:
                    Session.dummy_classes.add(full_name)
                    continue

                if Access.access_type(cls_node) == Access.PRIVATE:
                    continue

                if cls_node.attrib.get("incomplete", None) == "1":
                    continue

                # TODO: anonymous class
                # typedef struct { int a; } A;
                if cls_node.attrib.get("name", "") == "":
                    continue

                logging.info("---------------------------------------------")
                logging.info(">>> %s <<<" % full_name)
                logging.info("---------------------------------------------")

                cls = Class.Class(self.root, cls_node, self)
                self.register_class(cls)

                # Inner (nested) classes
                self._do_process_classes(cls_node.attrib["id"])

                self.modified = True
Esempio n. 11
0
    def _do_process_classes(self, context_id):
        for decl_type in ("Class", "Struct"):
            xpath = ".//%s[@file='%s'][@context='%s']" % (
                decl_type, self.current_file_id(), context_id
            )

            for cls_node in self.root.findall(xpath):
                full_name = cls_node.attrib["demangled"]

                if self.blacklist.klass(full_name):
                    Session.ignored_classes.add(full_name)
                    continue

                if full_name in self.blacklist.dummy_classes:
                    Session.dummy_classes.add(full_name)
                    continue

                if Access.access_type(cls_node) == Access.PRIVATE:
                    continue

                if cls_node.attrib.get("incomplete", None) == "1":
                    continue

                # TODO: anonymous class
                # typedef struct { int a; } A;
                if cls_node.attrib.get("name", "") == "":
                    continue

                logging.info("---------------------------------------------")
                logging.info(">>> %s <<<" % full_name)
                logging.info("---------------------------------------------")

                cls = Class.Class(self.root, cls_node, self)
                self.register_class(cls)

                # Inner (nested) classes
                self._do_process_classes(cls_node.attrib["id"])

                self.modified = True
Esempio n. 12
0
    def _filter(root, mnode, allows_subclassing, blacklist):
        # always collect pure virtual functions
        if mnode.attrib.get("pure_virtual") == "1":
            return False

        if blacklist.method(mnode.attrib["demangled"]):
            Session.ignored_methods.add(mnode.attrib["demangled"])
            return True

        if MethodJar._filter_by_return_type(mnode, blacklist, root,
                                            Session.ignored_methods):
            return True

        maccess = Access.access_type(mnode)
        if not allows_subclassing and maccess != Access.PUBLIC:
            return True

        # private non-pure-virtuals will be handled later
        if maccess != Access.PRIVATE or mnode.attrib.get("virtual",
                                                         None) == "1":
            return False

        # filter all the other
        return True
Esempio n. 13
0
 def _destructor(self):
     dtor = self.root.find("Destructor[@context='%s']" % self.node.attrib["id"])
     if dtor is not None:
         self.dtor_access_type = Access.access_type(dtor)
Esempio n. 14
0
 def _destructor(self):
     dtor = self.root.find("Destructor[@context='%s']" %
                           self.node.attrib["id"])
     if dtor is not None:
         self.dtor_access_type = Access.access_type(dtor)