source: trunk/src/xmlpatterns/functions/qfunctionsignature.cpp@ 561

Last change on this file since 561 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

File size: 5.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtXmlPatterns module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qxmlname.h"
43
44#include "qfunctionsignature_p.h"
45
46QT_BEGIN_NAMESPACE
47
48using namespace QPatternist;
49
50FunctionSignature::FunctionSignature(const QXmlName nameP,
51 const Arity minArgs,
52 const Arity maxArgs,
53 const SequenceType::Ptr &returnTypeP,
54 const Expression::Properties props,
55 const Expression::ID idP) : CallTargetDescription(nameP)
56 , m_minArgs(minArgs)
57 , m_maxArgs(maxArgs)
58 , m_returnType(returnTypeP)
59 , m_arguments()
60 , m_props(props)
61 , m_id(idP)
62{
63 Q_ASSERT(minArgs <= maxArgs || maxArgs == FunctionSignature::UnlimitedArity);
64 Q_ASSERT(m_maxArgs >= -1);
65 Q_ASSERT(returnTypeP);
66}
67
68void FunctionSignature::appendArgument(const QXmlName::LocalNameCode nameP,
69 const SequenceType::Ptr &type)
70{
71 Q_ASSERT(type);
72
73 m_arguments.append(FunctionArgument::Ptr(new FunctionArgument(QXmlName(StandardNamespaces::empty, nameP), type)));
74}
75
76QString FunctionSignature::displayName(const NamePool::Ptr &np) const
77{
78 QString result;
79 result += np->displayName(name());
80 result += QLatin1Char('(');
81
82 FunctionArgument::List::const_iterator it(m_arguments.constBegin());
83 const FunctionArgument::List::const_iterator end(m_arguments.constEnd());
84
85 if(it != end)
86 {
87 while(true)
88 {
89 result += QLatin1Char('$');
90 result += np->displayName((*it)->name());
91 result += QLatin1String(" as ");
92 result += (*it)->type()->displayName(np);
93
94 ++it;
95 if(it == end)
96 break;
97
98 result += QLatin1String(", ");
99 }
100 }
101
102 if(m_maxArgs == FunctionSignature::UnlimitedArity)
103 result += QLatin1String(", ...");
104
105 result += QLatin1String(") as ");
106 result += m_returnType->displayName(np);
107
108 return result;
109}
110
111bool FunctionSignature::operator==(const FunctionSignature &other) const
112{
113 return name() == other.name() &&
114 isArityValid(other.maximumArguments()) &&
115 isArityValid(other.minimumArguments());
116}
117
118void FunctionSignature::setArguments(const FunctionArgument::List &args)
119{
120 m_arguments = args;
121}
122
123FunctionArgument::List FunctionSignature::arguments() const
124{
125 return m_arguments;
126}
127
128bool FunctionSignature::isArityValid(const xsInteger arity) const
129{
130 return arity >= m_minArgs && arity <= m_maxArgs;
131}
132
133FunctionSignature::Arity FunctionSignature::minimumArguments() const
134{
135 return m_minArgs;
136}
137
138FunctionSignature::Arity FunctionSignature::maximumArguments() const
139{
140 return m_maxArgs;
141}
142
143SequenceType::Ptr FunctionSignature::returnType() const
144{
145 return m_returnType;
146}
147
148Expression::Properties FunctionSignature::properties() const
149{
150 return m_props;
151}
152
153Expression::ID FunctionSignature::id() const
154{
155 return m_id;
156}
157
158QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.