net.sf.saxon.expr.flwor.TupleExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Saxon-HE Show documentation
Show all versions of Saxon-HE Show documentation
The XSLT and XQuery Processor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2018-2023 Saxonica Limited
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package net.sf.saxon.expr.flwor;
import net.sf.saxon.expr.*;
import net.sf.saxon.expr.oper.OperandArray;
import net.sf.saxon.expr.parser.ContextItemStaticInfo;
import net.sf.saxon.expr.parser.ExpressionTool;
import net.sf.saxon.expr.parser.ExpressionVisitor;
import net.sf.saxon.expr.parser.RebindingMap;
import net.sf.saxon.om.Sequence;
import net.sf.saxon.trace.ExpressionPresenter;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.type.ItemType;
import net.sf.saxon.type.JavaExternalObjectType;
import java.util.ArrayList;
import java.util.List;
/**
* A tuple expression is an expression that returns a FLWOR tuple. Specifically,
* it is a list local variables references; it returns a Tuple item
* containing the current value of these variables.
*/
public class TupleExpression extends Expression {
private OperandArray operanda;
public TupleExpression() {
}
/**
* Set the data structure for the operands of this expression. This must be created during initialisation of the
* expression and must not be subsequently changed
* @param operanda the data structure for expression operands
*/
protected void setOperanda(OperandArray operanda) {
this.operanda = operanda;
}
/**
* Get the data structure holding the operands of this expression.
* @return the data structure holding expression operands
*/
protected OperandArray getOperanda() {
return operanda;
}
@Override
public Iterable operands() {
return operanda;
}
public void setVariables(List refs) {
Expression[] e = new Expression[refs.size()];
for (int i=0; i refs2 = new ArrayList(n);
for (int i = 0; i < n; i++) {
refs2.add ((LocalVariableReference) getSlot(i).copy(rebindings));
}
TupleExpression t2 = new TupleExpression();
ExpressionTool.copyLocationInfo(this, t2);
t2.setVariables(refs2);
return t2;
}
/**
* Diagnostic print of expression structure. The abstract expression tree
* is written to the supplied output destination.
*/
@Override
public void export(ExpressionPresenter out) throws XPathException {
out.startElement("tuple", this);
for (Operand o : operands()) {
o.getChildExpression().export(out);
}
out.endElement();
}
@Override
public Tuple evaluateItem(XPathContext context) throws XPathException {
final int n = getSize();
Sequence[] tuple = new Sequence[n];
for (int i=0; i