Change copyrights from Nokia to Digia
[profile/ivi/qtxmlpatterns.git] / src / xmlpatterns / functions / qxslt20corefunctions.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 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.
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 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.
24 **
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.
28 **
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.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
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"
56
57 #include "qxslt20corefunctions_p.h"
58
59 QT_BEGIN_NAMESPACE
60
61 using namespace QPatternist;
62
63 Expression::Ptr XSLT20CoreFunctions::retrieveExpression(const QXmlName lname,
64                                                         const Expression::List &args,
65                                                         const FunctionSignature::Ptr &sign) const
66 {
67     Q_ASSERT(sign);
68
69     Expression::Ptr fn;
70 #define testXSLTFN(ln, cname) else if(lname.localName() == StandardLocalNames::ln) fn = Expression::Ptr(new cname())
71
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);
86 #undef testXSLTFN
87
88     Q_ASSERT(fn);
89     fn->setOperands(args);
90     fn->as<FunctionCall>()->setSignature(sign);
91
92     return fn;
93 }
94
95 FunctionSignature::Ptr XSLT20CoreFunctions::retrieveFunctionSignature(const NamePool::Ptr &np, const QXmlName name)
96 {
97     if(StandardNamespaces::fn != name.namespaceURI())
98         return FunctionSignature::Ptr();
99
100     FunctionSignature::Ptr s(functionSignatures().value(name));
101
102     if(!s)
103     {
104         /* Alphabetic order. */
105         if(name.localName() == StandardLocalNames::element_available)
106         {
107             s = addFunction(StandardLocalNames::element_available, 1, 1, CommonSequenceTypes::ExactlyOneBoolean);
108             s->appendArgument(argument(np, "element-name"), CommonSequenceTypes::ExactlyOneString);
109         }
110         else if(name.localName() == StandardLocalNames::function_available)
111         {
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);
115         }
116         else if(name.localName() == StandardLocalNames::type_available)
117         {
118             s = addFunction(StandardLocalNames::type_available, 1, 1, CommonSequenceTypes::ExactlyOneBoolean);
119             s->appendArgument(argument(np, "type_name"), CommonSequenceTypes::ExactlyOneString);
120         }
121         else if(name.localName() == StandardLocalNames::system_property)
122         {
123             s = addFunction(StandardLocalNames::system_property, 1, 1, CommonSequenceTypes::ExactlyOneString);
124             s->appendArgument(argument(np, "property_name"), CommonSequenceTypes::ExactlyOneString);
125         }
126         else if(name.localName() == StandardLocalNames::generate_id)
127         {
128             s = addFunction(StandardLocalNames::generate_id, 0, 1, CommonSequenceTypes::ExactlyOneString,
129                             Expression::UseContextItem);
130             s->appendArgument(argument(np, "node"), CommonSequenceTypes::ZeroOrOneNode);
131         }
132         else if(name.localName() == StandardLocalNames::unparsed_text)
133         {
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);
138         }
139         else if(name.localName() == StandardLocalNames::unparsed_text_available)
140         {
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);
145         }
146         else if(name.localName() == StandardLocalNames::current)
147         {
148             s = addFunction(StandardLocalNames::current, 0, 0, CommonSequenceTypes::ExactlyOneItem,
149                             Expression::DisableElimination | Expression::RequiresCurrentItem);
150         }
151         else if(name.localName() == StandardLocalNames::document)
152         {
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);
157         }
158         else if(name.localName() == StandardLocalNames::unparsed_entity_uri)
159         {
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);
163         }
164         else if(name.localName() == StandardLocalNames::unparsed_entity_public_id)
165         {
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);
169         }
170     }
171
172     return s;
173 }
174
175 QT_END_NAMESPACE