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

Constructs an element node. This covers both computed and directly constructed element nodes. More...

#include <qelementconstructor_p.h>

Inheritance diagram for QPatternist::ElementConstructor:
QPatternist::PairContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Functions

virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
 ElementConstructor (const Expression::Ptr &operand1, const Expression::Ptr &operand2, const bool isXSLT)
 
virtual Item evaluateSingleton (const DynamicContext::Ptr &context) const
 
virtual void evaluateToSequenceReceiver (const DynamicContext::Ptr &context) const
 
virtual SequenceType::List expectedOperandTypes () const
 
virtual Properties properties () const
 
virtual SequenceType::Ptr staticType () const
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
- Public Functions inherited from QPatternist::PairContainer
virtual bool compressOperands (const StaticContext::Ptr &)
 
virtual Expression::List operands () const
 
virtual void setOperands (const Expression::List &operands)
 
- 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 ItemType::Ptr expectedContextItemType () const
 
 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 QList< QExplicitlySharedDataPointer< OptimizationPass > > optimizationPasses () const
 
virtual PatternPriority patternPriority () const
 
const Expression::Ptrrewrite (const Expression::Ptr &to, const StaticContext::Ptr &context) const
 Rewrites this Expression to to, and return to. More...
 
virtual ~Expression ()
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 
- Public Functions inherited from QPatternist::CppCastingHelper< Expression >
const TCastTarget * as () const
 
TCastTarget * as ()
 
- Public Functions inherited from QPatternist::SourceLocationReflection
virtual QSourceLocation sourceLocation () const
 
 SourceLocationReflection ()
 
virtual ~SourceLocationReflection ()
 

Properties

const bool m_isXSLT
 
QUrl m_staticBaseURI
 

Additional Inherited Members

- 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::PairContainer
 PairContainer (const Expression::Ptr &operand1, const Expression::Ptr &operand2)
 
- 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::PairContainer
Expression::Ptr m_operand1
 
Expression::Ptr m_operand2
 

Detailed Description

Constructs an element node. This covers both computed and directly constructed element nodes.

See also
XQuery 1.0: An XML Query Language, 3.7 Constructors
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 74 of file qelementconstructor_p.h.

Constructors and Destructors

◆ ElementConstructor()

ElementConstructor::ElementConstructor ( const Expression::Ptr operand1,
const Expression::Ptr operand2,
const bool  isXSLT 
)

Definition at line 56 of file qelementconstructor.cpp.

58  : PairContainer(op1, op2)
59  , m_isXSLT(isXSLT)
60 {
61 }
PairContainer(const Expression::Ptr &operand1, const Expression::Ptr &operand2)

Functions

◆ accept()

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

Implements QPatternist::Expression.

Definition at line 155 of file qelementconstructor.cpp.

156 {
157  return visitor->visit(this);
158 }

◆ evaluateSingleton()

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

Reimplemented from QPatternist::Expression.

Definition at line 63 of file qelementconstructor.cpp.

64 {
65  const Item name(m_operand1->evaluateSingleton(context));
66 
67  const NodeBuilder::Ptr nodeBuilder(context->nodeBuilder(m_staticBaseURI));
68  OutputValidator validator(nodeBuilder.data(), context, this, m_isXSLT);
69 
70  const DynamicContext::Ptr receiverContext(context->createReceiverContext(&validator));
71 
72  nodeBuilder->startElement(name.as<QNameValue>()->qName());
73  m_operand2->evaluateToSequenceReceiver(receiverContext);
74  nodeBuilder->endElement();
75 
76  const QAbstractXmlNodeModel::Ptr nm(nodeBuilder->builtDocument());
77  context->addNodeModel(nm);
78 
79  return nm->root(QXmlNodeModelIndex());
80 }
The QXmlNodeModelIndex class identifies a node in an XML node model subclassed from QAbstractXmlNodeM...
virtual void addNodeModel(const QAbstractXmlNodeModel::Ptr &nm)=0
QXmlName qName() const
Definition: qqnamevalue_p.h:96
const char * name
Receives QAbstractXmlReceiver events and validates that they are correct, before sending them on to a...
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Implements the value instance of the xs:QName type.
Definition: qqnamevalue_p.h:73
DynamicContext::Ptr createReceiverContext(QAbstractXmlReceiver *const receiver)
virtual NodeBuilder::Ptr nodeBuilder(const QUrl &baseURI) const =0
virtual void evaluateToSequenceReceiver(const DynamicContext::Ptr &context) const
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

◆ evaluateToSequenceReceiver()

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

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

Reimplemented from QPatternist::Expression.

Definition at line 82 of file qelementconstructor.cpp.

