1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
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"
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"
62 #include "qxpath10corefunctions_p.h"
66 using namespace QPatternist;
68 Expression::Ptr XPath10CoreFunctions::retrieveExpression(const QXmlName name,
69 const Expression::List &args,
70 const FunctionSignature::Ptr &sign) const
75 #define testFN(ln, cname) else if(name.localName() == StandardLocalNames::ln) fn = Expression::Ptr(new cname())
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);
90 testFN(local_name, LocalNameFN);
92 testFN(namespace_uri, NamespaceURIFN);
93 testFN(normalize_space, NormalizeSpaceFN);
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);
105 testFN(translate, TranslateFN);
106 testFN(True, TrueFN);
110 fn->setOperands(args);
111 fn->as<FunctionCall>()->setSignature(sign);
116 FunctionSignature::Ptr XPath10CoreFunctions::retrieveFunctionSignature(const NamePool::Ptr &np, const QXmlName name)
118 if(StandardNamespaces::fn != name.namespaceURI())
119 return FunctionSignature::Ptr();
121 FunctionSignature::Ptr s(functionSignatures().value(name));
125 const QXmlName::LocalNameCode localName(name.localName());
127 /* Alphabetic order. */
128 if(StandardLocalNames::boolean == localName)
130 s = addFunction(StandardLocalNames::boolean, 1, 1, CommonSequenceTypes::ExactlyOneBoolean);
131 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::EBV);
133 else if(StandardLocalNames::ceiling == localName)
135 s = addFunction(StandardLocalNames::ceiling, 1, 1, CommonSequenceTypes::ZeroOrOneNumeric,
136 Expression::EmptynessFollowsChild | Expression::RewriteToEmptyOnEmpty);
137 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneNumeric);
139 else if(StandardLocalNames::concat == localName)
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);
146 else if(StandardLocalNames::contains == localName)
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);
154 else if(StandardLocalNames::count == localName)
156 s = addFunction(StandardLocalNames::count, 1, 1, CommonSequenceTypes::ExactlyOneInteger, Expression::IDCountFN);
157 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrMoreItems);
159 else if(StandardLocalNames::False == localName)
161 s = addFunction(StandardLocalNames::False, 0, 0, CommonSequenceTypes::ExactlyOneBoolean);
163 else if(StandardLocalNames::floor == localName)
165 s = addFunction(StandardLocalNames::floor, 1, 1, CommonSequenceTypes::ZeroOrOneNumeric,
166 Expression::EmptynessFollowsChild | Expression::RewriteToEmptyOnEmpty);
167 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneNumeric);
169 else if(StandardLocalNames::id == localName)
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);
176 else if(StandardLocalNames::lang == localName)
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);
183 else if(StandardLocalNames::last == localName)
185 s = addFunction(StandardLocalNames::last, 0, 0, CommonSequenceTypes::ExactlyOneInteger,
186 Expression::DisableElimination | Expression::RequiresFocus);
188 else if(StandardLocalNames::local_name == localName)
190 s = addFunction(StandardLocalNames::local_name, 0, 1, CommonSequenceTypes::ExactlyOneString,
191 Expression::UseContextItem);
192 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneNode);
194 else if(StandardLocalNames::name == localName)
196 s = addFunction(StandardLocalNames::name, 0, 1, CommonSequenceTypes::ExactlyOneString,
197 Expression::UseContextItem);
198 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneNode);
200 else if(StandardLocalNames::namespace_uri == localName)
202 s = addFunction(StandardLocalNames::namespace_uri, 0, 1, CommonSequenceTypes::ExactlyOneAnyURI,
203 Expression::UseContextItem);
204 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneNode);
206 else if(StandardLocalNames::normalize_space == localName)
208 s = addFunction(StandardLocalNames::normalize_space, 0, 1, CommonSequenceTypes::ExactlyOneString,
209 Expression::UseContextItem);
210 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneString);
212 else if(StandardLocalNames::Not == localName)
214 s = addFunction(StandardLocalNames::Not, 1, 1, CommonSequenceTypes::ExactlyOneBoolean);
215 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::EBV);
217 else if(StandardLocalNames::number == localName)
219 s = addFunction(StandardLocalNames::number, 0, 1, CommonSequenceTypes::ExactlyOneDouble,
220 Expression::UseContextItem);
221 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneAtomicType);
223 else if(StandardLocalNames::position == localName)
225 s = addFunction(StandardLocalNames::position, 0, 0, CommonSequenceTypes::ExactlyOneInteger,
226 Expression::DisableElimination | Expression::RequiresFocus);
228 else if(StandardLocalNames::round == localName)
230 s = addFunction(StandardLocalNames::round, 1, 1, CommonSequenceTypes::ZeroOrOneNumeric,
231 Expression::EmptynessFollowsChild | Expression::RewriteToEmptyOnEmpty);
232 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneNumeric);
234 else if(StandardLocalNames::starts_with == localName)
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);
242 else if(StandardLocalNames::string == localName)
244 s = addFunction(StandardLocalNames::string, 0, 1, CommonSequenceTypes::ExactlyOneString,
245 Expression::UseContextItem);
246 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneItem);
248 else if(StandardLocalNames::string_length == localName)
250 s = addFunction(StandardLocalNames::string_length, 0, 1,
251 CommonSequenceTypes::ExactlyOneInteger,
252 Expression::UseContextItem);
253 s->appendArgument(argument(np, "arg"), CommonSequenceTypes::ZeroOrOneString);
255 else if(StandardLocalNames::substring == localName)
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);
262 else if(StandardLocalNames::substring_after == localName)
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);
270 else if(StandardLocalNames::substring_before == localName)
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);
278 else if(StandardLocalNames::sum == localName)
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);
284 else if(StandardLocalNames::translate == localName)
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);
291 else if(StandardLocalNames::True == localName)
293 s = addFunction(StandardLocalNames::True, 0, 0, CommonSequenceTypes::ExactlyOneBoolean);