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

Creates an xs:QName value from a lexical QName using statically known namespace bindings. More...

#include <qqnameconstructor_p.h>

Inheritance diagram for QPatternist::QNameConstructor:
QPatternist::SingleContainer QPatternist::Expression QSharedData QPatternist::CppCastingHelper< Expression > QPatternist::SourceLocationReflection

Public Functions

virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
virtual const SourceLocationReflectionactualReflection () const
 Returns this. More...
 
virtual Item evaluateSingleton (const DynamicContext::Ptr &) const
 
virtual SequenceType::List expectedOperandTypes () const
 
 QNameConstructor (const Expression::Ptr &source, const NamespaceResolver::Ptr &nsResolver)
 
virtual SequenceType::Ptr staticType () const
 
- Public Functions inherited from QPatternist::SingleContainer
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 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 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
 
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
 
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 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

template<typename TReportContext , const ReportContext::ErrorCode InvalidQName, const ReportContext::ErrorCode NoBinding>
static QXmlName expandQName (const QString &lexicalQName, const TReportContext &context, const NamespaceResolver::Ptr &nsResolver, const SourceLocationReflection *const r, const bool asForAttribute=false)
 
static QXmlName::NamespaceCode namespaceForPrefix (const QXmlName::PrefixCode prefix, const StaticContext::Ptr &context, const SourceLocationReflection *const r)
 
