|
1 | 1 | /* |
| 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 | + * |
2 | 26 | * eXist-db Open Source Native XML Database |
3 | 27 | * Copyright (C) 2001 The eXist-db Authors |
4 | 28 | * |
|
33 | 57 |
|
34 | 58 | /** |
35 | 59 | * An XQuery 3.0 inline function expression. |
36 | | - * |
37 | | - * @author wolf |
38 | 60 | * |
| 61 | + * @author wolf |
39 | 62 | */ |
40 | 63 | public class InlineFunction extends AbstractExpression { |
41 | 64 |
|
42 | | - public final static QName INLINE_FUNCTION_QNAME = QName.EMPTY_QNAME; |
43 | | - |
44 | | - private UserDefinedFunction function; |
45 | | - private ArrayDeque<FunctionCall> calls = new ArrayDeque<>(); |
46 | | - |
47 | | - private AnalyzeContextInfo cachedContextInfo; |
| 65 | + public static final QName INLINE_FUNCTION_QNAME = QName.EMPTY_QNAME; |
| 66 | + |
| 67 | + private final UserDefinedFunction function; |
| 68 | + private final ArrayDeque<FunctionCall> calls = new ArrayDeque<>(); |
48 | 69 |
|
49 | | - public InlineFunction(XQueryContext context, UserDefinedFunction function) { |
50 | | - super(context); |
51 | | - this.function = function; |
52 | | - } |
| 70 | + private AnalyzeContextInfo cachedContextInfo; |
53 | 71 |
|
54 | | - @Override |
55 | | - public void analyze(AnalyzeContextInfo contextInfo) throws XPathException { |
| 72 | + public InlineFunction(final XQueryContext context, final UserDefinedFunction function) { |
| 73 | + super(context); |
| 74 | + this.function = function; |
| 75 | + } |
56 | 76 |
|
| 77 | + @Override |
| 78 | + public void analyze(final AnalyzeContextInfo contextInfo) throws XPathException { |
57 | 79 | cachedContextInfo = new AnalyzeContextInfo(contextInfo); |
58 | 80 | cachedContextInfo.addFlag(SINGLE_STEP_EXECUTION); |
59 | 81 | cachedContextInfo.setParent(this); |
60 | | - } |
| 82 | + } |
61 | 83 |
|
62 | | - @Override |
63 | | - public void dump(ExpressionDumper dumper) { |
64 | | - dumper.display("function"); |
65 | | - function.dump(dumper); |
66 | | - } |
| 84 | + @Override |
| 85 | + public void dump(final ExpressionDumper dumper) { |
| 86 | + dumper.display("function"); |
| 87 | + function.dump(dumper); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Wraps a function call around the function and returns a |
| 92 | + * reference to it. Make sure local variables in the context |
| 93 | + * are visible. |
| 94 | + */ |
| 95 | + @Override |
| 96 | + public Sequence eval(final Sequence contextSequence, final Item contextItem) throws XPathException { |
| 97 | + // local variable context is known within inline function |
| 98 | + final List<ClosureVariable> closureVars = context.getLocalStack(); |
67 | 99 |
|
68 | | - /** |
69 | | - * Wraps a function call around the function and returns a |
70 | | - * reference to it. Make sure local variables in the context |
71 | | - * are visible. |
72 | | - */ |
73 | | - public Sequence eval(Sequence contextSequence, Item contextItem) |
74 | | - throws XPathException { |
75 | | - // local variable context is known within inline function |
76 | | - final List<ClosureVariable> closureVars = context.getLocalStack(); |
77 | | - |
78 | | - final FunctionCall call = new FunctionCall(context, function); |
79 | | - call.getFunction().setClosureVariables(closureVars); |
80 | | - call.setLocation(function.getLine(), function.getColumn()); |
81 | | - call.analyze(new AnalyzeContextInfo(cachedContextInfo)); |
| 100 | + final FunctionCall call = new FunctionCall(context, function); |
| 101 | + call.getFunction().setClosureVariables(closureVars); |
| 102 | + call.setLocation(function.getLine(), function.getColumn()); |
| 103 | + call.analyze(new AnalyzeContextInfo(cachedContextInfo)); |
82 | 104 |
|
83 | | - // push the created function call to the stack so we can clear |
| 105 | + // push the created function call to the stack so we can clear |
84 | 106 | // it after execution |
85 | | - calls.push(call); |
| 107 | + calls.push(call); |
86 | 108 |
|
87 | | - return new FunctionReference(this, call); |
88 | | - } |
| 109 | + return new FunctionReference(this, call); |
| 110 | + } |
89 | 111 |
|
90 | | - @Override |
91 | | - public int returnsType() { |
92 | | - return Type.FUNCTION; |
93 | | - } |
| 112 | + @Override |
| 113 | + public int returnsType() { |
| 114 | + return Type.FUNCTION; |
| 115 | + } |
94 | 116 |
|
95 | 117 | @Override |
96 | | - public void resetState(boolean postOptimization) { |
| 118 | + public void resetState(final boolean postOptimization) { |
97 | 119 | super.resetState(postOptimization); |
98 | 120 | calls.clear(); |
99 | 121 | function.resetState(postOptimization); |
|
0 commit comments