U
    {±Ëh'  ã                   @   s>   d Z ddlmZ ddlmZ G dd„ dƒZeƒ Zd
dd	„ZdS )z±
This module deals with interpreting the parse tree as Python
would have done, in the compiler.

For now this only covers parse tree to value conversion of
compile-time values.
é   )ÚDictNode)ÚCompileErrorc                   @   s   e Zd Zdd„ ZdS )Ú
EmptyScopec                 C   s   d S )N© )ÚselfÚnamer   r   ú?/tmp/pip-unpacked-wheel-fhl22ezh/Cython/Compiler/Interpreter.pyÚlookup   s    zEmptyScope.lookupN)Ú__name__Ú
__module__Ú__qualname__r	   r   r   r   r   r      s   r   Nr   c                    sz   ‡‡fdd„‰ | r(‡ fdd„t | ƒD ƒ} |rrt|tƒs:t‚i }|jD ](}ˆ |jdƒ\}}ˆ |j|jjƒ||< qD|}| |fS )a,  
    Tries to interpret a list of compile time option nodes.
    The result will be a tuple (optlist, optdict) but where
    all expression nodes have been interpreted. The result is
    in the form of tuples (value, pos).

    optlist is a list of nodes, while optdict is a DictNode (the
    result optdict is a dict)

    If type_env is set, all type nodes will be analysed and the resulting
    type set. Otherwise only interpretateable ExprNodes
    are allowed, other nodes raises errors.

    A CompileError will be raised if there are problems.
    c                    sL   |ˆ kr<ˆr0|   ˆ¡}|s&t| jdƒ‚|| jfS t| jdƒ‚|  t¡| jfS )NzInvalid type.zType not allowed here.)Zanalyse_as_typer   ÚposZcompile_time_valueÚempty_scope)ÚnodeÚixÚtype)Ú	type_argsÚtype_envr   r   Ú	interpret%   s    

z0interpret_compiletime_options.<locals>.interpretc                    s   g | ]\}}ˆ ||ƒ‘qS r   r   )Ú.0r   Úx)r   r   r   Ú
<listcomp>1   s     z1interpret_compiletime_options.<locals>.<listcomp>N)Ú	enumerateÚ
isinstancer   ÚAssertionErrorZkey_value_pairsÚkeyÚvalue)ZoptlistÚoptdictr   r   Znew_optdictÚitemZnew_keyÚdummyr   )r   r   r   r   Úinterpret_compiletime_options   s    
r    )Nr   )Ú__doc__Z	ExprNodesr   ZErrorsr   r   r   r    r   r   r   r   Ú<module>   s
   	