public class RedundentExprEliminator extends XSLTVisitor
Modifier and Type | Field and Description |
---|---|
static boolean |
DEBUG |
static boolean |
DIAGNOSE_MULTISTEPLIST |
static boolean |
DIAGNOSE_NUM_PATHS_REDUCED |
Constructor and Description |
---|
RedundentExprEliminator()
Construct a RedundentExprEliminator.
|
Modifier and Type | Method and Description |
---|---|
protected ElemVariable |
addVarDeclToElem(ElemTemplateElement psuedoVarRecipient,
LocPathIterator lpi,
ElemVariable psuedoVar)
Add the given variable to the psuedoVarRecipient.
|
protected static void |
assertion(boolean b,
String msg)
Simple assertion.
|
protected LocPathIterator |
changePartToRef(QName uniquePseudoVarName,
WalkingIterator wi,
int numSteps,
boolean isGlobal)
Change a given number of steps to a single variable reference.
|
protected void |
changeToVarRef(QName varName,
ExpressionOwner owner,
Vector paths,
ElemTemplateElement psuedoVarRecipient)
Change the expression owned by the owner argument to a variable reference
of the given name.
|
protected int |
countAncestors(ElemTemplateElement elem)
Count the number of ancestors that a ElemTemplateElement has.
|
protected int |
countSteps(LocPathIterator lpi)
Count the steps in a given location path.
|
protected ElemVariable |
createGlobalPseudoVarDecl(QName uniquePseudoVarName,
StylesheetRoot stylesheetRoot,
LocPathIterator lpi)
Create a psuedo variable reference that will represent the
shared redundent XPath, for a local reduction.
|
protected WalkingIterator |
createIteratorFromSteps(WalkingIterator wi,
int numSteps)
Create a new WalkingIterator from the steps in another WalkingIterator.
|
protected ElemVariable |
createLocalPseudoVarDecl(QName uniquePseudoVarName,
ElemTemplateElement psuedoVarRecipient,
LocPathIterator lpi)
Create a psuedo variable reference that will represent the
shared redundent XPath, for a local reduction.
|
protected org.apache.xalan.templates.RedundentExprEliminator.MultistepExprHolder |
createMultistepExprList(Vector paths)
For the reduction of location path parts, create a list of all
the multistep paths with more than one step, sorted by the
number of steps, with the most steps occuring earlier in the list.
|
protected ElemVariable |
createPseudoVarDecl(ElemTemplateElement psuedoVarRecipient,
LocPathIterator lpi,
boolean isGlobal)
Create a psuedo variable reference that will represent the
shared redundent XPath, and add it to the stylesheet.
|
protected void |
diagnoseLineNumber(Expression expr)
Tell what line number belongs to a given expression.
|
protected void |
diagnoseMultistepList(int matchCount,
int lengthToTest,
boolean isGlobal)
Print out diagnostics about partial multistep evaluation.
|
protected void |
diagnoseNumPaths(Vector paths,
int numPathsEliminated,
int numUniquePathsEliminated)
Print out to std err the number of paths reduced.
|
protected void |
eleminateRedundent(ElemTemplateElement psuedoVarRecipient,
Vector paths)
Method to be called after the all expressions within an
node context have been visited.
|
void |
eleminateRedundentGlobals(StylesheetRoot stylesheet)
Method to be called after the all global expressions within a stylesheet
have been collected.
|
void |
eleminateRedundentLocals(ElemTemplateElement psuedoVarRecipient)
Method to be called after the all expressions within an
node context have been visited.
|
protected void |
eleminateSharedPartialPaths(ElemTemplateElement psuedoVarRecipient,
Vector paths)
Eliminate the shared partial paths in the expression list.
|
protected int |
findAndEliminateRedundant(int start,
int firstOccuranceIndex,
ExpressionOwner firstOccuranceOwner,
ElemTemplateElement psuedoVarRecipient,
Vector paths)
Look through the vector from start point, looking for redundant occurances.
|
protected ElemTemplateElement |
findCommonAncestor(org.apache.xalan.templates.RedundentExprEliminator.MultistepExprHolder head)
Given a linked list of expressions, find the common ancestor that is
suitable for holding a psuedo variable for shared access.
|
protected ElemTemplateElement |
getElemFromExpression(Expression expr)
From an XPath expression component, get the ElemTemplateElement
owner.
|
protected ElemTemplateElement |
getPrevElementWithinContext(ElemTemplateElement elem)
Get the previous sibling or parent of the given template, stopping at
xsl:for-each, xsl:template, or xsl:stylesheet.
|
protected ElemVariable |
getPrevVariableElem(ElemTemplateElement elem)
Find the previous occurance of a xsl:variable.
|
boolean |
isAbsolute(LocPathIterator path)
Tell if the given LocPathIterator is relative to an absolute path, i.e.
|
protected boolean |
isNotSameAsOwner(org.apache.xalan.templates.RedundentExprEliminator.MultistepExprHolder head,
ElemTemplateElement ete)
Find out if the given ElemTemplateElement is not the same as one of
the ElemTemplateElement owners of the expressions.
|
protected boolean |
isParam(ExpressionNode expr)
Tell if the expr param is contained within an xsl:param.
|
protected org.apache.xalan.templates.RedundentExprEliminator.MultistepExprHolder |
matchAndEliminatePartialPaths(org.apache.xalan.templates.RedundentExprEliminator.MultistepExprHolder testee,
org.apache.xalan.templates.RedundentExprEliminator.MultistepExprHolder head,
boolean isGlobal,
int lengthToTest,
ElemTemplateElement varScope)
For a given path, see if there are any partitial matches in the list,
and, if there are, replace those partial paths with psuedo variable refs,
and create the psuedo variable decl.
|
protected int |
oldFindAndEliminateRedundant(int start,
int firstOccuranceIndex,
ExpressionOwner firstOccuranceOwner,
ElemTemplateElement psuedoVarRecipient,
Vector paths)
To be removed.
|
protected boolean |
stepsEqual(WalkingIterator iter1,
WalkingIterator iter2,
int numSteps)
Compare a given number of steps between two iterators, to see if they are equal.
|
boolean |
visitInstruction(ElemTemplateElement elem)
Visit an XSLT instruction.
|
boolean |
visitLocationPath(ExpressionOwner owner,
LocPathIterator path)
Visit a LocationPath.
|
boolean |
visitPredicate(ExpressionOwner owner,
Expression pred)
Visit a predicate within a location path.
|
boolean |
visitTopLevelInstruction(ElemTemplateElement elem)
Visit an XSLT top-level instruction.
|
visitAVT, visitExtensionElement, visitLiteralResultElement, visitStylesheet, visitTopLevelVariableOrParamDecl, visitVariableOrParamDecl
visitBinaryOperation, visitFunction, visitMatchPattern, visitNumberLiteral, visitStep, visitStringLiteral, visitUnaryOperation, visitUnionPath, visitUnionPattern, visitVariableRef
public static final boolean DEBUG
public static final boolean DIAGNOSE_NUM_PATHS_REDUCED
public static final boolean DIAGNOSE_MULTISTEPLIST
public RedundentExprEliminator()
public void eleminateRedundentLocals(ElemTemplateElement psuedoVarRecipient)
psuedoVarRecipient
- The recipient of the psuedo vars. The
variables will be inserted as first children of the element, before
any existing variables.public void eleminateRedundentGlobals(StylesheetRoot stylesheet)
protected void eleminateRedundent(ElemTemplateElement psuedoVarRecipient, Vector paths)
psuedoVarRecipient
- The owner of the subtree from where the
paths were collected.paths
- A vector of paths that hold ExpressionOwner objects,
which must yield LocationPathIterators.protected void eleminateSharedPartialPaths(ElemTemplateElement psuedoVarRecipient, Vector paths)
psuedoVarRecipient
- The recipient of the psuedo vars.paths
- A vector of paths that hold ExpressionOwner objects,
which must yield LocationPathIterators.protected org.apache.xalan.templates.RedundentExprEliminator.MultistepExprHolder matchAndEliminatePartialPaths(org.apache.xalan.templates.RedundentExprEliminator.MultistepExprHolder testee, org.apache.xalan.templates.RedundentExprEliminator.MultistepExprHolder head, boolean isGlobal, int lengthToTest, ElemTemplateElement varScope)
protected void diagnoseLineNumber(Expression expr)
protected ElemTemplateElement findCommonAncestor(org.apache.xalan.templates.RedundentExprEliminator.MultistepExprHolder head)
protected boolean isNotSameAsOwner(org.apache.xalan.templates.RedundentExprEliminator.MultistepExprHolder head, ElemTemplateElement ete)
head
- Head of linked list of expression owners.ete
- The ElemTemplateElement that is a candidate for a psuedo
variable parent.protected int countAncestors(ElemTemplateElement elem)
elem
- An representation of an element in an XSLT stylesheet.protected void diagnoseMultistepList(int matchCount, int lengthToTest, boolean isGlobal)
protected LocPathIterator changePartToRef(QName uniquePseudoVarName, WalkingIterator wi, int numSteps, boolean isGlobal)
uniquePseudoVarName
- The name of the variable reference.wi
- The walking iterator that is to be changed.numSteps
- The number of steps to be changed.isGlobal
- true if this will be a global reference.protected WalkingIterator createIteratorFromSteps(WalkingIterator wi, int numSteps)
wi
- The iterator from where the steps will be taken.numSteps
- The number of steps from the first to copy into the new
iterator.protected boolean stepsEqual(WalkingIterator iter1, WalkingIterator iter2, int numSteps)
iter1
- The first iterator to compare.iter2
- The second iterator to compare.numSteps
- The number of steps to compare.protected org.apache.xalan.templates.RedundentExprEliminator.MultistepExprHolder createMultistepExprList(Vector paths)
paths
- Vector of ExpressionOwner objects, which may contain null entries.
The ExpressionOwner objects must own LocPathIterator objects.protected int findAndEliminateRedundant(int start, int firstOccuranceIndex, ExpressionOwner firstOccuranceOwner, ElemTemplateElement psuedoVarRecipient, Vector paths) throws DOMException
start
- The position to start looking in the vector.firstOccuranceIndex
- The position of firstOccuranceOwner.firstOccuranceOwner
- The owner of the expression we are looking for.psuedoVarRecipient
- Where to put the psuedo variables.DOMException
protected int oldFindAndEliminateRedundant(int start, int firstOccuranceIndex, ExpressionOwner firstOccuranceOwner, ElemTemplateElement psuedoVarRecipient, Vector paths) throws DOMException
DOMException
protected int countSteps(LocPathIterator lpi)
lpi
- The location path iterator that owns the steps.protected void changeToVarRef(QName varName, ExpressionOwner owner, Vector paths, ElemTemplateElement psuedoVarRecipient)
varName
- The name of the variable which will be referenced.owner
- The owner of the expression which will be replaced by a variable ref.paths
- The paths list that the iterator came from, mainly to determine
if this is a local or global reduction.psuedoVarRecipient
- The element within whose scope the variable is
being inserted, possibly a StylesheetRoot.protected ElemVariable createPseudoVarDecl(ElemTemplateElement psuedoVarRecipient, LocPathIterator lpi, boolean isGlobal) throws DOMException
psuedoVarRecipient
- The broadest scope of where the variable
should be inserted, usually an xsl:template or xsl:for-each.lpi
- The LocationPathIterator that the variable should represent.isGlobal
- true if the paths are global.DOMException
protected ElemVariable createGlobalPseudoVarDecl(QName uniquePseudoVarName, StylesheetRoot stylesheetRoot, LocPathIterator lpi) throws DOMException
uniquePseudoVarName
- The name of the new variable.stylesheetRoot
- The broadest scope of where the variable
should be inserted, which must be a StylesheetRoot element in this case.lpi
- The LocationPathIterator that the variable should represent.DOMException
protected ElemVariable createLocalPseudoVarDecl(QName uniquePseudoVarName, ElemTemplateElement psuedoVarRecipient, LocPathIterator lpi) throws DOMException
uniquePseudoVarName
- The name of the new variable.psuedoVarRecipient
- The broadest scope of where the variable
should be inserted, usually an xsl:template or xsl:for-each.lpi
- The LocationPathIterator that the variable should represent.DOMException
protected ElemVariable addVarDeclToElem(ElemTemplateElement psuedoVarRecipient, LocPathIterator lpi, ElemVariable psuedoVar) throws DOMException
DOMException
protected boolean isParam(ExpressionNode expr)
protected ElemVariable getPrevVariableElem(ElemTemplateElement elem)
elem
- Should be non-null template element.protected ElemTemplateElement getPrevElementWithinContext(ElemTemplateElement elem)
elem
- Should be non-null template element.protected ElemTemplateElement getElemFromExpression(Expression expr)
expr
- Should be static expression with proper parentage.public boolean isAbsolute(LocPathIterator path)
public boolean visitLocationPath(ExpressionOwner owner, LocPathIterator path)
visitLocationPath
in class XPathVisitor
owner
- The owner of the expression, to which the expression can
be reset if rewriting takes place.path
- The LocationPath object.public boolean visitPredicate(ExpressionOwner owner, Expression pred)
visitPredicate
in class XPathVisitor
owner
- The owner of the expression, to which the expression can
be reset if rewriting takes place.pred
- The predicate object.public boolean visitTopLevelInstruction(ElemTemplateElement elem)
visitTopLevelInstruction
in class XSLTVisitor
elem
- The xsl instruction element object.public boolean visitInstruction(ElemTemplateElement elem)
visitInstruction
in class XSLTVisitor
elem
- The xsl instruction element object.protected void diagnoseNumPaths(Vector paths, int numPathsEliminated, int numUniquePathsEliminated)
protected static void assertion(boolean b, String msg)
Copyright © 2017 JBoss by Red Hat. All rights reserved.