Class UnrollLoops

  • All Implemented Interfaces:
    AtRuleHandler, CssCompilerPass, CssTreeVisitor

    public class UnrollLoops
    extends DefaultTreeVisitor
    implements CssCompilerPass
    A compiler pass that unrolls loops.

    For every loop, we iterate over the different values of the loop variables, create a copy of the loop block and invoke LoopVariableReplacementPass to replace all references of the loop variable with the current iteration value. So for a loop with N iterations, we'll replace the loop block with N blocks which only differ in the replacement to the loop variable value.

    NOTE: There is special treatment for @defs in this pass. Since definition references might appear before declaration, it's easier for LoopVariableReplacementPass to know all definitions declarations beforehand (the latter pass needs to do name replacement for definitions declared inside the loop). That's why this pass scrapes them prior to calling LoopVariableReplacementPass.