o :`r@sddZddlZddlmZddlmZejrddlm Z dej dd d ej fd d Z Gd ddeZ dS)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 environmentrreturncCst|}ttj||S)z^The context hint can be used to perform an static optimization based on the context given.) OptimizertcastrNodevisit)rr optimizerr2/usr/lib/python3/dist-packages/jinja2/optimizer.pyoptimizesrcs@eZdZd ddZdejdejd ejdejffd d ZZ S) r rt.Optional[Environment]rNcCs ||_dS)N)r)selfrrrr__init__s zOptimizer.__init__rargskwargscsltj|g|Ri|}t|tjr4ztjj||r|dnd|j|j dWStj y3Y|Sw|S)Nr)linenor) super generic_visit isinstancerExprConstfrom_untrustedas_constrr Impossible)rrrr __class__rrrs zOptimizer.generic_visit)rrrN) __name__ __module__ __qualname__rrr r Anyr __classcell__rrr rr s r ) __doc__typingr rvisitorr TYPE_CHECKINGrrr rr rrrrs