Qt 4.8
qoptimizerblocks.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 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.
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 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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qcommonnamespaces_p.h"
43 
44 #include "qcommonsequencetypes_p.h"
45 #include "qfunctionfactory_p.h"
46 #include "qgeneralcomparison_p.h"
47 #include "qliteral_p.h"
48 #include "qschemanumeric_p.h"
49 #include "qvaluecomparison_p.h"
50 
51 #include "qoptimizerblocks_p.h"
52 
54 
55 using namespace QPatternist;
56 
58 {
59 }
60 
62 {
63  return expr->is(m_id);
64 }
65 
67  const AtomicComparator::Operator op) : m_hosts(hosts),
68  m_op(op)
69 {
70 }
71 
73 {
74  const Expression::ID eID = e->id();
75 
77  {
79  return e->as<GeneralComparison>()->operatorID() == m_op;
80  else
81  return false;
82  }
83  else if(eID == Expression::IDValueComparison)
84  {
86  return e->as<ValueComparison>()->operatorID() == m_op;
87  else
88  return false;
89  }
90  else
91  return false;
92 }
93 
95 {
96  Q_ASSERT(seqType);
97 }
98 
100 {
101  const SequenceType::Ptr t(expr->staticType());
102 
103  return m_seqType->itemType()->xdtTypeMatches(t->itemType())
104  &&
105  m_seqType->cardinality().isMatch(t->cardinality());
106 }
107 
109 {
110 }
111 
113 {
114  return expr->is(Expression::IDIntegerValue) &&
115  expr->as<Literal>()->item().as<Numeric>()->toInteger() == m_num;
116 }
117 
118 BooleanIdentifier::BooleanIdentifier(const bool value) : m_value(value)
119 {
120 }
121 
123 {
124  return expr->is(Expression::IDBooleanValue) &&
126 }
127 
129 {
131 }
132 
134  const StaticContext::Ptr &context,
135  const SourceLocationReflection *const r) const
136 {
137  return create(m_id, operands, context, r);
138 }
139 
141  const Expression::List &operands,
142  const StaticContext::Ptr &context,
143  const SourceLocationReflection *const r)
144 {
145  Q_ASSERT(context);
146 
148 
149  switch(id)
150  {
152  {
154  break;
155  }
157  {
158  fnName = StandardLocalNames::empty;
159  break;
160  }
161  default:
162  {
163  Q_ASSERT_X(false, Q_FUNC_INFO,
164  "Cannot create an expression of requested type; m_id is wrong.");
165  return Expression::Ptr();
166  }
167  }
168 
169  /* The reason we don't simply do 'new ExistsFN()' ourselves, is that all FunctionCall
170  * instances needs their FunctionSignature in order to function, and the FunctionFactories
171  * sets that. */
172  const QXmlName qName(StandardNamespaces::fn, fnName);
173 
174  const Expression::Ptr result(context->functionSignatures()->createFunctionCall(qName, operands, context, r));
175  context->wrapExpressionWith(r, result);
176  return result;
177 }
178 
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
NamespaceCode LocalNameCode
Definition: qxmlname.h:84
qint64 xsInteger
virtual bool evaluateEBV(const DynamicContext::Ptr &context) const
ByIDIdentifier(const Expression::ID id)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual bool matches(const Expression::Ptr &expr) const
virtual bool matches(const Expression::Ptr &expr) const
Implements XPath 2.0&#39;s general comparions, such as the = operator.
virtual ID id() const
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const TCastTarget * as() const
AtomicComparator::Operator operatorID() const
ComparisonIdentifier(const QVector< Expression::ID > comparatorHosts, const AtomicComparator::Operator op)
The namespace for the internal API of QtXmlPatterns.
IntegerIdentifier(const xsInteger num)
virtual Cardinality cardinality() const =0
virtual QExplicitlySharedDataPointer< FunctionFactory > functionSignatures() const =0
ByIDCreator(const Expression::ID id)
virtual bool matches(const Expression::Ptr &expr) const
Houses an AtomicValue, making it available as an Expression.
Definition: qliteral_p.h:74
QExplicitlySharedDataPointer< Expression > Ptr
A smart pointer wrapping mutable Expression instances.
virtual SequenceType::Ptr staticType() const =0
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
const QVector< Expression::ID > m_hosts
Base class for all numeric values.
Contains class Numeric. This file was originally called qnumeric_p.h, but various build systems canno...
virtual bool matches(const Expression::Ptr &expr) const
const AtomicComparator::Operator m_op
virtual bool matches(const Expression::Ptr &expr) const
bool contains(const T &t) const
Returns true if the vector contains an occurrence of value; otherwise returns false.
Definition: qvector.h:731
AtomicComparator::Operator operatorID() const
virtual bool xdtTypeMatches(const ItemType::Ptr &other) const =0
Returns true if other matches this type. That is, if other is equal to this type or a subtype of this...
virtual Expression::Ptr create(const Expression::List &operands, const StaticContext::Ptr &context, const SourceLocationReflection *const r) const
Implements XPath 2.0 value comparions, such as the eq operator.
virtual ItemType::Ptr itemType() const =0
bool isMatch(const Cardinality &other) const
BySequenceTypeIdentifier(const SequenceType::Ptr &seqType)
void wrapExpressionWith(const SourceLocationReflection *const existingNode, const QExplicitlySharedDataPointer< Expression > &newNode)
Ensures source locations are handled in such a manner that existingNode wraps newNode.
bool is(const ID id) const
virtual Expression::Ptr createFunctionCall(const QXmlName name, const Expression::List &arguments, const StaticContext::Ptr &context, const SourceLocationReflection *const r)=0
Base class for all instances that represents something at a certain location.
const Expression::ID m_id
#define Q_FUNC_INFO
Definition: qglobal.h:1871