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

Base class for implementations of builtin functions. More...

#include <qfunctioncall_p.h>

Inheritance diagram for QPatternist::FunctionCall:
QPatternist::UnlimitedContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection QPatternist::ExtractFromDateTimeFN< DayFromAbstractDateTimeFN > QPatternist::ExtractFromDateTimeFN< HoursFromAbstractDateTimeFN > QPatternist::ExtractFromDateTimeFN< MinutesFromAbstractDateTimeFN > QPatternist::ExtractFromDateTimeFN< MonthFromAbstractDateTimeFN > QPatternist::ExtractFromDateTimeFN< SecondsFromAbstractDateTimeFN > QPatternist::ExtractFromDateTimeFN< TimezoneFromAbstractDateTimeFN > QPatternist::ExtractFromDateTimeFN< YearFromAbstractDateTimeFN > QPatternist::ExtractFromDurationFN< DaysFromDurationFN > QPatternist::ExtractFromDurationFN< HoursFromDurationFN > QPatternist::ExtractFromDurationFN< MinutesFromDurationFN > QPatternist::ExtractFromDurationFN< MonthsFromDurationFN > QPatternist::ExtractFromDurationFN< SecondsFromDurationFN > QPatternist::ExtractFromDurationFN< YearsFromDurationFN > QPatternist::AddingAggregate QPatternist::AdjustTimezone QPatternist::Aggregator QPatternist::BaseURIFN QPatternist::BooleanFN QPatternist::CodepointsToStringFN QPatternist::CollectionFN QPatternist::ComparesCaseAware QPatternist::ConcatFN QPatternist::ContextNodeChecker QPatternist::CountFN QPatternist::CurrentDateFN QPatternist::CurrentDateTimeFN QPatternist::CurrentFN QPatternist::CurrentTimeFN QPatternist::DateTimeFN QPatternist::DeepEqualFN QPatternist::DefaultCollationFN QPatternist::DistinctValuesFN QPatternist::DocumentFN QPatternist::DocumentURIFN QPatternist::EncodeString QPatternist::ErrorFN QPatternist::Existence< Id > QPatternist::ExtractFromDateTimeFN< TSubClass > QPatternist::ExtractFromDurationFN< TSubClass > QPatternist::FalseFN QPatternist::GenerateIDFN QPatternist::ImplicitTimezoneFN QPatternist::IndexOfFN QPatternist::InScopePrefixesFN QPatternist::InsertBeforeFN QPatternist::LangFN QPatternist::LastFN QPatternist::LocalNameFN QPatternist::LocalNameFromQNameFN QPatternist::LowerCaseFN QPatternist::NameFN QPatternist::NamespaceURIFN QPatternist::NamespaceURIForPrefixFN QPatternist::NamespaceURIFromQNameFN QPatternist::NilledFN QPatternist::NodeNameFN QPatternist::NormalizeSpaceFN QPatternist::NormalizeUnicodeFN QPatternist::NotFN QPatternist::NumberFN QPatternist::PatternPlatform QPatternist::PositionFN QPatternist::PrefixFromQNameFN QPatternist::QNameFN QPatternist::RemoveFN QPatternist::ResolveQNameFN QPatternist::ResolveURIFN QPatternist::ReverseFN QPatternist::RootFN QPatternist::StaticBaseUriContainer QPatternist::StaticBaseURIFN QPatternist::StaticNamespacesContainer QPatternist::StringFN QPatternist::StringJoinFN QPatternist::StringLengthFN QPatternist::StringToCodepointsFN QPatternist::SubsequenceFN QPatternist::SubstringAfterFN QPatternist::SubstringBeforeFN QPatternist::SubstringFN QPatternist::TraceFN QPatternist::TranslateFN QPatternist::TrueFN QPatternist::UpperCaseFN

Public Types

typedef QExplicitlySharedDataPointer< FunctionCallPtr
 
- Public Types inherited from QPatternist::UnlimitedContainer
enum  CardinalityComputation { ProductOfCardinality, UnionOfCardinality }
 
- Public Types inherited from QPatternist::Expression
typedef QExplicitlySharedDataPointer< const ExpressionConstPtr
 A smart pointer wrapping const Expression instances. More...
 