- Static Public Functions inherited from QPatternist::Expression
static void rewrite (Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
 

Properties

const NamespaceResolver::Ptr m_nsResolver
 

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
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 
- Protected Functions inherited from QPatternist::SingleContainer
 SingleContainer (const Expression::Ptr &operand)
 
- 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::SingleContainer
Expression::Ptr m_operand
 

Detailed Description

Creates an xs:QName value from a lexical QName using statically known namespace bindings.

See also
QQNameValue
QXmlUtils
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 75 of file qqnameconstructor_p.h.

Constructors and Destructors

◆ QNameConstructor()

QNameConstructor::QNameConstructor ( const Expression::Ptr source,
const NamespaceResolver::Ptr nsResolver 
)

Definition at line 52 of file qqnameconstructor.cpp.

53  : SingleContainer(source),
54  m_nsResolver(nsResolver)
55 {
57 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
SingleContainer(const Expression::Ptr &operand)
const NamespaceResolver::Ptr m_nsResolver

Functions

◆ accept()

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

Implements QPatternist::Expression.

Definition at line 104 of file qqnameconstructor.cpp.

105 {
106  return visitor->visit(this);
107 }

◆ actualReflection()

const SourceLocationReflection * QNameConstructor::actualReflection ( ) const
virtual

Returns this.

Reimplemented from QPatternist::Expression.

Definition at line 109 of file qqnameconstructor.cpp.

110 {
111  return m_operand.data();
112 }
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145

◆ evaluateSingleton()

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

Reimplemented from QPatternist::Expression.

Definition at line 59 of file qqnameconstructor.cpp.

60 {
61  Q_ASSERT(context);
62  const QString lexQName(m_operand->evaluateSingleton(context).stringValue());
63 
66  ReportContext::XQDY0074>(lexQName,
67  context,
69  this));
70  return toItem(QNameValue::fromValue(context->namePool(), expQName));
71 }
virtual NamePool::Ptr namePool() const =0
Item toItem(const QExplicitlySharedDataPointer< T > atomicValue)
Definition: qitem_p.h:431
static QXmlName expandQName(const QString &lexicalQName, const TReportContext &context, const NamespaceResolver::Ptr &nsResolver, const SourceLocationReflection *const r, const bool asForAttribute=false)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QNameValue::Ptr fromValue(const NamePool::Ptr &np, const QXmlName name)
Definition: qqnamevalue.cpp:59
QString stringValue() const
Returns the string value of this Item.
Definition: qitem_p.h:302
const NamespaceResolver::Ptr m_nsResolver
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

◆ expandQName()

template<typename TReportContext , const ReportContext::ErrorCode InvalidQName, const ReportContext::ErrorCode NoBinding>
QXmlName QPatternist::QNameConstructor::expandQName ( const QString lexicalQName,
const TReportContext &  context,
const NamespaceResolver::Ptr nsResolver,
const SourceLocationReflection *const  r,
const bool  asForAttribute = false 
)
static

Expands lexicalQName, which is a lexical representation of a QName such as "x:body", into a QName using nsResolver to supply the namespace bindings.

If lexicalQName is lexically invalid InvalidQName is raised via context, or if no namespace binding does not exists for a prefix(if any) in lexicalQName, NoBinding is raised via context.

If asForAttribute is true, the name is considered to be for an attribute in some way, and lexicalQName will not pick up the default namespace if it doesn't have a prefix.

nsResolver is parameterized meaning the function can be instantiated with either DynamicContext or StaticContext.

See also
QQNameValue
QXmlUtils

Definition at line 137 of file qqnameconstructor_p.h.

Referenced by QPatternist::CastAs::castToQName(), QPatternist::ElementAvailableFN::evaluateEBV(), QPatternist::SystemPropertyFN::evaluateSingleton(), QPatternist::FunctionAvailableFN::evaluateSingleton(), QPatternist::TypeAvailableFN::evaluateSingleton(), evaluateSingleton(), QPatternist::ResolveQNameFN::evaluateSingleton(), and QPatternist::yyparse().

142  {
143  Q_ASSERT(nsResolver);
144  Q_ASSERT(context);
145 
146  if(XPathHelper::isQName(lexicalQName))
147  {
148  QString prefix;
149  QString local;
150  XPathHelper::splitQName(lexicalQName, prefix, local);
151  const QXmlName::NamespaceCode nsCode = asForAttribute && prefix.isEmpty() ? QXmlName::NamespaceCode(StandardNamespaces::empty)
152  : (nsResolver->lookupNamespaceURI(context->namePool()->allocatePrefix(prefix)));
153 
154  if(nsCode == NamespaceResolver::NoBinding)
155  {
156  context->error(QtXmlPatterns::tr("No namespace binding exists for "
157  "the prefix %1 in %2").arg(formatKeyword(prefix),
158  formatKeyword(lexicalQName)),
159  NoBinding,
160  r);
161  return QXmlName(); /* Silence compiler warning. */
162  }
163  else
164  return context->namePool()->allocateQName(context->namePool()->stringForNamespace(nsCode), local, prefix);
165  }
166  else
167  {
168  context->error(QtXmlPatterns::tr("%1 is an invalid %2")
169  .arg(formatData(lexicalQName))
170  .arg(formatType(context->namePool(), BuiltinTypes::xsQName)),
171  InvalidQName,
172  r);
173  return QXmlName(); /* Silence compiler warning. */
174  }
175  }
QString formatKeyword(const QString &keyword)
qint16 NamespaceCode
Definition: qxmlname.h:82
QString formatType(const NamePool::Ptr &np, const T &type)
Formats ItemType and SequenceType.
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QString formatData(const QString &data)
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
static const AtomicType::Ptr xsQName
static void splitQName(const QString &qName, QString &prefix, QString &localName)
Splits qName into localName and prefix.
static bool isQName(const QString &qName)

◆ expectedOperandTypes()

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

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

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

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

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

Implements QPatternist::Expression.

Definition at line 97 of file qqnameconstructor.cpp.

98 {
99  SequenceType::List result;
101  return result;
102 }
static const SequenceType::Ptr ExactlyOneString
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

◆ namespaceForPrefix()

QXmlName::NamespaceCode QNameConstructor::namespaceForPrefix ( const QXmlName::PrefixCode  prefix,
const StaticContext::Ptr context,
const SourceLocationReflection *const  r 
)
static

Resolves the namespace prefix prefix to its namespace if it exists, or raised ReportContext::XPST0081 otherwise.

Returns
the namespace URI corresponding to prefix

Definition at line 73 of file qqnameconstructor.cpp.

Referenced by QPatternist::yyparse().

76 {
77  Q_ASSERT(context);
78  const QXmlName::NamespaceCode ns(context->namespaceBindings()->lookupNamespaceURI(prefix));
79 
81  {
82  context->error(QtXmlPatterns::tr("No namespace binding exists for the prefix %1")
83  .arg(formatKeyword(context->namePool()->stringForPrefix(prefix))),
85  r);
87  }
88  else
89  return ns;
90 }
QString formatKeyword(const QString &keyword)
qint16 NamespaceCode
Definition: qxmlname.h:82
virtual NamePool::Ptr namePool() const =0
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const QString & stringForPrefix(const QXmlName::PrefixCode code) const
Definition: qnamepool_p.h:174
void error(const QString &message, const ReportContext::ErrorCode errorCode, const QSourceLocation &sourceLocation)
virtual NamespaceResolver::Ptr namespaceBindings() const =0
virtual QXmlName::NamespaceCode lookupNamespaceURI(const QXmlName::PrefixCode prefix) const =0

◆ staticType()

SequenceType::Ptr QNameConstructor::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 92 of file qqnameconstructor.cpp.

93 {
95 }
static const SequenceType::Ptr ExactlyOneQName

Properties

◆ m_nsResolver

const NamespaceResolver::Ptr QPatternist::QNameConstructor::m_nsResolver
private

Definition at line 131 of file qqnameconstructor_p.h.

Referenced by evaluateSingleton(), and QNameConstructor().


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