fsdZddlZddlmZddlmZejrddlm Z dejdd d ejfd Z Gd d eZ y)aThe 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) Environmentnode environmentrreturnc~t|}tjtj|j |S)z^The context hint can be used to perform an static optimization based on the context given.) OptimizertcastrNodevisit)rr optimizers Y/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/jinja2/optimizer.pyoptimizers,+&I 66%**iood3 44ceZdZddZdej dejdejdej ffd ZxZ S)r r c||_y)N)r)selfrs r__init__zOptimizer.__init__s &rrargskwargsc0t||g|i|}t|tjrM tj j |j|r|dnd|j|jS|S#tj$rY|SwxYw)Nr)linenor) super generic_visit isinstancerExprConstfrom_untrustedas_constrr Impossible)rrrr __class__s rrzOptimizer.generic_visitsw$T;D;F; dEJJ ' {{11MMT$q't<;; $ 0 02 ##   sA A>>BB)rzt.Optional[Environment]r N) __name__ __module__ __qualname__rrrr Anyr __classcell__)r$s@rr r sB'JJ'(uu89 rr ) __doc__typingr rvisitorr TYPE_CHECKINGrrrrr rrr0sM$??(55::5M5ejj5r