3
\f[                   @   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 |}|j| S )z^The context hint can be used to perform an static optimization
    based on the context given.)	Optimizervisit)nodeenvironment	optimizer r	   BC:\prj\env\wsgidav_build_3.6\lib\site-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   sB   | j |}ytjj|j||j| jdS  tjk
r<   |S X dS )zDo constant folding.)linenor   N)generic_visitr   Constfrom_untrustedas_constr   r   
Impossible)r   r   eval_ctxr	   r	   r
   fold#   s    

zOptimizer.fold)N)__name__
__module____qualname__r   r   	visit_Add	visit_Sub	visit_Mul	visit_Divvisit_FloorDiv	visit_Pow	visit_Mod	visit_Andvisit_Or	visit_Pos	visit_Neg	visit_Notvisit_Comparevisit_Getitemvisit_Getattr
visit_Callvisit_Filter
visit_Testvisit_CondExprr	   r	   r	   r
   r      s   
Lr   N)__doc__jinja2r   jinja2.visitorr   r   r   r	   r	   r	   r
   <module>   s   