use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method visit.
/**
* visit function call.
*
* @param e
* is the function call.
* @return a new function or null
*/
public Object visit(FunctionCall e) {
ArrayList args = new ArrayList();
for (Iterator i = e.iterator(); i.hasNext(); ) {
Expr arg = (Expr) i.next();
// each argument will produce a result sequence
args.add((ResultSequence) arg.accept(this));
}
try {
Function function = e.function();
if (function == null) {
function = _sc.resolveFunction(e.name().asQName(), args.size());
e.set_function(function);
}
return function.evaluate(args, _ec);
} catch (DynamicError err) {
report_error(err);
// unreach
return null;
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr in project webtools.sourceediting by eclipse.
the class DefaultEvaluator method do_predicate.
// do the predicate for all items in focus
private ResultSequence do_predicate(Collection exprs) {
ResultBuffer rs = new ResultBuffer();
Focus focus = focus();
int original_cp = focus.position();
// check if predicate is single numeric constant
if (exprs.size() == 1) {
Expr expr = (Expr) exprs.iterator().next();
if (expr instanceof XPathExpr) {
XPathExpr xpe = (XPathExpr) expr;
if (xpe.next() == null && xpe.slashes() == 0 && xpe.expr() instanceof FilterExpr) {
FilterExpr fex = (FilterExpr) xpe.expr();
if (fex.primary() instanceof IntegerLiteral) {
int pos = (((IntegerLiteral) fex.primary()).value().int_value()).intValue();
if (pos <= focus.last() && pos > 0) {
focus.set_position(pos);
rs.add(focus.context_item());
}
focus.set_position(original_cp);
return rs.getSequence();
}
}
}
}
// go through all elements
while (true) {
// do the predicate
// XXX saxon doesn't allow for predicates to have
// commas... but XPath 2.0 spec seems to do
ResultSequence res = do_expr(exprs.iterator());
// in the sequence
if (predicate_truth(res))
rs.add(focus().context_item());
if (!focus.advance_cp())
break;
}
// restore
focus.set_position(original_cp);
return rs.getSequence();
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr in project webtools.sourceediting by eclipse.
the class StaticNameResolver method visitExprs.
private void visitExprs(Iterator i) {
while (i.hasNext()) {
Expr e = (Expr) i.next();
e.accept(this);
}
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr 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;
}
use of org.eclipse.wst.xml.xpath2.processor.internal.ast.Expr in project webtools.sourceediting by eclipse.
the class Normalizer method doForExpr.
// does a for and a quantified expression
// takes the iterator for var expr paris
private void doForExpr(Iterator iter, Expr expr) {
Collection vars = new ArrayList();
// go through expression and cache variables
while (iter.hasNext()) {
VarExprPair pair = (VarExprPair) iter.next();
QName var = pair.varname();
Expr e = pair.expr();
// XXX this is wrong!
// need to define new scope, and reference "inner scope"
// [shadow outer vars]
/*
* if(_sc.variable_exists(var)) report_error(new
* StaticNameError("Variable " + var.string() +
* " already defined"));
*/
// ok we can cheat here cuz we only care about variable
// "presence" not its specific instance / value so we
// can fakely shadow without creating explicit scopes
// if variable already exists.... then leave it there...
// [we do not need to create a new instance and delete
// it at the end]
// we only need to if variable does not exist
// XXX: i fink this is all wrong
vars.add(var);
e.accept(this);
}
// add variables to scope
for (Iterator i = vars.iterator(); i.hasNext(); ) {
QName var = (QName) i.next();
}
// do the bounded expression
expr.accept(this);
// remove variables
}
Aggregations