Search in sources :

Example 6 with ExpressionOwner

use of org.apache.xpath.ExpressionOwner in project robovm by robovm.

the class RedundentExprEliminator method oldFindAndEliminateRedundant.

/**
   * To be removed.
   */
protected int oldFindAndEliminateRedundant(int start, int firstOccuranceIndex, ExpressionOwner firstOccuranceOwner, ElemTemplateElement psuedoVarRecipient, Vector paths) throws org.w3c.dom.DOMException {
    QName uniquePseudoVarName = null;
    boolean foundFirst = false;
    int numPathsFound = 0;
    int n = paths.size();
    Expression expr1 = firstOccuranceOwner.getExpression();
    if (DEBUG)
        assertIsLocPathIterator(expr1, firstOccuranceOwner);
    boolean isGlobal = (paths == m_absPaths);
    LocPathIterator lpi = (LocPathIterator) expr1;
    for (int j = start; j < n; j++) {
        ExpressionOwner owner2 = (ExpressionOwner) paths.elementAt(j);
        if (null != owner2) {
            Expression expr2 = owner2.getExpression();
            boolean isEqual = expr2.deepEquals(lpi);
            if (isEqual) {
                LocPathIterator lpi2 = (LocPathIterator) expr2;
                if (!foundFirst) {
                    foundFirst = true;
                    // Insert variable decl into psuedoVarRecipient
                    // We want to insert this into the first legitimate 
                    // position for a variable.
                    ElemVariable var = createPseudoVarDecl(psuedoVarRecipient, lpi, isGlobal);
                    if (null == var)
                        return 0;
                    uniquePseudoVarName = var.getName();
                    changeToVarRef(uniquePseudoVarName, firstOccuranceOwner, paths, psuedoVarRecipient);
                    // Replace the first occurance with the variable's XPath, so  
                    // that further reduction may take place if needed.
                    paths.setElementAt(var.getSelect(), firstOccuranceIndex);
                    numPathsFound++;
                }
                changeToVarRef(uniquePseudoVarName, owner2, paths, psuedoVarRecipient);
                // Null out the occurance, so we don't have to test it again.
                paths.setElementAt(null, j);
                // foundFirst = true;
                numPathsFound++;
            }
        }
    }
    // Change all globals in xsl:templates, etc, to global vars no matter what.
    if ((0 == numPathsFound) && (paths == m_absPaths)) {
        ElemVariable var = createPseudoVarDecl(psuedoVarRecipient, lpi, true);
        if (null == var)
            return 0;
        uniquePseudoVarName = var.getName();
        changeToVarRef(uniquePseudoVarName, firstOccuranceOwner, paths, psuedoVarRecipient);
        paths.setElementAt(var.getSelect(), firstOccuranceIndex);
        numPathsFound++;
    }
    return numPathsFound;
}
Also used : Expression(org.apache.xpath.Expression) QName(org.apache.xml.utils.QName) LocPathIterator(org.apache.xpath.axes.LocPathIterator) ExpressionOwner(org.apache.xpath.ExpressionOwner)

Example 7 with ExpressionOwner

use of org.apache.xpath.ExpressionOwner in project robovm by robovm.

the class RedundentExprEliminator method eleminateRedundent.

/**
   * Method to be called after the all expressions within an  
   * node context have been visited.  It eliminates redundent 
   * expressions by creating a variable in the psuedoVarRecipient 
   * for each redundent expression, and then rewriting the redundent 
   * expression to be a variable reference.
   * 
   * @param psuedoVarRecipient The owner of the subtree from where the 
   *                           paths were collected.
   * @param paths A vector of paths that hold ExpressionOwner objects, 
   *              which must yield LocationPathIterators.
   */
protected void eleminateRedundent(ElemTemplateElement psuedoVarRecipient, Vector paths) {
    int n = paths.size();
    int numPathsEliminated = 0;
    int numUniquePathsEliminated = 0;
    for (int i = 0; i < n; i++) {
        ExpressionOwner owner = (ExpressionOwner) paths.elementAt(i);
        if (null != owner) {
            int found = findAndEliminateRedundant(i + 1, i, owner, psuedoVarRecipient, paths);
            if (found > 0)
                numUniquePathsEliminated++;
            numPathsEliminated += found;
        }
    }
    eleminateSharedPartialPaths(psuedoVarRecipient, paths);
    if (DIAGNOSE_NUM_PATHS_REDUCED)
        diagnoseNumPaths(paths, numPathsEliminated, numUniquePathsEliminated);
}
Also used : ExpressionOwner(org.apache.xpath.ExpressionOwner)

Example 8 with ExpressionOwner

use of org.apache.xpath.ExpressionOwner in project robovm by robovm.

the class RedundentExprEliminator method matchAndEliminatePartialPaths.

/**
   * 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.
   * 
   * @return The head of the list, which may have changed.
   */
