Esempio n. 1
0
        def _match(self, typ, mt):
            types = [typ]

            # If recursive, go fetch all types to check for matching
            if self.recursive:
                while typ.code in (gdb.TYPE_CODE_RANGE, gdb.TYPE_CODE_TYPEDEF):
                    typ = typ.target()
                    types.append(typ)

            for typ in types:
                type_name = (pretty_typename(typ)
                             if self.match_pretty_name else typ.name)

                with mt.scope(self, typ):

                    # If a name constraint is given, check it is satisfied
                    if isinstance(self.name, str) and (not type_name or
                                                       type_name != self.name):
                        continue
                    if isinstance(self.name, regex_type) and (
                            not type_name or not self.name.match(type_name)):
                        continue
                    if self.suffix and not (type_name and type_name.endswith(
                            self.suffix)):
                        continue

                    # Likewise for the type sub-pattern
                    if self.type_pattern and not self.type_pattern._match(
                            typ, mt):
                        continue

                    # If we reach this point, all checks have suceeded: we
                    # found a matching type.
                    return True

            # If we reach this point, no type we analyzed satisfied the given
            # constraints: the original type does not match.
            with mt.scope(self, types[0]):
                return mt.tag_mismatch()
Esempio n. 2
0
 def to_string(self):
     return "{} of length {}".format(pretty_typename(self.value.type),
                                     self.length)