1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit. |
7 | ** |
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 The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
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 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qanyuri_p.h" |
41 | #include "qcommonnamespaces_p.h" |
42 | #include "qcommonsequencetypes_p.h" |
43 | #include "qcurrentfn_p.h" |
44 | #include "qdocumentfn_p.h" |
45 | #include "qelementavailablefn_p.h" |
46 | #include "qfunctionavailablefn_p.h" |
47 | #include "qgenerateidfn_p.h" |
48 | #include "qsystempropertyfn_p.h" |
49 | #include "qtypeavailablefn_p.h" |
50 | #include "qunparsedentitypublicidfn_p.h" |
51 | #include "qunparsedentityurifn_p.h" |
52 | #include "qunparsedtextavailablefn_p.h" |
53 | #include "qunparsedtextfn_p.h" |
54 | |
55 | #include "qxslt20corefunctions_p.h" |
56 | |
57 | QT_BEGIN_NAMESPACE |
58 | |
59 | using namespace QPatternist; |
60 | |
61 | Expression::Ptr XSLT20CoreFunctions::retrieveExpression(const QXmlName lname, |
62 | const Expression::List &args, |
63 | const FunctionSignature::Ptr &sign) const |
64 | { |
65 | Q_ASSERT(sign); |
66 | |
67 | Expression::Ptr fn; |
68 | #define testXSLTFN(ln, cname) else if(lname.localName() == StandardLocalNames::ln) fn = Expression::Ptr(new cname()) |
69 | |
70 | if(false) /* Dummy for the macro handling. Will be optimized away anyway. */ |
71 | return Expression::Ptr(); |
72 | /* Alphabetic order. */ |
73 | testXSLTFN(current, CurrentFN); |
74 | testXSLTFN(document, DocumentFN); |
75 | testXSLTFN(element_available, ElementAvailableFN); |
76 | testXSLTFN(function_available, FunctionAvailableFN); |
77 | testXSLTFN(generate_id, GenerateIDFN); |
78 | testXSLTFN(system_property, SystemPropertyFN); |
79 | testXSLTFN(type_available, TypeAvailableFN); |
80 | testXSLTFN(unparsed_entity_public_id, UnparsedEntityPublicIDFN); |
81 | testXSLTFN(unparsed_entity_uri, UnparsedEntityURIFN); |
82 | testXSLTFN(unparsed_text_available, UnparsedTextAvailableFN); |
83 | testXSLTFN(unparsed_text, UnparsedTextFN); |
84 | #undef testXSLTFN |
85 | |
86 | Q_ASSERT(fn); |
87 | fn->setOperands(args); |
88 | fn->as<FunctionCall>()->setSignature(sign); |
89 | |
90 | return fn; |
91 | } |
92 | |
93 | FunctionSignature::Ptr XSLT20CoreFunctions::retrieveFunctionSignature(const NamePool::Ptr &np, const QXmlName name) |
94 | { |
95 | if(StandardNamespaces::fn != name.namespaceURI()) |
96 | return FunctionSignature::Ptr(); |
97 | |
98 | FunctionSignature::Ptr s(functionSignatures().value(akey: name)); |
99 | |
100 | if(!s) |
101 | { |
102 | /* Alphabetic order. */ |
103 | if(name.localName() == StandardLocalNames::element_available) |
104 | { |
105 | s = addFunction(localName: StandardLocalNames::element_available, minArgs: 1, maxArgs: 1, returnType: CommonSequenceTypes::ExactlyOneBoolean); |
106 | s->appendArgument(name: argument(np, name: "element-name" ), type: CommonSequenceTypes::ExactlyOneString); |
107 | } |
108 | else if(name.localName() == StandardLocalNames::function_available) |
109 | { |
110 | s = addFunction(localName: StandardLocalNames::function_available, minArgs: 1, maxArgs: 2, returnType: CommonSequenceTypes::ExactlyOneBoolean); |
111 | s->appendArgument(name: argument(np, name: "function_name" ), type: CommonSequenceTypes::ExactlyOneString); |
112 | s->appendArgument(name: argument(np, name: "arity" ), type: CommonSequenceTypes::ExactlyOneInteger); |
113 | } |
114 | else if(name.localName() == StandardLocalNames::type_available) |
115 | { |
116 | s = addFunction(localName: StandardLocalNames::type_available, minArgs: 1, maxArgs: 1, returnType: CommonSequenceTypes::ExactlyOneBoolean); |
117 | s->appendArgument(name: argument(np, name: "type_name" ), type: CommonSequenceTypes::ExactlyOneString); |
118 | } |
119 | else if(name.localName() == StandardLocalNames::system_property) |
120 | { |
121 | s = addFunction(localName: StandardLocalNames::system_property, minArgs: 1, maxArgs: 1, returnType: CommonSequenceTypes::ExactlyOneString); |
122 | s->appendArgument(name: argument(np, name: "property_name" ), type: CommonSequenceTypes::ExactlyOneString); |
123 | } |
124 | else if(name.localName() == StandardLocalNames::generate_id) |
125 | { |
126 | s = addFunction(localName: StandardLocalNames::generate_id, minArgs: 0, maxArgs: 1, returnType: CommonSequenceTypes::ExactlyOneString, |
127 | props: Expression::UseContextItem); |
128 | s->appendArgument(name: argument(np, name: "node" ), type: CommonSequenceTypes::ZeroOrOneNode); |
129 | } |
130 | else if(name.localName() == StandardLocalNames::unparsed_text) |
131 | { |
132 | s = addFunction(localName: StandardLocalNames::unparsed_text, minArgs: 1, maxArgs: 2, returnType: CommonSequenceTypes::ZeroOrOneString, |
133 | props: Expression::DisableElimination); |
134 | s->appendArgument(name: argument(np, name: "href" ), type: CommonSequenceTypes::ZeroOrOneString); |
135 | s->appendArgument(name: argument(np, name: "encoding" ), type: CommonSequenceTypes::ExactlyOneString); |
136 | } |
137 | else if(name.localName() == StandardLocalNames::unparsed_text_available) |
138 | { |
139 | s = addFunction(localName: StandardLocalNames::unparsed_text_available, minArgs: 1, maxArgs: 2, returnType: CommonSequenceTypes::ExactlyOneBoolean, |
140 | props: Expression::DisableElimination); |
141 | s->appendArgument(name: argument(np, name: "href" ), type: CommonSequenceTypes::ZeroOrOneString); |
142 | s->appendArgument(name: argument(np, name: "encoding" ), type: CommonSequenceTypes::ZeroOrOneString); |
143 | } |
144 | else if(name.localName() == StandardLocalNames::current) |
145 | { |
146 | s = addFunction(localName: StandardLocalNames::current, minArgs: 0, maxArgs: 0, returnType: CommonSequenceTypes::ExactlyOneItem, |
147 | props: Expression::DisableElimination | Expression::RequiresCurrentItem); |
148 | } |
149 | else if(name.localName() == StandardLocalNames::document) |
150 | { |
151 | s = addFunction(localName: StandardLocalNames::document, minArgs: 1, maxArgs: 2, returnType: CommonSequenceTypes::OneOrMoreDocumentNodes, |
152 | props: Expression::DisableElimination); |
153 | s->appendArgument(name: argument(np, name: "uri-sequence" ), type: CommonSequenceTypes::ZeroOrMoreStrings); |
154 | s->appendArgument(name: argument(np, name: "base-uri-node" ), type: CommonSequenceTypes::ExactlyOneNode); |
155 | } |
156 | else if(name.localName() == StandardLocalNames::unparsed_entity_uri) |
157 | { |
158 | s = addFunction(localName: StandardLocalNames::unparsed_entity_uri, minArgs: 1, maxArgs: 1, returnType: CommonSequenceTypes::ExactlyOneAnyURI, |
159 | props: Expression::RequiresFocus | Expression::DisableElimination); |
160 | s->appendArgument(name: argument(np, name: "entity-name" ), type: CommonSequenceTypes::ExactlyOneString); |
161 | } |
162 | else if(name.localName() == StandardLocalNames::unparsed_entity_public_id) |
163 | { |
164 | s = addFunction(localName: StandardLocalNames::unparsed_entity_public_id, minArgs: 1, maxArgs: 1, returnType: CommonSequenceTypes::ExactlyOneString, |
165 | props: Expression::RequiresFocus | Expression::DisableElimination); |
166 | s->appendArgument(name: argument(np, name: "entity-name" ), type: CommonSequenceTypes::ExactlyOneString); |
167 | } |
168 | } |
169 | |
170 | return s; |
171 | } |
172 | |
173 | QT_END_NAMESPACE |
174 | |