author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 (2010-10-03) | |
changeset 37 | 758a864f9613 |
parent 18 | 2f34d5167611 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtXmlPatterns module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include "qcontextitem_p.h" |
|
44 |
#include "qcommonsequencetypes_p.h" |
|
45 |
#include "qemptysequence_p.h" |
|
46 |
#include "qfunctionsignature_p.h" |
|
47 |
#include "qgenericsequencetype_p.h" |
|
48 |
#include "qcollationchecker_p.h" |
|
49 |
#include "qcommonnamespaces_p.h" |
|
50 |
||
51 |
#include "qfunctioncall_p.h" |
|
52 |
||
53 |
QT_BEGIN_NAMESPACE |
|
54 |
||
55 |
using namespace QPatternist; |
|
56 |
||
57 |
SequenceType::List FunctionCall::expectedOperandTypes() const |
|
58 |
{ |
|
59 |
const FunctionArgument::List args(signature()->arguments()); |
|
60 |
FunctionArgument::List::const_iterator it(args.constBegin()); |
|
61 |
const FunctionArgument::List::const_iterator end(args.constEnd()); |
|
62 |
// TODO reserve/resize() |
|
63 |
SequenceType::List result; |
|
64 |
||
65 |
for(; it != end; ++it) |
|
66 |
result.append((*it)->type()); |
|
67 |
||
68 |
return result; |
|
69 |
} |
|
70 |
||
71 |
Expression::Ptr FunctionCall::typeCheck(const StaticContext::Ptr &context, |
|
72 |
const SequenceType::Ptr &reqType) |
|
73 |
{ |
|
74 |
/* We don't cache properties() at some stages because it can be invalidated |
|
75 |
* by the typeCheck(). */ |
|
76 |
||
77 |
const FunctionSignature::Arity maxArgs = signature()->maximumArguments(); |
|
78 |
/* We do this before the typeCheck() such that the appropriate conversions |
|
79 |
* are applied to the ContextItem. */ |
|
80 |
if(m_operands.count() < maxArgs && |
|
81 |
has(UseContextItem)) |
|
82 |
{ |
|
83 |
m_operands.append(Expression::Ptr(new ContextItem())); |
|
84 |
context->wrapExpressionWith(this, m_operands.last()); |
|
85 |
} |
|
86 |
||
87 |
const Expression::Ptr me(UnlimitedContainer::typeCheck(context, reqType)); |
|
88 |
if(me != this) |
|
89 |
return me; |
|
90 |
||
91 |
const Properties props(properties()); |
|
92 |
||
93 |
if(props.testFlag(RewriteToEmptyOnEmpty) && |
|
94 |
*CommonSequenceTypes::Empty == *m_operands.first()->staticType()->itemType()) |
|
95 |
{ |
|
96 |
return EmptySequence::create(this, context); |
|
97 |
} |
|
98 |
||
99 |
if(props.testFlag(LastOperandIsCollation) && |
|
100 |
m_operands.count() == maxArgs) |
|
101 |
{ |
|
102 |
m_operands.last() = Expression::Ptr(new CollationChecker(m_operands.last())); |
|
103 |
context->wrapExpressionWith(this, m_operands.last()); |
|
104 |
} |
|
105 |
||
106 |
return me; |
|
107 |
} |
|
108 |
||
109 |
void FunctionCall::setSignature(const FunctionSignature::Ptr &sign) |
|
110 |
{ |
|
111 |
m_signature = sign; |
|
112 |
} |
|
113 |
||
114 |
FunctionSignature::Ptr FunctionCall::signature() const |
|
115 |
{ |
|
116 |
Q_ASSERT(m_signature); /* It really should be set. */ |
|
117 |
return m_signature; |
|
118 |
} |
|
119 |
||
120 |
SequenceType::Ptr FunctionCall::staticType() const |
|
121 |
{ |
|
122 |
Q_ASSERT(m_signature); |
|
123 |
if(has(EmptynessFollowsChild)) |
|
124 |
{ |
|
125 |
if(m_operands.isEmpty()) |
|
126 |
{ |
|
127 |
/* This is a function which uses the context item when having no arguments. */ |
|
128 |
return signature()->returnType(); |
|
129 |
} |
|
130 |
const Cardinality card(m_operands.first()->staticType()->cardinality()); |
|
131 |
if(card.allowsEmpty()) |
|
132 |
return signature()->returnType(); |
|
133 |
else |
|
134 |
{ |
|
135 |
/* Remove empty. */ |
|
136 |
return makeGenericSequenceType(signature()->returnType()->itemType(), |
|
137 |
card & Cardinality::oneOrMore()); |
|
138 |
} |
|
139 |
} |
|
140 |
return signature()->returnType(); |
|
141 |
} |
|
142 |
||
143 |
Expression::Properties FunctionCall::properties() const |
|
144 |
{ |
|
145 |
Q_ASSERT(m_signature); |
|
146 |
return signature()->properties(); |
|
147 |
} |
|
148 |
||
149 |
ExpressionVisitorResult::Ptr FunctionCall::accept(const ExpressionVisitor::Ptr &visitor) const |
|
150 |
{ |
|
151 |
return visitor->visit(this); |
|
152 |
} |
|
153 |
||
154 |
Expression::ID FunctionCall::id() const |
|
155 |
{ |
|
156 |
Q_ASSERT(m_signature); |
|
157 |
return m_signature->id(); |
|
158 |
} |
|
159 |
||
160 |
QT_END_NAMESPACE |