Qt 4.8
|
Evaluates to the same result as its operand, but ensures the operand is evaluated once even if this Expression is evaluated several times. More...
#include <qevaluationcache_p.h>
Static Private Functions | |
static DynamicContext::Ptr | topFocusContext (const DynamicContext::Ptr &context) |
Properties | |
const VariableDeclaration * | m_declaration |
bool | m_declarationUsedByMany |
const VariableSlotID | m_varSlot |
Evaluates to the same result as its operand, but ensures the operand is evaluated once even if this Expression is evaluated several times.
EvaluationCache does this in a pipelined way, by delivering items from its cache, which is stored in the DynamicContext. If the cache has less items than what the caller requests, EvaluationCache continues to deliver but this time from the source, which it also populates into the cache.
EvaluationCache is used as an optimization in order to avoid running expensive code paths multiple times, but also is sometimes a necessity: for instance, when objects must be unique, such as potentially in the case of node identity.
EvaluationCache is in particular used for variables, whose sole purpose is to store it once(at least conceptually) and then use it in multiple places.
In some cases an EvaluationCache isn't necessary. For instance, when a variable is only referenced once. In those cases EvaluationCache removes itself as an optimization; implemented in compress().
Definition at line 96 of file qevaluationcache_p.h.
QPatternist::EvaluationCache< IsForGlobal >::EvaluationCache | ( | const Expression::Ptr & | operand, |
const VariableDeclaration * | varDecl, | ||
const VariableSlotID | slot | ||
) |
Definition at line 49 of file qevaluationcache.cpp.
|
virtual |
Implements QPatternist::Expression.
Definition at line 263 of file qevaluationcache.cpp.
|
virtual |
Returns this
.
Reimplemented from QPatternist::Expression.
Definition at line 269 of file qevaluationcache.cpp.
|
virtual |
compress() is the last stage performs in compiling an expression, done after the initial AST build and calling typeCheck(). compress() performs crucial simplifications, either by having drastic performance implications or that some expressions depend on it for proper behavior.
The default implementation performs a sparse conditional constant propagation. In short, a recursive process is performed in the AST which examines if the Expression's operands are constant values, and if so, performs a const fold(AST rewrite) into the result of evaluating the expression in question. This default behavior can be disabled by letting properties() return DisableElimination.
This compress() stage can be relative effective due to the design of XPath, in part because intrinsic functions are heavily used. Many Expressions override compress() and do optimizations specific to what they do. Also, many Expressions performs optimizations in their typeCheck().
context | the static context. Supplies compile time information, and is the channel for communicating error messages. |
Reimplemented from QPatternist::Expression.
Definition at line 191 of file qevaluationcache.cpp.
|
virtual |
Evaluate this Expression by iterating over it. This is a central function for evaluating expressions.
Expressions must always always return a valid QAbstractXmlForwardIterator and may never return 0. If an empty result is of interest to be returned, the EmptyIterator should be returned.
The default implementation returns a SingletonIterator over the item returned from evaluateSingleton().
We don't use makeListIterator() here because the MIPSPro compiler can't handle it.
We don't use makeListIterator() here because the MIPSPro compiler can't handle it.
Reimplemented from QPatternist::Expression.
Definition at line 108 of file qevaluationcache.cpp.
|
virtual |
Reimplemented from QPatternist::Expression.
Definition at line 76 of file qevaluationcache.cpp.
|
virtual |
The first operand must be exactly one xs:string
.
Implements QPatternist::Expression.
Definition at line 232 of file qevaluationcache.cpp.
|
virtual |
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.
Reimplemented from QPatternist::Expression.
Definition at line 251 of file qevaluationcache.cpp.
|
inline |
Definition at line 120 of file qevaluationcache_p.h.
|
virtual |
Implements QPatternist::Expression.
Definition at line 226 of file qevaluationcache.cpp.
|
staticprivate |
Definition at line 59 of file qevaluationcache.cpp.
Referenced by QPatternist::EvaluationCache< IsForGlobal >::evaluateSequence(), QPatternist::EvaluationCache< IsForGlobal >::evaluateSingleton(), and QPatternist::EvaluationCache< IsForGlobal >::slot().
|
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.
context | supplies 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. |
reqType | the static type that this Expression must match when evaluated. reqType is guaranteed by the caller to never null. |
reqType
Reimplemented from QPatternist::Expression.
Definition at line 152 of file qevaluationcache.cpp.
|
private |
Definition at line 127 of file qevaluationcache_p.h.
|
private |
Definition at line 128 of file qevaluationcache_p.h.
Referenced by QPatternist::EvaluationCache< IsForGlobal >::compress().
|
private |
This variable must not be called m_slot. If it so, a compiler bug on HP-UX-aCC-64 is triggered in the constructor initializor. See the preprocessor output.
Note that this is the cache slot, and is disjoint to any variable's regular slot.
Definition at line 137 of file qevaluationcache_p.h.
Referenced by QPatternist::EvaluationCache< IsForGlobal >::evaluateSequence(), QPatternist::EvaluationCache< IsForGlobal >::evaluateSingleton(), QPatternist::EvaluationCache< IsForGlobal >::EvaluationCache(), and QPatternist::EvaluationCache< IsForGlobal >::slot().