Search in sources :

Example 1 with Variable

use of org.apache.xpath.operations.Variable in project robovm by robovm.

the class Compiler method variable.

/**
   * Compile a variable reference.
   * 
   * @param opPos The current position in the m_opMap array.
   *
   * @return reference to {@link org.apache.xpath.operations.Variable} instance.
   *
   * @throws TransformerException if a error occurs creating the Expression.
   */
protected Expression variable(int opPos) throws TransformerException {
    Variable var = new Variable();
    opPos = getFirstChildPos(opPos);
    int nsPos = getOp(opPos);
    java.lang.String namespace = (OpCodes.EMPTY == nsPos) ? null : (java.lang.String) getTokenQueue().elementAt(nsPos);
    java.lang.String localname = (java.lang.String) getTokenQueue().elementAt(getOp(opPos + 1));
    QName qname = new QName(namespace, localname);
    var.setQName(qname);
    return var;
}
Also used : Variable(org.apache.xpath.operations.Variable) QName(org.apache.xml.utils.QName) XString(org.apache.xpath.objects.XString)

Example 2 with Variable

use of org.apache.xpath.operations.Variable in project j2objc by google.

the class RedundentExprEliminator method changePartToRef.

/**
   * Change a given number of steps to a single variable reference.
   * 
   * @param uniquePseudoVarName The name of the variable reference.
   * @param wi The walking iterator that is to be changed.
   * @param numSteps The number of steps to be changed.
   * @param isGlobal true if this will be a global reference.
   */
protected LocPathIterator changePartToRef(final QName uniquePseudoVarName, WalkingIterator wi, final int numSteps, final boolean isGlobal) {
    Variable var = new Variable();
    var.setQName(uniquePseudoVarName);
    var.setIsGlobal(isGlobal);
    if (isGlobal) {
        ElemTemplateElement elem = getElemFromExpression(wi);
        StylesheetRoot root = elem.getStylesheetRoot();
        Vector vars = root.getVariablesAndParamsComposed();
        var.setIndex(vars.size() - 1);
    }
    // Walk to the first walker after the one's we are replacing.
    AxesWalker walker = wi.getFirstWalker();
    for (int i = 0; i < numSteps; i++) {
        assertion(null != walker, "Walker should not be null!");
        walker = walker.getNextWalker();
    }
    if (null != walker) {
        FilterExprWalker few = new FilterExprWalker(wi);
        few.setInnerExpression(var);
        few.exprSetParent(wi);
        few.setNextWalker(walker);
        walker.setPrevWalker(few);
        wi.setFirstWalker(few);
        return wi;
    } else {
        FilterExprIteratorSimple feis = new FilterExprIteratorSimple(var);
        feis.exprSetParent(wi.exprGetParent());
        return feis;
    }
}
Also used : Variable(org.apache.xpath.operations.Variable) FilterExprWalker(org.apache.xpath.axes.FilterExprWalker) AxesWalker(org.apache.xpath.axes.AxesWalker) FilterExprIteratorSimple(org.apache.xpath.axes.FilterExprIteratorSimple) Vector(java.util.Vector)

Example 3 with Variable

use of org.apache.xpath.operations.Variable in project j2objc by google.

the class Compiler method variable.

/**
   * Compile a variable reference.
   * 
   * @param opPos The current position in the m_opMap array.
   *
   * @return reference to {@link org.apache.xpath.operations.Variable} instance.
   *
   * @throws TransformerException if a error occurs creating the Expression.
   */
protected Expression variable(int opPos) throws TransformerException {
    Variable var = new Variable();
    opPos = getFirstChildPos(opPos);
    int nsPos = getOp(opPos);
    java.lang.String namespace = (OpCodes.EMPTY == nsPos) ? null : (java.lang.String) getTokenQueue().elementAt(nsPos);
    java.lang.String localname = (java.lang.String) getTokenQueue().elementAt(getOp(opPos + 1));
    QName qname = new QName(namespace, localname);
    var.setQName(qname);
    return var;
}
Also used : Variable(org.apache.xpath.operations.Variable) QName(org.apache.xml.utils.QName) XString(org.apache.xpath.objects.XString)

Example 4 with Variable

