3 C\@s8dZddlmZddlmZddZGdddeZdS) 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)NodeTransformercCst|}|j|S)z^The context hint can be used to perform an static optimization based on the context given.) Optimizervisit)node environmentZ optimizerrh/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/jinja2/jinja2/optimizer.pyoptimizesr c@sleZdZddZdddZeZZZZZ Z Z Z Z ZZZZZZZZZZ[dS)rcCs ||_dS)N)r)selfrrrr __init__ szOptimizer.__init__Nc CsB|j|}ytjj|j||j|jdStjk r<|SXdS)zDo constant folding.)linenorN) generic_visitrZConstZfrom_untrustedZas_constr rZ Impossible)r rZeval_ctxrrr fold#s  zOptimizer.fold)N)__name__ __module__ __qualname__r rZ visit_AddZ visit_SubZ visit_MulZ visit_DivZvisit_FloorDivZ visit_PowZ visit_ModZ visit_AndZvisit_OrZ visit_PosZ visit_NegZ visit_NotZ visit_CompareZ visit_GetitemZ visit_GetattrZ visit_CallZ visit_FilterZ visit_TestZvisit_CondExprrrrr rs LrN)__doc__Zjinja2rZjinja2.visitorrr rrrrr s