83 {
84  /* We create an OutputValidator here too. If we're serializing(a common
85  * case, unfortunately) the receiver is already validating in order to
86  * catch cases where a computed attribute constructor is followed by an
87  * element constructor, but in the cases where we're not serializing it's
88  * necessary that we validate in this step. */
89  const Item name(m_operand1->evaluateSingleton(context));
90  QAbstractXmlReceiver *const receiver = context->outputReceiver();
91 
92  OutputValidator validator(receiver, context, this, m_isXSLT);
93  const DynamicContext::Ptr receiverContext(context->createReceiverContext(&validator));
94 
95  receiver->startElement(name.as<QNameValue>()->qName());
96  m_operand2->evaluateToSequenceReceiver(receiverContext);
97  receiver->endElement();
98 }
A push interface for the XPath Data Model. Similar to SAX&#39;s ContentHandler.
QXmlName qName() const
Definition: qqnamevalue_p.h:96
const char * name
Receives QAbstractXmlReceiver events and validates that they are correct, before sending them on to a...
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
Implements the value instance of the xs:QName type.
Definition: qqnamevalue_p.h:73
DynamicContext::Ptr createReceiverContext(QAbstractXmlReceiver *const receiver)
virtual QAbstractXmlReceiver * outputReceiver() const =0
virtual void evaluateToSequenceReceiver(const DynamicContext::Ptr &context) const
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

◆ expectedOperandTypes()

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

The first operand must be exactly one xs:QName, and the second argument can be zero or more items.

Implements QPatternist::Expression.

Definition at line 141 of file qelementconstructor.cpp.

142 {
143  SequenceType::List result;
146  return result;
147 }
static const SequenceType::Ptr ZeroOrMoreItems
static const SequenceType::Ptr ExactlyOneQName
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ properties()

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

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

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

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

Reimplemented from QPatternist::Expression.

Definition at line 149 of file qelementconstructor.cpp.

◆ staticType()

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

Implements QPatternist::Expression.

Definition at line 136 of file qelementconstructor.cpp.

137 {
139 }
static const SequenceType::Ptr ExactlyOneElement

◆ typeCheck()

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

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

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

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

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

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

Reimplemented from QPatternist::Expression.

Definition at line 100 of file qelementconstructor.cpp.

102 {
103  /* What does this code do? When type checking our children, our namespace
104  * bindings, which are also children of the form of NamespaceConstructor
105  * instances, must be statically in-scope for them, so find them and
106  * shuffle their bindings into the StaticContext. */
107 
108  m_staticBaseURI = context->baseURI();
109 
110  /* Namespace declarations changes the in-scope bindings, so let's
111  * first lookup our child NamespaceConstructors. */
112  const ID operandID = m_operand2->id();
113 
114  NamespaceResolver::Bindings overrides;
115  if(operandID == IDExpressionSequence)
116  {
118  const int len = operands.count();
119 
120  for(int i = 0; i < len; ++i)
121  {
123  {
124  const QXmlName &nb = operands.at(i)->as<NamespaceConstructor>()->namespaceBinding();
125  overrides.insert(nb.prefix(), nb.namespaceURI());
126  }
127  }
128  }
129 
130  const NamespaceResolver::Ptr newResolver(new DelegatingNamespaceResolver(context->namespaceBindings(), overrides));
131  const StaticContext::Ptr augmented(new StaticNamespaceContext(newResolver, context));
132 
133  return PairContainer::typeCheck(augmented, reqType);
134 }
virtual Expression::List operands() const
Constructs a namespace on an element, and naturally only appears as a child of ElementConstructor.
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Definition: qexpression.cpp:70
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
Definition: qxmlname.cpp:370
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
Contains a set of bindings, plus a pointer to another resolver which is delegates requests to...
virtual ID id() const
const TCastTarget * as() const
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
virtual NamespaceResolver::Ptr namespaceBindings() const =0
virtual Expression::List operands() const =0
NamespaceCode namespaceURI() const
Definition: qnamepool_p.h:503
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
A StaticContext that carries a specified namespace resolver for the context item, but otherwise deleg...
bool is(const ID id) const
virtual QUrl baseURI() const =0

Properties

◆ m_isXSLT

const bool QPatternist::ElementConstructor::m_isXSLT
private

Definition at line 99 of file qelementconstructor_p.h.

Referenced by evaluateSingleton(), and evaluateToSequenceReceiver().

◆ m_staticBaseURI

QUrl QPatternist::ElementConstructor::m_staticBaseURI
private

Definition at line 98 of file qelementconstructor_p.h.

Referenced by evaluateSingleton(), and typeCheck().


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