1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the test suite of the Qt Toolkit.
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include <QStringList>
45 #include <QXmlNamePool>
47 #include <private/qfunctionfactorycollection_p.h>
50 #include "ExpressionInfo.h"
51 #include "ExpressionNamer.h"
54 #include "DebugExpressionFactory.h"
56 using namespace QPatternistSDK;
57 using namespace QPatternist;
59 static const QPatternist::ExpressionVisitor::Ptr namer(new ExpressionNamer());
61 QStringList DebugExpressionFactory::availableFunctionSignatures()
63 const QPatternist::FunctionFactory::Ptr factory(QPatternist::FunctionFactoryCollection::xpath20Factory(Global::namePool()));
64 const QPatternist::FunctionSignature::Hash signs(factory->functionSignatures());
65 const QPatternist::FunctionSignature::Hash::const_iterator end(signs.constEnd());
66 QPatternist::FunctionSignature::Hash::const_iterator it(signs.constBegin());
71 retval << it.value()->displayName(Global::namePool());
78 ASTItem *DebugExpressionFactory::buildASTTree(const QPatternist::Expression::Ptr &expr,
80 const QPatternist::SequenceType::Ptr &reqType)
83 const QPatternist::ExpressionVisitorResult::Ptr exprInfo(expr->accept(namer));
85 const ExpressionInfo *const constExprInfo = static_cast<const ExpressionInfo *>(exprInfo.data());
86 const QString name(constExprInfo->first);
87 const QString details(constExprInfo->second);
88 const QString rType(reqType ? reqType->displayName(Global::namePool()) : QLatin1String("Not specified"));
90 /* ---------- Handle its staticType() -------- */
91 const QPatternist::SequenceType::Ptr type(expr->staticType());
95 seqType = type->displayName(Global::namePool());
97 seqType = QLatin1String("no type, null pointer returned");
98 /* ------------------------------------------- */
100 ASTItem *const node = new ASTItem(parent, name, details, seqType, rType);
102 /* ------------ Handle child nodes ----------- */
103 const QPatternist::Expression::List children(expr->operands());
104 QPatternist::Expression::List::const_iterator it(children.constBegin());
105 const QPatternist::Expression::List::const_iterator end(children.constEnd());
107 const QPatternist::SequenceType::List reqTypes(expr->expectedOperandTypes());
108 const QPatternist::SequenceType::List::const_iterator typeEnd(reqTypes.constEnd());
109 QPatternist::SequenceType::List::const_iterator typeIt(reqTypes.constBegin());
110 QPatternist::SequenceType::Ptr t;
112 for(; it != end; ++it)
114 if(typeIt != typeEnd)
120 node->appendChild(buildASTTree(*it, node, t));
122 /* ------------------------------------------- */
127 QPatternist::Expression::Ptr
128 DebugExpressionFactory::createExpression(QIODevice *const expr,
129 const QPatternist::StaticContext::Ptr &context,
130 const QXmlQuery::QueryLanguage lang,
131 const QPatternist::SequenceType::Ptr &requiredType,
133 const QXmlName &initialTemplateName)
135 /* Create the root node. */
136 m_ast = new ASTItem(0, QString());
138 return ExpressionFactory::createExpression(expr, context, lang, requiredType, baseURI, initialTemplateName);
141 void DebugExpressionFactory::processTreePass(const QPatternist::Expression::Ptr &expr,
142 const CompilationStage stage)
144 ASTItem *newChild = 0;
148 case QueryBodyInitial:
150 newChild = new ASTItem(m_ast, QLatin1String("Initial Build"));
153 case QueryBodyTypeCheck:
155 newChild = new ASTItem(m_ast, QLatin1String("Type Check"));
158 case QueryBodyCompression:
160 newChild = new ASTItem(m_ast, QLatin1String("Compression"));
163 case UserFunctionTypeCheck:
165 newChild = new ASTItem(m_ast, QLatin1String("User Function Type Check"));
168 case UserFunctionCompression:
170 newChild = new ASTItem(m_ast, QLatin1String("User Function Compression"));
173 case GlobalVariableTypeCheck:
175 newChild = new ASTItem(m_ast, QLatin1String("Global Variable Type Check"));
181 m_ast->appendChild(newChild);
182 newChild->appendChild(buildASTTree(expr, newChild, QPatternist::SequenceType::Ptr()));
185 void DebugExpressionFactory::processTemplateRule(const Expression::Ptr &body,
186 const TemplatePattern::Ptr &pattern,
187 const QXmlName &mode,
188 const TemplateCompilationStage stage)
194 case TemplateInitial:
196 title = "Initial Build";
199 case TemplateTypeCheck:
201 title = "Type Check";
204 case TemplateCompress:
206 title = "Compression";
211 const QString modeName(Global::namePool()->displayName(mode));
213 ASTItem *const newChild = new ASTItem(m_ast, QLatin1String("T-Rule ")
214 + QLatin1String(title)
215 + QLatin1String(" mode: ")
217 + QLatin1String(" priority: ")
218 + QString::number(pattern->priority()));
219 m_ast->appendChild(newChild);
221 newChild->appendChild(buildASTTree(pattern->matchPattern(), newChild, QPatternist::SequenceType::Ptr()));
222 newChild->appendChild(buildASTTree(body, newChild, QPatternist::SequenceType::Ptr()));
225 void DebugExpressionFactory::processNamedTemplate(const QXmlName &name,
226 const Expression::Ptr &body,
227 const TemplateCompilationStage stage)
233 case TemplateInitial:
235 title = "Named Template Initial Build";
238 case TemplateTypeCheck:
240 title = "Named Template Type Check";
243 case TemplateCompress:
245 title = "Named Template Compression";
251 ASTItem *const newChild = new ASTItem(m_ast, QLatin1String(title)
252 + QLatin1String(": ")
253 + Global::namePool()->displayName(name));
255 m_ast->appendChild(newChild);
256 newChild->appendChild(buildASTTree(body, newChild, QPatternist::SequenceType::Ptr()));
259 ASTItem *DebugExpressionFactory::astTree() const
264 // vim: et:ts=4:sw=4:sts=4