enum  ID {
  IDBooleanValue = 1, IDCountFN, IDEmptyFN, IDExistsFN,
  IDExpressionSequence, IDGeneralComparison, IDIfThenClause, IDIgnorableExpression,
  IDIntegerValue, IDPositionFN, IDStringValue, IDValueComparison,
  IDRangeVariableReference, IDContextItem, IDUserFunctionCallsite, IDExpressionVariableReference,
  IDAttributeConstructor, IDUpperCaseFN, IDLowerCaseFN, IDFirstItemPredicate,
  IDEmptySequence, IDReturnOrderBy, IDLetClause, IDForClause,
  IDPath, IDNamespaceConstructor, IDArgumentReference, IDGenericPredicate,
  IDAxisStep, IDFloat, IDCombineNodes, IDUnresolvedVariableReference,
  IDCardinalityVerifier
}
 
typedef QList< Expression::PtrList
 
typedef QFlags< PropertyProperties
 
enum  Property {
  UseContextItem = 1, DisableElimination = 1 << 1, IsEvaluated = 1 << 2, DisableTypingDeduction = 1 << 3,
  EmptynessFollowsChild = 1 << 4, RewriteToEmptyOnEmpty = 1 << 5, RequiresFocus = 1 << 6, AffectsOrderOnly = 1 << 7,
  RequiresContextItem = (1 << 8) | RequiresFocus, CreatesFocusForLast = 1 << 9, LastOperandIsCollation = 1 << 10, DependsOnLocalVariable = (1 << 11) | DisableElimination,
  EvaluationCacheRedundant = (1 << 12), IsNodeConstructor = 1 << 13, RequiresCurrentItem = 1 << 14
}
 
typedef QExplicitlySharedDataPointer< ExpressionPtr
 A smart pointer wrapping mutable Expression instances. More...
 
typedef ::QAbstractXmlForwardIterator< Expression::PtrQAbstractXmlForwardIterator
 
typedef QVector< Expression::PtrVector
 

Public Functions

virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
virtual SequenceType::List expectedOperandTypes () const
 
virtual ID id () const
 
virtual Expression::Properties properties () const
 
virtual void setSignature (const FunctionSignature::Ptr &sign)
 
virtual FunctionSignature::Ptr signature () const
 
virtual SequenceType::Ptr staticType () const
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
- Public Functions inherited from QPatternist::UnlimitedContainer
virtual bool compressOperands (const StaticContext::Ptr &)
 
virtual Expression::List operands () const
 
virtual void setOperands (const Expression::List &list)
 
 UnlimitedContainer (const Expression::List &operands=Expression::List())
 
- Public Functions inherited from QPatternist::Expression
virtual const SourceLocationReflectionactualReflection () const
 Returns this. More...
 
virtual void announceFocusType (const ItemType::Ptr &itemType)
 
virtual Expression::Ptr compress (const StaticContext::Ptr &context)
 
Properties deepProperties () const
 Computes the union of properties for this Expression and all its descending children. More...
 
virtual Properties dependencies () const
 
virtual QString description () const
 
virtual bool evaluateEBV (const DynamicContext::Ptr &context) const
 
virtual Item::Iterator::Ptr evaluateSequence (const DynamicContext::Ptr &context) const
 
virtual Item evaluateSingleton (const DynamicContext::Ptr &context) const
 
virtual void evaluateToSequenceReceiver (const DynamicContext::Ptr &context) const
 
virtual ItemType::Ptr expectedContextItemType () const
 
 Expression ()
 
bool has (const Property prop) const
 
bool hasDependency (const Property prop) const
 
bool is (const ID id) const
 
bool isEvaluated () const
 
virtual ItemType::Ptr newFocusType () const
 
virtual QList< QExplicitlySharedDataPointer< OptimizationPass > > optimizationPasses () const
 
virtual PatternPriority patternPriority () const
 
const Expression::Ptrrewrite (const Expression::Ptr &to, const StaticContext::Ptr &context) const
 Rewrites this Expression to to, and return to. More...
 
virtual ~Expression ()
 
- 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...
 
- Public Functions inherited from QPatternist::CppCastingHelper< Expression >
const TCastTarget * as () const
 
TCastTarget * as ()
 
- Public Functions inherited from QPatternist::SourceLocationReflection
virtual QSourceLocation sourceLocation () const
 
 SourceLocationReflection ()
 
virtual ~SourceLocationReflection ()
 

Properties

FunctionSignature::Ptr m_signature
 

Additional Inherited Members

