Search in sources :

Example 1 with VarExprPair

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair in project webtools.sourceediting by eclipse.

the class StaticNameResolver method doForExpr.

// does a for and a quantified expression
// takes the iterator for var expr paris
private void doForExpr(Iterator iter, Expr expr) {
    int scopes = 0;
    // add variables to scope and check the binding sequence
    while (iter.hasNext()) {
        VarExprPair pair = (VarExprPair) iter.next();
        QName var = pair.varname();
        if (!expandVarQName(var))
            reportBadPrefix(var.prefix());
        Expr e = pair.expr();
        e.accept(this);
        pushScope(var, BuiltinTypeLibrary.XS_ANYTYPE);
        scopes++;
    }
    expr.accept(this);
    // kill the scopes
    for (int i = 0; i < scopes; i++) popScope();
}
Also used : PipeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PipeExpr) BinExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.BinExpr) QuantifiedExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.QuantifiedExpr) MulExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.MulExpr) IfExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IfExpr) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr) Expr(org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr) MinusExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.MinusExpr) OrExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.OrExpr) TreatAsExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.TreatAsExpr) ForExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr) ParExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ParExpr) FilterExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr) DivExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.DivExpr) CastableExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastableExpr) SubExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.SubExpr) PlusExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PlusExpr) CastExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastExpr) AndExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AndExpr) RangeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.RangeExpr) StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) InstOfExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.InstOfExpr) IntersectExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IntersectExpr) IDivExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IDivExpr) UnExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.UnExpr) CntxItemExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CntxItemExpr) ExceptExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ExceptExpr) AddExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AddExpr) UnionExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.UnionExpr) CmpExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CmpExpr) ModExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ModExpr) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)

Example 2 with VarExprPair

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair in project webtools.sourceediting by eclipse.

the class DefaultEvaluator method do_exists.

private XSBoolean do_exists(ListIterator iter, Expr finalexpr) {
    // we have more vars to bind...
    if (iter.hasNext()) {
        VarExprPair ve = (VarExprPair) iter.next();
        // evaluate binding sequence
        ResultSequence rs = (ResultSequence) ve.expr().accept(this);
        QName varname = ve.varname();
        try {
            for (Iterator i = rs.iterator(); i.hasNext(); ) {
                AnyType item = (AnyType) i.next();
                pushScope(varname, item);
                XSBoolean effbool = do_exists(iter, finalexpr);
                popScope();
                // out what to do with it
                if (effbool.value())
                    return XSBoolean.TRUE;
            }
        } finally {
            iter.previous();
        }
        // since none in this sequence evaluated to true, return false
        return XSBoolean.FALSE;
    } else // we finally got to do the "last expression"
    {
        return effective_boolean_value((ResultSequence) finalexpr.accept(this));
    }
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)

Example 3 with VarExprPair

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair in project webtools.sourceediting by eclipse.

the class DefaultEvaluator method do_for_each.

private void do_for_each(ListIterator iter, Expr finalexpr, ResultBuffer destination) {
    // we have more vars to bind...
    if (iter.hasNext()) {
        VarExprPair ve = (VarExprPair) iter.next();
        // evaluate binding sequence
        ResultSequence rs = (ResultSequence) ve.expr().accept(this);
        // XXX
        if (rs.empty()) {
            iter.previous();
            return;
        }
        QName varname = ve.varname();
        for (Iterator i = rs.iterator(); i.hasNext(); ) {
            AnyType item = (AnyType) i.next();
            pushScope(varname, item);
            do_for_each(iter, finalexpr, destination);
            popScope();
        }
        iter.previous();
    } else // we finally got to do the "last expression"
    {
        destination.concat((ResultSequence) finalexpr.accept(this));
    }
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)

Example 4 with VarExprPair

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair in project webtools.sourceediting by eclipse.

the class DefaultEvaluator method do_for_all.

