3

U'ícrã@s`dZddlZddlmZddlmZejr6ddlm	Z	ej
dej
dœd	d
„ZGdd„deƒZdS)
a¯The optimizer tries to constant fold expressions and modify the AST
in place so that it should be faster to evaluate.

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 scope. The solution would be a second syntax tree
that stored the scoping rules.
éNé)Únodes)ÚNodeTransformer)ÚEnvironmentr)ÚnodeÚenvironmentÚreturncCst|ƒ}tjtj|j|ƒƒS)z^The context hint can be used to perform an static optimization
    based on the context given.)Ú	OptimizerÚtÚcastrÚNodeÚvisit)rrZ	optimizer©rú2/tmp/pip-build-gk9425m9/Jinja2/jinja2/optimizer.pyÚoptimizesrcs@eZdZdddœdd„Zejejejejdœ‡fdd„Z‡Z	S)	r	zt.Optional[Environment]N)rrcCs
||_dS)N)r)ÚselfrrrrÚ__init__szOptimizer.__init__)rÚargsÚkwargsrcsdtƒj|f|ž|Ž}t|tjƒr`y(tjj|j|r8|dndƒ|j|j	dStj
k
r^YnX|S)Nr)Úlinenor)ÚsuperÚ
generic_visitÚ
isinstancerÚExprZConstZfrom_untrustedZas_constrrZ
Impossible)rrrr)Ú	__class__rrrs
zOptimizer.generic_visit)
Ú__name__Ú
__module__Ú__qualname__rrrr
ZAnyrÚ
__classcell__rr)rrr	sr	)
Ú__doc__Útypingr
ÚrÚvisitorrZ
TYPE_CHECKINGrrrrr	rrrrÚ<module>	s