[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "qcommonnamespaces_p.h"
|
---|
| 43 |
|
---|
| 44 | #include "qcommonsequencetypes_p.h"
|
---|
| 45 | #include "qfunctionfactory_p.h"
|
---|
| 46 | #include "qgeneralcomparison_p.h"
|
---|
| 47 | #include "qliteral_p.h"
|
---|
| 48 | #include "qschemanumeric_p.h"
|
---|
| 49 | #include "qvaluecomparison_p.h"
|
---|
| 50 |
|
---|
| 51 | #include "qoptimizerblocks_p.h"
|
---|
| 52 |
|
---|
| 53 | QT_BEGIN_NAMESPACE
|
---|
| 54 |
|
---|
| 55 | using namespace QPatternist;
|
---|
| 56 |
|
---|
| 57 | ByIDIdentifier::ByIDIdentifier(const Expression::ID id) : m_id(id)
|
---|
| 58 | {
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | bool ByIDIdentifier::matches(const Expression::Ptr &expr) const
|
---|
| 62 | {
|
---|
| 63 | return expr->is(m_id);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | ComparisonIdentifier::ComparisonIdentifier(const QVector<Expression::ID> hosts,
|
---|
| 67 | const AtomicComparator::Operator op) : m_hosts(hosts),
|
---|
| 68 | m_op(op)
|
---|
| 69 | {
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | bool ComparisonIdentifier::matches(const Expression::Ptr &e) const
|
---|
| 73 | {
|
---|
| 74 | const Expression::ID eID = e->id();
|
---|
| 75 |
|
---|
| 76 | if(eID == Expression::IDGeneralComparison)
|
---|
| 77 | {
|
---|
| 78 | if(m_hosts.contains(Expression::IDGeneralComparison))
|
---|
| 79 | return e->as<GeneralComparison>()->operatorID() == m_op;
|
---|
| 80 | else
|
---|
| 81 | return false;
|
---|
| 82 | }
|
---|
| 83 | else if(eID == Expression::IDValueComparison)
|
---|
| 84 | {
|
---|
| 85 | if(m_hosts.contains(Expression::IDValueComparison))
|
---|
| 86 | return e->as<ValueComparison>()->operatorID() == m_op;
|
---|
| 87 | else
|
---|
| 88 | return false;
|
---|
| 89 | }
|
---|
| 90 | else
|
---|
| 91 | return false;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | BySequenceTypeIdentifier::BySequenceTypeIdentifier(const SequenceType::Ptr &seqType) : m_seqType(seqType)
|
---|
| 95 | {
|
---|
| 96 | Q_ASSERT(seqType);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | bool BySequenceTypeIdentifier::matches(const Expression::Ptr &expr) const
|
---|
| 100 | {
|
---|
| 101 | const SequenceType::Ptr t(expr->staticType());
|
---|
| 102 |
|
---|
| 103 | return m_seqType->itemType()->xdtTypeMatches(t->itemType())
|
---|
| 104 | &&
|
---|
| 105 | m_seqType->cardinality().isMatch(t->cardinality());
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | IntegerIdentifier::IntegerIdentifier(const xsInteger num) : m_num(num)
|
---|
| 109 | {
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | bool IntegerIdentifier::matches(const Expression::Ptr &expr) const
|
---|
| 113 | {
|
---|
| 114 | return expr->is(Expression::IDIntegerValue) &&
|
---|
| 115 | expr->as<Literal>()->item().as<Numeric>()->toInteger() == m_num;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | BooleanIdentifier::BooleanIdentifier(const bool value) : m_value(value)
|
---|
| 119 | {
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | bool BooleanIdentifier::matches(const Expression::Ptr &expr) const
|
---|
| 123 | {
|
---|
| 124 | return expr->is(Expression::IDBooleanValue) &&
|
---|
| 125 | expr->evaluateEBV(DynamicContext::Ptr()) == m_value;
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | ByIDCreator::ByIDCreator(const Expression::ID id) : m_id(id)
|
---|
| 129 | {
|
---|
| 130 | Q_ASSERT(id != Expression::IDIgnorableExpression);
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | Expression::Ptr ByIDCreator::create(const Expression::List &operands,
|
---|
| 134 | const StaticContext::Ptr &context,
|
---|
| 135 | const SourceLocationReflection *const r) const
|
---|
| 136 | {
|
---|
| 137 | return create(m_id, operands, context, r);
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | Expression::Ptr ByIDCreator::create(const Expression::ID id,
|
---|
| 141 | const Expression::List &operands,
|
---|
| 142 | const StaticContext::Ptr &context,
|
---|
| 143 | const SourceLocationReflection *const r)
|
---|
| 144 | {
|
---|
| 145 | Q_ASSERT(context);
|
---|
| 146 |
|
---|
| 147 | QXmlName::LocalNameCode fnName;
|
---|
| 148 |
|
---|
| 149 | switch(id)
|
---|
| 150 | {
|
---|
| 151 | case Expression::IDExistsFN:
|
---|
| 152 | {
|
---|
| 153 | fnName = StandardLocalNames::exists;
|
---|
| 154 | break;
|
---|
| 155 | }
|
---|
| 156 | case Expression::IDEmptyFN:
|
---|
| 157 | {
|
---|
| 158 | fnName = StandardLocalNames::empty;
|
---|
| 159 | break;
|
---|
| 160 | }
|
---|
| 161 | default:
|
---|
| 162 | {
|
---|
| 163 | Q_ASSERT_X(false, Q_FUNC_INFO,
|
---|
| 164 | "Cannot create an expression of requested type; m_id is wrong.");
|
---|
| 165 | return Expression::Ptr();
|
---|
| 166 | }
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | /* The reason we don't simply do 'new ExistsFN()' ourselves, is that all FunctionCall
|
---|
| 170 | * instances needs their FunctionSignature in order to function, and the FunctionFactories
|
---|
| 171 | * sets that. */
|
---|
| 172 | const QXmlName qName(StandardNamespaces::fn, fnName);
|
---|
| 173 |
|
---|
| 174 | const Expression::Ptr result(context->functionSignatures()->createFunctionCall(qName, operands, context, r));
|
---|
| 175 | context->wrapExpressionWith(r, result);
|
---|
| 176 | return result;
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | QT_END_NAMESPACE
|
---|