source: trunk/src/xmlpatterns/functions/qxslt20corefunctions.cpp@ 497

Last change on this file since 497 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 8.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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
59QT_BEGIN_NAMESPACE
60
61using namespace QPatternist;
62
63Expression::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
95FunctionSignature::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
175QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.