mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-25 02:13:06 +00:00
type: rename EnumType.compatible to compatible_name
More descriptive but not too verbose.
This commit is contained in:
parent
90f6913242
commit
e458348409
12
drgn/type.py
12
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', <pid_type.PIDTYPE_SID: 2>),
|
||||
('PIDTYPE_MAX', <pid_type.PIDTYPE_MAX: 3>),
|
||||
('__PIDTYPE_TGID', <pid_type.__PIDTYPE_TGID: 4>)]))
|
||||
>>> 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):
|
||||
|
@ -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(),
|
||||
|
Loading…
Reference in New Issue
Block a user