Qt 4.8
qexpression_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 //
43 // W A R N I N G
44 // -------------
45 //
46 // This file is not part of the Qt API. It exists purely as an
47 // implementation detail. This header file may change from version to
48 // version without notice, or even be removed.
49 //
50 // We mean it.
51 
52 #ifndef Patternist_Expression_H
53 #define Patternist_Expression_H
54 
55 #include <QFlags>
56 #include <QSharedData>
57 
58 #include "qcppcastinghelper_p.h"
59 #include "qdebug_p.h"
60 #include "qdynamiccontext_p.h"
61 #include "qexpressiondispatch_p.h"
62 #include "qitem_p.h"
63 #include "qsequencetype_p.h"
65 #include "qstaticcontext_p.h"
66 
68 
70 
71 template<typename T> class QList;
72 template<typename T> class QVector;
73 
74 namespace QPatternist
75 {
76  template<typename T, typename ListType> class ListIterator;
77  class OptimizationPass;
78 
166  , public CppCastingHelper<Expression>
167  , public SourceLocationReflection
168  {
169  public:
174 
179 
184 
189 
192 
198  enum Property
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 
323  DependsOnLocalVariable = (1 << 11) | DisableElimination,
324 
329  EvaluationCacheRedundant = (1 << 12),
330 
340  IsNodeConstructor = 1 << 13,
341 
348  RequiresCurrentItem = 1 << 14
349  };
350 
359 
365  enum ID
366  {
370  IDBooleanValue = 1,
371 
376 
381 
386 
391 
396 
401 
408 
413 
418 
423 
428 
433 
438 
443 
448 
453 
458 
463 
477 
483 
486  IDCardinalityVerifier
487  };
488 
489  inline Expression()
490  {
491  }
492  virtual ~Expression();
493 
509  virtual Item::Iterator::Ptr evaluateSequence(const DynamicContext::Ptr &context) const;
510 
514  virtual Item evaluateSingleton(const DynamicContext::Ptr &context) const;
515 
532  virtual bool evaluateEBV(const DynamicContext::Ptr &context) const;
533 
537  virtual void evaluateToSequenceReceiver(const DynamicContext::Ptr &context) const;
538 
545  virtual Expression::List operands() const = 0;
546 
547  virtual void setOperands(const Expression::List &operands) = 0;
548 
553  virtual SequenceType::Ptr staticType() const = 0;
554 
580  virtual SequenceType::List expectedOperandTypes() const = 0;
581 
616  virtual Expression::Ptr typeCheck(const StaticContext::Ptr &context,
617  const SequenceType::Ptr &reqType);
618 
646  virtual Expression::Ptr compress(const StaticContext::Ptr &context);
647 
664  virtual Properties properties() const;
665 
670  virtual Properties dependencies() const;
671 
678  Properties deepProperties() const;
679 
688  inline bool isEvaluated() const;
689 
698  inline bool is(const ID id) const;
699 
711  inline bool has(const Property prop) const;
712 
713  inline bool hasDependency(const Property prop) const;
714 
715  virtual ExpressionVisitorResult::Ptr accept(const ExpressionVisitor::Ptr &visitor) const = 0;
716 
724  virtual ID id() const;
725 
733  virtual QList<QExplicitlySharedDataPointer<OptimizationPass> > optimizationPasses() const;
734 
746  virtual ItemType::Ptr expectedContextItemType() const;
747 
756  virtual ItemType::Ptr newFocusType() const;
757 
761  virtual const SourceLocationReflection *actualReflection() const;
762 
766  virtual QString description() const;
767 
789  virtual void announceFocusType(const ItemType::Ptr &itemType);
790 
800  static inline void rewrite(Expression::Ptr &old,
801  const Expression::Ptr &New,
802  const StaticContext::Ptr &context);
803 
809  inline const Expression::Ptr &rewrite(const Expression::Ptr &to,
810  const StaticContext::Ptr &context) const;
811 
815  virtual PatternPriority patternPriority() const;
816 
817  protected:
818 
823  virtual bool compressOperands(const StaticContext::Ptr &) = 0;
824 
825  void typeCheckOperands(const StaticContext::Ptr &context);
826 
827  private:
828  static Expression::Ptr invokeOptimizers(const Expression::Ptr &expr,
829  const StaticContext::Ptr &context);
834  inline StaticContext::Ptr finalizeStaticContext(const StaticContext::Ptr &context) const;
835 
849  Expression::Ptr constantPropagate(const StaticContext::Ptr &context) const;
850 
852  };
853 
855 
856  inline bool Expression::is(const Expression::ID i) const
857  {
858  return id() == i;
859  }
860 
861  inline bool Expression::isEvaluated() const
862  {
863  return has(IsEvaluated);
864  }
865 
866  inline bool Expression::has(const Expression::Property prop) const
867  {
868  return properties().testFlag(prop);
869  }
870 
871  inline bool Expression::hasDependency(const Expression::Property prop) const
872  {
873  return dependencies().testFlag(prop);
874  }
875 
877  const Expression::Ptr &New,
878  const StaticContext::Ptr &context)
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  }
894 
896  const StaticContext::Ptr &context) const
897  {
898  context->addLocation(to.data(), context->locationFor(this));
899  return to;
900  }
901 }
902 
904 
906 
908 
909 #endif
Q_DECLARE_TYPEINFO(QPatternist::Expression::Ptr, Q_MOVABLE_TYPE)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
Base class for all AST nodes in an XPath/XQuery/XSL-T expression.
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
Provides convenience methods for performing static casts between C++ classes.
Due to strong interdependencies, this file contains the definitions for the classes Item...
QExplicitlySharedDataPointer< const Expression > ConstPtr
A smart pointer wrapping const Expression instances.
QList< Expression::Ptr > List
QVector< Expression::Ptr > Vector
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
Contains macros for debugging.
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
bool hasDependency(const Property prop) const
bool has(const Property prop) const
T * data() const
Returns a pointer to the shared data object.
Definition: qshareddata.h:145
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
static void rewrite(Expression::Ptr &old, const Expression::Ptr &New, const StaticContext::Ptr &context)
The QAbstractXmlForwardIterator class is a base class for forward iterators.
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
The namespace for the internal API of QtXmlPatterns.
QExplicitlySharedDataPointer< Expression > Ptr
A smart pointer wrapping mutable Expression instances.
QFlags< Property > Properties
Represents an item in the XPath 2.0 Data Model.
Definition: qitem_p.h:182
The QSharedData class is a base class for shared data objects.
Definition: qshareddata.h:56
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
The QFlags class provides a type-safe way of storing OR-combinations of enum values.
Definition: qglobal.h:2313
xsDouble PatternPriority
#define QT_END_HEADER
Definition: qglobal.h:137
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
Base class for all instances that represents something at a certain location.
QNoDebug pDebug()
Definition: qdebug_p.h:99