Qt 4.8
Public Functions | Protected Functions | Static Protected Functions | Protected Variables | Private Functions | List of all members
QPatternist::AbstractFunctionFactory Class Referenceabstract

Supplies convenience code for the function factories. More...

#include <qabstractfunctionfactory_p.h>

Inheritance diagram for QPatternist::AbstractFunctionFactory:
QPatternist::FunctionFactory QSharedData QPatternist::ConstructorFunctionsFactory QPatternist::XPath10CoreFunctions QPatternist::XPath20CoreFunctions QPatternist::XSLT20CoreFunctions

Public Functions

virtual Expression::Ptr createFunctionCall (const QXmlName name, const Expression::List &arguments, const StaticContext::Ptr &context, const SourceLocationReflection *const r)
 
virtual FunctionSignature::Hash functionSignatures () const
 
- Public Functions inherited from QPatternist::FunctionFactory
bool hasSignature (const FunctionSignature::Ptr &signature) const
 
virtual bool isAvailable (const NamePool::Ptr &np, const QXmlName name, const xsInteger arity)
 
virtual ~FunctionFactory ()
 
- 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...
 

Protected Functions

FunctionSignature::Ptr addFunction (const QXmlName::LocalNameCode localName, const FunctionSignature::Arity minArgs, const FunctionSignature::Arity maxArgs, const SequenceType::Ptr &returnType, const Expression::Properties props)
 
FunctionSignature::Ptr addFunction (const QXmlName::LocalNameCode &localName, const FunctionSignature::Arity minArgs, const FunctionSignature::Arity maxArgs, const SequenceType::Ptr &returnType, const Expression::ID id=Expression::IDIgnorableExpression, const Expression::Properties props=Expression::Properties(), const StandardNamespaces::ID ns=StandardNamespaces::fn)
 
virtual Expression::Ptr retrieveExpression (const QXmlName name, const Expression::List &args, const FunctionSignature::Ptr &sign) const =0
 
- Protected Functions inherited from QPatternist::FunctionFactory
 FunctionFactory ()
 This constructor cannot be removed, because it can't be synthesized, for some reason. More...
 
virtual FunctionSignature::Ptr retrieveFunctionSignature (const NamePool::Ptr &np, const QXmlName name)=0
 

Static Protected Functions

static QXmlName::LocalNameCode argument (const NamePool::Ptr &np, const char *const name)
 

Protected Variables

FunctionSignature::Hash m_signatures
 

Private Functions

void verifyArity (const FunctionSignature::Ptr &sign, const StaticContext::Ptr &context, const xsInteger arity, const SourceLocationReflection *const r) const
 Determines whether arity is a valid number of arguments for the function with signature sign. More...
 

Additional Inherited Members

- Public Types inherited from QPatternist::FunctionFactory
typedef QList< FunctionFactory::PtrList
 
typedef QExplicitlySharedDataPointer< FunctionFactoryPtr
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Supplies convenience code for the function factories.

See also
XPath10CoreFunctions
XPath20CoreFunctions
XSLT10CoreFunctions
Author
Vincent Ricard magic.nosp@m.@mag.nosp@m.icnin.nosp@m.ja.o.nosp@m.rg

Definition at line 75 of file qabstractfunctionfactory_p.h.

Functions

◆ addFunction() [1/2]

FunctionSignature::Ptr QPatternist::AbstractFunctionFactory::addFunction ( const QXmlName::LocalNameCode  localName,
const FunctionSignature::Arity  minArgs,
const FunctionSignature::Arity  maxArgs,
const SequenceType::Ptr returnType,
const Expression::Properties  props 
)
inlineprotected

Definition at line 99 of file qabstractfunctionfactory_p.h.

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

104  {
105  return addFunction(localName,
106  minArgs,
107  maxArgs,
108  returnType,
110  props);
111  }
FunctionSignature::Ptr addFunction(const QXmlName::LocalNameCode localName, const FunctionSignature::Arity minArgs, const FunctionSignature::Arity maxArgs, const SequenceType::Ptr &returnType, const Expression::Properties props)

◆ addFunction() [2/2]

FunctionSignature::Ptr QPatternist::AbstractFunctionFactory::addFunction ( const QXmlName::LocalNameCode localName,
const FunctionSignature::Arity  minArgs,
const FunctionSignature::Arity  maxArgs,
const SequenceType::Ptr returnType,
const Expression::ID  id = Expression::IDIgnorableExpression,
const Expression::Properties  props = Expression::Properties(),
const StandardNamespaces::ID  ns = StandardNamespaces::fn 
)
inlineprotected

Definition at line 113 of file qabstractfunctionfactory_p.h.

120  {
121  const QXmlName name(ns, localName);
122 
123  const FunctionSignature::Ptr s(new FunctionSignature(name, minArgs, maxArgs,
124  returnType, props, id));
125 
127  return s;
128  }
QExplicitlySharedDataPointer< FunctionSignature > Ptr
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
const char * name
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58

◆ argument()

