Package org.htmlunit.xpath.compiler
Class OpMap
- java.lang.Object
-
- org.htmlunit.xpath.compiler.OpMap
-
- Direct Known Subclasses:
Compiler
public class OpMap extends java.lang.ObjectThis class represents the data structure basics of the XPath object.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static intBLOCKTOKENQUEUESIZEprotected java.lang.Stringm_currentPatternThe current pattern string, for diagnostics purposes(package private) OpMapVectorm_opMapAn operations map is used instead of a proper parse tree.(package private) java.util.ArrayList<java.lang.Object>m_tokenQueueTokenStack is the queue of used tokens.static intMAPINDEX_LENGTHThe length is always the opcode position + 1.(package private) static intMAXTOKENQUEUESIZEThe starting size of the token queue.
-
Constructor Summary
Constructors Constructor Description OpMap()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiderror(java.lang.String msg, java.lang.Object[] args)Tell the user of an error, and probably throw an exception.intgetArgLengthOfStep(int opPos)Given a location step, get the length of that step.static intgetFirstChildPos(int opPos)Go to the first child of a given operation.static intgetFirstChildPosOfStep(int opPos)Get the first child position of a given location step.intgetFirstPredicateOpPos(int opPos)Given an FROM_stepType position, return the position of the first predicate, if there is one, or else this will point to the end of the FROM_stepType.intgetNextOpPos(int opPos)Given an operation position, return the end position, i.e.intgetNextStepPos(int opPos)Given a location step position, return the end position, i.e.intgetOp(int opPos)Given an operation position, return the current op.java.lang.StringgetPatternString()Return the expression as a string for diagnostics.java.lang.StringgetStepLocalName(int opPosOfStep)Get the local name of the step.java.lang.StringgetStepNS(int opPosOfStep)Get the namespace of the step.intgetStepTestType(int opPosOfStep)Get the test type of the step, i.e.java.util.ArrayList<java.lang.Object>getTokenQueue()Get the XPath as a list of tokens.intgetTokenQueueSize()Get size of the token queue.voidsetOp(int opPos, int value)Set the op at index to the given int.(package private) voidshrink()Replace the large arrays with a small array.java.lang.StringtoString()
-
-
-
Field Detail
-
m_currentPattern
protected java.lang.String m_currentPattern
The current pattern string, for diagnostics purposes
-
MAXTOKENQUEUESIZE
static final int MAXTOKENQUEUESIZE
The starting size of the token queue.- See Also:
- Constant Field Values
-
BLOCKTOKENQUEUESIZE
static final int BLOCKTOKENQUEUESIZE
- See Also:
- Constant Field Values
-
m_tokenQueue
final java.util.ArrayList<java.lang.Object> m_tokenQueue
TokenStack is the queue of used tokens. The current token is the token at the end of the m_tokenQueue. The idea is that the queue can be marked and a sequence of tokens can be reused.
-
m_opMap
OpMapVector m_opMap
An operations map is used instead of a proper parse tree. It contains operations codes and indexes into the m_tokenQueue. I use an array instead of a full parse tree in order to cut down on the number of objects created.
-
MAPINDEX_LENGTH
public static final int MAPINDEX_LENGTH
The length is always the opcode position + 1. Length is always expressed as the opcode+length bytes, so it is always 2 or greater.- See Also:
- Constant Field Values
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getPatternString
public java.lang.String getPatternString()
Return the expression as a string for diagnostics.- Returns:
- The expression string.
-
getTokenQueue
public java.util.ArrayList<java.lang.Object> getTokenQueue()
Get the XPath as a list of tokens.- Returns:
- ObjectVector of tokens.
-
getTokenQueueSize
public int getTokenQueueSize()
Get size of the token queue.- Returns:
- The size of the token queue.
-
shrink
void shrink()
Replace the large arrays with a small array.
-
getOp
public int getOp(int opPos)
Given an operation position, return the current op.- Parameters:
opPos- index into op map.- Returns:
- the op that corresponds to the opPos argument.
-
setOp
public void setOp(int opPos, int value)Set the op at index to the given int.- Parameters:
opPos- index into op map.value- Value to set
-
getNextOpPos
public int getNextOpPos(int opPos)
Given an operation position, return the end position, i.e. the beginning of the next operation.- Parameters:
opPos- An op position of an operation for which there is a size entry following.- Returns:
- position of next operation in m_opMap.
-
getNextStepPos
public int getNextStepPos(int opPos)
Given a location step position, return the end position, i.e. the beginning of the next step.- Parameters:
opPos- the position of a location step.- Returns:
- the position of the next location step.
-
getFirstPredicateOpPos
public int getFirstPredicateOpPos(int opPos) throws javax.xml.transform.TransformerExceptionGiven an FROM_stepType position, return the position of the first predicate, if there is one, or else this will point to the end of the FROM_stepType. Example: int posOfPredicate = xpath.getNextOpPos(stepPos); boolean hasPredicates = OpCodes.OP_PREDICATE == xpath.getOp(posOfPredicate);- Parameters:
opPos- position of FROM_stepType op.- Returns:
- position of predicate in FROM_stepType structure.
- Throws:
javax.xml.transform.TransformerException
-
error
public void error(java.lang.String msg, java.lang.Object[] args) throws javax.xml.transform.TransformerExceptionTell the user of an error, and probably throw an exception.- Parameters:
msg- An error msgkey that corresponds to one of the constants found inXPATHErrorResources, which is a key for a format string.args- An array of arguments represented in the format string, which may be null.- Throws:
javax.xml.transform.TransformerException- if the current ErrorListoner determines to throw an exception.
-
getFirstChildPos
public static int getFirstChildPos(int opPos)
Go to the first child of a given operation.- Parameters:
opPos- position of operation.- Returns:
- The position of the first child of the operation.
-
getArgLengthOfStep
public int getArgLengthOfStep(int opPos)
Given a location step, get the length of that step.- Parameters:
opPos- Position of location step in op map.- Returns:
- The length of the step.
-
getFirstChildPosOfStep
public static int getFirstChildPosOfStep(int opPos)
Get the first child position of a given location step.- Parameters:
opPos- Position of location step in the location map.- Returns:
- The first child position of the step.
-
getStepTestType
public int getStepTestType(int opPosOfStep)
Get the test type of the step, i.e. NODETYPE_XXX value.- Parameters:
opPosOfStep- The position of the FROM_XXX step.- Returns:
- NODETYPE_XXX value.
-
getStepNS
public java.lang.String getStepNS(int opPosOfStep)
Get the namespace of the step.- Parameters:
opPosOfStep- The position of the FROM_XXX step.- Returns:
- The step's namespace, NodeTest.WILD, or null for null namespace.
-
getStepLocalName
public java.lang.String getStepLocalName(int opPosOfStep)
Get the local name of the step.- Parameters:
opPosOfStep- The position of the FROM_XXX step.- Returns:
- OpCodes.EMPTY, OpCodes.ELEMWILDCARD, or the local name.
-
-