11/*
2+ * Elemental
3+ * Copyright (C) 2024, Evolved Binary Ltd
4+ *
5+ * admin@evolvedbinary.com
6+ * https://www.evolvedbinary.com | https://www.elemental.xyz
7+ *
8+ * This library is free software; you can redistribute it and/or
9+ * modify it under the terms of the GNU Lesser General Public
10+ * License as published by the Free Software Foundation; version 2.1.
11+ *
12+ * This library is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+ * Lesser General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU Lesser General Public
18+ * License along with this library; if not, write to the Free Software
19+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+ *
21+ * NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+ * The original license header is included below.
23+ *
24+ * =====================================================================
25+ *
226 * eXist-db Open Source Native XML Database
327 * Copyright (C) 2001 The eXist-db Authors
428 *
3458
3559/**
3660 * An XQuery 3.0 inline function expression.
37- *
38- * @author wolf
3961 *
62+ * @author wolf
4063 */
4164public class InlineFunction extends AbstractExpression {
4265
43- public final static QName INLINE_FUNCTION_QNAME = QName .EMPTY_QNAME ;
44-
45- private UserDefinedFunction function ;
46- private ArrayDeque <FunctionCall > calls = new ArrayDeque <>();
47-
48- private AnalyzeContextInfo cachedContextInfo ;
66+ public static final QName INLINE_FUNCTION_QNAME = QName .EMPTY_QNAME ;
67+
68+ private final UserDefinedFunction function ;
69+ private final ArrayDeque <FunctionCall > calls = new ArrayDeque <>();
4970
50- public InlineFunction (XQueryContext context , UserDefinedFunction function ) {
51- super (context );
52- this .function = function ;
53- }
71+ private AnalyzeContextInfo cachedContextInfo ;
5472
55- @ Override
56- public void analyze (AnalyzeContextInfo contextInfo ) throws XPathException {
73+ public InlineFunction (final XQueryContext context , final UserDefinedFunction function ) {
74+ super (context );
75+ this .function = function ;
76+ }
5777
78+ @ Override
79+ public void analyze (final AnalyzeContextInfo contextInfo ) throws XPathException {
5880 cachedContextInfo = new AnalyzeContextInfo (contextInfo );
5981 cachedContextInfo .addFlag (SINGLE_STEP_EXECUTION );
6082 cachedContextInfo .setParent (this );
61- }
83+ }
6284
63- @ Override
64- public void dump (ExpressionDumper dumper ) {
65- dumper .display ("function" );
66- function .dump (dumper );
67- }
85+ @ Override
86+ public void dump (final ExpressionDumper dumper ) {
87+ dumper .display ("function" );
88+ function .dump (dumper );
89+ }
90+
91+ /**
92+ * Wraps a function call around the function and returns a
93+ * reference to it. Make sure local variables in the context
94+ * are visible.
95+ */
96+ @ Override
97+ public Sequence eval (final Sequence contextSequence , final Item contextItem ) throws XPathException {
98+ // local variable context is known within inline function
99+ final List <ClosureVariable > closureVars = context .getLocalStack ();
68100
69- /**
70- * Wraps a function call around the function and returns a
71- * reference to it. Make sure local variables in the context
72- * are visible.
73- */
74- public Sequence eval (Sequence contextSequence , Item contextItem )
75- throws XPathException {
76- // local variable context is known within inline function
77- final List <ClosureVariable > closureVars = context .getLocalStack ();
78-
79- final FunctionCall call = new FunctionCall (context , function );
80- call .getFunction ().setClosureVariables (closureVars );
81- call .setLocation (function .getLine (), function .getColumn ());
82- call .analyze (new AnalyzeContextInfo (cachedContextInfo ));
101+ final FunctionCall call = new FunctionCall (context , function );
102+ call .getFunction ().setClosureVariables (closureVars );
103+ call .setLocation (function .getLine (), function .getColumn ());
104+ call .analyze (new AnalyzeContextInfo (cachedContextInfo ));
83105
84- // push the created function call to the stack so we can clear
106+ // push the created function call to the stack so we can clear
85107 // it after execution
86- calls .push (call );
108+ calls .push (call );
87109
88- return new FunctionReference (this , call );
89- }
110+ return new FunctionReference (this , call );
111+ }
90112
91- @ Override
92- public int returnsType () {
93- return Type .FUNCTION_REFERENCE ;
94- }
113+ @ Override
114+ public int returnsType () {
115+ return Type .FUNCTION_REFERENCE ;
116+ }
95117
96118 @ Override
97- public void resetState (boolean postOptimization ) {
119+ public void resetState (final boolean postOptimization ) {
98120 super .resetState (postOptimization );
99121 calls .clear ();
100122 function .resetState (postOptimization );
101123 }
102- }
124+ }
0 commit comments