Qt 4.8
Public Types | Public Functions | Properties | List of all members
QPatternist::FunctionSignature Class Reference

Represents the signature of an XPath function. More...

#include <qfunctionsignature_p.h>

Inheritance diagram for QPatternist::FunctionSignature:
QPatternist::CallTargetDescription QSharedData

Public Types

enum  { UnlimitedArity = -1 }
 
typedef qint16 Arity
 
typedef QHash< QXmlName, FunctionSignature::PtrHash
 
typedef QList< FunctionSignature::PtrList
 
typedef QExplicitlySharedDataPointer< FunctionSignaturePtr
 
- Public Types inherited from QPatternist::CallTargetDescription
typedef QList< PtrList
 
typedef QExplicitlySharedDataPointer< CallTargetDescriptionPtr
 

Public Functions

void appendArgument (const QXmlName::LocalNameCode name, const SequenceType::Ptr &type)
 
FunctionArgument::List arguments () const
 
QString displayName (const NamePool::Ptr &np) const
 
 FunctionSignature (const QXmlName name, const Arity minArgs, const Arity maxArgs, const SequenceType::Ptr &returnType, const Expression::Properties chars=Expression::Properties(), const Expression::ID id=Expression::IDIgnorableExpression)
 
Expression::ID id () const
 
bool isArityValid (const xsInteger arity) const
 
Arity maximumArguments () const
 
Arity minimumArguments () const
 
bool operator== (const FunctionSignature &other) const
 
Expression::Properties properties () const
 
SequenceType::Ptr returnType () const
 
void setArguments (const FunctionArgument::List &args)
 
- Public Functions inherited from QPatternist::CallTargetDescription
 CallTargetDescription (const QXmlName &name)
 
QXmlName name () const
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 

Properties

FunctionArgument::List m_arguments
 
const Expression::ID m_id
 
const Arity m_maxArgs
 
const Arity m_minArgs
 
const Expression::Properties m_props
 
const SequenceType::Ptr m_returnType
 

Additional Inherited Members

- Static Public Functions inherited from QPatternist::CallTargetDescription
static void checkCallsiteCircularity (CallTargetDescription::List &signList, const Expression::Ptr expr)
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Represents the signature of an XPath function.

FunctionSignature represents and allows inspection of a function signature, such as fn:string-join($arg1 as xs:string*, $arg2 as xs:string) as xs:string. No XPath related languages allows polymorphism on the type of the arguments, only the amount(arity) of the arguments. For example, fn:string() as xs:string and fn:string($arg as item()?) as xs:string can happily co-exist, but fn:string($arg as item()?) as xs:string and fn:string($arg as xs:anyAtomicType?) as xs:string would be an error. This fact is reflected by FunctionSignature that if minimumArguments() and maximumArguments() are not equal, it means that this FunctionSignature represents several function signatures.

See also
XQuery 1.0 and XPath 2.0 Functions and Operators, 1.4 Function Signatures and Descriptions
Wikipedia, the free encyclopedia, Arity
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 93 of file qfunctionsignature_p.h.

Typedefs

◆ Arity

A number which tells the amount of arguments a function has.

Definition at line 111 of file qfunctionsignature_p.h.

◆ Hash

Definition at line 105 of file qfunctionsignature_p.h.

◆ List

Definition at line 106 of file qfunctionsignature_p.h.

◆ Ptr

Definition at line 104 of file qfunctionsignature_p.h.

Enumerations

◆ anonymous enum

anonymous enum
Enumerator
UnlimitedArity 

Flags the function as allowing an unlimited amount of arguments.

Definition at line 96 of file qfunctionsignature_p.h.

Constructors and Destructors

◆ FunctionSignature()

FunctionSignature::FunctionSignature ( const QXmlName  name,
const Arity  minArgs,
const Arity  maxArgs,
const SequenceType::Ptr returnType,
const Expression::Properties  chars = Expression::Properties(),
const Expression::ID  id = Expression::IDIgnorableExpression 
)

Definition at line 50 of file qfunctionsignature.cpp.

55  : 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 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const SequenceType::Ptr m_returnType
const Expression::Properties m_props
FunctionArgument::List m_arguments

Functions

◆ appendArgument()

void FunctionSignature::appendArgument ( const QXmlName::LocalNameCode  name,
const SequenceType::Ptr type 
)

This is a convenience function. Calling this once, is equal to calling setArguments() with a list containing a FunctionsArgument with name name and type type.

Definition at line 68 of file qfunctionsignature.cpp.

Referenced by QPatternist::XPath10CoreFunctions::retrieveFunctionSignature(), QPatternist::XSLT20CoreFunctions::retrieveFunctionSignature(), and QPatternist::XPath20CoreFunctions::retrieveFunctionSignature().

