1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
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);