Qt 4.8
Public Functions | Static Public Functions | Static Private Functions | List of all members
QPatternist::NCNameConstructor Class Reference

Ensures the lexical space of the string value of the Item returned from its child Expression is an NCName. More...

#include <qncnameconstructor_p.h>

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

Public Functions

virtual ExpressionVisitorResult::Ptr accept (const ExpressionVisitor::Ptr &visitor) const
 
virtual Item evaluateSingleton (const DynamicContext::Ptr &) const
 
virtual SequenceType::List expectedOperandTypes () const
 
 NCNameConstructor (const Expression::Ptr &source)
 
virtual SequenceType::Ptr staticType () const
 
virtual Expression::Ptr typeCheck (const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
 
- 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 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 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 ()
 
- 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 NameIsXML, const ReportContext::ErrorCode LexicallyInvalid>
static void validateTargetName (const QString &lexicalNCName, const TReportContext &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)
 

Static Private Functions

static const QString nameIsXML (const QString &lexTarget)
 

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

Ensures the lexical space of the string value of the Item returned from its child Expression is an NCName.

Note
It doesn't actually construct an xs:NCName. It only ensures the lexical space is an NCName. The atomic value can be of any string type, such as xs:untypedAtomic of xs:string.
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 76 of file qncnameconstructor_p.h.

Constructors and Destructors

◆ NCNameConstructor()

NCNameConstructor::NCNameConstructor ( const Expression::Ptr source)

Definition at line 52 of file qncnameconstructor.cpp.

52  : SingleContainer(source)
53 {
54 }
SingleContainer(const Expression::Ptr &operand)

Functions

◆ accept()

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

Implements QPatternist::Expression.

Definition at line 91 of file qncnameconstructor.cpp.

92 {
93  return visitor->visit(this);
94 }

◆ evaluateSingleton()

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

Reimplemented from QPatternist::Expression.

Definition at line 56 of file qncnameconstructor.cpp.

57 {
58  Q_ASSERT(context);
59  /* Apply the whitespace facet for when casting to xs:NCName. */
60  const QString lexNCName(m_operand->evaluateSingleton(context).stringValue().trimmed());
61 
64  ReportContext::XQDY0041>(lexNCName,
65  context,
66  this);
67  return AtomicString::fromValue(lexNCName);
68 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static AtomicString::Ptr fromValue(const QString &value)
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
Definition: qstring.cpp:4506
QString stringValue() const
Returns the string value of this Item.
Definition: qitem_p.h:302
static void validateTargetName(const QString &lexicalNCName, const TReportContext &context, const SourceLocationReflection *const r)
QExplicitlySharedDataPointer< DynamicContext > Ptr
virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const

◆ expectedOperandTypes()

SequenceType::List NCNameConstructor::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 84 of file qncnameconstructor.cpp.

85 {
86  SequenceType::List result;
88  return result;
89 }
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

◆ nameIsXML()

static const QString QPatternist::NCNameConstructor::nameIsXML ( const QString lexTarget)
inlinestaticprivate

This translation string is put here in order to avoid duplicate messages and hence reduce work for translators and increase consistency.

Definition at line 111 of file qncnameconstructor_p.h.

Referenced by validateTargetName().

112  {
113  return QtXmlPatterns::tr("The target name in a processing instruction "
114  "cannot be %1 in any combination of upper "
115  "and lower case. Therefore, %2 is invalid.")
116  .arg(formatKeyword("xml"), formatKeyword(lexTarget));
117  }
QString formatKeyword(const QString &keyword)

◆ staticType()

SequenceType::Ptr NCNameConstructor::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 79 of file qncnameconstructor.cpp.

80 {
82 }
static const SequenceType::Ptr ExactlyOneString

◆ typeCheck()

Expression::Ptr NCNameConstructor::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 70 of file qncnameconstructor.cpp.

72 {
73  if(BuiltinTypes::xsNCName->xdtTypeMatches(m_operand->staticType()->itemType()))
74  return m_operand->typeCheck(context, reqType);
75  else
76  return SingleContainer::typeCheck(context, reqType);
77 }
virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context, const SequenceType::Ptr &reqType)
Definition: qexpression.cpp:70
virtual SequenceType::Ptr staticType() const =0
static const AtomicType::Ptr xsNCName
virtual ItemType::Ptr itemType() const =0

◆ validateTargetName()

template<typename TReportContext , const ReportContext::ErrorCode NameIsXML, const ReportContext::ErrorCode LexicallyInvalid>
void QPatternist::NCNameConstructor::validateTargetName ( const QString lexicalNCName,
const TReportContext &  context,
const SourceLocationReflection *const  r 
)
inlinestatic

Validates lexicalNCName as a processing instruction's target name, and raise an error if it's not an NCName.

Definition at line 124 of file qncnameconstructor_p.h.

Referenced by evaluateSingleton(), and QPatternist::yyparse().

127  {
128  Q_ASSERT(context);
129 
130  if(QXmlUtils::isNCName(lexicalTarget))
131  {
132  if(QString::compare(QLatin1String("xml"), lexicalTarget, Qt::CaseInsensitive) == 0)
133  context->error(nameIsXML(lexicalTarget), NameIsXML, r);
134  }
135  else
136  {
137  context->error(QtXmlPatterns::tr("%1 is not a valid target name in "
138  "a processing instruction. It "
139  "must be a %2 value, e.g. %3.")
140  .arg(formatKeyword(lexicalTarget))
141  .arg(formatType(context->namePool(),
143  .arg(formatKeyword("my-name.123")),
144  LexicallyInvalid,
145  r);
146  }
147  }
static const QString nameIsXML(const QString &lexTarget)
QString formatKeyword(const QString &keyword)
QString formatType(const NamePool::Ptr &np, const T &type)
Formats ItemType and SequenceType.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int compare(const QString &s) const
Definition: qstring.cpp:5037
static const AtomicType::Ptr xsNCName
static bool isNCName(const QStringRef &ncName)
Determines whether c is a valid instance of production [4]NCName in the XML 1.0 Namespaces specificat...
Definition: qxmlutils.cpp:377

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