|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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 #include "qbuiltintypes_p.h" |
|
43 #include "qcommonnamespaces_p.h" |
|
44 #include "qcommonsequencetypes_p.h" |
|
45 #include "qcommonvalues_p.h" |
|
46 #include "qpatternistlocale_p.h" |
|
47 #include "qxmlname.h" |
|
48 |
|
49 /* Functions */ |
|
50 #include "qaccessorfns_p.h" |
|
51 #include "qaggregatefns_p.h" |
|
52 #include "qbooleanfns_p.h" |
|
53 #include "qcomparestringfns_p.h" |
|
54 #include "qcontextfns_p.h" |
|
55 #include "qnodefns_p.h" |
|
56 #include "qnumericfns_p.h" |
|
57 #include "qsequencefns_p.h" |
|
58 #include "qsequencegeneratingfns_p.h" |
|
59 #include "qstringvaluefns_p.h" |
|
60 #include "qsubstringfns_p.h" |
|
61 |
|
62 #include "qxpath10corefunctions_p.h" |
|
63 |
|
64 QT_BEGIN_NAMESPACE |
|
65 |
|
66 using namespace QPatternist; |
|
67 |
|
68 Expression::Ptr XPath10CoreFunctions::retrieveExpression(const QXmlName name, |
|
69 const Expression::List &args, |
|
70 const FunctionSignature::Ptr &sign) const |
|
71 { |
|
72 Q_ASSERT(sign); |
|
73 |
|
74 Expression::Ptr fn; |
|
75 #define testFN(ln, cname) else if(name.localName() == StandardLocalNames::ln) fn = Expression::Ptr(new cname()) |
|
76 |
|
77 if(false) /* Dummy for the macro handling. Will be optimized away anyway. */ |
|
78 return Expression::Ptr(); |
|
79 /* Alphabetic order. */ |
|
80 testFN(boolean, BooleanFN); |
|
81 testFN(ceiling, CeilingFN); |
|
82 testFN(concat, ConcatFN); |
|
83 testFN(contains, ContainsFN); |
|
84 testFN(count, CountFN); |
|
85 testFN(False, FalseFN); |
|
86 testFN(floor, FloorFN); |
|
87 testFN(id, IdFN); |
|
88 testFN(lang, LangFN); |
|
89 testFN(last, LastFN); |
|
90 testFN(local_name, LocalNameFN); |
|
91 testFN(name, NameFN); |
|
92 testFN(namespace_uri, NamespaceURIFN); |
|
93 testFN(normalize_space, NormalizeSpaceFN); |
|
94 testFN(Not, NotFN); |
|
95 testFN(number, NumberFN); |
|
96 testFN(position, PositionFN); |
|
97 testFN(round, RoundFN); |
|
98 testFN(starts_with, StartsWithFN); |
|
99 testFN(string, StringFN); |
|
100 testFN(string_length, StringLengthFN); |
|
101 testFN(substring, SubstringFN); |
|
102 testFN(substring_after, SubstringAfterFN); |
|
103 testFN(substring_before, SubstringBeforeFN); |
|
104 testFN(sum, SumFN); |
|
105 testFN(translate, TranslateFN); |
|
106 testFN(True, TrueFN); |
|
107 #undef testFN |
|
108 |
|
109 Q_ASSERT(fn); |
|
110 fn->setOperands(args); |
|
111 fn->as<FunctionCall>()->setSignature(sign); |
|
112 |
|
113 return fn; |
|
114 } |
|
115 |
|
116 FunctionSignature::Ptr XPath10CoreFunctions::retrieveFunctionSignature(const NamePool::Ptr &np, const QXmlName name) |
|
117 { |
|
118 if(StandardNamespaces::fn != name.namespaceURI()) |
|
119 return FunctionSignature::Ptr(); |
|
120 |
|
121 FunctionSignature::Ptr s(functionSignatures().value(name)); |
|
122 |
|
123 if(!s) |
|
124 { |
|
125 const QXmlName::LocalNameCode localName(name.localName()); |
|
126 |
|
127 /* Alphabetic order. */ |
|
128 if(StandardLocalNames::boolean == localName) |
|
129 { |
|
130 s = addFunction(StandardLocalNames::boolean, 1, 1, CommonSequenceTypes::ExactlyOneBoolean); |
|
131 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::EBV); |
|
132 } |
|
133 else if(StandardLocalNames::ceiling == localName) |
|
134 { |
|
135 s = addFunction(StandardLocalNames::ceiling, 1, 1, CommonSequenceTypes::ZeroOrOneNumeric, |
|
136 Expression::EmptynessFollowsChild | Expression::RewriteToEmptyOnEmpty); |
|
137 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneNumeric); |
|
138 } |
|
139 else if(StandardLocalNames::concat == localName) |
|
140 { |
|
141 s = addFunction(StandardLocalNames::concat, 2, FunctionSignature::UnlimitedArity, |
|
142 CommonSequenceTypes::ExactlyOneString); |
|
143 s->appendArgument(argument(np, "arg1"), CommonSequenceTypes::ZeroOrOneAtomicType); |
|
144 s->appendArgument(argument(np, "arg2"), CommonSequenceTypes::ZeroOrOneAtomicType); |
|
145 } |
|
146 else if(StandardLocalNames::contains == localName) |
|
147 { |
|
148 s = addFunction(StandardLocalNames::contains, 2, 3, CommonSequenceTypes::ExactlyOneBoolean, |
|
149 Expression::LastOperandIsCollation); |
|
150 s->appendArgument(argument(np, "arg1"), CommonSequenceTypes::ZeroOrOneString); |
|
151 s->appendArgument(argument(np, "arg2"), CommonSequenceTypes::ZeroOrOneString); |
|
152 s->appendArgument(argument(np, "collation"), CommonSequenceTypes::ExactlyOneString); |
|
153 } |
|
154 else if(StandardLocalNames::count == localName) |
|
155 { |
|
156 s = addFunction(StandardLocalNames::count, 1, 1, CommonSequenceTypes::ExactlyOneInteger, Expression::IDCountFN); |
|
157 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrMoreItems); |
|
158 } |
|
159 else if(StandardLocalNames::False == localName) |
|
160 { |
|
161 s = addFunction(StandardLocalNames::False, 0, 0, CommonSequenceTypes::ExactlyOneBoolean); |
|
162 } |
|
163 else if(StandardLocalNames::floor == localName) |
|
164 { |
|
165 s = addFunction(StandardLocalNames::floor, 1, 1, CommonSequenceTypes::ZeroOrOneNumeric, |
|
166 Expression::EmptynessFollowsChild | Expression::RewriteToEmptyOnEmpty); |
|
167 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneNumeric); |
|
168 } |
|
169 else if(StandardLocalNames::id == localName) |
|
170 { |
|
171 s = addFunction(StandardLocalNames::id, 1, 2, CommonSequenceTypes::ZeroOrMoreElements, |
|
172 Expression::UseContextItem); |
|
173 s->appendArgument(argument(np, "idrefs"), CommonSequenceTypes::ZeroOrMoreStrings); |
|
174 s->appendArgument(argument(np, "node"), CommonSequenceTypes::ExactlyOneNode); |
|
175 } |
|
176 else if(StandardLocalNames::lang == localName) |
|
177 { |
|
178 s = addFunction(StandardLocalNames::lang, 1, 2, CommonSequenceTypes::ExactlyOneBoolean, |
|
179 Expression::UseContextItem); |
|
180 s->appendArgument(argument(np, "testLang"), CommonSequenceTypes::ZeroOrOneString); |
|
181 s->appendArgument(argument(np, "node"), CommonSequenceTypes::ExactlyOneNode); |
|
182 } |
|
183 else if(StandardLocalNames::last == localName) |
|
184 { |
|
185 s = addFunction(StandardLocalNames::last, 0, 0, CommonSequenceTypes::ExactlyOneInteger, |
|
186 Expression::DisableElimination | Expression::RequiresFocus); |
|
187 } |
|
188 else if(StandardLocalNames::local_name == localName) |
|
189 { |
|
190 s = addFunction(StandardLocalNames::local_name, 0, 1, CommonSequenceTypes::ExactlyOneString, |
|
191 Expression::UseContextItem); |
|
192 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneNode); |
|
193 } |
|
194 else if(StandardLocalNames::name == localName) |
|
195 { |
|
196 s = addFunction(StandardLocalNames::name, 0, 1, CommonSequenceTypes::ExactlyOneString, |
|
197 Expression::UseContextItem); |
|
198 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneNode); |
|
199 } |
|
200 else if(StandardLocalNames::namespace_uri == localName) |
|
201 { |
|
202 s = addFunction(StandardLocalNames::namespace_uri, 0, 1, CommonSequenceTypes::ExactlyOneAnyURI, |
|
203 Expression::UseContextItem); |
|
204 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneNode); |
|
205 } |
|
206 else if(StandardLocalNames::normalize_space == localName) |
|
207 { |
|
208 s = addFunction(StandardLocalNames::normalize_space, 0, 1, CommonSequenceTypes::ExactlyOneString, |
|
209 Expression::UseContextItem); |
|
210 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneString); |
|
211 } |
|
212 else if(StandardLocalNames::Not == localName) |
|
213 { |
|
214 s = addFunction(StandardLocalNames::Not, 1, 1, CommonSequenceTypes::ExactlyOneBoolean); |
|
215 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::EBV); |
|
216 } |
|
217 else if(StandardLocalNames::number == localName) |
|
218 { |
|
219 s = addFunction(StandardLocalNames::number, 0, 1, CommonSequenceTypes::ExactlyOneDouble, |
|
220 Expression::UseContextItem); |
|
221 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneAtomicType); |
|
222 } |
|
223 else if(StandardLocalNames::position == localName) |
|
224 { |
|
225 s = addFunction(StandardLocalNames::position, 0, 0, CommonSequenceTypes::ExactlyOneInteger, |
|
226 Expression::DisableElimination | Expression::RequiresFocus); |
|
227 } |
|
228 else if(StandardLocalNames::round == localName) |
|
229 { |
|
230 s = addFunction(StandardLocalNames::round, 1, 1, CommonSequenceTypes::ZeroOrOneNumeric, |
|
231 Expression::EmptynessFollowsChild | Expression::RewriteToEmptyOnEmpty); |
|
232 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneNumeric); |
|
233 } |
|
234 else if(StandardLocalNames::starts_with == localName) |
|
235 { |
|
236 s = addFunction(StandardLocalNames::starts_with, 2, 3, CommonSequenceTypes::ExactlyOneBoolean, |
|
237 Expression::LastOperandIsCollation); |
|
238 s->appendArgument(argument(np, "arg1"), CommonSequenceTypes::ZeroOrOneString); |
|
239 s->appendArgument(argument(np, "arg2"), CommonSequenceTypes::ZeroOrOneString); |
|
240 s->appendArgument(argument(np, "collation"), CommonSequenceTypes::ExactlyOneString); |
|
241 } |
|
242 else if(StandardLocalNames::string == localName) |
|
243 { |
|
244 s = addFunction(StandardLocalNames::string, 0, 1, CommonSequenceTypes::ExactlyOneString, |
|
245 Expression::UseContextItem); |
|
246 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneItem); |
|
247 } |
|
248 else if(StandardLocalNames::string_length == localName) |
|
249 { |
|
250 s = addFunction(StandardLocalNames::string_length, 0, 1, |
|
251 CommonSequenceTypes::ExactlyOneInteger, |
|
252 Expression::UseContextItem); |
|
253 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneString); |
|
254 } |
|
255 else if(StandardLocalNames::substring == localName) |
|
256 { |
|
257 s = addFunction(StandardLocalNames::substring, 2, 3, CommonSequenceTypes::ExactlyOneString); |
|
258 s->appendArgument(argument(np, "sourceString"), CommonSequenceTypes::ZeroOrOneString); |
|
259 s->appendArgument(argument(np, "startingLoc"), CommonSequenceTypes::ExactlyOneDouble); |
|
260 s->appendArgument(argument(np, "length"), CommonSequenceTypes::ExactlyOneDouble); |
|
261 } |
|
262 else if(StandardLocalNames::substring_after == localName) |
|
263 { |
|
264 s = addFunction(StandardLocalNames::substring_after, 2, 3, CommonSequenceTypes::ExactlyOneString, |
|
265 Expression::LastOperandIsCollation); |
|
266 s->appendArgument(argument(np, "arg1"), CommonSequenceTypes::ZeroOrOneString); |
|
267 s->appendArgument(argument(np, "arg2"), CommonSequenceTypes::ZeroOrOneString); |
|
268 s->appendArgument(argument(np, "collation"), CommonSequenceTypes::ExactlyOneString); |
|
269 } |
|
270 else if(StandardLocalNames::substring_before == localName) |
|
271 { |
|
272 s = addFunction(StandardLocalNames::substring_before, 2, 3, CommonSequenceTypes::ExactlyOneString, |
|
273 Expression::LastOperandIsCollation); |
|
274 s->appendArgument(argument(np, "arg1"), CommonSequenceTypes::ZeroOrOneString); |
|
275 s->appendArgument(argument(np, "arg2"), CommonSequenceTypes::ZeroOrOneString); |
|
276 s->appendArgument(argument(np, "collation"), CommonSequenceTypes::ExactlyOneString); |
|
277 } |
|
278 else if(StandardLocalNames::sum == localName) |
|
279 { |
|
280 s = addFunction(StandardLocalNames::sum, 1, 2, CommonSequenceTypes::ZeroOrOneAtomicType); |
|
281 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrMoreAtomicTypes); |
|
282 s->appendArgument(argument(np, "zero"), CommonSequenceTypes::ZeroOrOneAtomicType); |
|
283 } |
|
284 else if(StandardLocalNames::translate == localName) |
|
285 { |
|
286 s = addFunction(StandardLocalNames::translate, 3, 3, CommonSequenceTypes::ExactlyOneString); |
|
287 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneString); |
|
288 s->appendArgument(argument(np, "mapString"), CommonSequenceTypes::ExactlyOneString); |
|
289 s->appendArgument(argument(np, "transString"), CommonSequenceTypes::ExactlyOneString); |
|
290 } |
|
291 else if(StandardLocalNames::True == localName) |
|
292 { |
|
293 s = addFunction(StandardLocalNames::True, 0, 0, CommonSequenceTypes::ExactlyOneBoolean); |
|
294 } |
|
295 } |
|
296 |
|
297 return s; |
|
298 } |
|
299 |
|
300 QT_END_NAMESPACE |