protected MultistepExprHolder matchAndEliminatePartialPaths(MultistepExprHolder testee, MultistepExprHolder head, boolean isGlobal, int lengthToTest, ElemTemplateElement varScope) {
    if (null == testee.m_exprOwner)
        return head;
    // Start with the longest possible match, and move down.
    WalkingIterator iter1 = (WalkingIterator) testee.m_exprOwner.getExpression();
    if (partialIsVariable(testee, lengthToTest))
        return head;
    MultistepExprHolder matchedPaths = null;
    MultistepExprHolder matchedPathsTail = null;
    MultistepExprHolder meh = head;
    while (null != meh) {
        if ((meh != testee) && (null != meh.m_exprOwner)) {
            WalkingIterator iter2 = (WalkingIterator) meh.m_exprOwner.getExpression();
            if (stepsEqual(iter1, iter2, lengthToTest)) {
                if (null == matchedPaths) {
                    try {
                        matchedPaths = (MultistepExprHolder) testee.clone();
                        // So it won't be processed again.
                        testee.m_exprOwner = null;
                    } catch (CloneNotSupportedException cnse) {
                    }
                    matchedPathsTail = matchedPaths;
                    matchedPathsTail.m_next = null;
                }
                try {
                    matchedPathsTail.m_next = (MultistepExprHolder) meh.clone();
                    // So it won't be processed again.
                    meh.m_exprOwner = null;
                } catch (CloneNotSupportedException cnse) {
                }
                matchedPathsTail = matchedPathsTail.m_next;
                matchedPathsTail.m_next = null;
            }
        }
        meh = meh.m_next;
    }
    int matchCount = 0;
    if (null != matchedPaths) {
        ElemTemplateElement root = isGlobal ? varScope : findCommonAncestor(matchedPaths);
        WalkingIterator sharedIter = (WalkingIterator) matchedPaths.m_exprOwner.getExpression();
        WalkingIterator newIter = createIteratorFromSteps(sharedIter, lengthToTest);
        ElemVariable var = createPseudoVarDecl(root, newIter, isGlobal);
        if (DIAGNOSE_MULTISTEPLIST)
            System.err.println("Created var: " + var.getName() + (isGlobal ? "(Global)" : ""));
        while (null != matchedPaths) {
            ExpressionOwner owner = matchedPaths.m_exprOwner;
            WalkingIterator iter = (WalkingIterator) owner.getExpression();
            if (DIAGNOSE_MULTISTEPLIST)
                diagnoseLineNumber(iter);
            LocPathIterator newIter2 = changePartToRef(var.getName(), iter, lengthToTest, isGlobal);
            owner.setExpression(newIter2);
            matchedPaths = matchedPaths.m_next;
        }
    }
    if (DIAGNOSE_MULTISTEPLIST)
        diagnoseMultistepList(matchCount, lengthToTest, isGlobal);
    return head;
}
Also used : WalkingIterator(org.apache.xpath.axes.WalkingIterator) LocPathIterator(org.apache.xpath.axes.LocPathIterator) ExpressionOwner(org.apache.xpath.ExpressionOwner)

Example 9 with ExpressionOwner

use of org.apache.xpath.ExpressionOwner in project j2objc by google.

the class RedundentExprEliminator method createMultistepExprList.

/**
 * 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.
 * If the list is only one member, don't bother returning it.
 *
 * @param paths Vector of ExpressionOwner objects, which may contain null entries.
 *              The ExpressionOwner objects must own LocPathIterator objects.
 * @return null if no multipart paths are found or the list is only of length 1,
 * otherwise the first MultistepExprHolder in a linked list of these objects.
 */
protected MultistepExprHolder createMultistepExprList(Vector paths) {
    MultistepExprHolder first = null;
    int n = paths.size();
    for (int i = 0; i < n; i++) {
        ExpressionOwner eo = (ExpressionOwner) paths.elementAt(i);
        if (null == eo)
            continue;
        // Assuming location path iterators should be OK.
        LocPathIterator lpi = (LocPathIterator) eo.getExpression();
        int numPaths = countSteps(lpi);
        if (numPaths > 1) {
            if (null == first)
                first = new MultistepExprHolder(eo, numPaths, null);
            else
                first = first.addInSortedOrder(eo, numPaths);
        }
    }
    if ((null == first) || (first.getLength() <= 1))
        return null;
    else
        return first;
}
Also used : LocPathIterator(org.apache.xpath.axes.LocPathIterator) ExpressionOwner(org.apache.xpath.ExpressionOwner)

Example 10 with ExpressionOwner

use of org.apache.xpath.ExpressionOwner in project j2objc by google.

the class RedundentExprEliminator method eleminateRedundent.

/**
 * Method to be called after the all expressions within an
 * node context have been visited.  It eliminates redundent
 * expressions by creating a variable in the psuedoVarRecipient
 * for each redundent expression, and then rewriting the redundent
 * expression to be a variable reference.
 *
 * @param psuedoVarRecipient The owner of the subtree from where the
 *                           paths were collected.
 * @param paths A vector of paths that hold ExpressionOwner objects,
 *              which must yield LocationPathIterators.
 */
protected void eleminateRedundent(ElemTemplateElement psuedoVarRecipient, Vector paths) {
    int n = paths.size();
    int numPathsEliminated = 0;
    int numUniquePathsEliminated = 0;
    for (int i = 0; i < n; i++) {
        ExpressionOwner owner = (ExpressionOwner) paths.elementAt(i);
        if (null != owner) {
            int found = findAndEliminateRedundant(i + 1, i, owner, psuedoVarRecipient, paths);
            if (found > 0)
                numUniquePathsEliminated++;
            numPathsEliminated += found;
        }
    }
    eleminateSharedPartialPaths(psuedoVarRecipient, paths);
    if (DIAGNOSE_NUM_PATHS_REDUCED)
        diagnoseNumPaths(paths, numPathsEliminated, numUniquePathsEliminated);
}
Also used : ExpressionOwner(org.apache.xpath.ExpressionOwner)

Aggregations

ExpressionOwner (org.apache.xpath.ExpressionOwner)12 LocPathIterator (org.apache.xpath.axes.LocPathIterator)8 QName (org.apache.xml.utils.QName)4 Expression (org.apache.xpath.Expression)4 WalkingIterator (org.apache.xpath.axes.WalkingIterator)2