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

Base class for all AST nodes in an XPath/XQuery/XSL-T expression. More...

#include <qexpression_p.h>

Inheritance diagram for QPatternist::Expression:
QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection QPatternist::EmptyContainer QPatternist::PairContainer QPatternist::SingleContainer QPatternist::TripleContainer QPatternist::UnlimitedContainer QPatternist::AxisStep QPatternist::ContextItem QPatternist::EmptySequence QPatternist::ExternalVariableReference QPatternist::Literal QPatternist::LiteralSequence QPatternist::NamespaceConstructor QPatternist::ParentNodeAxis QPatternist::TemplateParameterReference QPatternist::UnresolvedVariableReference QPatternist::VariableReference QPatternist::AndExpression QPatternist::ArithmeticExpression QPatternist::AttributeConstructor QPatternist::CombineNodes QPatternist::ComputedNamespaceConstructor QPatternist::ElementConstructor QPatternist::ForClause QPatternist::GeneralComparison QPatternist::GenericPredicate QPatternist::LetClause QPatternist::NodeComparison QPatternist::Path QPatternist::ProcessingInstructionConstructor QPatternist::QuantifiedExpression QPatternist::RangeExpression QPatternist::ValueComparison QPatternist::Atomizer QPatternist::AttributeNameValidator QPatternist::CardinalityVerifier QPatternist::CastableAs QPatternist::CastAs QPatternist::CollationChecker QPatternist::CommentConstructor QPatternist::CopyOf QPatternist::CurrentItemStore QPatternist::DocumentConstructor QPatternist::DynamicContextStore QPatternist::EBVExtractor QPatternist::EvaluationCache< IsForGlobal > QPatternist::FirstItemPredicate QPatternist::InstanceOf QPatternist::ItemVerifier QPatternist::NCNameConstructor QPatternist::NodeSortExpression QPatternist::OrderBy QPatternist::QNameConstructor QPatternist::SimpleContentConstructor QPatternist::StaticBaseURIStore QPatternist::StaticCompatibilityStore QPatternist::TextNodeConstructor QPatternist::TreatAs QPatternist::UntypedAtomicConverter QPatternist::IfThenClause QPatternist::CallSite QPatternist::ExpressionSequence QPatternist::FunctionCall QPatternist::ReturnOrderBy

Public Types

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 =0
 
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
 
virtual SequenceType::List expectedOperandTypes () const =0
 
 Expression ()
 
bool has (const Property prop) const
 
bool hasDependency (const Property prop) const
 
virtual ID id () const
 
bool is (const ID id) const
 
bool isEvaluated () const
 
virtual ItemType::Ptr newFocusType () const
 
virtual Expression::List operands () const =0
 
virtual QList< QExplicitlySharedDataPointer< OptimizationPass > > optimizationPasses () const
 
virtual PatternPriority patternPriority () const
 
virtual Properties properties () const
 
const Expression::Ptrrewrite (const Expression::Ptr &to, const StaticContext::Ptr &context) const
 Rewrites this Expression to to, and return to. More...
 
virtual void setOperands (const Expression::List &operands)=0
 
virtual SequenceType::Ptr staticType () const =0
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
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 ()
 

Static Public Functions

static void rewrite (Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
 

Protected Functions

virtual bool compressOperands (const StaticContext::Ptr &)=0
 
void typeCheckOperands (const StaticContext::Ptr &context)
 
- Protected Functions inherited from QPatternist::CppCastingHelper< Expression >
 CppCastingHelper ()
 

Private Functions

Expression::Ptr constantPropagate (const StaticContext::Ptr &context) const
 Performs constant propagation, also called constant folding, on this expression. More...
 
StaticContext::Ptr finalizeStaticContext (const StaticContext::Ptr &context) const
 

Static Private Functions

static Expression::Ptr invokeOptimizers (const Expression::Ptr &expr, const StaticContext::Ptr &context)
 

Additional Inherited Members

- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Base class for all AST nodes in an XPath/XQuery/XSL-T expression.

Expression Compilation

The process of creating an Expression

The initial step of creating an internal representation(in some circles called an IR tree) of the XPath string follows classic compiler design: a scanner is invoked, resulting in tokens, which sub-sequently are consumed by a parser which groups the tokens into rules, resulting in the creation of Abstract Syntax Tree(AST) nodes that are arranged in a hierarchical structure similar to the EBNF.

More specifically, ExpressionFactory::createExpression() is called with a pointer to a static context, and the string for the expression. This is subsequently tokenized by a Flex scanner. Mistakes detected at this stage is syntax errors, as well as a few semantical errors. Syntax errors can be divided in two types:

- The scanner detects it. An example is the expression "23Eb3" which
is not a valid number literal, or "1prefix:my-element" which is not a
valid QName.
- The parser detects it. This means a syntax error at a
higher level, that a group of tokens couldn't be reduced to a
rule(expression). An example is the expression "if(a = b) 'match' else
'no match'"; the tokenizer would handle it fine, but the parser would
fail because the tokens could not be reduced to a rule due to the token
for the "then" word was missing.

Apart from the syntax errors, the actions in the parser also detects errors when creating the corresponding expressions. This is for example that no namespace binding for a prefix could be found, or that a function call was used which no function implementation could be found for.

When the parser has finished, the result is an AST. That is, a hierarchical structure consisting of Expression sub-classes. The individual expressions haven't at this point done anything beyond receiving their child-expressions(if any), and hence reminds of a "construction scaffold". In other words, a tree for the expression 'string' + 1 and xs:date('2001-03-13') could have been created, even if that expression contains errors(one can't add a xs:integer to a xs:string, and the Effective Boolean Value cannot be extracted for date types).

Type Checking

After the AST creation, ExpressionFactory::createExpression continues with calling the AST node(which is an Expression instance)'s typeCheck() function. This step ensures that the static types of the operands matches the operators, and in the cases where it doesn't, modifies the AST such that the necessary conversions are done – if possible, otherwise the result is a type error.

This step corresponds roughly to what 2.2.3.1 Static Analysis Phase labels operation tree normalization; step SQ5.

Compressing -- Optimization and Fixup

The last step is calling compress(). This function is not called 'optimize', 'simplify' or the like, because although it performs all optimization, it also involves mandatory stages.

One such is const folding, which while being an efficient optimization, also is a necessity for many XSL-T constructs. Another important step is that functions which had an evaluation dependency on the static context(as opposed to the dynamic) performs their "fixup".

