use of org.apache.xpath.patterns.StepPattern in project robovm by robovm.
the class WalkerFactory method createDefaultStepPattern.
/**
* Create a StepPattern that is contained within a LocationPath.
*
*
* @param compiler The compiler that holds the syntax tree/op map to
* construct from.
* @param stepOpCodePos The current op code position within the opmap.
* @param mpi The MatchPatternIterator to which the steps will be attached.
* @param analysis 32 bits of analysis, from which the type of AxesWalker
* may be influenced.
* @param tail The step that is the first step analyzed, but the last
* step in the relative match linked list, i.e. the tail.
* May be null.
* @param head The step that is the current head of the relative
* match step linked list.
* May be null.
*
* @return the head of the list.
*
* @throws javax.xml.transform.TransformerException
*/
private static StepPattern createDefaultStepPattern(Compiler compiler, int opPos, MatchPatternIterator mpi, int analysis, StepPattern tail, StepPattern head) throws javax.xml.transform.TransformerException {
int stepType = compiler.getOp(opPos);
boolean simpleInit = false;
boolean prevIsOneStepDown = true;
int whatToShow = compiler.getWhatToShow(opPos);
StepPattern ai = null;
int axis, predicateAxis;
switch(stepType) {
case OpCodes.OP_VARIABLE:
case OpCodes.OP_EXTFUNCTION:
case OpCodes.OP_FUNCTION:
case OpCodes.OP_GROUP:
prevIsOneStepDown = false;
Expression expr;
switch(stepType) {
case OpCodes.OP_VARIABLE:
case OpCodes.OP_EXTFUNCTION:
case OpCodes.OP_FUNCTION:
case OpCodes.OP_GROUP:
expr = compiler.compile(opPos);
break;
default:
expr = compiler.compile(opPos + 2);
}
axis = Axis.FILTEREDLIST;
predicateAxis = Axis.FILTEREDLIST;
ai = new FunctionPattern(expr, axis, predicateAxis);
simpleInit = true;
break;
case OpCodes.FROM_ROOT:
whatToShow = DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT;
axis = Axis.ROOT;
predicateAxis = Axis.ROOT;
ai = new StepPattern(DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT, axis, predicateAxis);
break;
case OpCodes.FROM_ATTRIBUTES:
whatToShow = DTMFilter.SHOW_ATTRIBUTE;
axis = Axis.PARENT;
predicateAxis = Axis.ATTRIBUTE;
// ai = new StepPattern(whatToShow, Axis.SELF, Axis.SELF);
break;
case OpCodes.FROM_NAMESPACE:
whatToShow = DTMFilter.SHOW_NAMESPACE;
axis = Axis.PARENT;
predicateAxis = Axis.NAMESPACE;
// ai = new StepPattern(whatToShow, axis, predicateAxis);
break;
case OpCodes.FROM_ANCESTORS:
axis = Axis.DESCENDANT;
predicateAxis = Axis.ANCESTOR;
break;
case OpCodes.FROM_CHILDREN:
axis = Axis.PARENT;
predicateAxis = Axis.CHILD;
break;
case OpCodes.FROM_ANCESTORS_OR_SELF:
axis = Axis.DESCENDANTORSELF;
predicateAxis = Axis.ANCESTORORSELF;
break;
case OpCodes.FROM_SELF:
axis = Axis.SELF;
predicateAxis = Axis.SELF;
break;
case OpCodes.FROM_PARENT:
axis = Axis.CHILD;
predicateAxis = Axis.PARENT;
break;
case OpCodes.FROM_PRECEDING_SIBLINGS:
axis = Axis.FOLLOWINGSIBLING;
predicateAxis = Axis.PRECEDINGSIBLING;
break;
case OpCodes.FROM_PRECEDING:
axis = Axis.FOLLOWING;
predicateAxis = Axis.PRECEDING;
break;
case OpCodes.FROM_FOLLOWING_SIBLINGS:
axis = Axis.PRECEDINGSIBLING;
predicateAxis = Axis.FOLLOWINGSIBLING;
break;
case OpCodes.FROM_FOLLOWING:
axis = Axis.PRECEDING;
predicateAxis = Axis.FOLLOWING;
break;
case OpCodes.FROM_DESCENDANTS_OR_SELF:
axis = Axis.ANCESTORORSELF;
predicateAxis = Axis.DESCENDANTORSELF;
break;
case OpCodes.FROM_DESCENDANTS:
axis = Axis.ANCESTOR;
predicateAxis = Axis.DESCENDANT;
break;
default:
//"Programmer's assertion: unknown opcode: "
throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[] { Integer.toString(stepType) }));
}
if (null == ai) {
// %REVIEW%
whatToShow = compiler.getWhatToShow(opPos);
ai = new StepPattern(whatToShow, compiler.getStepNS(opPos), compiler.getStepLocalName(opPos), axis, predicateAxis);
}
if (false || DEBUG_PATTERN_CREATION) {
System.out.print("new step: " + ai);
System.out.print(", axis: " + Axis.getNames(ai.getAxis()));
System.out.print(", predAxis: " + Axis.getNames(ai.getAxis()));
System.out.print(", what: ");
System.out.print(" ");
ai.debugWhatToShow(ai.getWhatToShow());
}
int argLen = compiler.getFirstPredicateOpPos(opPos);
ai.setPredicates(compiler.getCompiledPredicates(argLen));
return ai;
}
use of org.apache.xpath.patterns.StepPattern in project robovm by robovm.
the class Compiler method stepPattern.
/**
* Compile a step pattern unit expression, used for both location paths
* and match patterns.
*
* @param opPos The current position in the m_opMap array.
* @param stepCount The number of steps to expect.
* @param ancestorPattern The owning StepPattern, which may be null.
*
* @return reference to {@link org.apache.xpath.patterns.StepPattern} instance.
*
* @throws TransformerException if a error occurs creating the Expression.
*/
protected StepPattern stepPattern(int opPos, int stepCount, StepPattern ancestorPattern) throws TransformerException {
int startOpPos = opPos;
int stepType = getOp(opPos);
if (OpCodes.ENDOP == stepType) {
return null;
}
boolean addMagicSelf = true;
int endStep = getNextOpPos(opPos);
// int nextStepType = getOpMap()[endStep];
StepPattern pattern;
// boolean isSimple = ((OpCodes.ENDOP == nextStepType) && (stepCount == 0));
int argLen;
switch(stepType) {
case OpCodes.OP_FUNCTION:
if (DEBUG)
System.out.println("MATCH_FUNCTION: " + m_currentPattern);
addMagicSelf = false;
argLen = getOp(opPos + OpMap.MAPINDEX_LENGTH);
pattern = new FunctionPattern(compileFunction(opPos), Axis.PARENT, Axis.CHILD);
break;
case OpCodes.FROM_ROOT:
if (DEBUG)
System.out.println("FROM_ROOT, " + m_currentPattern);
addMagicSelf = false;
argLen = getArgLengthOfStep(opPos);
opPos = getFirstChildPosOfStep(opPos);
pattern = new StepPattern(DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT, Axis.PARENT, Axis.CHILD);
break;
case OpCodes.MATCH_ATTRIBUTE:
if (DEBUG)
System.out.println("MATCH_ATTRIBUTE: " + getStepLocalName(startOpPos) + ", " + m_currentPattern);
argLen = getArgLengthOfStep(opPos);
opPos = getFirstChildPosOfStep(opPos);
pattern = new StepPattern(DTMFilter.SHOW_ATTRIBUTE, getStepNS(startOpPos), getStepLocalName(startOpPos), Axis.PARENT, Axis.ATTRIBUTE);
break;
case OpCodes.MATCH_ANY_ANCESTOR:
if (DEBUG)
System.out.println("MATCH_ANY_ANCESTOR: " + getStepLocalName(startOpPos) + ", " + m_currentPattern);
argLen = getArgLengthOfStep(opPos);
opPos = getFirstChildPosOfStep(opPos);
int what = getWhatToShow(startOpPos);
// bit-o-hackery, but this code is due for the morgue anyway...
if (0x00000500 == what)
addMagicSelf = false;
pattern = new StepPattern(getWhatToShow(startOpPos), getStepNS(startOpPos), getStepLocalName(startOpPos), Axis.ANCESTOR, Axis.CHILD);
break;
case OpCodes.MATCH_IMMEDIATE_ANCESTOR:
if (DEBUG)
System.out.println("MATCH_IMMEDIATE_ANCESTOR: " + getStepLocalName(startOpPos) + ", " + m_currentPattern);
argLen = getArgLengthOfStep(opPos);
opPos = getFirstChildPosOfStep(opPos);
pattern = new StepPattern(getWhatToShow(startOpPos), getStepNS(startOpPos), getStepLocalName(startOpPos), Axis.PARENT, Axis.CHILD);
break;
default:
//"unknown match operation!");
error(XPATHErrorResources.ER_UNKNOWN_MATCH_OPERATION, null);
return null;
}
pattern.setPredicates(getCompiledPredicates(opPos + argLen));
if (null == ancestorPattern) {
// This is the magic and invisible "." at the head of every
// match pattern, and corresponds to the current node in the context
// list, from where predicates are counted.
// So, in order to calculate "foo[3]", it has to count from the
// current node in the context list, so, from that current node,
// the full pattern is really "self::node()/child::foo[3]". If you
// translate this to a select pattern from the node being tested,
// which is really how we're treating match patterns, it works out to
// self::foo/parent::node[child::foo[3]]", or close enough.
/* if(addMagicSelf && pattern.getPredicateCount() > 0)
{
StepPattern selfPattern = new StepPattern(DTMFilter.SHOW_ALL,
Axis.PARENT, Axis.CHILD);
// We need to keep the new nodetest from affecting the score...
XNumber score = pattern.getStaticScore();
pattern.setRelativePathPattern(selfPattern);
pattern.setStaticScore(score);
selfPattern.setStaticScore(score);
}*/
} else {
// System.out.println("Setting "+ancestorPattern+" as relative to "+pattern);
pattern.setRelativePathPattern(ancestorPattern);
}
StepPattern relativePathPattern = stepPattern(endStep, stepCount + 1, pattern);
return (null != relativePathPattern) ? relativePathPattern : pattern;
}
use of org.apache.xpath.patterns.StepPattern in project robovm by robovm.
the class Compiler method matchPattern.
/**
* Compile an entire match pattern expression.
*
* @param opPos The current position in the m_opMap array.
*
* @return reference to {@link org.apache.xpath.patterns.UnionPattern} instance.
*
* @throws TransformerException if a error occurs creating the Expression.
*/
protected Expression matchPattern(int opPos) throws TransformerException {
locPathDepth++;
try {
// First, count...
int nextOpPos = opPos;
int i;
for (i = 0; getOp(nextOpPos) == OpCodes.OP_LOCATIONPATHPATTERN; i++) {
nextOpPos = getNextOpPos(nextOpPos);
}
if (i == 1)
return compile(opPos);
UnionPattern up = new UnionPattern();
StepPattern[] patterns = new StepPattern[i];
for (i = 0; getOp(opPos) == OpCodes.OP_LOCATIONPATHPATTERN; i++) {
nextOpPos = getNextOpPos(opPos);
patterns[i] = (StepPattern) compile(opPos);
opPos = nextOpPos;
}
up.setPatterns(patterns);
return up;
} finally {
locPathDepth--;
}
}
use of org.apache.xpath.patterns.StepPattern in project j2objc by google.
the class FuncCurrent method execute.
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
SubContextList subContextList = xctxt.getCurrentNodeList();
int currentNode = DTM.NULL;
if (null != subContextList) {
if (subContextList instanceof PredicatedNodeTest) {
LocPathIterator iter = ((PredicatedNodeTest) subContextList).getLocPathIterator();
currentNode = iter.getCurrentContextNode();
} else if (subContextList instanceof StepPattern) {
throw new RuntimeException(XSLMessages.createMessage(XSLTErrorResources.ER_PROCESSOR_ERROR, null));
}
} else {
// not predicate => ContextNode == CurrentNode
currentNode = xctxt.getContextNode();
}
return new XNodeSet(currentNode, xctxt.getDTMManager());
}
use of org.apache.xpath.patterns.StepPattern in project j2objc by google.
the class WalkerFactory method createDefaultStepPattern.
/**
* Create a StepPattern that is contained within a LocationPath.
*
* @param compiler The compiler that holds the syntax tree/op map to
* construct from.
* @param stepOpCodePos The current op code position within the opmap.
* @param mpi The MatchPatternIterator to which the steps will be attached.
* @param analysis 32 bits of analysis, from which the type of AxesWalker
* may be influenced.
* @param tail The step that is the first step analyzed, but the last
* step in the relative match linked list, i.e. the tail.
* May be null.
* @param head The step that is the current head of the relative
* match step linked list.
* May be null.
*
* @return the head of the list.
*
* @throws javax.xml.transform.TransformerException
*/
private static StepPattern createDefaultStepPattern(Compiler compiler, int opPos, MatchPatternIterator mpi, int analysis, StepPattern tail, StepPattern head) throws javax.xml.transform.TransformerException {
int stepType = compiler.getOp(opPos);
boolean simpleInit = false;
boolean prevIsOneStepDown = true;
int whatToShow = compiler.getWhatToShow(opPos);
StepPattern ai = null;
int axis, predicateAxis;
switch(stepType) {
case OpCodes.OP_VARIABLE:
case OpCodes.OP_EXTFUNCTION:
case OpCodes.OP_FUNCTION:
case OpCodes.OP_GROUP:
prevIsOneStepDown = false;
Expression expr;
switch(stepType) {
case OpCodes.OP_VARIABLE:
case OpCodes.OP_EXTFUNCTION:
case OpCodes.OP_FUNCTION:
case OpCodes.OP_GROUP:
expr = compiler.compile(opPos);
break;
default:
expr = compiler.compile(opPos + 2);
}
axis = Axis.FILTEREDLIST;
predicateAxis = Axis.FILTEREDLIST;
ai = new FunctionPattern(expr, axis, predicateAxis);
simpleInit = true;
break;
case OpCodes.FROM_ROOT:
whatToShow = DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT;
axis = Axis.ROOT;
predicateAxis = Axis.ROOT;
ai = new StepPattern(DTMFilter.SHOW_DOCUMENT | DTMFilter.SHOW_DOCUMENT_FRAGMENT, axis, predicateAxis);
break;
case OpCodes.FROM_ATTRIBUTES:
whatToShow = DTMFilter.SHOW_ATTRIBUTE;
axis = Axis.PARENT;
predicateAxis = Axis.ATTRIBUTE;
// ai = new StepPattern(whatToShow, Axis.SELF, Axis.SELF);
break;
case OpCodes.FROM_NAMESPACE:
whatToShow = DTMFilter.SHOW_NAMESPACE;
axis = Axis.PARENT;
predicateAxis = Axis.NAMESPACE;
// ai = new StepPattern(whatToShow, axis, predicateAxis);
break;
case OpCodes.FROM_ANCESTORS:
axis = Axis.DESCENDANT;
predicateAxis = Axis.ANCESTOR;
break;
case OpCodes.FROM_CHILDREN:
axis = Axis.PARENT;
predicateAxis = Axis.CHILD;
break;
case OpCodes.FROM_ANCESTORS_OR_SELF:
axis = Axis.DESCENDANTORSELF;
predicateAxis = Axis.ANCESTORORSELF;
break;
case OpCodes.FROM_SELF:
axis = Axis.SELF;
predicateAxis = Axis.SELF;
break;
case OpCodes.FROM_PARENT:
axis = Axis.CHILD;
predicateAxis = Axis.PARENT;
break;
case OpCodes.FROM_PRECEDING_SIBLINGS:
axis = Axis.FOLLOWINGSIBLING;
predicateAxis = Axis.PRECEDINGSIBLING;
break;
case OpCodes.FROM_PRECEDING:
axis = Axis.FOLLOWING;
predicateAxis = Axis.PRECEDING;
break;
case OpCodes.FROM_FOLLOWING_SIBLINGS:
axis = Axis.PRECEDINGSIBLING;
predicateAxis = Axis.FOLLOWINGSIBLING;
break;
case OpCodes.FROM_FOLLOWING:
axis = Axis.PRECEDING;
predicateAxis = Axis.FOLLOWING;
break;
case OpCodes.FROM_DESCENDANTS_OR_SELF:
axis = Axis.ANCESTORORSELF;
predicateAxis = Axis.DESCENDANTORSELF;
break;
case OpCodes.FROM_DESCENDANTS:
axis = Axis.ANCESTOR;
predicateAxis = Axis.DESCENDANT;
break;
default:
// "Programmer's assertion: unknown opcode: "
throw new RuntimeException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, new Object[] { Integer.toString(stepType) }));
}
if (null == ai) {
// %REVIEW%
whatToShow = compiler.getWhatToShow(opPos);
ai = new StepPattern(whatToShow, compiler.getStepNS(opPos), compiler.getStepLocalName(opPos), axis, predicateAxis);
}
if (false || DEBUG_PATTERN_CREATION) {
System.out.print("new step: " + ai);
System.out.print(", axis: " + Axis.getNames(ai.getAxis()));
System.out.print(", predAxis: " + Axis.getNames(ai.getAxis()));
System.out.print(", what: ");
System.out.print(" ");
ai.debugWhatToShow(ai.getWhatToShow());
}
int argLen = compiler.getFirstPredicateOpPos(opPos);
ai.setPredicates(compiler.getCompiledPredicates(argLen));
return ai;
}
Aggregations