Qt 4.8
Public Functions | List of all members
QPatternist::DocumentFN Class Reference

Implements XSL-T's function fn:document(). More...

#include <qdocumentfn_p.h>

Inheritance diagram for QPatternist::DocumentFN:
QPatternist::FunctionCall QPatternist::UnlimitedContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Functions

virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
- Public Functions inherited from QPatternist::FunctionCall
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
 
- 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 ()
 

Additional Inherited Members

- Public Types inherited from QPatternist::FunctionCall
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
 
- 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

Implements XSL-T's function fn:document().

fn:document() has no evaluation functions, because it rewrites itself to a set of expressions that is the implementation.

The two-argument version:

document($uris as item()*, $baseURINode as node()) as node()*

is rewritten into:

for $uri in distinct-values($uris) return doc(resolve-uri($uri, base-uri($baseURINode)))

and the single version argument:

document($uris as item()*) as node()*

is rewritten into:

for $uri in distinct-values($uris) return doc($uri)

The distinct-values() call ensures the node deduplication and sorting, although it fails in the case that URIs resolve/directs in some way to the same document. Some of those cases can be solved by wrapping the whole expression with a node deduplication(conceptually the-for-loop/.). One advantage with distinct-values() over generating traditional node sorting/deduplication code is that the latter contains node sorting which is uecessary and can be hard to analyze away. distinct-values() doesn't have this problem due to its narrower task..

This works without problems, assuming XTRE1160 is not raised and that the recover action instead is ignore. In the case XTRE1160 is raised, one must cater for this.

In addition to this, both signatures has its first argument changed to type xs:string*, in order to generate atomization code.

One notable thing is that the expression for $baseURINode, is moved inside a loop, and will be evaluated repeatedly, unless moved out as part of optimization.

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

Definition at line 112 of file qdocumentfn_p.h.

Functions

◆ typeCheck()

Expression::Ptr DocumentFN::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::FunctionCall.

Definition at line 52 of file qdocumentfn.cpp.

54 {
55  /* See the class documentation for the rewrite that we're doing here. */
56 
57  /* Generate type checking code for our operands such that they match. */
58  typeCheckOperands(context);
59 
60  const QSourceLocation myLocation(context->locationFor(this));
61  const FunctionFactory::Ptr functions(context->functionSignatures());
62 
63  Expression::Ptr uriSource;
64 
65  {
66  Expression::List distinctValuesArgs;
67  distinctValuesArgs.append(m_operands.first());
68 
69  uriSource = functions->createFunctionCall(QXmlName(StandardNamespaces::fn, StandardLocalNames::distinct_values),
70  distinctValuesArgs,
71  context,
72  this);
73  context->addLocation(uriSource.data(), myLocation);
74  }
75 
76  const VariableSlotID rangeSlot = context->allocateRangeSlot();
77  const Expression::Ptr uriReference(new RangeVariableReference(uriSource, rangeSlot));
78  context->addLocation(uriReference.data(), myLocation);
79 
80  Expression::List docArgs;
81 
82  if(m_operands.count() == 2)
83  {
84  Expression::List baseUriArgs;
85  baseUriArgs.append(uriReference);
86  baseUriArgs.append(m_operands.at(1));
87 
88  const Expression::Ptr fnBaseUri(functions->createFunctionCall(QXmlName(StandardNamespaces::fn, StandardLocalNames::resolve_uri),
89  baseUriArgs,
90  context,
91  this));
92  context->addLocation(fnBaseUri.data(), myLocation);
93  docArgs.append(fnBaseUri);
94  }
95  else
96  docArgs.append(uriReference);
97 
98  const Expression::Ptr fnDoc(functions->createFunctionCall(QXmlName(StandardNamespaces::fn, StandardLocalNames::doc),
99  docArgs,
100  context,
101  this));
102  context->addLocation(fnDoc.data(), myLocation);
103 
104 
105  Expression::Ptr newMe(new ForClause(rangeSlot,
106  uriSource,
107  fnDoc,
108  -1 /* We have no position variable. */));
109 
110  Expression::Ptr oldMe(this);
111  rewrite(oldMe, newMe, context);
112  return newMe->typeCheck(context, reqType);
113 }
qint32 VariableSlotID
Implements XPath 2.0&#39;s for expression.
Definition: qforclause_p.h:72
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
virtual VariableSlotID allocateRangeSlot()=0
void typeCheckOperands(const StaticContext::Ptr &context)
Definition: qexpression.cpp:78
static void rewrite(Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QSourceLocation class identifies a location in a resource by URI, line, and column.
virtual QExplicitlySharedDataPointer< FunctionFactory > functionSignatures() const =0
virtual QSourceLocation locationFor(const SourceLocationReflection *const reflection) const =0
Returns the source location applying for reflection.
T & first()
Returns a reference to the first item in the list.
Definition: qlist.h:282
virtual void addLocation(const SourceLocationReflection *const reflection, const QSourceLocation &location)=0
Adds location for reflection.
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
A reference to a variable declared with for or a quantification expression, but not for instance a le...

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