Change copyrights from Nokia to Digia
[profile/ivi/qtxmlpatterns.git] / src / xmlpatterns / functions / qfunctionsignature.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 "qxmlname.h"
43
44 #include "qfunctionsignature_p.h"
45
46 QT_BEGIN_NAMESPACE
47
48 using namespace QPatternist;
49
50 FunctionSignature::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
68 void 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
76 QString 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
111 bool FunctionSignature::operator==(const FunctionSignature &other) const
112 {
113     return name() == other.name() &&
114            isArityValid(other.maximumArguments()) &&
115            isArityValid(other.minimumArguments());
116 }
117
118 void FunctionSignature::setArguments(const FunctionArgument::List &args)
119 {
120     m_arguments = args;
121 }
122
123 FunctionArgument::List FunctionSignature::arguments() const
124 {
125     return m_arguments;
126 }
127
128 bool FunctionSignature::isArityValid(const xsInteger arity) const
129 {
130     return arity >= m_minArgs && arity <= m_maxArgs;
131 }
132
133 FunctionSignature::Arity FunctionSignature::minimumArguments() const
134 {
135     return m_minArgs;
136 }
137
138 FunctionSignature::Arity FunctionSignature::maximumArguments() const
139 {
140     return m_maxArgs;
141 }
142
143 SequenceType::Ptr FunctionSignature::returnType() const
144 {
145     return m_returnType;
146 }
147
148 Expression::Properties FunctionSignature::properties() const
149 {
150     return m_props;
151 }
152
153 Expression::ID FunctionSignature::id() const
154 {
155     return m_id;
156 }
157
158 QT_END_NAMESPACE