1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
46 // This file is not part of the Qt API. It exists purely as an
47 // implementation detail. This header file may change from version to
48 // version without notice, or even be removed.
52 #ifndef Patternist_AccelTreeBuilder_H
53 #define Patternist_AccelTreeBuilder_H
58 #include <private/qxmlutils_p.h>
59 #include <private/qacceltree_p.h>
60 #include <private/qbuiltintypes_p.h>
61 #include <private/qcompressedwhitespace_p.h>
62 #include <private/qnamepool_p.h>
63 #include <private/qnodebuilder_p.h>
64 #include <private/qreportcontext_p.h>
65 #include <private/qsourcelocationreflection_p.h>
66 #include <private/qpatternistlocale_p.h>
76 * @short Builds an AccelTree from a stream of XML/Item events
77 * received through the NodeBuilder interface.
79 * If FromDocument is @c true, it is assumed that AccelTreeBuilder is fed
80 * events from an XML document, otherwise it is assumed the events
81 * are from node constructor expressions.
83 * @author Frans Englich <frans.englich@nokia.com>
85 template<bool FromDocument>
86 class AccelTreeBuilder : public NodeBuilder
87 , public SourceLocationReflection
90 typedef QExplicitlySharedDataPointer<AccelTreeBuilder> Ptr;
93 * Describes the memory relevant features the builder shall support.
97 NoneFeature, ///< No special features are enabled.
98 SourceLocationsFeature = 1 ///< The accel tree builder will store source locations for each start element.
100 Q_DECLARE_FLAGS(Features, Feature)
103 * @param context may be @c null.
105 AccelTreeBuilder(const QUrl &docURI,
107 const NamePool::Ptr &np,
108 ReportContext *const context,
109 Features features = NoneFeature);
110 virtual void startDocument();
111 virtual void endDocument();
112 virtual void startElement(const QXmlName &name);
113 void startElement(const QXmlName &name, qint64 line, qint64 column);
114 virtual void endElement();
115 virtual void attribute(const QXmlName &name, const QStringRef &value);
116 virtual void characters(const QStringRef &ch);
117 virtual void whitespaceOnly(const QStringRef &ch);
118 virtual void processingInstruction(const QXmlName &target,
119 const QString &data);
120 virtual void namespaceBinding(const QXmlName &nb);
121 virtual void comment(const QString &content);
122 virtual void item(const Item &it);
124 virtual QAbstractXmlNodeModel::Ptr builtDocument();
125 virtual NodeBuilder::Ptr create(const QUrl &baseURI) const;
126 virtual void startOfSequence();
127 virtual void endOfSequence();
129 inline AccelTree::Ptr builtDocument() const
134 virtual void atomicValue(const QVariant &value);
136 virtual const SourceLocationReflection *actualReflection() const;
137 virtual QSourceLocation sourceLocation() const;
140 inline void startStructure();
142 inline AccelTree::PreNumber currentDepth() const
144 return m_ancestors.count() -1;
147 inline AccelTree::PreNumber currentParent() const
149 return m_ancestors.isEmpty() ? -1 : m_ancestors.top();
154 DefaultNodeStackSize = 10,
158 AccelTree::PreNumber m_preNumber;
159 bool m_isPreviousAtomic;
160 bool m_hasCharacters;
162 * Whether m_characters has been run through
163 * CompressedWhitespace::compress().
165 bool m_isCharactersCompressed;
166 QString m_characters;
167 NamePool::Ptr m_namePool;
168 AccelTree::Ptr m_document;
169 QStack<AccelTree::PreNumber> m_ancestors;
170 QStack<AccelTree::PreNumber> m_size;
172 /** If we have already commenced a document, we don't want to
173 * add more document nodes. We keep track of them with this
174 * counter, which ensures that startDocument() and endDocument()
175 * are skipped consistently. */
176 AccelTree::PreNumber m_skippedDocumentNodes;
179 * All attribute values goes through this set such that we store only
180 * one QString for identical attribute values.
182 QSet<QString> m_attributeCompress;
183 const QUrl m_documentURI;
185 * We don't store a reference pointer here because then we get a
186 * circular reference with GenericDynamicContext, when it stores us as
189 ReportContext *const m_context;
194 Q_DECLARE_OPERATORS_FOR_FLAGS(AccelTreeBuilder<true>::Features)
195 Q_DECLARE_OPERATORS_FOR_FLAGS(AccelTreeBuilder<false>::Features)
197 #include "qacceltreebuilder.cpp"