Class NameRecoverer


  • public class NameRecoverer
    extends Object
    Recovers variable names from debug info or generates synthetic names.
    • Constructor Detail

      • NameRecoverer

        public NameRecoverer​(IRMethod irMethod,
                             MethodEntry sourceMethod,
                             NameRecoveryStrategy strategy)
        Creates a recoverer and eagerly indexes the method's local variable table and lifted instruction offsets.
        Parameters:
        irMethod - the lifted method
        sourceMethod - the method the IR came from
        strategy - whether debug names are preferred over synthetic ones
        Throws:
        NullPointerException - if the source method has no owning class file
    • Method Detail

      • nextOffsetAfter

        public int nextOffsetAfter​(int off)
        The smallest instruction offset strictly greater than off, or off + 1 if none known.
        Parameters:
        off - the bytecode offset to search past
        Returns:
        the next known instruction offset, or one past the given offset
      • debugNameAtStore

        public String debugNameAtStore​(int slot,
                                       int storeOffset)
        The LVT name for slot at the pc where a STORE at storeOffset takes effect - the following instruction, which is where javac opens the variable's range.
        Parameters:
        slot - the local slot written
        storeOffset - the bytecode offset of the store
        Returns:
        the name in scope, falling back to the name at the store itself, or null when neither has an entry
      • debugDescriptorAtStore

        public String debugDescriptorAtStore​(int slot,
                                             int storeOffset)
        As debugNameAtStore(int, int) for the entry's descriptor.
        Parameters:
        slot - the local slot written
        storeOffset - the bytecode offset of the store
        Returns:
        the declared descriptor in scope, falling back to the one at the store itself, or null when neither has an entry
      • unambiguousDebugName

        public String unambiguousDebugName​(int slot)
        The LVT name for slot when every entry for that slot agrees on a single name, else null.
        Parameters:
        slot - the local slot to name
        Returns:
        the single agreed name, or null when the entries disagree or the strategy forbids it
      • debugNameAt

        public String debugNameAt​(int slot,
                                  int offset)
        The LocalVariableTable name in scope for slot at bytecode offset - the entry whose [startPc, startPc + length) range contains the offset - or null when there is no debug info or no entry covers it.
        Parameters:
        slot - the local slot to name
        offset - the bytecode offset the name must be in scope at
        Returns:
        the name in scope, or null when no entry covers the offset
      • debugDescriptorAt

        public String debugDescriptorAt​(int slot,
                                        int offset)
        The LocalVariableTable type descriptor in scope for slot at bytecode offset - the declared type of the variable there (e.g. "C" for char), or null when no debug info or no entry covers it.
        Parameters:
        slot - the local slot to type
        offset - the bytecode offset the entry must be in scope at
        Returns:
        the declared descriptor, or null when no entry covers the offset
      • generateSyntheticName

        public String generateSyntheticName​(SSAValue value)
        Generates a synthetic name based on the value's type.
        Parameters:
        value - the value to name
        Returns:
        a type-prefixed name with a per-recoverer counter appended