Class LineNumberTable

java.lang.Object
org.htmlunit.corejs.javascript.interpreterv2.LineNumberTable

public abstract class LineNumberTable extends Object
Packed array-based line number table implementation.

Uses four parallel arrays for memory efficiency:

  • pcs[] - Program counter values (sorted)
  • lineOffsets[] - Start index in lines[] for each PC
  • lineCounts[] - Number of lines for each PC
  • lines[] - All line numbers packed sequentially

Example: PC 10 has lines [5,6,7], PC 15 has line [8]

 pcs = [10, 15]
 lineOffsets = [0, 3]
 lineCounts = [3, 1]
 lines = [5, 6, 7, 8]
 

Lookup uses binary search on pcs[] with O(log n) performance. Memory usage is approximately 12 bytes per PC + 4 bytes per line number (no object overhead).

  • Constructor Details

    • LineNumberTable

      public LineNumberTable()
  • Method Details

    • getFirstLineNo

      protected abstract int getFirstLineNo()
    • getPcFirstLineNo

      protected abstract int getPcFirstLineNo()
    • getLineSetFromPcInt

      protected abstract List<Integer> getLineSetFromPcInt(int pc)
    • getLineNoFromPc

      protected abstract int getLineNoFromPc(int pc)
    • getLineNos

      protected abstract int[] getLineNos()
    • debugString

      protected abstract String debugString()
    • isEmptyTable

      protected abstract boolean isEmptyTable()
    • getFirstLineNumber

      public static int getFirstLineNumber(LineNumberTable lineNumberTable)
    • getPcFirstLineNumber

      public static int getPcFirstLineNumber(LineNumberTable lineNumberTable)
    • getLineSetFromPc

      public static List<Integer> getLineSetFromPc(LineNumberTable lineNumberTable, int pc)
      Get the set of line numbers associated with a given PC.
      Parameters:
      lineNumberTable - The line number table
      pc - The program counter
      Returns:
      List of line numbers, or null if PC not found or synthetic
    • getLineNumberFromPc

      public static int getLineNumberFromPc(LineNumberTable lineNumberTable, int pc)
      Get the last (most specific) line number associated with a given PC. If the PC is not found, returns the line number of the largest PC that is less than the given PC.

      When multiple line numbers are recorded at the same PC (e.g., from nested structures like a BLOCK containing statements), this returns the last recorded line, which is typically the most specific one from the actual statement rather than the outer container.

      Parameters:
      lineNumberTable - The line number table
      pc - The program counter
      Returns:
      The last line number, or -1 if not found or synthetic
    • getLineNumbers

      public static int[] getLineNumbers(LineNumberTable lineNumberTable)
      Get all unique line numbers in the table (excluding synthetic -1).
      Parameters:
      lineNumberTable - The line number table
      Returns:
      Array of unique line numbers
    • getDebugString

      public static String getDebugString(LineNumberTable lineNumberTable)
      Get a debug string representation of the line number table.
      Parameters:
      lineNumberTable - The line number table
      Returns:
      Debug string showing PC -> lines mapping
    • isEmpty

      public static boolean isEmpty(LineNumberTable lineNumberTable)
      Check if the line number table is empty.
      Parameters:
      lineNumberTable - The line number table
      Returns:
      true if empty