U
    ,d                     @   s>   d Z ddlZddlmZ G dd dejZdd Zdd	 ZdS )
zR
This module provides helper functions to find the first line of a function
body.
    N)	PYVERSIONc                       s8   e Zd ZdZdd Z fddZejdddZ  Z	S )	FindDefFirstLinez
    Attributes
    ----------
    first_stmt_line : int or None
        This stores the first statement line number if the definition is found.
        Or, ``None`` if the definition is not found.
    c                 C   s   |j | _|j| _d| _dS )zf
        Parameters
        ----------
        code :
            The function's code object.
        N)co_name_co_nameco_firstlineno_co_firstlinenofirst_stmt_line)selfcode r   >/tmp/pip-unpacked-wheel-eu7e0c37/numba/misc/firstlinefinder.py__init__   s    zFindDefFirstLine.__init__c                    s    t |D ]}t | q
d S )N)astZiter_child_nodessupervisit)r	   nodechild	__class__r   r   _visit_children   s    z FindDefFirstLine._visit_childrenr   c                 C   sz   |j | jkrlt|jg}|jr4|jd }||j | j|krl|jrl|jd }t|r`|jd }|j| _	d S | 
| d S )Nr      )namer   setlinenoZdecorator_listaddr   body_is_docstringr   r   )r	   r   Zpossible_start_linesZfirst_decorZ
first_stmtr   r   r   visit_FunctionDef#   s    



z"FindDefFirstLine.visit_FunctionDef)
__name__
__module____qualname____doc__r   r   r   ZFunctionDefr   __classcell__r   r   r   r   r      s   r   c                 C   sF   t | tjrBtdkr"t | jtjS t | jtjrBt | jjtrBdS dS )N)      TF)
isinstancer   ZExprr   valueZStrConstantstrr   r   r   r   r   A   s    r   c              	   C   sj   | j }z"t|j}| }W 5 Q R X W n ttfk
rB   Y dS X t|}t|}|	| |j
S dS )a  
    Look up the first line of function body using the file in
    ``pyfunc.__code__.co_filename``.

    Returns
    -------
    lineno : int; or None
        The first line number of the function body; or ``None`` if the first
        line cannot be determined.
    N)__code__openco_filenamereadFileNotFoundErrorOSErrorr   parser   r   r   )ZpyfunccoZfinZfile_contenttreefinderr   r   r   get_func_body_first_linenoK   s    

r4   )r"   r   Znumba.core.utilsr   ZNodeVisitorr   r   r4   r   r   r   r   <module>   s
   6
