source: trunk/src/xmlpatterns/functions/qsequencefns.cpp@ 163

Last change on this file since 163 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 12.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qbuiltintypes_p.h"
43#include "qcommonsequencetypes_p.h"
44#include "qcommonvalues_p.h"
45#include "qdistinctiterator_p.h"
46#include "qebvextractor_p.h"
47#include "qemptysequence_p.h"
48#include "qgenericsequencetype_p.h"
49#include "qindexofiterator_p.h"
50#include "qinsertioniterator_p.h"
51#include "qinteger_p.h"
52#include "qremovaliterator_p.h"
53#include "qsequencegeneratingfns_p.h"
54#include "qsubsequenceiterator_p.h"
55
56#include "qsequencefns_p.h"
57
58QT_BEGIN_NAMESPACE
59
60using namespace QPatternist;
61
62bool BooleanFN::evaluateEBV(const DynamicContext::Ptr &context) const
63{
64 return m_operands.first()->evaluateEBV(context);
65}
66
67Expression::Ptr BooleanFN::typeCheck(const StaticContext::Ptr &context,
68 const SequenceType::Ptr &reqType)
69{
70 return EBVExtractor::typeCheck<FunctionCall>(context, reqType, this);
71}
72
73Item::Iterator::Ptr IndexOfFN::evaluateSequence(const DynamicContext::Ptr &context) const
74{
75 return Item::Iterator::Ptr(new IndexOfIterator(m_operands.first()->evaluateSequence(context),
76 m_operands.at(1)->evaluateSingleton(context),
77 comparator(), context,
78 ConstPtr(this)));
79}
80
81Expression::Ptr IndexOfFN::typeCheck(const StaticContext::Ptr &context,
82 const SequenceType::Ptr &reqType)
83{
84 const Expression::Ptr me(FunctionCall::typeCheck(context, reqType));
85 const ItemType::Ptr t1(m_operands.first()->staticType()->itemType());
86 const ItemType::Ptr t2(m_operands.at(1)->staticType()->itemType());
87
88 if(*CommonSequenceTypes::Empty == *t1 ||
89 *CommonSequenceTypes::Empty == *t2)
90 {
91 return EmptySequence::create(this, context);
92 }
93 else
94 {
95 prepareComparison(fetchComparator(t1, t2, context));
96 return me;
97 }
98}
99
100Item::Iterator::Ptr DistinctValuesFN::evaluateSequence(const DynamicContext::Ptr &context) const
101{
102 return Item::Iterator::Ptr(new DistinctIterator(m_operands.first()->evaluateSequence(context),
103 comparator(),
104 ConstPtr(this),
105 context));
106}
107
108Expression::Ptr DistinctValuesFN::typeCheck(const StaticContext::Ptr &context,
109 const SequenceType::Ptr &reqType)
110{
111 const Expression::Ptr me(FunctionCall::typeCheck(context, reqType));
112 const ItemType::Ptr t1(m_operands.first()->staticType()->itemType());
113
114 if(*CommonSequenceTypes::Empty == *t1)
115 return EmptySequence::create(this, context);
116 else if(!m_operands.first()->staticType()->cardinality().allowsMany())
117 return m_operands.first();
118 else if(BuiltinTypes::xsAnyAtomicType->xdtTypeMatches(t1))
119 return me;
120 else
121 {
122 prepareComparison(fetchComparator(t1, t1, context));
123 return me;
124 }
125}
126
127SequenceType::Ptr DistinctValuesFN::staticType() const
128{
129 const SequenceType::Ptr t(m_operands.first()->staticType());
130 return makeGenericSequenceType(t->itemType(),
131 t->cardinality().allowsMany() ? Cardinality::oneOrMore()
132 : Cardinality::exactlyOne());
133}