From e458348409ffec63849c12053390d162d14659a0 Mon Sep 17 00:00:00 2001 From: Omar Sandoval Date: Tue, 1 May 2018 21:07:38 -0700 Subject: [PATCH] type: rename EnumType.compatible to compatible_name More descriptive but not too verbose. --- drgn/type.py | 12 ++++++------ drgn/typeindex.py | 13 +++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/drgn/type.py b/drgn/type.py index b51acda5..feec0ad6 100644 --- a/drgn/type.py +++ b/drgn/type.py @@ -613,7 +613,7 @@ class UnionType(CompoundType): class EnumType(IntType): """ An EnumType has a name, size, signedness, enumerators (as a Python - enum.IntEnum), a name of a compatible integer type, and qualifiers. See + enum.IntEnum), the name of its compatible integer type, and qualifiers. See help(IntType) and help(Type) for more information. >>> print(prog.type('enum pid_type')) @@ -633,13 +633,13 @@ class EnumType(IntType): ('PIDTYPE_SID', ), ('PIDTYPE_MAX', ), ('__PIDTYPE_TGID', )])) - >>> prog.type('enum pid_type').compatible + >>> prog.type('enum pid_type').compatible_name 'unsigned int' """ def __init__(self, name: str, size: int, signed: bool, enumerators: Optional[List[Tuple[str, int]]], - compatible: Optional[str], + compatible_name: Optional[str], qualifiers: FrozenSet[str] = frozenset()) -> None: super().__init__(name, size, signed, qualifiers) if enumerators is None: @@ -647,7 +647,7 @@ class EnumType(IntType): else: self.enum = enum.IntEnum('' if name is None else name, enumerators) # type: ignore # mypy issue #4865. - self.compatible = compatible + self.compatible_name = compatible_name def __repr__(self) -> str: parts = [ @@ -656,7 +656,7 @@ class EnumType(IntType): repr(self.size), ', ', repr(self.signed), ', ', repr(None if self.enum is None else self.enum.__members__), ', ', - repr(self.compatible), + repr(self.compatible_name), ] if self.qualifiers: parts.append(', ') @@ -728,7 +728,7 @@ class EnumType(IntType): return self return EnumType(self.name, self.size, self.signed, None if self.enum is None else self.enum.__members__, - self.compatible) + self.compatible_name) class TypedefType(Type): diff --git a/drgn/typeindex.py b/drgn/typeindex.py index 4e70119c..d6f6f3c3 100644 --- a/drgn/typeindex.py +++ b/drgn/typeindex.py @@ -110,7 +110,8 @@ def _corresponding_unsigned_type(type_: Type) -> Type: return type_ elif isinstance(type_, EnumType): if type_.signed: - return IntType('unsigned ' + type_.compatible, type_.size, False) + return IntType('unsigned ' + type_.compatible_name, type_.size, + False) else: return type_ elif isinstance(type_, IntType): @@ -140,8 +141,8 @@ class TypeIndex: real_type = type.real_type() if isinstance(real_type, EnumType): - type = real_type = IntType(real_type.compatible, real_type.size, - real_type.signed) + type = real_type = IntType(real_type.compatible_name, + real_type.size, real_type.signed) if isinstance(real_type, BitFieldType): int_type = self.find_type('int') @@ -382,7 +383,7 @@ class DwarfTypeIndex(TypeIndex): if dwarf_type.find_flag(DW_AT.declaration): size = None signed = None - compatible = None + compatible_name = None enumerators = None else: size = dwarf_type.size() @@ -400,12 +401,12 @@ class DwarfTypeIndex(TypeIndex): name = child.name() value = child.find_constant(DW_AT.const_value) enumerators.append((name, value)) - compatible = str(parse_type_name(dwarf_type.type().name())) + compatible_name = str(parse_type_name(dwarf_type.type().name())) try: name = dwarf_type.name() except DwarfAttribNotFoundError: name = None - return EnumType(name, size, signed, enumerators, compatible, + return EnumType(name, size, signed, enumerators, compatible_name, qualifiers) elif dwarf_type.tag == DW_TAG.typedef: return TypedefType(dwarf_type.name(),