Module org.htmlunit.corejs
Class LineNumberTable
java.lang.Object
org.htmlunit.corejs.javascript.interpreterv2.LineNumberTable
Packed array-based line number table implementation.
Uses four parallel arrays for memory efficiency:
pcs[]- Program counter values (sorted)lineOffsets[]- Start index inlines[]for each PClineCounts[]- Number of lines for each PClines[]- 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).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for LineNumberTable. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Stringstatic StringgetDebugString(LineNumberTable lineNumberTable) Get a debug string representation of the line number table.protected abstract intstatic intgetFirstLineNumber(LineNumberTable lineNumberTable) protected abstract intgetLineNoFromPc(int pc) protected abstract int[]static intgetLineNumberFromPc(LineNumberTable lineNumberTable, int pc) Get the last (most specific) line number associated with a given PC.static int[]getLineNumbers(LineNumberTable lineNumberTable) Get all unique line numbers in the table (excluding synthetic -1).getLineSetFromPc(LineNumberTable lineNumberTable, int pc) Get the set of line numbers associated with a given PC.getLineSetFromPcInt(int pc) protected abstract intstatic intgetPcFirstLineNumber(LineNumberTable lineNumberTable) static booleanisEmpty(LineNumberTable lineNumberTable) Check if the line number table is empty.protected abstract boolean
-
Constructor Details
-
LineNumberTable
public LineNumberTable()
-
-
Method Details
-
getFirstLineNo
protected abstract int getFirstLineNo() -
getPcFirstLineNo
protected abstract int getPcFirstLineNo() -
getLineSetFromPcInt
-
getLineNoFromPc
protected abstract int getLineNoFromPc(int pc) -
getLineNos
protected abstract int[] getLineNos() -
debugString
-
isEmptyTable
protected abstract boolean isEmptyTable() -
getFirstLineNumber
-
getPcFirstLineNumber
-
getLineSetFromPc
Get the set of line numbers associated with a given PC.- Parameters:
lineNumberTable- The line number tablepc- The program counter- Returns:
- List of line numbers, or null if PC not found or synthetic
-
getLineNumberFromPc
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 tablepc- The program counter- Returns:
- The last line number, or -1 if not found or synthetic
-
getLineNumbers
Get all unique line numbers in the table (excluding synthetic -1).- Parameters:
lineNumberTable- The line number table- Returns:
- Array of unique line numbers
-
getDebugString
Get a debug string representation of the line number table.- Parameters:
lineNumberTable- The line number table- Returns:
- Debug string showing PC -> lines mapping
-
isEmpty
Check if the line number table is empty.- Parameters:
lineNumberTable- The line number table- Returns:
- true if empty
-