70 {
71  Q_ASSERT(type);
72 
74 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
Carries meta data for a function argument as found in XPath&#39;s builtin functions and user declared fun...
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
FunctionArgument::List m_arguments

◆ arguments()

FunctionArgument::List FunctionSignature::arguments ( ) const

◆ displayName()

QString FunctionSignature::displayName ( const NamePool::Ptr np) const

Builds a string representation for this function signature. The syntax used is the one used in the XQuery. It looks like this:

prefix:function-name($parameter-name as parameter-type, ...) as return-type

The prefix used for the name is conventional. For example, for constructor functions is xs used.

See also
XQuery 1.0 and XPath 2.0 Functions and Operators, 1.4 Function Signatures and Descriptions

Definition at line 76 of file qfunctionsignature.cpp.

77 {
78  QString result;
79  result += np->displayName(name());
80  result += QLatin1Char('(');
81 
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 
103  result += QLatin1String(", ...");
104 
105  result += QLatin1String(") as ");
106  result += m_returnType->displayName(np);
107 
108  return result;
109 }
QString displayName(const QXmlName qName) const
Definition: qnamepool.cpp:347
#define it(className, varName)
virtual QString displayName(const NamePool::Ptr &np) const =0
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
friend class const_iterator
Definition: qlist.h:264
const SequenceType::Ptr m_returnType
static const KeyPair *const end
FunctionArgument::List m_arguments
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
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

◆ id()

Expression::ID FunctionSignature::id ( ) const

The ID that the corresponding FunctionCall instance should return in Expression::id().

Definition at line 153 of file qfunctionsignature.cpp.

Referenced by QPatternist::FunctionCall::id().

154 {
155  return m_id;
156 }

◆ isArityValid()

bool FunctionSignature::isArityValid ( const xsInteger  arity) const

Checks whether arity is within the range of allowed count of arguments. For example, when the minimum arguments is 1 and maximum arguments 2, false will be returned for passing 0 while true will be returned when 2 is passed.

Definition at line 128 of file qfunctionsignature.cpp.

Referenced by QPatternist::FunctionFactory::isAvailable(), QPatternist::UserFunctionCallsite::isSignatureValid(), and operator==().

129 {
130  return arity >= m_minArgs && arity <= m_maxArgs;
131 }

◆ maximumArguments()

FunctionSignature::Arity FunctionSignature::maximumArguments ( ) const

◆ minimumArguments()

FunctionSignature::Arity FunctionSignature::minimumArguments ( ) const

◆ operator==()

bool FunctionSignature::operator== ( const FunctionSignature other) const

Determines whether this FunctionSignature is equal to other, taking into account XPath's function polymorphism. other is equal to this FunctionSignature if their name() instances are equal, and that the maximumArguments() and minimumArguments() arguments of other are allowed, as per isArityValid().

In other words, this equalness operator can return true for different signatures, but it do make sense since a FunctionSignature can represent multiple signatures.

Returns
true if this FunctionSignature is equal to other, otherwise false

Definition at line 111 of file qfunctionsignature.cpp.

112 {
113  return name() == other.name() &&
114  isArityValid(other.maximumArguments()) &&
116 }
bool isArityValid(const xsInteger arity) const

◆ properties()

Expression::Properties FunctionSignature::properties ( ) const

The properties that the corresponding FunctionCall instance should return in Expression::properties().

Definition at line 148 of file qfunctionsignature.cpp.

Referenced by QPatternist::FunctionCall::properties(), and QPatternist::ErrorFN::signature().

149 {
150  return m_props;
151 }
const Expression::Properties m_props

◆ returnType()

SequenceType::Ptr FunctionSignature::returnType ( ) const

The return type of this function signature. For example, if the represented function signature is fn:string() as xs:string, the return type is xs:string.

Definition at line 143 of file qfunctionsignature.cpp.

Referenced by QPatternist::ErrorFN::signature(), and QPatternist::FunctionCall::staticType().

144 {
145  return m_returnType;
146 }
const SequenceType::Ptr m_returnType

◆ setArguments()

void FunctionSignature::setArguments ( const FunctionArgument::List args)

Definition at line 118 of file qfunctionsignature.cpp.

119 {
120  m_arguments = args;
121 }
FunctionArgument::List m_arguments

Properties

◆ m_arguments

FunctionArgument::List QPatternist::FunctionSignature::m_arguments
private

Definition at line 193 of file qfunctionsignature_p.h.

Referenced by appendArgument(), arguments(), displayName(), and setArguments().

◆ m_id

const Expression::ID QPatternist::FunctionSignature::m_id
private

Definition at line 195 of file qfunctionsignature_p.h.

Referenced by id().

◆ m_maxArgs

const Arity QPatternist::FunctionSignature::m_maxArgs
private

◆ m_minArgs

const Arity QPatternist::FunctionSignature::m_minArgs
private

Definition at line 190 of file qfunctionsignature_p.h.

Referenced by isArityValid(), and minimumArguments().

◆ m_props

const Expression::Properties QPatternist::FunctionSignature::m_props
private

Definition at line 194 of file qfunctionsignature_p.h.

Referenced by properties().

◆ m_returnType

const SequenceType::Ptr QPatternist::FunctionSignature::m_returnType
private

Definition at line 192 of file qfunctionsignature_p.h.

Referenced by displayName(), and returnType().


The documentation for this class was generated from the following files: