| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | // |
| 41 | // W A R N I N G |
| 42 | // ------------- |
| 43 | // |
| 44 | // This file is not part of the Qt API. It exists purely as an |
| 45 | // implementation detail. This header file may change from version to |
| 46 | // version without notice, or even be removed. |
| 47 | // |
| 48 | // We mean it. |
| 49 | |
| 50 | #ifndef Patternist_DynamicContext_H |
| 51 | #define Patternist_DynamicContext_H |
| 52 | |
| 53 | #include <private/qautoptr_p.h> |
| 54 | #include <private/qcachecells_p.h> |
| 55 | #include <private/qexternalvariableloader_p.h> |
| 56 | #include <private/qitem_p.h> |
| 57 | #include <private/qnamepool_p.h> |
| 58 | #include <private/qnodebuilder_p.h> |
| 59 | #include <private/qprimitives_p.h> |
| 60 | #include <private/qreportcontext_p.h> |
| 61 | #include <private/qresourceloader_p.h> |
| 62 | |
| 63 | QT_BEGIN_NAMESPACE |
| 64 | |
| 65 | class QDateTime; |
| 66 | template<typename T> class QVector; |
| 67 | |
| 68 | namespace QPatternist |
| 69 | { |
| 70 | class DayTimeDuration; |
| 71 | class Expression; |
| 72 | class TemplateMode; |
| 73 | |
| 74 | /** |
| 75 | * @short Carries information and facilities used at runtime, and hence |
| 76 | * provides a state for that stage in a thread-safe manner. |
| 77 | * |
| 78 | * @see <a href="http://www.w3.org/TR/xquery/#eval_context">XQuery |
| 79 | * 1.0: An XML Query Language, 2.1.2 Dynamic Context</a> |
| 80 | * @see <a href="http://www.w3.org/TR/xquery/#id-dynamic-evaluation">XQuery |
| 81 | * 1.0: An XML Query Language, 2.2.3.2 Dynamic Evaluation Phase</a> |
| 82 | * @author Frans Englich <frans.englich@nokia.com> |
| 83 | */ |
| 84 | class DynamicContext : public ReportContext |
| 85 | { |
| 86 | public: |
| 87 | /** |
| 88 | * @short Carries template parameters at runtime. |
| 89 | * |
| 90 | * The key is the name of the parameter, and the value the Expression |
| 91 | * which supplies the value. |
| 92 | */ |
| 93 | typedef QHash<QXmlName, QExplicitlySharedDataPointer<Expression> > TemplateParameterHash; |
| 94 | typedef QExplicitlySharedDataPointer<DynamicContext> Ptr; |
| 95 | |
| 96 | virtual ~DynamicContext() |
| 97 | { |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * This function intentionally returns by reference. |
| 102 | * |
| 103 | * @see globalItemCacheCell() |
| 104 | */ |
| 105 | virtual ItemCacheCell &itemCacheCell(const VariableSlotID slot) = 0; |
| 106 | |
| 107 | /** |
| 108 | * This function intentionally returns by reference. |
| 109 | * |
| 110 | * @see globalItemSequenceCacheCells |
| 111 | */ |
| 112 | virtual ItemSequenceCacheCell::Vector &itemSequenceCacheCells(const VariableSlotID slot) = 0; |
| 113 | |
| 114 | virtual xsInteger contextPosition() const = 0; |
| 115 | virtual Item contextItem() const = 0; |
| 116 | virtual xsInteger contextSize() = 0; |
| 117 | |
| 118 | virtual void setRangeVariable(const VariableSlotID slot, |
| 119 | const Item &newValue) = 0; |
| 120 | virtual Item rangeVariable(const VariableSlotID slot) const = 0; |
| 121 | virtual void setExpressionVariable(const VariableSlotID slot, |
| 122 | const QExplicitlySharedDataPointer<Expression> &newValue) = 0; |
| 123 | virtual QExplicitlySharedDataPointer<Expression> |
| 124 | expressionVariable(const VariableSlotID slot) const = 0; |
| 125 | |
| 126 | virtual Item::Iterator::Ptr positionIterator(const VariableSlotID slot) const = 0; |
| 127 | virtual void setPositionIterator(const VariableSlotID slot, |
| 128 | const Item::Iterator::Ptr &newValue) = 0; |
| 129 | |
| 130 | virtual void setFocusIterator(const Item::Iterator::Ptr &it) = 0; |
| 131 | virtual Item::Iterator::Ptr focusIterator() const = 0; |
| 132 | |
| 133 | virtual QExplicitlySharedDataPointer<DayTimeDuration> implicitTimezone() const = 0; |
| 134 | virtual QDateTime currentDateTime() const = 0; |
| 135 | |
| 136 | virtual QAbstractXmlReceiver *outputReceiver() const = 0; |
| 137 | virtual NodeBuilder::Ptr nodeBuilder(const QUrl &baseURI) const = 0; |
| 138 | virtual ResourceLoader::Ptr resourceLoader() const = 0; |
| 139 | virtual ExternalVariableLoader::Ptr externalVariableLoader() const = 0; |
| 140 | virtual NamePool::Ptr namePool() const = 0; |
| 141 | |
| 142 | /** |
| 143 | * @short Returns the item that @c fn:current() returns. |
| 144 | * |
| 145 | * Hence, this is not the focus, and very different from the focus. |
| 146 | * |
| 147 | * @see CurrentItemStore |
| 148 | * @see CurrentFN |
| 149 | */ |
| 150 | virtual Item currentItem() const = 0; |
| 151 | |
| 152 | DynamicContext::Ptr createFocus(); |
| 153 | DynamicContext::Ptr createStack(); |
| 154 | DynamicContext::Ptr createReceiverContext(QAbstractXmlReceiver *const receiver); |
| 155 | |
| 156 | /** |
| 157 | * Whenever a tree gets built, this function is called. DynamicContext |
| 158 | * has the responsibility of keeping a copy of @p nm, such that it |
| 159 | * doesn't go out of scope, since no one else will reference @p nm. |
| 160 | * |
| 161 | * I think this is currently only used for temporary node trees. In |
| 162 | * other cases they are stored in the ExternalResourceLoader. |
| 163 | * |
| 164 | * The caller guarantees that @p nm is not @c null. |
| 165 | */ |
| 166 | virtual void addNodeModel(const QAbstractXmlNodeModel::Ptr &nm) = 0; |
| 167 | |
| 168 | /** |
| 169 | * Same as itemCacheCell(), but is only used for global varibles. This |
| 170 | * is needed because sometimes stack frames needs to be created for |
| 171 | * other kinds of variables(such as in the case of user function |
| 172 | * calls), while the global variable(s) needs to continue to use the |
| 173 | * same cache, instead of one for each new stack frame, typically an |
| 174 | * instance of StackContextBase. |
| 175 | * |
| 176 | * This has two effects: |
| 177 | * |
| 178 | * - It's an optimization. Instead of that a global variable gets evaluated each |
| 179 | * time a user function is called, think recursive functions, it's done |
| 180 | * only once. |
| 181 | * - Query stability, hence affects things like node identity and |
| 182 | * therefore conformance. Hence affects for instance what nodes a query |
| 183 | * returns, since node identity affect node deduplication. |
| 184 | */ |
| 185 | virtual ItemCacheCell &globalItemCacheCell(const VariableSlotID slot) = 0; |
| 186 | |
| 187 | /** |
| 188 | * @short When a template is called, this member carries the template |
| 189 | * parameters. |
| 190 | * |
| 191 | * Hence this is similar to the other variable stack functions such as |
| 192 | * rangeVariable() and expressionVariable(), the difference being that |
| 193 | * the order of template parameters as well as its arguments can appear |
| 194 | * in arbitrary order. Hence the name is used to make the order |
| 195 | * insignificant. |
| 196 | */ |
| 197 | virtual TemplateParameterHash &templateParameterStore() = 0; |
| 198 | |
| 199 | /** |
| 200 | * Same as itemSequenceCacheCells() but applies only for global |
| 201 | * variables. |
| 202 | * |
| 203 | * @see globalItemCacheCell() |
| 204 | */ |
| 205 | virtual ItemSequenceCacheCell::Vector &globalItemSequenceCacheCells(const VariableSlotID slot) = 0; |
| 206 | |
| 207 | /** |
| 208 | * @short Returns the previous DynamicContext. If this context is the |
| 209 | * top-level one, @c null is returned. |
| 210 | */ |
| 211 | virtual DynamicContext::Ptr previousContext() const = 0; |
| 212 | |
| 213 | /** |
| 214 | * @short Returns the current template mode that is in effect. |
| 215 | * |
| 216 | * If @c null is returned, it means that the default mode should be |
| 217 | * used as the current mode. |
| 218 | */ |
| 219 | virtual QExplicitlySharedDataPointer<TemplateMode> currentTemplateMode() const = 0; |
| 220 | }; |
| 221 | } |
| 222 | |
| 223 | QT_END_NAMESPACE |
| 224 | |
| 225 | #endif |
| 226 | |