// XXX ugly
// type: 0 = for [return == "correct"]
// 1 = for all [return false, return empty on true]
// 2 = there exists [return true, return empty on false]
private XSBoolean do_for_all(ListIterator iter, Expr finalexpr) {
    // we have more vars to bind...
    if (iter.hasNext()) {
        VarExprPair ve = (VarExprPair) iter.next();
        // evaluate binding sequence
        ResultSequence rs = (ResultSequence) ve.expr().accept(this);
        QName varname = ve.varname();
        try {
            for (Iterator i = rs.iterator(); i.hasNext(); ) {
                AnyType item = (AnyType) i.next();
                pushScope(varname, item);
                XSBoolean effbool = do_for_all(iter, finalexpr);
                popScope();
                // out what to do with it
                if (!effbool.value())
                    return XSBoolean.FALSE;
            }
        } finally {
            iter.previous();
        }
        return XSBoolean.TRUE;
    } else // we finally got to do the "last expression"
    {
        return effective_boolean_value((ResultSequence) finalexpr.accept(this));
    }
}
Also used : ResultSequence(org.eclipse.wst.xml.xpath2.api.ResultSequence) QName(org.eclipse.wst.xml.xpath2.processor.internal.types.QName) XSBoolean(org.eclipse.wst.xml.xpath2.processor.internal.types.XSBoolean) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) AnyType(org.eclipse.wst.xml.xpath2.processor.internal.types.AnyType) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)

Example 5 with VarExprPair

use of org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair in project webtools.sourceediting by eclipse.

the class Normalizer method visit.

/**
 * @param qex
 *            is the Quantified expression.
 * @return qex expression.
 */
// XXX: code duplication
public Object visit(QuantifiedExpr qex) {
    QuantifiedExpr last = qex;
    Expr ret = qex.expr();
    int depth = 0;
    for (Iterator i = qex.iterator(); i.hasNext(); ) {
        VarExprPair ve = (VarExprPair) i.next();
        // ok we got nested fors...
        if (depth > 0) {
            Collection pairs = new ArrayList();
            pairs.add(ve);
            QuantifiedExpr qe = new QuantifiedExpr(qex.type(), pairs, ret);
            last.set_expr(qe);
            last = qe;
        }
        depth++;
    }
    // normalize return value, and set it to the last for expr
    ret.accept(this);
    // get rid of the pairs in the parent (original) for
    if (depth > 1)
        qex.truncate_pairs();
    return qex;
}
Also used : QuantifiedExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.QuantifiedExpr) PipeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PipeExpr) BinExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.BinExpr) QuantifiedExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.QuantifiedExpr) MulExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.MulExpr) IfExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IfExpr) XPathExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.XPathExpr) Expr(org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr) MinusExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.MinusExpr) OrExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.OrExpr) TreatAsExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.TreatAsExpr) PrimaryExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PrimaryExpr) ForExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr) ParExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ParExpr) FilterExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr) DivExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.DivExpr) CastableExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastableExpr) SubExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.SubExpr) PlusExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.PlusExpr) CastExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CastExpr) AndExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AndExpr) RangeExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.RangeExpr) StepExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.StepExpr) InstOfExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.InstOfExpr) IntersectExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IntersectExpr) IDivExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.IDivExpr) UnExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.UnExpr) CntxItemExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CntxItemExpr) ExceptExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ExceptExpr) AddExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.AddExpr) UnionExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.UnionExpr) CmpExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.CmpExpr) ModExpr(org.eclipse.wst.xml.xpath2.processor.internal.ast.ModExpr) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) Collection(java.util.Collection) VarExprPair(org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)

Aggregations

VarExprPair (org.eclipse.wst.xml.xpath2.processor.internal.ast.VarExprPair)8 Iterator (java.util.Iterator)6 QName (org.eclipse.wst.xml.xpath2.processor.internal.types.QName)6 AddExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.AddExpr)5 AndExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.AndExpr)5 BinExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.BinExpr)5 CastExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.CastExpr)5 CastableExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.CastableExpr)5 CmpExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.CmpExpr)5 CntxItemExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.CntxItemExpr)5 DivExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.DivExpr)5 ExceptExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.ExceptExpr)5 Expr (org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr)5 FilterExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.FilterExpr)5 ForExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.ForExpr)5 IDivExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.IDivExpr)5 IfExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.IfExpr)5 InstOfExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.InstOfExpr)5 IntersectExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.IntersectExpr)5 MinusExpr (org.eclipse.wst.xml.xpath2.processor.internal.ast.MinusExpr)5