static QXmlName::LocalNameCode QPatternist::AbstractFunctionFactory::argument ( const NamePool::Ptr np,
const char *const  name 
)
inlinestaticprotected

Definition at line 130 of file qabstractfunctionfactory_p.h.

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

131  {
132  return np->allocateLocalName(QLatin1String(name));
133  }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
const char * name

◆ createFunctionCall()

Expression::Ptr AbstractFunctionFactory::createFunctionCall ( const QXmlName  name,
const Expression::List arguments,
const StaticContext::Ptr context,
const SourceLocationReflection *const  r 
)
virtual

Creates a function call implementation.

A FunctionFactory represents a set of functions, which it is able to instantiate and to serve FunctionSignatures for. Conventionally, a FunctionFactory per namespace exists.

Note
This function should not issue any error unless it is absolutely confident that the error cannot be fixed in another way. For example, in some cases it might be that a function is available in another FunctionFactory and it would therefore be wrong to issue an error signalling that no function by that name exists, but leave that to the callee.
Parameters
namethe name of the function to create. In Clark syntax, this could for example be {http://www.w3.org/2005/04/xpath-functions}lower-case
argumentsthe function's operands
contextthe usual StaticContext which supplies compile time data and reporting functionality.
rthe SourceLocationReflection that identifies the callsite.
Returns
an instance of Expression which is the function implementation for name. Or, a static error was raised.

Implements QPatternist::FunctionFactory.

Definition at line 50 of file qabstractfunctionfactory.cpp.

54 {
56 
57  if(!sign) /* The function doesn't exist(at least not in this factory). */
58  return Expression::Ptr();
59 
60  /* May throw. */
61  verifyArity(sign, context, args.count(), r);
62 
63  /* Ok, the function does exist and the arity is correct. */
64  return retrieveExpression(name, args, sign);
65 }
virtual NamePool::Ptr namePool() const =0
virtual Expression::Ptr retrieveExpression(const QXmlName name, const Expression::List &args, const FunctionSignature::Ptr &sign) const =0
static int sign(int x)
void verifyArity(const FunctionSignature::Ptr &sign, const StaticContext::Ptr &context, const xsInteger arity, const SourceLocationReflection *const r) const
Determines whether arity is a valid number of arguments for the function with signature sign...
const char * name
virtual FunctionSignature::Ptr retrieveFunctionSignature(const NamePool::Ptr &np, const QXmlName name)=0
QExplicitlySharedDataPointer< Expression > Ptr
A smart pointer wrapping mutable Expression instances.

◆ functionSignatures()

FunctionSignature::Hash AbstractFunctionFactory::functionSignatures ( ) const
virtual

◆ retrieveExpression()

virtual Expression::Ptr QPatternist::AbstractFunctionFactory::retrieveExpression ( const QXmlName  name,
const Expression::List args,
const FunctionSignature::Ptr sign 
) const
protectedpure virtual

This function is responsible for creating the actual Expression, corresponding to localName and the function signature sign. It is called by createFunctionCall(), once it have been determined the function actually exists and have the correct arity.

This function will only be called for names in the fn namespace.

Implemented in QPatternist::XPath20CoreFunctions, QPatternist::ConstructorFunctionsFactory, QPatternist::XPath10CoreFunctions, and QPatternist::XSLT20CoreFunctions.

Referenced by createFunctionCall().

◆ verifyArity()

void AbstractFunctionFactory::verifyArity ( const FunctionSignature::Ptr sign,
const StaticContext::Ptr context,
const xsInteger  arity,
const SourceLocationReflection *const  r 
) const
private

Determines whether arity is a valid number of arguments for the function with signature sign.

If it is not, a static error with error code ReportContext::XPST0017 is issued via context.

Definition at line 67 of file qabstractfunctionfactory.cpp.

Referenced by createFunctionCall().

71 {
72  /* Same code in both branches, but more specific error messages in order
73  * to improve usability. */
74  if(s->maximumArguments() != FunctionSignature::UnlimitedArity &&
75  arity > s->maximumArguments())
76  {
77  context->error(QtXmlPatterns::tr("%1 takes at most %n argument(s). "
78  "%2 is therefore invalid.", 0, s->maximumArguments())
79  .arg(formatFunction(context->namePool(), s))
80  .arg(arity),
82  r);
83  return;
84  }
85 
86  if(arity < s->minimumArguments())
87  {
88  context->error(QtXmlPatterns::tr("%1 requires at least %n argument(s). "
89  "%2 is therefore invalid.", 0, s->minimumArguments())
90  .arg(formatFunction(context->namePool(), s))
91  .arg(arity),
93  r);
94  return;
95  }
96 }
virtual NamePool::Ptr namePool() const =0
void error(const QString &message, const ReportContext::ErrorCode errorCode, const QSourceLocation &sourceLocation)
static QString formatFunction(const NamePool::Ptr &np, const FunctionSignature::Ptr &func)
Formats FunctionSignature.

Properties

◆ m_signatures

FunctionSignature::Hash QPatternist::AbstractFunctionFactory::m_signatures
protected

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