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 test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
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 General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtDebug>
30
31#include <private/qabstractfloat_p.h>
32#include <private/qandexpression_p.h>
33#include <private/qanyuri_p.h>
34#include <private/qapplytemplate_p.h>
35#include <private/qargumentreference_p.h>
36#include <private/qarithmeticexpression_p.h>
37#include <private/qatomicstring_p.h>
38#include <private/qatomizer_p.h>
39#include <private/qattributeconstructor_p.h>
40#include <private/qattributenamevalidator_p.h>
41#include <private/qaxisstep_p.h>
42#include <private/qbase64binary_p.h>
43#include <private/qboolean_p.h>
44#include <private/qcardinalityverifier_p.h>
45#include <private/qcastableas_p.h>
46#include <private/qcastas_p.h>
47#include <private/qcombinenodes_p.h>
48#include <private/qcontextitem_p.h>
49#include <private/qdate_p.h>
50#include <private/qdecimal_p.h>
51#include <private/qdynamiccontextstore_p.h>
52#include <private/qelementconstructor_p.h>
53#include <private/qemptysequence_p.h>
54#include <private/qevaluationcache_p.h>
55#include <private/qexpressionsequence_p.h>
56#include <private/qexpressionvariablereference_p.h>
57#include <private/qfirstitempredicate_p.h>
58#include <private/qforclause_p.h>
59#include <private/qfunctioncall_p.h>
60#include <private/qgday_p.h>
61#include <private/qgeneralcomparison_p.h>
62#include <private/qgenericpredicate_p.h>
63#include <private/qgmonthday_p.h>
64#include <private/qgmonth_p.h>
65#include <private/qgyearmonth_p.h>
66#include <private/qgyear_p.h>
67#include <private/qhexbinary_p.h>
68#include <private/qifthenclause_p.h>
69#include <private/qinstanceof_p.h>
70#include <private/qinteger_p.h>
71#include <private/qitem_p.h>
72#include <private/qitemverifier_p.h>
73#include <private/qliteral_p.h>
74#include <private/qnamespaceconstructor_p.h>
75#include <private/qncnameconstructor_p.h>
76#include <private/qnodecomparison_p.h>
77#include <private/qorexpression_p.h>
78#include <private/qpath_p.h>
79#include <private/qpositionalvariablereference_p.h>
80#include <private/qqnameconstructor_p.h>
81#include <private/qqnamevalue_p.h>
82#include <private/qquantifiedexpression_p.h>
83#include <private/qrangeexpression_p.h>
84#include <private/qrangevariablereference_p.h>
85#include <private/qschemadatetime_p.h>
86#include <private/qschematime_p.h>
87#include <private/qsimplecontentconstructor_p.h>
88#include <private/qtreatas_p.h>
89#include <private/qtruthpredicate_p.h>
90#include <private/quntypedatomicconverter_p.h>
91#include <private/quntypedatomic_p.h>
92#include <private/quserfunctioncallsite_p.h>
93#include <private/qvalidationerror_p.h>
94#include <private/qvaluecomparison_p.h>
95
96#include "ExpressionInfo.h"
97#include "Global.h"
98
99#include "ExpressionNamer.h"
100
101using namespace QPatternistSDK;
102
103/* Simple ones, they have no additional data. */
104#define implClass(cls) \
105QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *) const \
106{ \
107 return QPatternist::ExpressionVisitorResult::Ptr \
108 (new ExpressionInfo(QLatin1String(#cls), QString())); \
109}
110
111implClass(AndExpression)
112implClass(ArgumentConverter)
113implClass(Atomizer)
114implClass(AttributeConstructor)
115implClass(AttributeNameValidator)
116implClass(CallTemplate)
117implClass(CardinalityVerifier)
118implClass(CollationChecker)
119implClass(CommentConstructor)
120implClass(ComputedNamespaceConstructor)
121implClass(ContextItem)
122implClass(CopyOf)
123implClass(CurrentItemStore)
124implClass(DocumentConstructor)
125implClass(DynamicContextStore)
126implClass(EBVExtractor)
127implClass(ElementConstructor)
128implClass(EmptySequence)
129implClass(ExpressionSequence)
130implClass(ExternalVariableReference)
131implClass(FirstItemPredicate)
132implClass(ForClause)
133implClass(GenericPredicate)
134implClass(IfThenClause)
135implClass(ItemVerifier)
136implClass(LetClause)
137implClass(LiteralSequence)
138implClass(NCNameConstructor)
139implClass(NodeSortExpression)
140implClass(OrderBy)
141implClass(OrExpression)
142implClass(ParentNodeAxis)
143implClass(ProcessingInstructionConstructor)
144implClass(QNameConstructor)
145implClass(RangeExpression)
146implClass(ReturnOrderBy)
147implClass(SimpleContentConstructor)
148implClass(StaticBaseURIStore)
149implClass(StaticCompatibilityStore)
150implClass(TemplateParameterReference)
151implClass(TextNodeConstructor)
152implClass(TreatAs)
153implClass(TruthPredicate)
154implClass(UnresolvedVariableReference)
155implClass(UntypedAtomicConverter)
156implClass(UserFunctionCallsite)
157implClass(ValidationError)
158#undef implClass
159
160/** Variable references. */
161#define implVarRef(name) \
162QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::name *i) const \
163{ \
164 return QPatternist::ExpressionVisitorResult::Ptr \
165 (new ExpressionInfo(QLatin1String(#name), \
166 QString(QLatin1String("Slot: %1")).arg(i->slot()))); \
167}
168implVarRef(RangeVariableReference)
169implVarRef(ArgumentReference)
170implVarRef(ExpressionVariableReference)
171implVarRef(PositionalVariableReference)
172#undef implVarRef
173
174/* Type related classes which have a targetType() function. */
175#define implTypeClass(cls) \
176QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *i) const \
177{ \
178 return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String(#cls), \
179 i->targetType()->displayName(Global::namePool()))); \
180}
181
182implTypeClass(InstanceOf)
183implTypeClass(CastableAs)
184#undef implTypeClass
185
186/* Type related classes which have a targetType() function. */
187QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::CastAs *i) const
188{
189 return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("CastAs"),
190 i->targetSequenceType()->displayName(np: Global::namePool())));
191}
192
193/* Classes which represent operators. */
194#define implOPClass(cls, compClass) \
195QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *i) const \
196{ \
197 return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String(#cls), \
198 QPatternist::compClass::displayName(i->operatorID()))); \
199}
200
201implOPClass(ArithmeticExpression, AtomicMathematician)
202implOPClass(NodeComparison, NodeComparison)
203implOPClass(QuantifiedExpression, QuantifiedExpression)
204implOPClass(CombineNodes, CombineNodes)
205#undef implOPClass
206
207/* Classes which represent operators. */
208#define implCompClass(cls, type) \
209QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *i) const \
210{ \
211 return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String(#cls), \
212 QPatternist::AtomicComparator::displayName(i->operatorID(), \
213 QPatternist::AtomicComparator::type))); \
214}
215
216implCompClass(GeneralComparison, AsGeneralComparison)
217implCompClass(ValueComparison, AsValueComparison)
218#undef implCompClass
219
220QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::FunctionCall *i) const
221{
222 return QPatternist::ExpressionVisitorResult::Ptr
223 (new ExpressionInfo(QLatin1String("FunctionCall"),
224 Global::namePool()->displayName(qName: i->signature()->name())));
225}
226
227QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::Literal *i) const
228{
229 return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(
230 i->item().type()->displayName(np: Global::namePool()),
231 i->item().stringValue()));
232}
233
234QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::AxisStep *i) const
235{
236 return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("AxisStep"),
237 QPatternist::AxisStep::axisName(axis: i->axis()) +
238 QLatin1String("::") +
239 i->nodeTest()->displayName(np: Global::namePool())));
240
241}
242
243
244QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::EvaluationCache<true> *i) const
245{
246 return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("EvaluationCache<IsForGlobal=true>"),
247 QLatin1String("Slot: ") + QString::number(i->slot())));
248
249}
250
251QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::EvaluationCache<false> *i) const
252{
253 return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("EvaluationCache<IsForGlobal=false>"),
254 QLatin1String("Slot: ") + QString::number(i->slot())));
255
256}
257
258QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::NamespaceConstructor *i) const
259{
260 return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("NamespaceConstructor"),
261 Global::namePool()->stringForPrefix(code: i->namespaceBinding().prefix()) +
262 QLatin1Char('=') +
263 Global::namePool()->stringForNamespace(code: i->namespaceBinding().namespaceURI())));
264
265}
266
267QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::Path *path) const
268{
269
270 QPatternist::Path::Kind k = path->kind();
271 QString type;
272
273 switch(k)
274 {
275 case QPatternist::Path::XSLTForEach:
276 {
277 type = QLatin1String("XSLTForEach");
278 break;
279 }
280 case QPatternist::Path::RegularPath:
281 {
282 type = QLatin1String("RegularPath");
283 break;
284 }
285 case QPatternist::Path::ForApplyTemplate:
286 {
287 type = QLatin1String("ForApplyTemplate");
288 break;
289 }
290 }
291
292 return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("Path"), type));
293}
294
295QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::ApplyTemplate *path) const
296{
297 const QPatternist::TemplateMode::Ptr mode(path->mode());
298 return QPatternist::ExpressionVisitorResult::Ptr
299 (new ExpressionInfo(QLatin1String("ApplyTemplate"), mode ? Global::namePool()->displayName(qName: mode->name()) : QString::fromLatin1(str: "#current")));
300}
301
302// vim: et:ts=4:sw=4:sts=4
303
304

source code of qtxmlpatterns/tests/auto/xmlpatternssdk/ExpressionNamer.cpp