Qt 4.8
qvaluecomparison.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 "qitem_p.h"
43 #include "qboolean_p.h"
44 #include "qbuiltintypes_p.h"
45 #include "qcommonsequencetypes_p.h"
46 #include "qemptysequence_p.h"
47 #include "qoptimizationpasses_p.h"
48 
49 #include "qvaluecomparison_p.h"
50 
52 
53 using namespace QPatternist;
54 
57  const Expression::Ptr &op2) : PairContainer(op1, op2),
58  m_operator(op)
59 {
60 }
61 
63 {
64  const Item it1(m_operand1->evaluateSingleton(context));
65  if(!it1)
66  return Item();
67 
68  const Item it2(m_operand2->evaluateSingleton(context));
69  if(!it2)
70  return Item();
71 
72  return Boolean::fromValue(flexibleCompare(it1, it2, context));
73 }
74 
76  const SequenceType::Ptr &reqType)
77 {
78  const Expression::Ptr me(PairContainer::typeCheck(context, reqType));
81  Q_ASSERT(t1);
82  Q_ASSERT(t2);
83 
84  if(*CommonSequenceTypes::Empty == *t1 ||
86  {
87  return EmptySequence::create(this, context);
88  }
89  else
90  {
91  prepareComparison(fetchComparator(t1, t2, context));
92 
93  return me;
94  }
95 }
96 
98 {
99  const Expression::Ptr me(PairContainer::compress(context));
100 
101  if(me != this)
102  return me;
103 
106 
107  return me;
108 }
109 
111 {
112  Q_ASSERT(op1);
113  Q_ASSERT(op2);
114 
115  const ID iD = op1->id();
116 
117  if((iD == IDLowerCaseFN || iD == IDUpperCaseFN) && iD == op2->id())
118  {
119  /* Both are either fn:lower-case() or fn:upper-case(). */
120 
121  /* Replace the calls to the functions with its operands. */
122  op1 = op1->operands().first();
123  op2 = op2->operands().first();
124 
125  return true;
126  }
127  else
128  return false;
129 }
130 
132 {
134 }
135 
137 {
138  SequenceType::List result;
141  return result;
142 }
143 
145 {
149  else
151 }
152 
154 {
155  return visitor->visit(this);
156 }
157 
159 {
160  return IDValueComparison;
161 }
162 
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual SequenceType::List expectedOperandTypes() const
Due to strong interdependencies, this file contains the definitions for the classes Item...
virtual SequenceType::Ptr staticType() const
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Definition: qexpression.cpp:70
static Expression::Ptr create(const Expression *const replacementFor, const StaticContext::Ptr &context)
Creates an EmptySequence that is a replacement for replacementFor.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
AtomicComparator::Ptr fetchComparator(const ItemType::Ptr &type1, const ItemType::Ptr &type2, const ReportContext::Ptr &context) const
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
virtual ID id() const
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
ValueComparison(const Expression::Ptr &op1, const AtomicComparator::Operator op, const Expression::Ptr &op2)
OptimizationPass::List comparisonPasses
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The namespace for the internal API of QtXmlPatterns.
virtual Cardinality cardinality() const =0
static const SequenceType::Ptr ZeroOrOneBoolean
static Boolean::Ptr fromValue(const bool value)
Definition: qboolean.cpp:115
virtual Expression::List operands() const =0
virtual Item evaluateSingleton(const DynamicContext::Ptr &) const
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
static const SequenceType::Ptr ExactlyOneBoolean
virtual SequenceType::Ptr staticType() const =0
static const EmptySequenceType::Ptr Empty
virtual ExpressionVisitorResult::Ptr accept(const ExpressionVisitor::Ptr &visitor) const
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
bool flexibleCompare(const Item &it1, const Item &it2, const DynamicContext::Ptr &context) const
Compares it1 against it2, using comparator() and operatorID().
virtual ItemType::Ptr itemType() const =0
static bool isCaseInsensitiveCompare(Expression::Ptr &op1, Expression::Ptr &op2)
static const SequenceType::Ptr ZeroOrOneAtomicType
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
virtual QList< QExplicitlySharedDataPointer< OptimizationPass > > optimizationPasses() const
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
Base class for expressions that has exactly two operands.
void prepareComparison(const AtomicComparator::Ptr &comparator)