Qt 4.8
qfunctioncall.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 
43 #include "qcontextitem_p.h"
44 #include "qcommonsequencetypes_p.h"
45 #include "qemptysequence_p.h"
46 #include "qfunctionsignature_p.h"
47 #include "qgenericsequencetype_p.h"
48 #include "qcollationchecker_p.h"
49 #include "qcommonnamespaces_p.h"
50 
51 #include "qfunctioncall_p.h"
52 
54 
55 using namespace QPatternist;
56 
58 {
59  const FunctionArgument::List args(signature()->arguments());
62  // TODO reserve/resize()
63  SequenceType::List result;
64 
65  for(; it != end; ++it)
66  result.append((*it)->type());
67 
68  return result;
69 }
70 
72  const SequenceType::Ptr &reqType)
73 {
74  /* We don't cache properties() at some stages because it can be invalidated
75  * by the typeCheck(). */
76 
78  /* We do this before the typeCheck() such that the appropriate conversions
79  * are applied to the ContextItem. */
80  if(m_operands.count() < maxArgs &&
82  {
84  context->wrapExpressionWith(this, m_operands.last());
85  }
86 
87  const Expression::Ptr me(UnlimitedContainer::typeCheck(context, reqType));
88  if(me != this)
89  return me;
90 
91  const Properties props(properties());
92 
93  if(props.testFlag(RewriteToEmptyOnEmpty) &&
95  {
96  return EmptySequence::create(this, context);
97  }
98 
99  if(props.testFlag(LastOperandIsCollation) &&
100  m_operands.count() == maxArgs)
101  {
103  context->wrapExpressionWith(this, m_operands.last());
104  }
105 
106  return me;
107 }
108 
110 {
111  m_signature = sign;
112 }
113 
115 {
116  Q_ASSERT(m_signature); /* It really should be set. */
117  return m_signature;
118 }
119 
121 {
124  {
125  if(m_operands.isEmpty())
126  {
127  /* This is a function which uses the context item when having no arguments. */
128  return signature()->returnType();
129  }
130  const Cardinality card(m_operands.first()->staticType()->cardinality());
131  if(card.allowsEmpty())
132  return signature()->returnType();
133  else
134  {
135  /* Remove empty. */
136  return makeGenericSequenceType(signature()->returnType()->itemType(),
137  card & Cardinality::oneOrMore());
138  }
139  }
140  return signature()->returnType();
141 }
142 
144 {
146  return signature()->properties();
147 }
148 
150 {
151  return visitor->visit(this);
152 }
153 
155 {
157  return m_signature->id();
158 }
159 
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual void setSignature(const FunctionSignature::Ptr &sign)
virtual Expression::Properties properties() const
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Definition: qexpression.cpp:70
bool testFlag(Enum f) const
Returns true if the flag is set, otherwise false.
Definition: qglobal.h:2345
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
virtual SequenceType::Ptr staticType() const
static Expression::Ptr create(const Expression *const replacementFor, const StaticContext::Ptr &context)
Creates an EmptySequence that is a replacement for replacementFor.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
SequenceType::Ptr returnType() const
bool has(const Property prop) const
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
static int sign(int x)
friend class const_iterator
Definition: qlist.h:264
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static Cardinality oneOrMore()
Checks that its operand evaluates to a supported string collation.
The namespace for the internal API of QtXmlPatterns.
Implements the context item, the dot: ..
virtual FunctionSignature::Ptr signature() const
virtual Cardinality cardinality() const =0
virtual SequenceType::List expectedOperandTypes() const
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
QExplicitlySharedDataPointer< Expression > Ptr
A smart pointer wrapping mutable Expression instances.
virtual ExpressionVisitorResult::Ptr accept(const ExpressionVisitor::Ptr &visitor) const
virtual SequenceType::Ptr staticType() const =0
static const EmptySequenceType::Ptr Empty
FunctionSignature::Ptr m_signature
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
Expression::Properties properties() const
Represents a cardinality, a possible , often represented by occurrence indicators.
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
Definition: qglobal.h:2313
virtual ItemType::Ptr itemType() const =0
static const KeyPair *const end
void wrapExpressionWith(const SourceLocationReflection *const existingNode, const QExplicitlySharedDataPointer< Expression > &newNode)
Ensures source locations are handled in such a manner that existingNode wraps newNode.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272