use of org.apache.xpath.operations.Variable in project robovm by robovm.

the class RedundentExprEliminator method changePartToRef.

/**
   * Change a given number of steps to a single variable reference.
   * 
   * @param uniquePseudoVarName The name of the variable reference.
   * @param wi The walking iterator that is to be changed.
   * @param numSteps The number of steps to be changed.
   * @param isGlobal true if this will be a global reference.
   */
protected LocPathIterator changePartToRef(final QName uniquePseudoVarName, WalkingIterator wi, final int numSteps, final boolean isGlobal) {
    Variable var = new Variable();
    var.setQName(uniquePseudoVarName);
    var.setIsGlobal(isGlobal);
    if (isGlobal) {
        ElemTemplateElement elem = getElemFromExpression(wi);
        StylesheetRoot root = elem.getStylesheetRoot();
        Vector vars = root.getVariablesAndParamsComposed();
        var.setIndex(vars.size() - 1);
    }
    // Walk to the first walker after the one's we are replacing.
    AxesWalker walker = wi.getFirstWalker();
    for (int i = 0; i < numSteps; i++) {
        assertion(null != walker, "Walker should not be null!");
        walker = walker.getNextWalker();
    }
    if (null != walker) {
        FilterExprWalker few = new FilterExprWalker(wi);
        few.setInnerExpression(var);
        few.exprSetParent(wi);
        few.setNextWalker(walker);
        walker.setPrevWalker(few);
        wi.setFirstWalker(few);
        return wi;
    } else {
        FilterExprIteratorSimple feis = new FilterExprIteratorSimple(var);
        feis.exprSetParent(wi.exprGetParent());
        return feis;
    }
}
Also used : Variable(org.apache.xpath.operations.Variable) FilterExprWalker(org.apache.xpath.axes.FilterExprWalker) AxesWalker(org.apache.xpath.axes.AxesWalker) FilterExprIteratorSimple(org.apache.xpath.axes.FilterExprIteratorSimple) Vector(java.util.Vector)

Example 5 with Variable

use of org.apache.xpath.operations.Variable in project robovm by robovm.

the class RedundentExprEliminator method changeToVarRef.

/**
   * Change the expression owned by the owner argument to a variable reference 
   * of the given name.
   * 
   * Warning: For global vars, this function relies on the variable declaration 
   * to which it refers having been added just prior to this function being called,
   * so that the reference index can be determined from the size of the global variables 
   * list minus one.
   * 
   * @param varName The name of the variable which will be referenced.
   * @param owner The owner of the expression which will be replaced by a variable ref.
   * @param paths The paths list that the iterator came from, mainly to determine
   *              if this is a local or global reduction.
   * @param psuedoVarRecipient The element within whose scope the variable is 
   *                           being inserted, possibly a StylesheetRoot.
   */
protected void changeToVarRef(QName varName, ExpressionOwner owner, Vector paths, ElemTemplateElement psuedoVarRecipient) {
    Variable varRef = (paths == m_absPaths) ? new VariableSafeAbsRef() : new Variable();
    varRef.setQName(varName);
    if (paths == m_absPaths) {
        StylesheetRoot root = (StylesheetRoot) psuedoVarRecipient;
        Vector globalVars = root.getVariablesAndParamsComposed();
        // Assume this operation is occuring just after the decl has 
        // been added.
        varRef.setIndex(globalVars.size() - 1);
        varRef.setIsGlobal(true);
    }
    owner.setExpression(varRef);
}
Also used : Variable(org.apache.xpath.operations.Variable) VariableSafeAbsRef(org.apache.xpath.operations.VariableSafeAbsRef) Vector(java.util.Vector)

Aggregations

Variable (org.apache.xpath.operations.Variable)6 Vector (java.util.Vector)4 QName (org.apache.xml.utils.QName)2 AxesWalker (org.apache.xpath.axes.AxesWalker)2 FilterExprIteratorSimple (org.apache.xpath.axes.FilterExprIteratorSimple)2 FilterExprWalker (org.apache.xpath.axes.FilterExprWalker)2 XString (org.apache.xpath.objects.XString)2 VariableSafeAbsRef (org.apache.xpath.operations.VariableSafeAbsRef)2