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 "qanyuri_p.h"
43 #include "qcommonnamespaces_p.h"
44 #include "qcommonsequencetypes_p.h"
45 #include "qcurrentfn_p.h"
46 #include "qdocumentfn_p.h"
47 #include "qelementavailablefn_p.h"
48 #include "qfunctionavailablefn_p.h"
49 #include "qgenerateidfn_p.h"
50 #include "qsystempropertyfn_p.h"
51 #include "qtypeavailablefn_p.h"
52 #include "qunparsedentitypublicidfn_p.h"
53 #include "qunparsedentityurifn_p.h"
54 #include "qunparsedtextavailablefn_p.h"
55 #include "qunparsedtextfn_p.h"
57 #include "qxslt20corefunctions_p.h"
61 using namespace QPatternist;
63 Expression::Ptr XSLT20CoreFunctions::retrieveExpression(const QXmlName lname,
64 const Expression::List &args,
65 const FunctionSignature::Ptr &sign) const
70 #define testXSLTFN(ln, cname) else if(lname.localName() == StandardLocalNames::ln) fn = Expression::Ptr(new cname())
72 if(false) /* Dummy for the macro handling. Will be optimized away anyway. */
73 return Expression::Ptr();
74 /* Alphabetic order. */
75 testXSLTFN(current, CurrentFN);
76 testXSLTFN(document, DocumentFN);
77 testXSLTFN(element_available, ElementAvailableFN);
78 testXSLTFN(function_available, FunctionAvailableFN);
79 testXSLTFN(generate_id, GenerateIDFN);
80 testXSLTFN(system_property, SystemPropertyFN);
81 testXSLTFN(type_available, TypeAvailableFN);
82 testXSLTFN(unparsed_entity_public_id, UnparsedEntityPublicIDFN);
83 testXSLTFN(unparsed_entity_uri, UnparsedEntityURIFN);
84 testXSLTFN(unparsed_text_available, UnparsedTextAvailableFN);
85 testXSLTFN(unparsed_text, UnparsedTextFN);
89 fn->setOperands(args);
90 fn->as<FunctionCall>()->setSignature(sign);
95 FunctionSignature::Ptr XSLT20CoreFunctions::retrieveFunctionSignature(const NamePool::Ptr &np, const QXmlName name)
97 if(StandardNamespaces::fn != name.namespaceURI())
98 return FunctionSignature::Ptr();
100 FunctionSignature::Ptr s(functionSignatures().value(name));
104 /* Alphabetic order. */
105 if(name.localName() == StandardLocalNames::element_available)
107 s = addFunction(StandardLocalNames::element_available, 1, 1, CommonSequenceTypes::ExactlyOneBoolean);
108 s->appendArgument(argument(np, "element-name"), CommonSequenceTypes::ExactlyOneString);
110 else if(name.localName() == StandardLocalNames::function_available)
112 s = addFunction(StandardLocalNames::function_available, 1, 2, CommonSequenceTypes::ExactlyOneBoolean);
113 s->appendArgument(argument(np, "function_name"), CommonSequenceTypes::ExactlyOneString);
114 s->appendArgument(argument(np, "arity"), CommonSequenceTypes::ExactlyOneInteger);
116 else if(name.localName() == StandardLocalNames::type_available)
118 s = addFunction(StandardLocalNames::type_available, 1, 1, CommonSequenceTypes::ExactlyOneBoolean);
119 s->appendArgument(argument(np, "type_name"), CommonSequenceTypes::ExactlyOneString);
121 else if(name.localName() == StandardLocalNames::system_property)
123 s = addFunction(StandardLocalNames::system_property, 1, 1, CommonSequenceTypes::ExactlyOneString);
124 s->appendArgument(argument(np, "property_name"), CommonSequenceTypes::ExactlyOneString);
126 else if(name.localName() == StandardLocalNames::generate_id)
128 s = addFunction(StandardLocalNames::generate_id, 0, 1, CommonSequenceTypes::ExactlyOneString,
129 Expression::UseContextItem);
130 s->appendArgument(argument(np, "node"), CommonSequenceTypes::ZeroOrOneNode);
132 else if(name.localName() == StandardLocalNames::unparsed_text)
134 s = addFunction(StandardLocalNames::unparsed_text, 1, 2, CommonSequenceTypes::ZeroOrOneString,
135 Expression::DisableElimination);
136 s->appendArgument(argument(np, "href"), CommonSequenceTypes::ZeroOrOneString);
137 s->appendArgument(argument(np, "encoding"), CommonSequenceTypes::ExactlyOneString);
139 else if(name.localName() == StandardLocalNames::unparsed_text_available)
141 s = addFunction(StandardLocalNames::unparsed_text_available, 1, 2, CommonSequenceTypes::ExactlyOneBoolean,
142 Expression::DisableElimination);
143 s->appendArgument(argument(np, "href"), CommonSequenceTypes::ZeroOrOneString);
144 s->appendArgument(argument(np, "encoding"), CommonSequenceTypes::ZeroOrOneString);
146 else if(name.localName() == StandardLocalNames::current)
148 s = addFunction(StandardLocalNames::current, 0, 0, CommonSequenceTypes::ExactlyOneItem,
149 Expression::DisableElimination | Expression::RequiresCurrentItem);
151 else if(name.localName() == StandardLocalNames::document)
153 s = addFunction(StandardLocalNames::document, 1, 2, CommonSequenceTypes::OneOrMoreDocumentNodes,
154 Expression::DisableElimination);
155 s->appendArgument(argument(np, "uri-sequence"), CommonSequenceTypes::ZeroOrMoreStrings);
156 s->appendArgument(argument(np, "base-uri-node"), CommonSequenceTypes::ExactlyOneNode);
158 else if(name.localName() == StandardLocalNames::unparsed_entity_uri)
160 s = addFunction(StandardLocalNames::unparsed_entity_uri, 1, 1, CommonSequenceTypes::ExactlyOneAnyURI,
161 Expression::RequiresFocus | Expression::DisableElimination);
162 s->appendArgument(argument(np, "entity-name"), CommonSequenceTypes::ExactlyOneString);
164 else if(name.localName() == StandardLocalNames::unparsed_entity_public_id)
166 s = addFunction(StandardLocalNames::unparsed_entity_public_id, 1, 1, CommonSequenceTypes::ExactlyOneString,
167 Expression::RequiresFocus | Expression::DisableElimination);
168 s->appendArgument(argument(np, "entity-name"), CommonSequenceTypes::ExactlyOneString);