In other words, this stage potentially performs AST re-writes. For example, the expression 3 + 3, concat('foo', '-', 'bar'), true() and false() would result in an AST corresponding to 6, 'foo-bar', false(). This process is done backwards; each expression asks its operands to compress before it performs its own compression(and so forth, until the root expression's call returns to the caller).

See also
XML Path Language (XPath) 2.0, 2.3.4 Errors and Optimization
XML Path Language (XPath) 2.0, 2.2.3 Expression Processing
Building a Tokenizer for XPath or XQuery
ExpressionFactory
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 165 of file qexpression_p.h.

Typedefs

◆ ConstPtr

A smart pointer wrapping const Expression instances.

Definition at line 178 of file qexpression_p.h.

◆ List

A list of Expression instances, each wrapped in a smart pointer.

Definition at line 183 of file qexpression_p.h.

◆ Properties

A QFlags template for type-safe handling of ExpressionProperty values. If Expression::Property flags needs to be stored in a class, declared the variable to be of type Expression::Properties.

See also
QFlags

Definition at line 358 of file qexpression_p.h.

◆ Ptr

A smart pointer wrapping mutable Expression instances.

Definition at line 173 of file qexpression_p.h.

◆ QAbstractXmlForwardIterator

Definition at line 191 of file qexpression_p.h.

◆ Vector

A vector of Expression instances, each wrapped in a smart pointer.

Definition at line 188 of file qexpression_p.h.

Enumerations

◆ ID

Enumerators that identifies Expression sub-classes.

See also
id()
Enumerator
IDBooleanValue 

Identifies Boolean.

IDCountFN 

Identifies CountFN.

IDEmptyFN 

Identifies EmptyFN.

IDExistsFN 

Identifies ExistsFN.

IDExpressionSequence 

Identifies ExpressionSequence and LiteralSequence.

IDGeneralComparison 

Identifies GeneralComparison.

IDIfThenClause 

Identifies IfThenClause.

IDIgnorableExpression 

Identifies nothing in particular. The default implementation of id() returns this, which is suitable for Expression instances which never needs to be identified in this aspect.

IDIntegerValue 

Identifies Integer.

IDPositionFN 

Identifies PositionFN.

IDStringValue 

Identifies AtomicString, AnyURI, and UntypedAtomic.

IDValueComparison 

Identifies ValueComparison.

IDRangeVariableReference 

Identifies VariableReference.

IDContextItem 

Identifies ContextItem.

IDUserFunctionCallsite 

Identifies UserFunctionCallsite.

IDExpressionVariableReference 

Identifies ExpressionVariableReference.

IDAttributeConstructor 

Identifies ExpressionVariableReference.

IDUpperCaseFN 

Identifies UpperCaseFN.

IDLowerCaseFN 

Identifies LowerCaseFN.

IDFirstItemPredicate 

Identifies FirstItemPredicate.

IDEmptySequence 
IDReturnOrderBy 
IDLetClause 
IDForClause 
IDPath 
IDNamespaceConstructor 
IDArgumentReference 
IDGenericPredicate 
IDAxisStep 
IDFloat 

A literal which is either xs:float or xs:double.

IDCombineNodes 
IDUnresolvedVariableReference 
IDCardinalityVerifier 

Definition at line 365 of file qexpression_p.h.

366  {
370  IDBooleanValue = 1,
371 
375  IDCountFN,
376 
380  IDEmptyFN,
381 
385  IDExistsFN,
386 
391 
396 
401 
408 
413 
417  IDPositionFN,
418 
423 
428 
433 
438 
443 
448 
453 
458 
463 
470  IDLetClause,
471  IDForClause,
472  IDPath,
476  IDAxisStep,
477 
482  IDFloat,
483 
487  };

◆ Property

Enum flags describing the characteristics of the expression.

See also
Expression::properties()
Enumerator
UseContextItem 

This flag applies for functions, and results in the expression . being appended to its operands if its operand count is lower than the maximum amount of arguments.

In effect, it result in a modification of the function's arguments to have appended the context item.

One function which has this property is fn:number().

See also
ContextItem
XQuery 1.0 and XPath 2.0 Functions and Operators, 1.3 Function Signatures and Descriptions
DisableElimination 

Disables compression(evaluation at compile time), such that the Expression isn't const-folded, but ensured to be run at runtime. The operands are still attempted to be compressed, unless they override compression as well.

See also
compress()
IsEvaluated 

Signals that the expression is already evaluated and can be considered a constant value. For example, atomic values return this flag in their implementations of the properties() functions.

See also
isEvaluated()
DisableTypingDeduction 

Signals that the expression cannot be optimized away by judging its static type.

This is currently used for properly handling the none type, in the fn:error() function. In type operations, the none type doesn't show up and that can make expressions, such as InstanceOf, believe it is safe to const fold, while it in fact is not.

EmptynessFollowsChild 

This property affects the static type – staticType() – of an expression. It is implemented in FunctionCall::staticType() and therefore only work for FunctionCall sub-classes and when that function is not re-implemented in an inhibiting way.

When set, the cardinality of the static type is zero if the Expression's first operand allows an empty sequence, otherwise it is the cardinality of the Expression's static type modulo Cardinality::empty(). This is used for specifying proper static type inference for functions that have "If $arg is the empty sequence, the empty sequence is returned." However, before setting this property one must be aware that no other conditions can lead to the empty sequence, since otherwise the static type would be wrong.

RewriteToEmptyOnEmpty 

This is similar to EmptynessFollowsChild, and also implemented in FunctionCall. When set, it makes FunctionCall::typeCheck() rewrite itself into an empty sequence if the first operand is the empty sequence.

This property is often used together with EmptynessFollowsChild.

RequiresFocus 

When set, it signals that the focus cannot be undefined. For example, the fn:position() function extracts information from the focus. Setting this flag ensures type checking is carried out appropriately.

However, setting RequiresFocus does not imply this Expression requires the context item to be defined. It only means the focus, of somekind, needs to be defined.

See also
RequiresContextItem
AffectsOrderOnly 

An Expression with this Property set, signals that it only affects the order of its return value.

RequiresContextItem 

When set, signals that the context item, must be defined for this Expression. When setting this property, expectedContextItemType() must be re-implemented.

Setting this property also sets RequiresFocus.

See also
DynamicContext::contextItem()
CreatesFocusForLast 

When set, signals that this expression creates a focus for its last operand. When set, newFocusType() must be overridden to return the static type of the context item.

See also
announceFocusType()
newFocusType()
LastOperandIsCollation 

Signals that the last operand is a collation argument. This ensures that the necessary code is generated for checking that the collation is supported.

This only applies to sub-classes of FunctionCall.

DependsOnLocalVariable 

When set, the Expression depends on local variables such as those found in for expressions. However, this does not include let bindings.

EvaluationCacheRedundant 

When set, it signals that the Expression does not need an evaluation cache, despite what other flags might imply.

IsNodeConstructor 

Signals that the Expression constructs nodes, either directly or computationally. For example, AttributeConstructor has this property set.

Since node constructors constructs nodes which have node identities, node constructors are considered creative on evaluation.

RequiresCurrentItem 

Whether this expression requires the current item, as returned from fn:current().

CurrentFN uses this flag.

Definition at line 198 of file qexpression_p.h.

199  {
214  UseContextItem = 1,
215 
224  DisableElimination = 1 << 1,
225 
234  IsEvaluated = 1 << 2,
235 
245  DisableTypingDeduction = 1 << 3,
246 
260  EmptynessFollowsChild = 1 << 4,
261 
269  RewriteToEmptyOnEmpty = 1 << 5,
270 
281  RequiresFocus = 1 << 6,
282 
287  AffectsOrderOnly = 1 << 7,
288 
297  RequiresContextItem = (1 << 8) | RequiresFocus,
298 
307  CreatesFocusForLast = 1 << 9,
308 
316  LastOperandIsCollation = 1 << 10,
317 
324 
329  EvaluationCacheRedundant = (1 << 12),
330 
340  IsNodeConstructor = 1 << 13,
341 
348  RequiresCurrentItem = 1 << 14
349  };

Constructors and Destructors

◆ Expression()

QPatternist::Expression::Expression ( )
inline

Definition at line 489 of file qexpression_p.h.

490  {
491  }

◆ ~Expression()

Expression::~Expression ( )
virtual

Definition at line 58 of file qexpression.cpp.

59 {
60 }

Functions

◆ accept()

virtual ExpressionVisitorResult::Ptr QPatternist::Expression::accept ( const ExpressionVisitor::Ptr visitor) const
pure virtual

Implemented in QPatternist::OrderBy, QPatternist::EmptySequence, QPatternist::CastAs, QPatternist::Path, QPatternist::ExpressionSequence, QPatternist::EvaluationCache< IsForGlobal >, QPatternist::ArithmeticExpression, QPatternist::GenericPredicate, QPatternist::TreatAs, QPatternist::UserFunctionCallsite, QPatternist::NodeComparison, QPatternist::CombineNodes, QPatternist::RangeExpression, QPatternist::TruthPredicate, QPatternist::ValueComparison, QPatternist::AxisStep, QPatternist::ApplyTemplate, QPatternist::CopyOf, QPatternist::QuantifiedExpression, QPatternist::Atomizer, QPatternist::FirstItemPredicate, QPatternist::CastableAs, QPatternist::GeneralComparison, QPatternist::LetClause, QPatternist::UntypedAtomicConverter, QPatternist::ComputedNamespaceConstructor, QPatternist::ContextItem, QPatternist::ElementConstructor, QPatternist::AttributeNameValidator, QPatternist::CollationChecker, QPatternist::CurrentItemStore, QPatternist::ExternalVariableReference, QPatternist::ForClause, QPatternist::NamespaceConstructor, QPatternist::NCNameConstructor, QPatternist::PositionalVariableReference, QPatternist::AndExpression, QPatternist::ExpressionVariableReference, QPatternist::AttributeConstructor, QPatternist::Literal, QPatternist::LiteralSequence, QPatternist::ProcessingInstructionConstructor, QPatternist::RangeVariableReference, QPatternist::ReturnOrderBy, QPatternist::FunctionCall, QPatternist::QNameConstructor, QPatternist::SimpleContentConstructor, QPatternist::CommentConstructor, QPatternist::DocumentConstructor, QPatternist::IfThenClause, QPatternist::TextNodeConstructor, QPatternist::ArgumentConverter, QPatternist::ItemVerifier, QPatternist::DynamicContextStore, QPatternist::ParentNodeAxis, QPatternist::StaticBaseURIStore, QPatternist::CardinalityVerifier, QPatternist::CallTemplate, QPatternist::InstanceOf, QPatternist::StaticCompatibilityStore, QPatternist::EBVExtractor, QPatternist::ArgumentReference, QPatternist::UnresolvedVariableReference, QPatternist::OrExpression, QPatternist::TemplateParameterReference, and QPatternist::NodeSortExpression.

◆ actualReflection()

const SourceLocationReflection * Expression::actualReflection ( ) const
virtual

◆ announceFocusType()

void Expression::announceFocusType ( const ItemType::Ptr itemType)
virtual

When this function is called, it signals that the parent will create a focus of type itemType.

This type can also be retrieved through StaticContext::contextItemType() when inside typeCheck(), but in some cases this is too late. For instance, a parent needs to have the static type of its child properly reported before it calls its typeCheck()(and the child's type is inferred from the focus).

The default implementation delegates the call on to the children.

This function may be called at arbitrary times, in arbitrary amounts.

If the AST node overriding this call has children, it should be considered whether the default implementation should be called, such that they type is announced to them too.

The caller guarantees that itemType is not null.

Reimplemented in QPatternist::ContextItem.

Definition at line 361 of file qexpression.cpp.

Referenced by announceFocusType(), and QPatternist::Path::typeCheck().

362 {
363  const Expression::List ops(operands());
364  const int len = ops.count();
365 
366  for(int i = 0; i < len; ++i)
367  ops.at(i)->announceFocusType(itemType);
368 }
virtual Expression::List operands() const =0

◆ compress()

Expression::Ptr Expression::compress ( const StaticContext::Ptr context)
virtual

compress() is the last stage performs in compiling an expression, done after the initial AST build and calling typeCheck(). compress() performs crucial simplifications, either by having drastic performance implications or that some expressions depend on it for proper behavior.

The default implementation performs a sparse conditional constant propagation. In short, a recursive process is performed in the AST which examines if the Expression's operands are constant values, and if so, performs a const fold(AST rewrite) into the result of evaluating the expression in question. This default behavior can be disabled by letting properties() return DisableElimination.

This compress() stage can be relative effective due to the design of XPath, in part because intrinsic functions are heavily used. Many Expressions override compress() and do optimizations specific to what they do. Also, many Expressions performs optimizations in their typeCheck().

Parameters
contextthe static context. Supplies compile time information, and is the channel for communicating error messages.
See also
Wikipedia, the free encyclopedia, Sparse conditional constant propagation
Wikipedia, the free encyclopedia, Intrinsic function
Wikipedia, the free encyclopedia, Compiler optimization

Reimplemented in QPatternist::SubsequenceFN, QPatternist::NormalizeUnicodeFN, QPatternist::OrderBy, QPatternist::Existence< Id >, QPatternist::Path, QPatternist::CastAs, QPatternist::ApplyTemplate, QPatternist::GeneralComparison, QPatternist::PatternPlatform, QPatternist::ValueComparison, QPatternist::EvaluationCache< IsForGlobal >, QPatternist::CopyOf, QPatternist::ExpressionSequence, QPatternist::ForClause, QPatternist::StringJoinFN, QPatternist::FirstItemPredicate, QPatternist::CountFN, QPatternist::ReplaceFN, QPatternist::UserFunctionCallsite, QPatternist::ContextItem, QPatternist::CardinalityVerifier, QPatternist::NodeComparison, QPatternist::CastableAs, QPatternist::ReturnOrderBy, QPatternist::AndExpression, QPatternist::IfThenClause, QPatternist::InstanceOf, QPatternist::SimpleContentConstructor, QPatternist::TemplateInvoker, QPatternist::CurrentItemStore, QPatternist::OrExpression, QPatternist::NodeSortExpression, QPatternist::ComparesCaseAware, and QPatternist::CurrentFN.

Definition at line 241 of file qexpression.cpp.

Referenced by QPatternist::CurrentFN::compress(), QPatternist::NodeSortExpression::compress(), QPatternist::ComparesCaseAware::compress(), QPatternist::OrExpression::compress(), QPatternist::CurrentItemStore::compress(), QPatternist::TemplateInvoker::compress(), QPatternist::SimpleContentConstructor::compress(), QPatternist::InstanceOf::compress(), QPatternist::IfThenClause::compress(), QPatternist::AndExpression::compress(), QPatternist::CastableAs::compress(), QPatternist::ReturnOrderBy::compress(), QPatternist::NodeComparison::compress(), QPatternist::CardinalityVerifier::compress(), QPatternist::ContextItem::compress(), QPatternist::UserFunctionCallsite::compress(), QPatternist::CountFN::compress(), QPatternist::FirstItemPredicate::compress(), QPatternist::StringJoinFN::compress(), QPatternist::ForClause::compress(), QPatternist::ExpressionSequence::compress(), QPatternist::CopyOf::compress(), QPatternist::EvaluationCache< IsForGlobal >::compress(), QPatternist::ValueComparison::compress(), QPatternist::PatternPlatform::compress(), QPatternist::GeneralComparison::compress(), QPatternist::CastAs::compress(), QPatternist::Path::compress(), QPatternist::Existence< Id >::compress(), QPatternist::OrderBy::compress(), QPatternist::NormalizeUnicodeFN::compress(), QPatternist::SubsequenceFN::compress(), QPatternist::TripleContainer::compressOperands(), QPatternist::PairContainer::compressOperands(), QPatternist::SingleContainer::compressOperands(), and invokeOptimizers().

242 {
243  if(!compressOperands(context))
244  {
245  /* At least one of the operands cannot be evaluated at compile, so
246  * 'this' Expression cannot const fold. */
247  return invokeOptimizers(Expression::Ptr(this), context);
248  }
249 
250  Expression::Ptr retval;
251 
253  retval = Expression::Ptr(this);
254  else
255  retval = constantPropagate(context);
256 
257  return invokeOptimizers(retval, context);
258 }
static Expression::Ptr invokeOptimizers(const Expression::Ptr &expr, const StaticContext::Ptr &context)
bool hasDependency(const Property prop) const
QExplicitlySharedDataPointer< Expression > Ptr
A smart pointer wrapping mutable Expression instances.
virtual bool compressOperands(const StaticContext::Ptr &)=0
Expression::Ptr constantPropagate(const StaticContext::Ptr &context) const
Performs constant propagation, also called constant folding, on this expression.

◆ compressOperands()

virtual bool QPatternist::Expression::compressOperands ( const StaticContext::Ptr )
protectedpure virtual
Returns
true if all operands are constant values of somekind, and are already evaluated. A string literal, is a typical example.

Implemented in QPatternist::EmptyContainer, QPatternist::UnlimitedContainer, QPatternist::PairContainer, QPatternist::SingleContainer, and QPatternist::TripleContainer.

Referenced by compress().

◆ constantPropagate()

Expression::Ptr Expression::constantPropagate ( const StaticContext::Ptr context) const
private

Performs constant propagation, also called constant folding, on this expression.

This means that it attempts to evaluate this expression at compile and returns the result value appropriately as an Expression. For example, for the XPath expression 1 + 3 would an Integer of value 4 would be returned.

It is not checked whether constant propagation is possible, the caller is responsible for this.

See also
Constant folding, From Wikipedia, the free encyclopedia

Definition at line 260 of file qexpression.cpp.

Referenced by compress().

261 {
262  Q_ASSERT(context);
263 
264  /* Optimization: We rewrite literals to literals here, which is pointless.
265  * Maybe we should have a property which says "doesn't disable elimination
266  * but don't eliminate me." */
267  if(staticType()->cardinality().allowsMany())
268  {
270  Item::List result;
271  Item item(it->next());
272 
273  while(item)
274  {
275  result.append(item);
276  item = it->next();
277  }
278 
279  switch(result.count())
280  {
281  case 0:
282  return EmptySequence::create(this, context);
283  case 1:
284  return rewrite(Expression::Ptr(new Literal(result.first())), context);
285  default:
286  return rewrite(Expression::Ptr(new LiteralSequence(result)), context);
287  }
288  }
289  else
290  {
291  const Item item(evaluateSingleton(context->dynamicContext()));
292 
293  if(item)
294  return rewrite(Expression::Ptr(new Literal(item)), context);
295  else
296  return EmptySequence::create(this, context);
297  }
298 }
#define it(className, varName)
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
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
static void rewrite(Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
Houses an AtomicValue, making it available as an Expression.
Definition: qliteral_p.h:74
virtual SequenceType::Ptr staticType() const =0
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
QList< Item > List
Definition: qitem_p.h:195
virtual QExplicitlySharedDataPointer< DynamicContext > dynamicContext() const =0
Houses a sequence of atomic values, making it available as an Expression.
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const

◆ deepProperties()

Expression::Properties Expression::deepProperties ( ) const

Computes the union of properties for this Expression and all its descending children.

See also
properties()

Definition at line 370 of file qexpression.cpp.

Referenced by QPatternist::CurrentItemStore::compress(), deepProperties(), and QPatternist::LetClause::typeCheck().

371 {
372  Properties props(properties());
373  const Expression::List ops(operands());
374  const int len = ops.count();
375 
376  for(int i = 0; i < len; ++i)
377  props |= ops.at(i)->deepProperties();
378 
379  return props;
380 }
virtual Expression::List operands() const =0
QFlags< Property > Properties
virtual Properties properties() const

◆ dependencies()

Expression::Properties Expression::dependencies ( ) const
virtual

Recursively computes through all descendants until a Property is encount

Reimplemented in QPatternist::CallTemplate.

Definition at line 345 of file qexpression.cpp.

Referenced by QPatternist::Template::dependencies().

346 {
347  OperandsIterator it(Ptr(const_cast<Expression *>(this)), OperandsIterator::ExcludeParent);
348  Expression::Ptr next(it.next());
349 
351 
352  while(next)
353  {
354  dependencies |= next->dependencies();
355  next = it.next();
356  }
357 
359 }
#define it(className, varName)
QExplicitlySharedDataPointer< Expression > Ptr
A smart pointer wrapping mutable Expression instances.
QFlags< Property > Properties
virtual Properties properties() const
virtual Properties dependencies() const
A helper class that iterates a tree of Expression instances. It is not a sub-class of QAbstractXmlFor...

◆ description()

QString Expression::description ( ) const
virtual

Reimplementation of SourceLocationReflection::description().

Reimplemented from QPatternist::SourceLocationReflection.

Reimplemented in QPatternist::GenericPredicate, and QPatternist::Literal.

Definition at line 404 of file qexpression.cpp.

405 {
406  return QString::fromLatin1("Expression, id: %1").arg(QString::number(id()));
407 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ evaluateEBV()

bool Expression::evaluateEBV ( const DynamicContext::Ptr context) const
virtual

Determines the Effective Boolean Value of the expression.

The Effective Boolean Value of a value is not necessarily the same as converting the value to a new value of type xs:boolean.

Note that this function cannot return the empty sequence, evaluateSingleton() must be overridden in order to be able to do that.

The default implementation results in a type error. Hence, this function must be overridden if such behavior is not of interest.

See also
XML Path Language (XPath) 2.0, 2.4.3 Effective Boolean Value

Reimplemented in QPatternist::DocAvailableFN, QPatternist::Existence< Id >, QPatternist::EmptySequence, QPatternist::NotFN, QPatternist::FalseFN, QPatternist::CombineNodes, QPatternist::GeneralComparison, QPatternist::LetClause, QPatternist::UserFunctionCallsite, QPatternist::BooleanFN, QPatternist::Literal, QPatternist::QuantifiedExpression, QPatternist::ReturnOrderBy, QPatternist::PositionalVariableReference, QPatternist::TrueFN, QPatternist::ExpressionVariableReference, QPatternist::ExternalVariableReference, QPatternist::AndExpression, QPatternist::CallTemplate, QPatternist::CastableAs, QPatternist::NodeComparison, QPatternist::RangeVariableReference, QPatternist::InstanceOf, QPatternist::DeepEqualFN, QPatternist::EBVExtractor, QPatternist::ArgumentReference, QPatternist::IfThenClause, QPatternist::OrExpression, QPatternist::CurrentItemStore, QPatternist::DynamicContextStore, QPatternist::TemplateParameterReference, QPatternist::ElementAvailableFN, and QPatternist::UnparsedTextAvailableFN.

Definition at line 315 of file qexpression.cpp.

Referenced by QPatternist::OrExpression::compress(), QPatternist::AndExpression::compress(), QPatternist::IfThenClause::compress(), QPatternist::CurrentItemStore::evaluateEBV(), QPatternist::DynamicContextStore::evaluateEBV(), QPatternist::OrExpression::evaluateEBV(), QPatternist::ArgumentReference::evaluateEBV(), QPatternist::IfThenClause::evaluateEBV(), QPatternist::EBVExtractor::evaluateEBV(), QPatternist::CallTemplate::evaluateEBV(), QPatternist::AndExpression::evaluateEBV(), QPatternist::ExpressionVariableReference::evaluateEBV(), QPatternist::ReturnOrderBy::evaluateEBV(), QPatternist::QuantifiedExpression::evaluateEBV(), QPatternist::UserFunctionCallsite::evaluateEBV(), QPatternist::BooleanFN::evaluateEBV(), QPatternist::LetClause::evaluateEBV(), QPatternist::CombineNodes::evaluateEBV(), QPatternist::NotFN::evaluateEBV(), QPatternist::IfThenClause::evaluateSequence(), QPatternist::IfThenClause::evaluateSingleton(), evaluateSingleton(), QPatternist::IfThenClause::evaluateToSequenceReceiver(), and QPatternist::BooleanIdentifier::matches().

316 {
317  return Boolean::evaluateEBV(evaluateSequence(context), context);
318 }
static bool evaluateEBV(const Item::Iterator::Ptr &e, const QExplicitlySharedDataPointer< DynamicContext > &)
Definition: qboolean.cpp:55
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const

◆ evaluateSequence()

Item::Iterator::Ptr Expression::evaluateSequence ( const DynamicContext::Ptr context) const
virtual

Evaluate this Expression by iterating over it. This is a central function for evaluating expressions.

Expressions must always always return a valid QAbstractXmlForwardIterator and may never return 0. If an empty result is of interest to be returned, the EmptyIterator should be returned.

The default implementation returns a SingletonIterator over the item returned from evaluateSingleton().

Note
This function may raise an exception when calling, not only when QAbstractXmlForwardIterator::next() is called on the return value. This is because in some cases evaluateSingleton() is called directly.

Reimplemented in QPatternist::SubsequenceFN, QPatternist::ReverseFN, QPatternist::RemoveFN, QPatternist::InsertBeforeFN, QPatternist::DistinctValuesFN, QPatternist::CollectionFN, QPatternist::InScopePrefixesFN, QPatternist::OrderBy, QPatternist::TokenizeFN, QPatternist::IndexOfFN, QPatternist::IdrefFN, QPatternist::EvaluationCache< IsForGlobal >, QPatternist::Path, QPatternist::EmptySequence, QPatternist::GenericPredicate, QPatternist::ApplyTemplate, QPatternist::StringToCodepointsFN, QPatternist::UntypedAtomicConverter, QPatternist::UserFunctionCallsite, QPatternist::CombineNodes, QPatternist::LiteralSequence, QPatternist::IdFN, QPatternist::ArgumentConverter, QPatternist::LetClause, QPatternist::ExpressionSequence, QPatternist::ExpressionVariableReference, QPatternist::ForClause, QPatternist::Atomizer, QPatternist::ArgumentReference, QPatternist::ExternalVariableReference, QPatternist::RangeExpression, QPatternist::ItemVerifier, QPatternist::CallTemplate, QPatternist::IfThenClause, QPatternist::CardinalityVerifier, QPatternist::AxisStep, QPatternist::CurrentItemStore, QPatternist::DynamicContextStore, QPatternist::TemplateParameterReference, QPatternist::NodeSortExpression, and QPatternist::TraceFN.

Definition at line 300 of file qexpression.cpp.

Referenced by constantPropagate(), QPatternist::DistinctValuesFN::DistinctValuesFN(), QPatternist::DeepEqualFN::evaluateEBV(), QPatternist::InstanceOf::evaluateEBV(), QPatternist::CastableAs::evaluateEBV(), QPatternist::QuantifiedExpression::evaluateEBV(), QPatternist::GeneralComparison::evaluateEBV(), evaluateEBV(), QPatternist::NodeSortExpression::evaluateSequence(), QPatternist::DynamicContextStore::evaluateSequence(), QPatternist::CurrentItemStore::evaluateSequence(), QPatternist::CallTemplate::evaluateSequence(), QPatternist::IfThenClause::evaluateSequence(), QPatternist::CardinalityVerifier::evaluateSequence(), QPatternist::ArgumentReference::evaluateSequence(), QPatternist::ItemVerifier::evaluateSequence(), QPatternist::Atomizer::evaluateSequence(), QPatternist::ForClause::evaluateSequence(), QPatternist::VariableLoader::evaluateSequence(), QPatternist::ExpressionVariableReference::evaluateSequence(), QPatternist::LetClause::evaluateSequence(), QPatternist::ArgumentConverter::evaluateSequence(), QPatternist::CombineNodes::evaluateSequence(), QPatternist::UserFunctionCallsite::evaluateSequence(), QPatternist::UntypedAtomicConverter::evaluateSequence(), QPatternist::ApplyTemplate::evaluateSequence(), QPatternist::GenericPredicate::evaluateSequence(), QPatternist::Path::evaluateSequence(), QPatternist::IndexOfFN::evaluateSequence(), QPatternist::OrderBy::evaluateSequence(), QPatternist::DistinctValuesFN::evaluateSequence(), QPatternist::InsertBeforeFN::evaluateSequence(), QPatternist::RemoveFN::evaluateSequence(), QPatternist::ReverseFN::evaluateSequence(), QPatternist::SubsequenceFN::evaluateSequence(), QPatternist::XSLTSimpleContentConstructor::evaluateSingleton(), QPatternist::CardinalityVerifier::evaluateSingleton(), QPatternist::SimpleContentConstructor::evaluateSingleton(), QPatternist::CodepointsToStringFN::evaluateSingleton(), QPatternist::FirstItemPredicate::evaluateSingleton(), QPatternist::ReturnOrderBy::evaluateSingleton(), QPatternist::CountFN::evaluateSingleton(), QPatternist::StringJoinFN::evaluateSingleton(), QPatternist::Path::evaluateSingleton(), QPatternist::GenericPredicate::evaluateSingleton(), QPatternist::AvgFN::evaluateSingleton(), QPatternist::SumFN::evaluateSingleton(), QPatternist::InsertBeforeFN::evaluateSingleton(), QPatternist::ForClause::evaluateToSequenceReceiver(), QPatternist::CopyOf::evaluateToSequenceReceiver(), QPatternist::Path::evaluateToSequenceReceiver(), evaluateToSequenceReceiver(), QPatternist::IndexOfFN::IndexOfFN(), QPatternist::GenericPredicate::mapToItem(), QPatternist::ForClause::mapToSequence(), QPatternist::Path::mapToSequence(), and QPatternist::ExpressionSequence::mapToSequence().

301 {
302  const Item item(evaluateSingleton(context));
303 
304  if(item)
305  return makeSingletonIterator(item);
306  else
308 }
static const EmptyIterator< Item >::Ptr emptyIterator
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

◆ evaluateSingleton()

Item Expression::evaluateSingleton ( const DynamicContext::Ptr context) const
virtual

Reimplemented in QPatternist::SubsequenceFN, QPatternist::RemoveFN, QPatternist::InsertBeforeFN, QPatternist::EncodeString, QPatternist::TranslateFN, QPatternist::ExtractFromDateTimeFN< TSubClass >, QPatternist::ExtractFromDateTimeFN< DayFromAbstractDateTimeFN >, QPatternist::ExtractFromDateTimeFN< SecondsFromAbstractDateTimeFN >, QPatternist::ExtractFromDateTimeFN< HoursFromAbstractDateTimeFN >, QPatternist::ExtractFromDateTimeFN< YearFromAbstractDateTimeFN >, QPatternist::ExtractFromDateTimeFN< MonthFromAbstractDateTimeFN >, QPatternist::ExtractFromDateTimeFN< MinutesFromAbstractDateTimeFN >, QPatternist::ExtractFromDateTimeFN< TimezoneFromAbstractDateTimeFN >, QPatternist::LowerCaseFN, QPatternist::UpperCaseFN, QPatternist::RootFN, QPatternist::NormalizeUnicodeFN, QPatternist::CurrentTimeFN, QPatternist::LangFN, QPatternist::SumFN, QPatternist::NamespaceURIForPrefixFN, QPatternist::CurrentDateFN, QPatternist::NormalizeSpaceFN, QPatternist::RoundHalfToEvenFN, QPatternist::DocumentURIFN, QPatternist::NamespaceURIFromQNameFN, QPatternist::SubstringAfterFN, QPatternist::StringLengthFN, QPatternist::AvgFN, QPatternist::CurrentDateTimeFN, QPatternist::NumberFN, QPatternist::DocFN, QPatternist::BaseURIFN, QPatternist::CeilingFN, QPatternist::LocalNameFromQNameFN, QPatternist::SubstringBeforeFN, QPatternist::SubstringFN, QPatternist::ImplicitTimezoneFN, QPatternist::NamespaceURIFN, QPatternist::RoundFN, QPatternist::PrefixFromQNameFN, QPatternist::GenericPredicate, QPatternist::StringFN, QPatternist::EmptySequence, QPatternist::EndsWithFN, QPatternist::EvaluationCache< IsForGlobal >, QPatternist::Path, QPatternist::UnaryExpression, QPatternist::ExtractFromDurationFN< TSubClass >, QPatternist::ExtractFromDurationFN< MinutesFromDurationFN >, QPatternist::ExtractFromDurationFN< MonthsFromDurationFN >, QPatternist::ExtractFromDurationFN< YearsFromDurationFN >, QPatternist::ExtractFromDurationFN< HoursFromDurationFN >, QPatternist::ExtractFromDurationFN< DaysFromDurationFN >, QPatternist::ExtractFromDurationFN< SecondsFromDurationFN >, QPatternist::CastAs, QPatternist::LastFN, QPatternist::StringJoinFN, QPatternist::ComparingAggregator< oper, result >, QPatternist::ReplaceFN, QPatternist::CompareFN, QPatternist::LocalNameFN, QPatternist::AbsFN, QPatternist::ResolveQNameFN, QPatternist::NilledFN, QPatternist::StartsWithFN, QPatternist::UserFunctionCallsite, QPatternist::AdjustTimezone, QPatternist::UntypedAtomicConverter, QPatternist::CombineNodes, QPatternist::LetClause, QPatternist::RangeExpression, QPatternist::CountFN, QPatternist::ArithmeticExpression, QPatternist::ValueComparison, QPatternist::ArgumentConverter, QPatternist::ContextItem, QPatternist::ForClause, QPatternist::Literal, QPatternist::ReturnOrderBy, QPatternist::ConcatFN, QPatternist::ExpressionVariableReference, QPatternist::FirstItemPredicate, QPatternist::CodepointsToStringFN, QPatternist::PositionFN, QPatternist::NCNameConstructor, QPatternist::QNameConstructor, QPatternist::CodepointEqualFN, QPatternist::ErrorFN, QPatternist::NameFN, QPatternist::FloorFN, QPatternist::MatchesFN, QPatternist::QNameFN, QPatternist::ElementConstructor, QPatternist::ExternalVariableReference, QPatternist::RangeVariableReference, QPatternist::SimpleContentConstructor, QPatternist::NodeNameFN, QPatternist::Atomizer, QPatternist::AttributeNameValidator, QPatternist::IfThenClause, QPatternist::ContainsFN, QPatternist::CardinalityVerifier, QPatternist::ArgumentReference, QPatternist::CollationChecker, QPatternist::DocumentConstructor, QPatternist::NodeComparison, QPatternist::ItemVerifier, QPatternist::AttributeConstructor, QPatternist::AxisStep, QPatternist::CurrentItemStore, QPatternist::DynamicContextStore, QPatternist::ParentNodeAxis, QPatternist::ProcessingInstructionConstructor, QPatternist::CommentConstructor, QPatternist::TextNodeConstructor, QPatternist::PositionalVariableReference, QPatternist::TemplateParameterReference, QPatternist::XSLTSimpleContentConstructor, QPatternist::FunctionAvailableFN, QPatternist::GenerateIDFN, QPatternist::TypeAvailableFN, QPatternist::UnparsedTextFN, QPatternist::CurrentFN, QPatternist::DateTimeFN, QPatternist::SystemPropertyFN, QPatternist::UnparsedEntityPublicIDFN, QPatternist::UnparsedEntityURIFN, QPatternist::ResolveURIFN, and QPatternist::TraceFN.

Definition at line 310 of file qexpression.cpp.

Referenced by QPatternist::PatternPlatform::compress(), constantPropagate(), QPatternist::ProcessingInstructionConstructor::data(), QPatternist::NormalizeUnicodeFN::determineNormalizationForm(), QPatternist::NodeComparison::evaluate(), QPatternist::CommentConstructor::evaluateContent(), QPatternist::ElementAvailableFN::evaluateEBV(), QPatternist::UnparsedTextAvailableFN::evaluateEBV(), QPatternist::CastableAs::evaluateEBV(), QPatternist::RangeExpression::evaluateSequence(), QPatternist::StringToCodepointsFN::evaluateSequence(), QPatternist::IndexOfFN::evaluateSequence(), QPatternist::TokenizeFN::evaluateSequence(), QPatternist::InScopePrefixesFN::evaluateSequence(), QPatternist::InsertBeforeFN::evaluateSequence(), QPatternist::RemoveFN::evaluateSequence(), QPatternist::SubsequenceFN::evaluateSequence(), evaluateSequence(), QPatternist::ResolveURIFN::evaluateSingleton(), QPatternist::DateTimeFN::evaluateSingleton(), QPatternist::SystemPropertyFN::evaluateSingleton(), QPatternist::FunctionAvailableFN::evaluateSingleton(), QPatternist::TypeAvailableFN::evaluateSingleton(), QPatternist::GenerateIDFN::evaluateSingleton(), QPatternist::UnparsedTextFN::evaluateSingleton(), QPatternist::TextNodeConstructor::evaluateSingleton(), QPatternist::CurrentItemStore::evaluateSingleton(), QPatternist::AttributeConstructor::evaluateSingleton(), QPatternist::DynamicContextStore::evaluateSingleton(), QPatternist::CollationChecker::evaluateSingleton(), QPatternist::ArgumentReference::evaluateSingleton(), QPatternist::ItemVerifier::evaluateSingleton(), QPatternist::IfThenClause::evaluateSingleton(), QPatternist::ContainsFN::evaluateSingleton(), QPatternist::CardinalityVerifier::evaluateSingleton(), QPatternist::AttributeNameValidator::evaluateSingleton(), QPatternist::Atomizer::evaluateSingleton(), QPatternist::NodeNameFN::evaluateSingleton(), QPatternist::ElementConstructor::evaluateSingleton(), QPatternist::QNameFN::evaluateSingleton(), QPatternist::ErrorFN::evaluateSingleton(), QPatternist::CodepointEqualFN::evaluateSingleton(), QPatternist::NCNameConstructor::evaluateSingleton(), QPatternist::NameFN::evaluateSingleton(), QPatternist::QNameConstructor::evaluateSingleton(), QPatternist::FloorFN::evaluateSingleton(), QPatternist::MatchesFN::evaluateSingleton(), QPatternist::ExpressionVariableReference::evaluateSingleton(), QPatternist::ReturnOrderBy::evaluateSingleton(), QPatternist::ValueComparison::evaluateSingleton(), QPatternist::ArithmeticExpression::evaluateSingleton(), QPatternist::ArgumentConverter::evaluateSingleton(), QPatternist::LetClause::evaluateSingleton(), QPatternist::RangeExpression::evaluateSingleton(), QPatternist::UntypedAtomicConverter::evaluateSingleton(), QPatternist::UserFunctionCallsite::evaluateSingleton(), QPatternist::AdjustTimezone::evaluateSingleton(), QPatternist::StartsWithFN::evaluateSingleton(), QPatternist::NilledFN::evaluateSingleton(), QPatternist::ResolveQNameFN::evaluateSingleton(), QPatternist::CompareFN::evaluateSingleton(), QPatternist::LocalNameFN::evaluateSingleton(), QPatternist::AbsFN::evaluateSingleton(), QPatternist::ReplaceFN::evaluateSingleton(), QPatternist::StringJoinFN::evaluateSingleton(), QPatternist::CastAs::evaluateSingleton(), QPatternist::UnaryExpression::evaluateSingleton(), QPatternist::Path::evaluateSingleton(), QPatternist::EndsWithFN::evaluateSingleton(), QPatternist::StringFN::evaluateSingleton(), QPatternist::PrefixFromQNameFN::evaluateSingleton(), QPatternist::RoundFN::evaluateSingleton(), QPatternist::NamespaceURIFN::evaluateSingleton(), QPatternist::SubstringFN::evaluateSingleton(), QPatternist::SubstringBeforeFN::evaluateSingleton(), QPatternist::BaseURIFN::evaluateSingleton(), QPatternist::LocalNameFromQNameFN::evaluateSingleton(), QPatternist::CeilingFN::evaluateSingleton(), QPatternist::NumberFN::evaluateSingleton(), QPatternist::StringLengthFN::evaluateSingleton(), QPatternist::SubstringAfterFN::evaluateSingleton(), QPatternist::NamespaceURIFromQNameFN::evaluateSingleton(), QPatternist::DocumentURIFN::evaluateSingleton(), QPatternist::RoundHalfToEvenFN::evaluateSingleton(), QPatternist::NormalizeSpaceFN::evaluateSingleton(), QPatternist::NamespaceURIForPrefixFN::evaluateSingleton(), QPatternist::SumFN::evaluateSingleton(), QPatternist::LangFN::evaluateSingleton(), QPatternist::NormalizeUnicodeFN::evaluateSingleton(), QPatternist::RootFN::evaluateSingleton(), QPatternist::UpperCaseFN::evaluateSingleton(), QPatternist::LowerCaseFN::evaluateSingleton(), QPatternist::TranslateFN::evaluateSingleton(), QPatternist::EncodeString::evaluateSingleton(), QPatternist::RemoveFN::evaluateSingleton(), QPatternist::ProcessingInstructionConstructor::evaluateTardata(), QPatternist::ComputedNamespaceConstructor::evaluateToSequenceReceiver(), QPatternist::TextNodeConstructor::evaluateToSequenceReceiver(), QPatternist::AttributeConstructor::evaluateToSequenceReceiver(), QPatternist::ElementConstructor::evaluateToSequenceReceiver(), QPatternist::ArithmeticExpression::flexiblyCalculate(), QPatternist::GeneralComparison::generalCompare(), QPatternist::ForClause::mapToItem(), QPatternist::ReplaceFN::parseReplacement(), and QPatternist::PatternPlatform::pattern().

311 {
312  return Boolean::fromValue(evaluateEBV(context));
313 }
virtual bool evaluateEBV(const DynamicContext::Ptr &context) const
static Boolean::Ptr fromValue(const bool value)
Definition: qboolean.cpp:115

◆ evaluateToSequenceReceiver()

void Expression::evaluateToSequenceReceiver ( const DynamicContext::Ptr context) const
virtual

Evaluates this Expression by sending its output to DynamicContext::outputReceiver().

Reimplemented in QPatternist::EmptySequence, QPatternist::Path, QPatternist::UserFunctionCallsite, QPatternist::ExpressionSequence, QPatternist::LetClause, QPatternist::CopyOf, QPatternist::Literal, QPatternist::ForClause, QPatternist::ElementConstructor, QPatternist::CallTemplate, QPatternist::IfThenClause, QPatternist::DocumentConstructor, QPatternist::AttributeConstructor, QPatternist::ProcessingInstructionConstructor, QPatternist::CommentConstructor, QPatternist::TextNodeConstructor, QPatternist::ComputedNamespaceConstructor, and QPatternist::NamespaceConstructor.

Definition at line 320 of file qexpression.cpp.

Referenced by QPatternist::DocumentConstructor::evaluateSingleton(), QPatternist::ElementConstructor::evaluateSingleton(), QPatternist::DocumentConstructor::evaluateToSequenceReceiver(), QPatternist::CallTemplate::evaluateToSequenceReceiver(), QPatternist::IfThenClause::evaluateToSequenceReceiver(), QPatternist::ElementConstructor::evaluateToSequenceReceiver(), QPatternist::ForClause::evaluateToSequenceReceiver(), QPatternist::LetClause::evaluateToSequenceReceiver(), QPatternist::UserFunctionCallsite::evaluateToSequenceReceiver(), and QPatternist::Path::evaluateToSequenceReceiver().

321 {
322  QAbstractXmlReceiver *const receiver = context->outputReceiver();
323  const Item::Iterator::Ptr it(evaluateSequence(context));
324  Item next(it->next());
325 
326  while(next)
327  {
328  receiver->item(next);
329  next = it->next();
330  }
331 }
A push interface for the XPath Data Model. Similar to SAX&#39;s ContentHandler.
#define it(className, varName)
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
virtual void item(const Item &item)=0
Sends an Item to this QAbstractXmlReceiver that may be a QXmlNodeModelIndex or an AtomicValue...
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
virtual QAbstractXmlReceiver * outputReceiver() const =0
virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const

◆ expectedContextItemType()

ItemType::Ptr Expression::expectedContextItemType ( ) const
virtual

Returns the required type the context item must be an instance of.

If this Expression requires a focus, meaning its properties() function returns RequiresContextItem, it must return a type from this function. If any type is ok, BuiltinTypes::item should be returned.

In other words, this function must only be re-implemented if the focus is used. The default implementation performs an assert crash.

Reimplemented in QPatternist::ContextItem, QPatternist::CopyOf, QPatternist::AxisStep, and QPatternist::ParentNodeAxis.

Definition at line 333 of file qexpression.cpp.

Referenced by QPatternist::CopyOf::expectedContextItemType(), and QPatternist::TypeChecker::verifyType().

334 {
335  Q_ASSERT_X(false, Q_FUNC_INFO,
336  "expectedContextItemType() must be overridden when RequiresContextItem is set.");
337  return ItemType::Ptr();
338 }
QExplicitlySharedDataPointer< ItemType > Ptr
Definition: qitemtype_p.h:88
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ expectedOperandTypes()

virtual SequenceType::List QPatternist::Expression::expectedOperandTypes ( ) const
pure 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.

Implemented in QPatternist::OrderBy, QPatternist::EvaluationCache< IsForGlobal >, QPatternist::Path, QPatternist::GenericPredicate, QPatternist::TreatAs, QPatternist::UserFunctionCallsite, QPatternist::TruthPredicate, QPatternist::CastAs, QPatternist::CopyOf, QPatternist::TemplateInvoker, QPatternist::ValueComparison, QPatternist::CastableAs, QPatternist::EmptyContainer, QPatternist::GeneralComparison, QPatternist::UntypedAtomicConverter, QPatternist::ExpressionSequence, QPatternist::CombineNodes, QPatternist::ElementConstructor, QPatternist::LetClause, QPatternist::ArgumentConverter, QPatternist::ArithmeticExpression, QPatternist::FirstItemPredicate, QPatternist::ForClause, QPatternist::RangeExpression, QPatternist::AttributeConstructor, QPatternist::ProcessingInstructionConstructor, QPatternist::QuantifiedExpression, QPatternist::ReturnOrderBy, QPatternist::AxisStep, QPatternist::Atomizer, QPatternist::CommentConstructor, QPatternist::DocumentConstructor, QPatternist::SimpleContentConstructor, QPatternist::TextNodeConstructor, QPatternist::CollationChecker, QPatternist::NCNameConstructor, QPatternist::QNameConstructor, QPatternist::StaticBaseURIStore, QPatternist::IfThenClause, QPatternist::StaticCompatibilityStore, QPatternist::AndExpression, QPatternist::AttributeNameValidator, QPatternist::ComputedNamespaceConstructor, QPatternist::NodeComparison, QPatternist::CardinalityVerifier, QPatternist::ItemVerifier, QPatternist::InstanceOf, QPatternist::CurrentItemStore, QPatternist::DynamicContextStore, QPatternist::NamespaceConstructor, QPatternist::UnresolvedVariableReference, QPatternist::EBVExtractor, QPatternist::FunctionCall, QPatternist::NodeSortExpression, and QPatternist::XSLTSimpleContentConstructor.

Referenced by typeCheckOperands().

◆ finalizeStaticContext()

StaticContext::Ptr Expression::finalizeStaticContext ( const StaticContext::Ptr context) const
inlineprivate
Returns
a StaticContext that has adopted the context item type properly for this Expression.

Definition at line 62 of file qexpression.cpp.

Referenced by typeCheckOperands().

63 {
64  Q_ASSERT(context);
65  const ItemType::Ptr focusType(newFocusType());
66  Q_ASSERT(focusType);
67  return StaticContext::Ptr(new StaticFocusContext(focusType, context));
68 }
A StaticContext that carries a specified static type for the context item, but otherwise delegates to...
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QExplicitlySharedDataPointer< StaticContext > Ptr
virtual ItemType::Ptr newFocusType() const

◆ has()

bool QPatternist::Expression::has ( const Property  prop) const
inline

Determines whether this Expression has Property prop set.

Calling expr->has(MyProperty) is semantically equivalent to expr->properties().testFlag(MyProperty). In other words, has(), as well as is(), provides syntacti sugar and makes code more readable.

Note
Do not attempt to re-implement this function. Instead, return the appropriate flag by re-implementing the properties() function.

Definition at line 866 of file qexpression_p.h.

Referenced by QPatternist::InstanceOf::compress(), QPatternist::FunctionCall::staticType(), QPatternist::FunctionCall::typeCheck(), and typeCheckOperands().

867  {
868  return properties().testFlag(prop);
869  }
bool testFlag(Enum f) const
Returns true if the flag is set, otherwise false.
Definition: qglobal.h:2345
virtual Properties properties() const

◆ hasDependency()

bool QPatternist::Expression::hasDependency ( const Property  prop) const
inline

Definition at line 871 of file qexpression_p.h.

Referenced by compress().

872  {
873  return dependencies().testFlag(prop);
874  }
bool testFlag(Enum f) const
Returns true if the flag is set, otherwise false.
Definition: qglobal.h:2345
virtual Properties dependencies() const

◆ id()

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

◆ invokeOptimizers()

Expression::Ptr Expression::invokeOptimizers ( const Expression::Ptr expr,
const StaticContext::Ptr context 
)
staticprivate

Definition at line 126 of file qexpression.cpp.

Referenced by compress().

128 {
129  Q_ASSERT(expr);
130 
131  const OptimizationPass::List opts(expr->optimizationPasses());
132 
133  if(opts.isEmpty()) /* Early exit. */
134  {
135  return expr;
136  }
137 
138  const OptimizationPass::List::const_iterator passEnd(opts.constEnd());
139  const OptimizationPass::List::const_iterator end(opts.constEnd());
140  OptimizationPass::List::const_iterator passIt(opts.constBegin());
141 
142  for(; passIt != passEnd; ++passIt) /* Invoke each optimization pass. */
143  {
144  const OptimizationPass::Ptr pass(*passIt); /* Alias, for readability. */
145  OptimizationPass::ExpressionMarker sourceMarker(pass->sourceExpression);
146 
147  if(pass->startIdentifier && !pass->startIdentifier->matches(expr))
148  {
149  /* This pass specified a start identifier and it did
150  * not match -- let's try the next OptimizationPass. */
151  continue;
152  }
153 
154  const ExpressionIdentifier::List::const_iterator idEnd(pass->operandIdentifiers.constEnd());
155  ExpressionIdentifier::List::const_iterator idIt(pass->operandIdentifiers.constBegin());
156  const Expression::List ops(expr->operands());
157  const Expression::List::const_iterator opEnd(ops.constEnd());
158  Expression::List::const_iterator opIt(ops.constBegin());
159 
160  switch(pass->operandsMatchMethod)
161  {
163  {
164  for(; opIt != opEnd; ++opIt)
165  {
166  const Expression::Ptr operand(*opIt); /* Alias, for readability. */
167  const ExpressionIdentifier::Ptr opIdentifier(*idIt); /* Alias, for readability. */
168  if(opIdentifier && !opIdentifier->matches(operand))
169  {
170  break;
171  }
172 
173  ++idIt;
174  }
175 
176  if(opIt == opEnd)
177  break; /* All operands matched, so this pass matched. */
178  else
179  {
180  /* The loop above did not finish which means all operands did not match.
181  Therefore, this OptimizationPass did not match -- let's try the next one. */
182  continue;
183  }
184  }
186  {
187  Q_ASSERT_X(ops.count() == 2, Q_FUNC_INFO,
188  "AnyOrder is currently only supported for Expressions with two operands.");
189  if(pass->operandIdentifiers.first()->matches(ops.first()) &&
190  pass->operandIdentifiers.last()->matches(ops.last()))
191  {
192  break;
193  }
194  else if(pass->operandIdentifiers.first()->matches(ops.last()) &&
195  pass->operandIdentifiers.last()->matches(ops.first()))
196  {
197  sourceMarker.first() = 1;
198  sourceMarker[1] = 0;
199  break; /* This pass matched. */
200  }
201  else
202  continue; /* This pass didn't match, let's loop through the next pass. */
203  }
204  }
205 
206  /* Figure out the source Expression, if any. */
208  Expression::Ptr sourceExpr;
209 
210  if(!sourceMarker.isEmpty())
211  {
212  const OptimizationPass::ExpressionMarker::const_iterator mEnd(sourceMarker.constEnd());
213  OptimizationPass::ExpressionMarker::const_iterator mIt(sourceMarker.constBegin());
214  sourceExpr = expr;
215 
216  for(; mIt != mEnd; ++mIt)
217  {
218  Q_ASSERT(*mIt >= 0);
219  sourceExpr = sourceExpr->operands().at(*mIt);
220  }
221 
222  operands.append(sourceExpr);
223  }
224 
225  if(operands.isEmpty())
226  {
227  Q_ASSERT(pass->resultCreator);
228  return pass->resultCreator->create(Expression::List(), context, expr.data())->compress(context);
229  }
230  else if(pass->resultCreator)
231  return pass->resultCreator->create(operands, context, expr.data())->compress(context);
232  else
233  {
234  return sourceExpr;
235  }
236  }
237 
238  return expr;
239 }
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
The QList::const_iterator class provides an STL-style const iterator for QList and QQueue...
Definition: qlist.h:228
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual Expression::Ptr compress(const StaticContext::Ptr &context)
virtual QList< QExplicitlySharedDataPointer< OptimizationPass > > optimizationPasses() const
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
friend class const_iterator
Definition: qlist.h:264
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
virtual Expression::List operands() const =0
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
static const KeyPair *const end
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ is()

bool QPatternist::Expression::is ( const ID  id) const
inline

◆ isEvaluated()

bool QPatternist::Expression::isEvaluated ( ) const
inline

This function is a utility function, which performs bitwise logic on properties() in order to find out whether the Expression::IsEvaluated flag is set.

Note
Do not attempt to re-implement this function. Instead, return the IsEvaluated flag by re-implementing the properties() function.

Definition at line 861 of file qexpression_p.h.

Referenced by QPatternist::OrExpression::compress(), QPatternist::IfThenClause::compress(), QPatternist::AndExpression::compress(), QPatternist::SingleContainer::compressOperands(), QPatternist::PairContainer::compressOperands(), QPatternist::TripleContainer::compressOperands(), and QPatternist::SubsequenceFN::staticType().

862  {
863  return has(IsEvaluated);
864  }
bool has(const Property prop) const

◆ newFocusType()

ItemType::Ptr Expression::newFocusType ( ) const
virtual

If an Expression creates a focus because it has set the property CreatesFocusForLast, it should override this function and make it return the ItemType that the context item in the focus has.

Returns
never null.
See also
announceFocusType()

Reimplemented in QPatternist::GenericPredicate, and QPatternist::Path.

Definition at line 392 of file qexpression.cpp.

Referenced by finalizeStaticContext().

393 {
394  Q_ASSERT_X(false, Q_FUNC_INFO,
395  "This function must be overridden when CreatesFocusForLast is set.");
396  return ItemType::Ptr();
397 }
QExplicitlySharedDataPointer< ItemType > Ptr
Definition: qitemtype_p.h:88
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ operands()

virtual Expression::List QPatternist::Expression::operands ( ) const
pure virtual

◆ optimizationPasses()

OptimizationPass::List Expression::optimizationPasses ( ) const
virtual

Returns the OptimizationPasses that applies for this Expression. The default implementation returns an empty list. Sub-classes can re-implement this function and return actual OptimizationPasses.

Returns
always an empty list.

Reimplemented in QPatternist::NotFN, QPatternist::ValueComparison, QPatternist::GeneralComparison, QPatternist::ForClause, and QPatternist::IfThenClause.

Definition at line 387 of file qexpression.cpp.

Referenced by invokeOptimizers().

388 {
389  return OptimizationPass::List();
390 }
QList< OptimizationPass::Ptr > List

◆ patternPriority()

PatternPriority Expression::patternPriority ( ) const
virtual

By default 0.5 is returned.

Reimplemented in QPatternist::AxisStep.

Definition at line 409 of file qexpression.cpp.

410 {
411  return 0.5;
412 }

◆ properties()

Expression::Properties Expression::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 in QPatternist::OrderBy, QPatternist::EmptySequence, QPatternist::Path, QPatternist::GenericPredicate, QPatternist::EvaluationCache< IsForGlobal >, QPatternist::ExpressionSequence, QPatternist::ReturnOrderBy, QPatternist::CopyOf, QPatternist::AxisStep, QPatternist::RangeExpression, QPatternist::ApplyTemplate, QPatternist::UserFunctionCallsite, QPatternist::VariableReference, QPatternist::AttributeConstructor, QPatternist::Literal, QPatternist::ElementConstructor, QPatternist::ComputedNamespaceConstructor, QPatternist::LetClause, QPatternist::LiteralSequence, QPatternist::NamespaceConstructor, QPatternist::PositionalVariableReference, QPatternist::DocumentConstructor, QPatternist::ProcessingInstructionConstructor, QPatternist::ContextItem, QPatternist::RangeVariableReference, QPatternist::CommentConstructor, QPatternist::ExternalVariableReference, QPatternist::TextNodeConstructor, QPatternist::FunctionCall, QPatternist::CallTemplate, QPatternist::CurrentItemStore, QPatternist::ParentNodeAxis, QPatternist::TemplateParameterReference, and QPatternist::NodeSortExpression.

Definition at line 340 of file qexpression.cpp.

Referenced by deepProperties(), dependencies(), QPatternist::CurrentItemStore::properties(), QPatternist::CopyOf::properties(), QPatternist::Path::properties(), QPatternist::Template::properties(), QPatternist::OrderBy::properties(), and QPatternist::TypeChecker::verifyType().

341 {
342  return Properties();
343 }
QFlags< Property > Properties

◆ rewrite() [1/2]

void QPatternist::Expression::rewrite ( Expression::Ptr old,
const Expression::Ptr New,
const StaticContext::Ptr context 
)
inlinestatic

This function take the two Expression pointers old and New, and in a safe way, by handling reference counting and being aware of whether the two pointers actually are different, switches the two. When compiling in debug mode, informative debug messages are printed.

This function is conceptually similar to Qt's qSwap(), but has debugging functionality and also handles source locations.

Definition at line 876 of file qexpression_p.h.

Referenced by QPatternist::UserFunctionCallsite::compress(), QPatternist::PairContainer::compressOperands(), QPatternist::SingleContainer::compressOperands(), QPatternist::TripleContainer::compressOperands(), QPatternist::UnlimitedContainer::compressOperands(), constantPropagate(), QPatternist::GeneralComparison::typeCheck(), QPatternist::AxisStep::typeCheck(), and QPatternist::DocumentFN::typeCheck().

879  {
880  Q_ASSERT(old);
881  Q_ASSERT(New);
882 
883  if(old != New)
884  {
885  pDebug() << "AST REWRITE:" << old.data() << "to" << New.data()
886  << '(' << old->actualReflection() << "to" << New->actualReflection() << ", "
887  << old->description() << "to" << New->description() << ')';
888 
889  /* The order of these two lines is significant.. */
890  context->addLocation(New.data(), context->locationFor(old->actualReflection()));
891  old = New;
892  }
893  }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QNoDebug pDebug()
Definition: qdebug_p.h:99

◆ rewrite() [2/2]

const Expression::Ptr & QPatternist::Expression::rewrite ( const Expression::Ptr to,
const StaticContext::Ptr context 
) const
inline

Rewrites this Expression to to, and return to.

Source location annotations are adjusted appropriately.

Definition at line 895 of file qexpression_p.h.

897  {
898  context->addLocation(to.data(), context->locationFor(this));
899  return to;
900  }

◆ setOperands()

virtual void QPatternist::Expression::setOperands ( const Expression::List operands)
pure virtual

◆ staticType()

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

Implemented in QPatternist::SubsequenceFN, QPatternist::ReverseFN, QPatternist::RemoveFN, QPatternist::InsertBeforeFN, QPatternist::DistinctValuesFN, QPatternist::RootFN, QPatternist::OrderBy, QPatternist::SumFN, QPatternist::DocFN, QPatternist::AvgFN, QPatternist::EmptySequence, QPatternist::Path, QPatternist::GenericPredicate, QPatternist::UserFunctionCallsite, QPatternist::CastAs, QPatternist::EvaluationCache< IsForGlobal >, QPatternist::TreatAs, QPatternist::ApplyTemplate, QPatternist::NodeComparison, QPatternist::FirstItemPredicate, QPatternist::CastableAs, QPatternist::GeneralComparison, QPatternist::LetClause, QPatternist::RangeExpression, QPatternist::ValueComparison, QPatternist::CopyOf, QPatternist::DocumentConstructor, QPatternist::ExpressionSequence, QPatternist::ComputedNamespaceConstructor, QPatternist::ArgumentConverter, QPatternist::UntypedAtomicConverter, QPatternist::CurrentItemStore, QPatternist::ParentNodeAxis, QPatternist::AttributeNameValidator, QPatternist::CollationChecker, QPatternist::CombineNodes, QPatternist::NamespaceConstructor, QPatternist::NCNameConstructor, QPatternist::PositionalVariableReference, QPatternist::EBVExtractor, QPatternist::AndExpression, QPatternist::ExpressionVariableReference, QPatternist::Literal, QPatternist::ArithmeticExpression, QPatternist::AxisStep, QPatternist::ForClause, QPatternist::LiteralSequence, QPatternist::IfThenClause, QPatternist::QNameConstructor, QPatternist::QuantifiedExpression, QPatternist::ReturnOrderBy, QPatternist::SimpleContentConstructor, QPatternist::Aggregator, QPatternist::TraceFN, QPatternist::ContextItem, QPatternist::DynamicContextStore, QPatternist::ElementConstructor, QPatternist::ExternalVariableReference, QPatternist::Atomizer, QPatternist::CallTemplate, QPatternist::StaticBaseURIStore, QPatternist::CardinalityVerifier, QPatternist::ItemVerifier, QPatternist::InstanceOf, QPatternist::RangeVariableReference, QPatternist::StaticCompatibilityStore, QPatternist::ArgumentReference, QPatternist::AttributeConstructor, QPatternist::ProcessingInstructionConstructor, QPatternist::UnresolvedVariableReference, QPatternist::CommentConstructor, QPatternist::TextNodeConstructor, QPatternist::TemplateParameterReference, QPatternist::FunctionCall, QPatternist::XSLTSimpleContentConstructor, QPatternist::CurrentFN, and QPatternist::NodeSortExpression.

Referenced by QPatternist::VariableLoader::announceExternalVariable(), QPatternist::NodeSortExpression::compress(), QPatternist::InstanceOf::compress(), QPatternist::SimpleContentConstructor::compress(), QPatternist::CastableAs::compress(), QPatternist::NodeComparison::compress(), QPatternist::CardinalityVerifier::compress(), QPatternist::CountFN::compress(), QPatternist::ForClause::compress(), QPatternist::StringJoinFN::compress(), QPatternist::CopyOf::compress(), QPatternist::CastAs::compress(), QPatternist::Path::compress(), QPatternist::OrderBy::compress(), constantPropagate(), QPatternist::GenericPredicate::create(), QPatternist::CastableAs::evaluateEBV(), QPatternist::NodeSortExpression::evaluateSequence(), QPatternist::GeneralComparison::fetchGeneralComparator(), QPatternist::ArithmeticExpression::fetchMathematician(), QPatternist::BySequenceTypeIdentifier::matches(), QPatternist::Path::newFocusType(), QPatternist::GenericPredicate::newFocusType(), QPatternist::OrderBy::OrderSpec::prepare(), QPatternist::NodeSortExpression::staticType(), QPatternist::FunctionCall::staticType(), QPatternist::TextNodeConstructor::staticType(), QPatternist::UnresolvedVariableReference::staticType(), QPatternist::RangeVariableReference::staticType(), QPatternist::StaticCompatibilityStore::staticType(), QPatternist::CardinalityVerifier::staticType(), QPatternist::ItemVerifier::staticType(), QPatternist::StaticBaseURIStore::staticType(), QPatternist::DynamicContextStore::staticType(), QPatternist::Atomizer::staticType(), QPatternist::Aggregator::staticType(), QPatternist::ReturnOrderBy::staticType(), QPatternist::SimpleContentConstructor::staticType(), QPatternist::IfThenClause::staticType(), QPatternist::ArithmeticExpression::staticType(), QPatternist::ForClause::staticType(), QPatternist::ExpressionVariableReference::staticType(), QPatternist::AttributeNameValidator::staticType(), QPatternist::CollationChecker::staticType(), QPatternist::CombineNodes::staticType(), QPatternist::CurrentItemStore::staticType(), QPatternist::UntypedAtomicConverter::staticType(), QPatternist::CopyOf::staticType(), QPatternist::LetClause::staticType(), QPatternist::ValueComparison::staticType(), QPatternist::FirstItemPredicate::staticType(), QPatternist::NodeComparison::staticType(), QPatternist::CastAs::staticType(), QPatternist::UserFunctionCallsite::staticType(), QPatternist::GenericPredicate::staticType(), QPatternist::Path::staticType(), QPatternist::AvgFN::staticType(), QPatternist::SumFN::staticType(), QPatternist::OrderBy::staticType(), QPatternist::RootFN::staticType(), QPatternist::DistinctValuesFN::staticType(), QPatternist::InsertBeforeFN::staticType(), QPatternist::RemoveFN::staticType(), QPatternist::ReverseFN::staticType(), QPatternist::SubsequenceFN::staticType(), QPatternist::DeepEqualFN::typeCheck(), QPatternist::FunctionCall::typeCheck(), QPatternist::NCNameConstructor::typeCheck(), QPatternist::ValueComparison::typeCheck(), QPatternist::CastableAs::typeCheck(), QPatternist::ForClause::typeCheck(), QPatternist::GeneralComparison::typeCheck(), QPatternist::ArithmeticExpression::typeCheck(), QPatternist::Atomizer::typeCheck(), QPatternist::UntypedAtomicConverter::typeCheck(), QPatternist::StringFN::typeCheck(), QPatternist::AddingAggregate::typeCheck(), QPatternist::IndexOfFN::typeCheck(), QPatternist::CastAs::typeCheck(), QPatternist::AvgFN::typeCheck(), QPatternist::NumberFN::typeCheck(), QPatternist::SumFN::typeCheck(), QPatternist::DistinctValuesFN::typeCheck(), QPatternist::ReverseFN::typeCheck(), QPatternist::GeneralComparison::updateType(), QPatternist::CardinalityVerifier::verifyCardinality(), and QPatternist::TypeChecker::verifyType().

◆ typeCheck()

Expression::Ptr Expression::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 in QPatternist::SubsequenceFN, QPatternist::ReverseFN, QPatternist::DistinctValuesFN, QPatternist::StaticBaseURIFN, QPatternist::DefaultCollationFN, QPatternist::OrderBy, QPatternist::SumFN, QPatternist::DocFN, QPatternist::NumberFN, QPatternist::AvgFN, QPatternist::EvaluationCache< IsForGlobal >, QPatternist::DocumentFN, QPatternist::CastAs, QPatternist::IndexOfFN, QPatternist::AddingAggregate, QPatternist::ExpressionSequence, QPatternist::Path, QPatternist::StringFN, QPatternist::ContextItem, QPatternist::UntypedAtomicConverter, QPatternist::CallTemplate, QPatternist::TreatAs, QPatternist::ComparingAggregator< oper, result >, QPatternist::BooleanFN, QPatternist::Atomizer, QPatternist::ElementConstructor, QPatternist::CountFN, QPatternist::AxisStep, QPatternist::UserFunctionCallsite, QPatternist::StaticBaseUriContainer, QPatternist::ArithmeticExpression, QPatternist::CombineNodes, QPatternist::LetClause, QPatternist::IdFN, QPatternist::CastableAs, QPatternist::ForClause, QPatternist::GeneralComparison, QPatternist::DocumentConstructor, QPatternist::ValueComparison, QPatternist::ExpressionVariableReference, QPatternist::NCNameConstructor, QPatternist::StaticNamespacesContainer, QPatternist::FunctionCall, QPatternist::CurrentItemStore, QPatternist::EBVExtractor, QPatternist::StaticBaseURIStore, QPatternist::StaticCompatibilityStore, QPatternist::DeepEqualFN, QPatternist::FunctionAvailableFN, QPatternist::TypeAvailableFN, QPatternist::UnresolvedVariableReference, QPatternist::CurrentFN, and QPatternist::ResolveURIFN.

Definition at line 70 of file qexpression.cpp.

Referenced by QPatternist::UnresolvedVariableReference::typeCheck(), QPatternist::StaticCompatibilityStore::typeCheck(), QPatternist::StaticBaseURIStore::typeCheck(), QPatternist::CurrentItemStore::typeCheck(), QPatternist::FunctionCall::typeCheck(), QPatternist::NCNameConstructor::typeCheck(), QPatternist::ExpressionVariableReference::typeCheck(), QPatternist::ValueComparison::typeCheck(), QPatternist::DocumentConstructor::typeCheck(), QPatternist::CastableAs::typeCheck(), QPatternist::ForClause::typeCheck(), QPatternist::GeneralComparison::typeCheck(), QPatternist::IdFN::typeCheck(), QPatternist::LetClause::typeCheck(), QPatternist::ArithmeticExpression::typeCheck(), QPatternist::CombineNodes::typeCheck(), QPatternist::UserFunctionCallsite::typeCheck(), QPatternist::AxisStep::typeCheck(), QPatternist::ElementConstructor::typeCheck(), QPatternist::CountFN::typeCheck(), QPatternist::Atomizer::typeCheck(), QPatternist::TreatAs::typeCheck(), QPatternist::CallTemplate::typeCheck(), QPatternist::UntypedAtomicConverter::typeCheck(), QPatternist::ContextItem::typeCheck(), QPatternist::Path::typeCheck(), QPatternist::CastAs::typeCheck(), QPatternist::DocumentFN::typeCheck(), QPatternist::EvaluationCache< IsForGlobal >::typeCheck(), QPatternist::NumberFN::typeCheck(), QPatternist::DocFN::typeCheck(), QPatternist::TypeChecker::typeCheck(), QPatternist::OrderBy::typeCheck(), QPatternist::DefaultCollationFN::typeCheck(), QPatternist::ReverseFN::typeCheck(), and typeCheckOperands().

72 {
73  Q_ASSERT(reqType);
74  typeCheckOperands(context);
75  return TypeChecker::applyFunctionConversion(Expression::Ptr(this), reqType, context);
76 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void typeCheckOperands(const StaticContext::Ptr &context)
Definition: qexpression.cpp:78
static Expression::Ptr applyFunctionConversion(const Expression::Ptr &operand, const SequenceType::Ptr &reqType, const StaticContext::Ptr &context, const ReportContext::ErrorCode code=ReportContext::XPTY0004, const Options=Options(AutomaticallyConvert|CheckFocus))
Builds a pipeline of artificial AST nodes that ensures operand conforms to the type reqType by applyi...

◆ typeCheckOperands()

void Expression::typeCheckOperands ( const StaticContext::Ptr context)
protected

Definition at line 78 of file qexpression.cpp.

Referenced by QPatternist::UserFunctionCallsite::typeCheck(), QPatternist::DocumentFN::typeCheck(), and typeCheck().

79 {
80  const Expression::List ops(operands());
81 
82  /* Check if this expression has any operands at all. */
83  if(ops.isEmpty())
84  return; /* We're done, early exit. */
85 
87  Expression::List result;
88 
89  /* If we create a focus, we handle the last one specially, so avoid it in the loop. */
90  const bool createsFocus = has(CreatesFocusForLast);
91  const SequenceType::List::const_iterator typeEnd(createsFocus ? --opTypes.constEnd()
92  : opTypes.constEnd());
93  const Expression::List::const_iterator end(createsFocus ? --ops.constEnd()
94  : ops.constEnd());
95 
96  SequenceType::List::const_iterator reqType(opTypes.constBegin());
97  SequenceType::Ptr t(*reqType);
98  // TODO we assign twice to t here(also below in loop) when ops.size() > 1
99 
100  Expression::List::const_iterator it(ops.constBegin());
101 
102  for(; it != end; ++it)
103  {
104  /* This ensures that the last expectedOperandType stays, and is
105  * used for all other operands. This is used for expressions that
106  * have an infinite amount of operands, such as the concat() function. */
107  if(reqType != typeEnd)
108  {
109  t = *reqType;
110  ++reqType;
111  }
112 
113  /* Let the child & its children typecheck. */
114  result.append((*it)->typeCheck(context, t));
115  }
116 
117  if(createsFocus)
118  {
119  const StaticContext::Ptr newContext(finalizeStaticContext(context));
120  result.append(ops.last()->typeCheck(newContext, opTypes.last()));
121  }
122 
123  setOperands(result);
124 }
virtual SequenceType::List expectedOperandTypes() const =0
virtual void setOperands(const Expression::List &operands)=0
#define it(className, varName)
The QList::const_iterator class provides an STL-style const iterator for QList and QQueue...
Definition: qlist.h:228
bool has(const Property prop) const
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
StaticContext::Ptr finalizeStaticContext(const StaticContext::Ptr &context) const
Definition: qexpression.cpp:62
virtual Expression::List operands() const =0
static const KeyPair *const end

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