B
    0aI%                 @   sh   d dl mZ d dl mZ d dl mZ d dl mZ ddlmZ ddlmZ ddlm	Z	 G d	d
 d
e
ZdS )    )absolute_import)division)print_function)unicode_literals   )ast)message)TAG_RETURNSc               @   sp   e Zd Zdd Zdd ZdddZdd	 ZdddZdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )IntrospectablePassc             C   s   || _ |j| _|| _d S )N)_transformer	namespace
_namespace_blocks)selfZtransformerZblocks r   >/usr/lib/gobject-introspection/giscanner/introspectablepass.py__init__   s    zIntrospectablePass.__init__c             C   sf   | j | j | j | j | j | j | j | j | j | j | j | j | j | j d S )N)r   walk_introspectable_alias_analysis_propagate_callable_skips_analyze_node!_introspectable_callable_analysis_introspectable_pass3'_remove_non_reachable_backcompat_copies)r   r   r   r   validate&   s    zIntrospectablePass.validateNc       	      C   s   t |tjtjfrd S d }t|drJd|jf }| j|j}|rN|j}nd}t |tj	rhd|j
f }nd}|r|jt}|r|j}tj||| | |d d S )Nsymbolz%s:  zargument %s: zreturn value: )Z	positions)
isinstancer   Z	VFunctionCallbackhasattrr   r   getposition	ParameterargnameZtagsr	   r   Z	warn_node)	r   parentparamtextr!   blockprefixcontextZ
return_tagr   r   r   _parameter_warning/   s$    
z%IntrospectablePass._parameter_warningc             C   s  t |tj}t |tj}|jjd k	r4| j|j}nd }|jrBd S |jj	sl| 
||d|jjf  d|_d S t |jtjrd|_d S t |jtjtjfr|jjtjkr| 
||d d|_d S |rt |tjr|jjdkr|jd kr| 
||dtjtjf  d|_d S |r<t |tjr<| 
||d d|_d S |rt |tjtjfr|jd kr|js|jtjkr| 
||d d|_d S |jd kr| 
||d d|_d S d S )	NzUnresolved type: %rFz!Missing (element-type) annotation)zGLib.DestroyNotifyzGio.AsyncReadyCallbackzNMissing (scope) annotation for callback without GDestroyNotify (valid: %s, %s)z-Callbacks cannot be return values; use (skip)zXInvalid non-constant return of bare structure or union; register as boxed type or (skip)zMissing (transfer) annotation)r   r   ZReturnr"   typetarget_ginamer   lookup_typenodeskipresolvedr*   Zunresolved_stringintrospectableZVarargsListArrayelement_typeZTYPE_ANYr   ZscopeZPARAM_SCOPE_CALLZPARAM_SCOPE_ASYNCRecordUnionZget_typeZforeignZtransferZPARAM_TRANSFER_NONE)r   r$   nodeZ	is_returnZis_parametertargetr   r   r   _introspectable_param_analysisH   sb    z1IntrospectablePass._introspectable_param_analysisFc             C   s   |j s
dS t|tjrdS t|tjtjfr8| |jS t|tjr\| |j	oZ| |j
S |jrfdS |jr|tjr|dS |tjtjtjfrdS dS | j|}|sdS |jo|j S )NFT)r/   r   r   ZTypeUnknownr2   r1   _type_is_introspectabler3   ZMapZkey_typeZ
value_typeZtarget_foreignZtarget_fundamentalZis_equivZTYPE_VALISTZTYPE_LONG_LONGZTYPE_LONG_ULONGZTYPE_LONG_DOUBLEr   r-   r0   r.   )r   Ztypevalwarnr7   r   r   r   r9      s*    z*IntrospectablePass._type_is_introspectablec             C   s<   |j jd k	r(| j|j }|d kr,d S nd S |jr8d|_d S )NT)r+   r,   r   r-   r.   )r   r$   r6   r7   r   r   r   _propagate_parameter_skip   s    z,IntrospectablePass._propagate_parameter_skipc             C   s"   t |tjr| |jsd|_dS )NFT)r   r   ZAliasr9   r7   r0   )r   objstackr   r   r   r      s    z1IntrospectablePass._introspectable_alias_analysisc             C   s:   t |tjr6x|jD ]}| || qW | ||j dS )NT)r   r   Callable
parametersr;   retval)r   r<   r=   r%   r   r   r   r      s
    z,IntrospectablePass._propagate_callable_skipsc             C   s   |j r
dS t|tjr@x|jD ]}| || qW | ||j t|tjtjtj	tj
frx&|jD ]}|jrb| |jsbd|_qbW dS )NFT)r.   r   r   r>   r?   r8   r@   Class	Interfacer4   r5   fieldsr+   r9   r0   )r   r<   r=   r%   fieldr   r   r   r      s    
z IntrospectablePass._analyze_nodec             C   sX   |j r
dS t|tjrTx$|jD ]}| |jsd|_dS qW | |jjsTd|_dS dS )NFT)	r.   r   r   r>   r?   r9   r+   r0   r@   )r   r<   r=   r%   r   r   r   r      s    z4IntrospectablePass._introspectable_callable_analysisc             C   s   |j r
dS t|tjtjtjtjfr\x6|jD ],}|jrF|jj	sXd|_	q,| 
|js,d|_	q,W t|tjtjfrx |jD ]}| 
|jsvd|_	qvW x|jD ]}| ||g qW dS )NFT)r.   r   r   rA   rB   r4   r5   rC   Zanonymous_noder0   r9   r+   Z
propertiesZsignalsr   )r   r<   r=   rD   ZpropZsigr   r   r   r      s     

z(IntrospectablePass._introspectable_pass3c             C   s0   |j r
dS t|tjr,|jd k	r,|js,d|_dS )NFT)r.   r   r   ZFunctionZmoved_tor0   Zinternal_skipped)r   r<   r=   r   r   r   r      s    z:IntrospectablePass._remove_non_reachable_backcompat_copies)N)F)__name__
__module____qualname__r   r   r*   r8   r9   r;   r   r   r   r   r   r   r   r   r   r   r
      s   	
@
r
   N)Z
__future__r   r   r   r   r   r   r   Zannotationparserr	   objectr
   r   r   r   r   <module>   s   