�
�� Rc@stdZddlZd�Zd�Zd�Zd�Zdefd��YZd �Zd
�Z d�Z
d�ZdS(
s%Utilities for working with gdb.Types.i����NcCsbxU|jtjks'|jtjkrW|jtjkrH|j�}q|j�}qW|j�S(s�Return the "basic" type of a type.
Arguments:
type_: The type to reduce to its basic type.
Returns:
type_ with const/volatile is stripped away,
and typedefs/references converted to the underlying type.
(tcodetgdbt
TYPE_CODE_REFtTYPE_CODE_TYPEDEFttargettstrip_typedefstunqualified(ttype_((s"/usr/share/gdb/python/gdb/types.pytget_basic_typescCs�t|�}|jtjkr?|jtjkr?td��nxI|j�D];}|jrtt|j |�r�t
SqL|j|krLt
SqLWtS(syReturn True if a type has the specified field.
Arguments:
type_: The type to examine.
It must be one of gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION.
field: The name of the field to look up.
Returns:
True if the field is present either in type_ or any baseclass.
Raises:
TypeError: The type is not a struct or union.
snot a struct or union(
RRRtTYPE_CODE_STRUCTtTYPE_CODE_UNIONt TypeErrortfieldst
is_base_classt has_fieldttypetTruetnametFalse(Rtfieldtf((s"/usr/share/gdb/python/gdb/types.pyR*s cCsR|jtjkr!td��ni}x$|j�D]}|j||j<q4W|S(s�Return a dictionary from a program's enum type.
Arguments:
enum_type: The enum to compute the dictionary for.
Returns:
The dictionary of the enum.
Raises:
TypeError: The type is not an enum.
snot an enum type(RRtTYPE_CODE_ENUMRRtenumvalR(t enum_typet enum_dictR((s"/usr/share/gdb/python/gdb/types.pytmake_enum_dictHs
ccsTxM|j�D]?\}}|r-||fVq
xt|j�D]}|Vq=Wq
WdS(s�Return an iterator that recursively traverses anonymous fields.
Arguments:
type_: The type to traverse. It should be one of
gdb.TYPE_CODE_STRUCT or gdb.TYPE_CODE_UNION.
Returns:
an iterator similar to gdb.Type.iteritems(), i.e., it returns
pairs of key, value, but for any anonymous struct or union
field that field is traversed recursively, depth-first.
N(t iteritemst
deep_itemsR(Rtktvti((s"/usr/share/gdb/python/gdb/types.pyR^s
tTypePrintercBs eZdZd�Zd�ZRS(s�The base class for type printers.
Instances of this type can be used to substitute type names during
'ptype'.
A type printer must have at least 'name' and 'enabled' attributes,
and supply an 'instantiate' method.
The 'instantiate' method must either return None, or return an
object which has a 'recognize' method. This method must accept a
gdb.Type argument and either return None, meaning that the type
was not recognized, or a string naming the type.
cCs||_t|_dS(N(RRtenabled(tselfR((s"/usr/share/gdb/python/gdb/types.pyt__init__�s cCsdS(N(tNone(R!((s"/usr/share/gdb/python/gdb/types.pytinstantiate�s(t__name__t
__module__t__doc__R"R$(((s"/usr/share/gdb/python/gdb/types.pyRqs
cCsIxB|D]:}|jr|j�}|dk rA|j|�qAqqWdS(N(R R$R#tappend(tresulttplisttprintertinst((s"/usr/share/gdb/python/gdb/types.pyt_get_some_type_recognizers�s
cCsWg}x$tj�D]}t||j�qWt|tj�j�t|tj�|S(sFReturn a list of the enabled type recognizers for the current context.(RtobjfilesR-t
type_printerstcurrent_progspace(R)tobjfile((s"/usr/share/gdb/python/gdb/types.pytget_type_recognizers�scCs4x-|D]%}|j|�}|dk r|SqWdS(s�Apply the given list of type recognizers to the type TYPE_OBJ.
If any recognizer in the list recognizes TYPE_OBJ, returns the name
given by the recognizer. Otherwise, this returns None.N(t recognizeR#(trecognizersttype_objtrR)((s"/usr/share/gdb/python/gdb/types.pytapply_type_recognizers�s
cCs,|dkrt}n|jjd|�dS(s�Register a type printer.
PRINTER is the type printer instance.
LOCUS is either an objfile, a program space, or None, indicating
global registration.iN(R#RR/tinsert(tlocusR+((s"/usr/share/gdb/python/gdb/types.pytregister_type_printer�s (R'RRRRRtobjectRR-R2R7R:(((s"/usr/share/gdb/python/gdb/types.pyt<module>s
|