- Static Public Functions inherited from QPatternist::Expression
static void rewrite (Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 
- Protected Functions inherited from QPatternist::UnlimitedContainer
template<CardinalityComputation suppliedCard>
SequenceType::Ptr operandsUnionType () const
 
- Protected Functions inherited from QPatternist::Expression
void typeCheckOperands (const StaticContext::Ptr &context)
 
- Protected Functions inherited from QPatternist::CppCastingHelper< Expression >
 CppCastingHelper ()
 
- Protected Variables inherited from QPatternist::UnlimitedContainer
Expression::List m_operands
 

Detailed Description

Base class for implementations of builtin functions.

However, it doesn't handle user declared functions.

Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 73 of file qfunctioncall_p.h.

Typedefs

◆ Ptr

Definition at line 76 of file qfunctioncall_p.h.

Functions

◆ accept()

ExpressionVisitorResult::Ptr FunctionCall::accept ( const ExpressionVisitor::Ptr visitor) const
virtual

Implements QPatternist::Expression.

Definition at line 149 of file qfunctioncall.cpp.

150 {
151  return visitor->visit(this);
152 }

◆ expectedOperandTypes()

SequenceType::List FunctionCall::expectedOperandTypes ( ) const
virtual

Returns a list of Sequence Types, describing the type of each of the expression's operands. Hence, this function has a relationship to the operands() function:

- The lengths of the lists returned by expectedOperandTypes()
and operands() should always be equal in length, since one
cannot describe the type of a non-existent operand(and all
operands must have type information).
- A significant difference between the two functions is that while
the type of objects in the list returned by operands() may vary
between compilations/static context, simply because the particular
Expression is part of different XPath expressions, the
types in the list returned by expectedOperandTypes is always the same
since the function/operator signature never changes.

This function should not be confused with staticType(), which returns the static type of the expression itself, not its operands. The function call is an expression where this is clear: the type of the return value is not the same as the arguments' types. The static type of the operands supplied to the expression can be determined via the staticType() function of the instances returned by operands().

If the expression has no operands, an empty list should be returned.

Implements QPatternist::Expression.

Definition at line 57 of file qfunctioncall.cpp.

58 {
59  const FunctionArgument::List args(signature()->arguments());
60  FunctionArgument::List::const_iterator it(args.constBegin());
61  const FunctionArgument::List::const_iterator end(args.constEnd());
62  // TODO reserve/resize()
63  SequenceType::List result;
64 
65  for(; it != end; ++it)
66  result.append((*it)->type());
67 
68  return result;
69 }
#define it(className, varName)
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
virtual FunctionSignature::Ptr signature() const
static const KeyPair *const end

◆ id()

Expression::ID FunctionCall::id ( ) const
virtual

This property, which has no setter, returns an enum value that uniquely identifies this Expression. Patternist makes no use of C++'s dynamic_cast feature, but uses this polymorphic function instead.

Returns
always IgnorableExpression.

Reimplemented from QPatternist::Expression.

Definition at line 154 of file qfunctioncall.cpp.

155 {
157  return m_signature->id();
158 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
FunctionSignature::Ptr m_signature

◆ properties()

Expression::Properties FunctionCall::properties ( ) const
virtual
Returns
a bitwise OR'd value of properties, describing the characteristics of the expression. These properties affects how this Expression is treated in for example type checking stages.

The default implementation returns 0. Override and let the function return a different value, if that's of interest.

An important decision when re-implementing properties() is whether to OR in the properties() of ones operands. For instance, if an operand has RequiresFocus set, that flag nost likely applies to the apparent as well, since it depends on its operand.

See also
deepProperties()
Returns
Expression::None, meaning no special properties

Reimplemented from QPatternist::Expression.

Definition at line 143 of file qfunctioncall.cpp.

Referenced by typeCheck().

144 {
146  return signature()->properties();
147 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual FunctionSignature::Ptr signature() const
FunctionSignature::Ptr m_signature
Expression::Properties properties() const

◆ setSignature()

void FunctionCall::setSignature ( const FunctionSignature::Ptr sign)
virtual

Definition at line 109 of file qfunctioncall.cpp.

110 {
111  m_signature = sign;
112 }
static int sign(int x)
FunctionSignature::Ptr m_signature

◆ signature()

FunctionSignature::Ptr FunctionCall::signature ( ) const
virtual

◆ staticType()

SequenceType::Ptr FunctionCall::staticType ( ) const
virtual
Returns
the static type of this Expression. For example, an 'and' expression have as static type xs:boolean

Implements QPatternist::Expression.

Reimplemented in QPatternist::SubsequenceFN, QPatternist::ReverseFN, QPatternist::RemoveFN, QPatternist::InsertBeforeFN, QPatternist::DistinctValuesFN, QPatternist::RootFN, QPatternist::SumFN, QPatternist::DocFN, QPatternist::AvgFN, QPatternist::Aggregator, QPatternist::TraceFN, and QPatternist::CurrentFN.

Definition at line 120 of file qfunctioncall.cpp.

Referenced by QPatternist::DistinctValuesFN::DistinctValuesFN().

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 }
#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 Cardinality oneOrMore()
virtual FunctionSignature::Ptr signature() const
virtual Cardinality cardinality() const =0
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
virtual SequenceType::Ptr staticType() const =0
FunctionSignature::Ptr m_signature
Represents a cardinality, a possible , often represented by occurrence indicators.

◆ typeCheck()

Expression::Ptr FunctionCall::typeCheck ( const StaticContext::Ptr context,
const SequenceType::Ptr reqType 
)
virtual

This implementation guarantees to never rewrite away this Expression, but at most rewrite it as a child of another expression(that presumably have a type checking role). It is therefore always safe to override this function and call this implementation and not worry about that this Expression becomes deleted.

Many Expressions override typeCheck() and performs optimizations, as opposed to doing it in the compress() stage. This is due to that the design of those Expressions often are tied to that certain simplifications are done at the typeCheck() stage of the compilation process or that it in some other way is related to what the typeCheck() do. Also, the earlier the AST can be simplified, the better the chances are for subsequent optimizations.

It is important that the super class's typeCheck() is called before doing any custom type checking, since the call can change the children(notably, the childrens' static types). For example, if the Expression, MyExpression in the example, does not match the required type, typeCheck returns the Expression wrapped in for example ItemVerifier, CardinalityVerifier, or both.

typeCheck() may be called many times. typeCheck() must either raise an error if this Expression is an invalid expression. Thus, it is guaranteed that an Expression is valid after typeCheck() is called.

Parameters
contextsupplies information, such as namespace bindings and available function signatures, that can be needed at compilation time. context is guaranteed by the caller to never null.
reqTypethe static type that this Expression must match when evaluated. reqType is guaranteed by the caller to never null.
Returns
an Expression that can be this Expression, or another expression, which somehow is necessary for making this Expression conforming to reqType

Reimplemented from QPatternist::Expression.

Reimplemented in QPatternist::SubsequenceFN, QPatternist::ReverseFN, QPatternist::DistinctValuesFN, QPatternist::StaticBaseURIFN, QPatternist::DefaultCollationFN, QPatternist::SumFN, QPatternist::DocFN, QPatternist::NumberFN, QPatternist::AvgFN, QPatternist::DocumentFN, QPatternist::IndexOfFN, QPatternist::AddingAggregate, QPatternist::StringFN, QPatternist::ComparingAggregator< oper, result >, QPatternist::BooleanFN, QPatternist::CountFN, QPatternist::StaticBaseUriContainer, QPatternist::IdFN, QPatternist::StaticNamespacesContainer, QPatternist::DeepEqualFN, QPatternist::FunctionAvailableFN, QPatternist::TypeAvailableFN, QPatternist::CurrentFN, and QPatternist::ResolveURIFN.

Definition at line 71 of file qfunctioncall.cpp.

Referenced by QPatternist::ResolveURIFN::typeCheck(), QPatternist::CurrentFN::typeCheck(), QPatternist::DeepEqualFN::typeCheck(), QPatternist::StaticNamespacesContainer::typeCheck(), QPatternist::StaticBaseUriContainer::typeCheck(), QPatternist::CountFN::typeCheck(), QPatternist::StringFN::typeCheck(), QPatternist::AddingAggregate::typeCheck(), QPatternist::IndexOfFN::typeCheck(), QPatternist::AvgFN::typeCheck(), QPatternist::NumberFN::typeCheck(), QPatternist::DocFN::typeCheck(), QPatternist::StaticBaseURIFN::typeCheck(), QPatternist::DistinctValuesFN::typeCheck(), QPatternist::ReverseFN::typeCheck(), and QPatternist::SubsequenceFN::typeCheck().

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 }
virtual Expression::Properties properties() const
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Definition: qexpression.cpp:70
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static Expression::Ptr create(const Expression *const replacementFor, const StaticContext::Ptr &context)
Creates an EmptySequence that is a replacement for replacementFor.
bool has(const Property prop) const
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
Checks that its operand evaluates to a supported string collation.
Implements the context item, the dot: ..
virtual FunctionSignature::Ptr signature() 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 SequenceType::Ptr staticType() const =0
static const EmptySequenceType::Ptr Empty
QFlags< Property > Properties
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
virtual ItemType::Ptr itemType() const =0
void wrapExpressionWith(const SourceLocationReflection *const existingNode, const QExplicitlySharedDataPointer< Expression > &newNode)
Ensures source locations are handled in such a manner that existingNode wraps newNode.

Properties

◆ m_signature

FunctionSignature::Ptr QPatternist::FunctionCall::m_signature
private

Definition at line 94 of file qfunctioncall_p.h.

Referenced by id(), properties(), setSignature(), signature(), and staticType().


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