java.lang.Object
net.covers1624.coffeegrinder.bytecode.InsnVisitor<None,None>
net.covers1624.coffeegrinder.bytecode.SimpleInsnVisitor<None>
net.covers1624.coffeegrinder.bytecode.transform.transformers.VariableDeclarations
All Implemented Interfaces:
MethodTransformer, Transformer

public class VariableDeclarations extends SimpleInsnVisitor<None> implements MethodTransformer
A variable is in scope, if the parent of the declaration (IStoreInstruction) is an ancestor of the usage and the declaration has a lower child index in the common ancestor than the usage

Split variables with an aliased declaration in-scope are merged. Created by covers1624 on 15/9/21.

  • Constructor Details

    • VariableDeclarations

      public VariableDeclarations()
  • Method Details

    • transform

      public void transform(MethodDecl function, MethodTransformContext ctx)
      Description copied from interface: MethodTransformer
      Transform the MethodDecl.
      Specified by:
      transform in interface MethodTransformer
      Parameters:
      function - The function to transform.
      ctx - The MethodTransformContext.
    • unifyUsages

      public static Instruction unifyUsages(Instruction decl, Instruction usage)
      Finds a suitable declaration location such that usage is in scope with the previous declaration. Assumes that decl is 'before' usage
      Parameters:
      decl - The previous declaration for a variable
      usage - An instruction which requires the declaration to be in scope
      Returns:
      decl, if decl is in scope, otherwise a common ancestor of both decl and usage, which is a child of a block (so a declaration could be inserted before it)
    • selectDeclarableParent

      public static Instruction selectDeclarableParent(Instruction insn)
      find the first declaration point, the first ancestor which is a child of a block (which may be this instruction, or a parent)
    • visitLocalReference

      public None visitLocalReference(LocalReference localRef, None ctx)
      Overrides:
      visitLocalReference in class InsnVisitor<None,None>