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 "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)
|
---|
|
---|