U
    aG\                     @   s8   d Z ddlmZ ddlmZ dd ZG dd deZdS )	a[  
    jinja2.optimizer
    ~~~~~~~~~~~~~~~~

    The jinja optimizer is currently trying to constant fold a few expressions
    and modify the AST in place so that it should be easier to evaluate it.

    Because the AST does not contain all the scoping information and the
    compiler has to find that out, we cannot do all the optimizations we
    want.  For example loop unrolling doesn't work because unrolled loops would
    have a different scoping.

    The solution would be a second syntax tree that has the scoping rules stored.

    :copyright: (c) 2017 by the Jinja Team.
    :license: BSD.
    )nodes)NodeTransformerc                 C   s   t |}|| S )z^The context hint can be used to perform an static optimization
    based on the context given.)	OptimizerZvisit)nodeenvironmentZ	optimizer r   2/usr/lib/python3/dist-packages/jinja2/optimizer.pyoptimize   s    r	   c                   @   sl   e Zd Zdd ZdddZe Z Z Z Z Z	 Z
 Z Z Z Z Z Z Z Z Z Z Z ZZ[dS )r   c                 C   s
   || _ d S )N)r   )selfr   r   r   r   __init__    s    zOptimizer.__init__Nc                 C   sH   |  |}ztjj|||j| jdW S  tjk
rB   | Y S X dS )zDo constant folding.)linenor   N)Zgeneric_visitr   ZConstZfrom_untrustedZas_constr   r   Z
Impossible)r
   r   Zeval_ctxr   r   r   fold#   s    
zOptimizer.fold)N)__name__
__module____qualname__r   r   Z	visit_AddZ	visit_SubZ	visit_MulZ	visit_DivZvisit_FloorDivZ	visit_PowZ	visit_ModZ	visit_AndZvisit_OrZ	visit_PosZ	visit_NegZ	visit_NotZvisit_CompareZvisit_GetitemZvisit_GetattrZ
visit_CallZvisit_FilterZ
visit_TestZvisit_CondExprr   r   r   r   r      s>   
 r   N)__doc__Zjinja2r   Zjinja2.visitorr   r	   r   r   r   r   r   <module>   s   