author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtXmlPatterns module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** |
|
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. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
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_VariableDeclaration_H |
|
53 |
#define Patternist_VariableDeclaration_H |
|
54 |
||
55 |
#include <QSharedData> |
|
56 |
||
57 |
#include "qexpression_p.h" |
|
58 |
#include "qpatternistlocale_p.h" |
|
59 |
#include "qvariablereference_p.h" |
|
60 |
||
61 |
QT_BEGIN_HEADER |
|
62 |
||
63 |
QT_BEGIN_NAMESPACE |
|
64 |
||
65 |
template<typename T> class QStack; |
|
66 |
||
67 |
namespace QPatternist |
|
68 |
{ |
|
69 |
/** |
|
70 |
* @short Represents a declared variable. Only used at |
|
71 |
* the compilation stage. |
|
72 |
* |
|
73 |
* @see FunctionArgument |
|
74 |
* @author Frans Englich <frans.englich@nokia.com> |
|
75 |
* @ingroup Patternist_expressions |
|
76 |
*/ |
|
77 |
class VariableDeclaration : public QSharedData |
|
78 |
{ |
|
79 |
public: |
|
80 |
typedef QExplicitlySharedDataPointer<VariableDeclaration> Ptr; |
|
81 |
typedef QStack<VariableDeclaration::Ptr> Stack; |
|
82 |
typedef QList<VariableDeclaration::Ptr> List; |
|
83 |
||
84 |
/** |
|
85 |
* @short The key is the variable name. |
|
86 |
*/ |
|
87 |
typedef QHash<QXmlName, VariableDeclaration::Ptr> Hash; |
|
88 |
||
89 |
enum Type |
|
90 |
{ |
|
91 |
RangeVariable, |
|
92 |
ExpressionVariable, |
|
93 |
FunctionArgument, |
|
94 |
PositionalVariable, |
|
95 |
TemplateParameter, |
|
96 |
||
97 |
/** |
|
98 |
* A global variable is always an external variable, but it is |
|
99 |
* cached differently. |
|
100 |
* |
|
101 |
* @see DynamicContext::globalItemCacheCell() |
|
102 |
*/ |
|
103 |
GlobalVariable, |
|
104 |
||
105 |
/** |
|
106 |
* External variables doesn't use slots, that's a big difference |
|
107 |
* compared to the other types. |
|
108 |
*/ |
|
109 |
ExternalVariable |
|
110 |
}; |
|
111 |
||
112 |
/** |
|
113 |
* Creates a VariableDeclaration. |
|
114 |
* |
|
115 |
* @p sourceExpr and @p seqType may be @c null. |
|
116 |
*/ |
|
117 |
VariableDeclaration(const QXmlName n, |
|
118 |
const VariableSlotID varSlot, |
|
119 |
const Type t, |
|
120 |
const SequenceType::Ptr &seqType) : name(n) |
|
121 |
, slot(varSlot) |
|
122 |
, type(t) |
|
123 |
, sequenceType(seqType) |
|
124 |
, canSourceRewrite(true) |
|
125 |
{ |
|
126 |
Q_ASSERT(!name.isNull()); |
|
127 |
Q_ASSERT(t == ExternalVariable || t == TemplateParameter || varSlot > -1); |
|
128 |
} |
|
129 |
||
130 |
inline bool isUsed() const |
|
131 |
{ |
|
132 |
return !references.isEmpty(); |
|
133 |
} |
|
134 |
||
135 |
inline const Expression::Ptr &expression() const |
|
136 |
{ |
|
137 |
return m_expression; |
|
138 |
} |
|
139 |
||
140 |
inline void setExpression(const Expression::Ptr &expr) |
|
141 |
{ |
|
142 |
m_expression = expr; |
|
143 |
} |
|
144 |
||
145 |
/** |
|
146 |
* @short Returns how many times this variable is used. |
|
147 |
*/ |
|
148 |
inline bool usedByMany() const |
|
149 |
{ |
|
150 |
return references.count() > 1; |
|
151 |
} |
|
152 |
||
153 |
/** |
|
154 |
* @short Returns @c true if @p list contains @p lookup. |
|
155 |
*/ |
|
156 |
static bool contains(const VariableDeclaration::List &list, |
|
157 |
const QXmlName &lookup); |
|
158 |
||
159 |
const QXmlName name; |
|
160 |
const VariableSlotID slot; |
|
161 |
const Type type; |
|
162 |
||
163 |
/** |
|
164 |
* The declared type of the variable. What the value might be, depends |
|
165 |
* on the context which VariableDeclaration is used in. Note that |
|
166 |
* sequenceType is hence not in anyway obligated to the type of |
|
167 |
* expression(). |
|
168 |
*/ |
|
169 |
const SequenceType::Ptr sequenceType; |
|
170 |
VariableReference::List references; |
|
171 |
||
172 |
/** |
|
173 |
* @short Whether a reference can rewrite itself to expression(). |
|
174 |
* |
|
175 |
* The default value is @c true. |
|
176 |
*/ |
|
177 |
bool canSourceRewrite; |
|
178 |
||
179 |
private: |
|
180 |
Expression::Ptr m_expression; |
|
181 |
Q_DISABLE_COPY(VariableDeclaration) |
|
182 |
}; |
|
183 |
||
184 |
/** |
|
185 |
* @short Formats @p var appropriately for display. |
|
186 |
* |
|
187 |
* @relates VariableDeclaration |
|
188 |
*/ |
|
189 |
static inline QString formatKeyword(const VariableDeclaration::Ptr &var, |
|
190 |
const NamePool::Ptr &np) |
|
191 |
{ |
|
192 |
Q_ASSERT(var); |
|
193 |
Q_ASSERT(np); |
|
194 |
return formatKeyword(np->displayName(var->name)); |
|
195 |
} |
|
196 |
||
197 |
} |
|
198 |
||
199 |
QT_END_NAMESPACE |
|
200 |
||
201 |
QT_END_HEADER |
|
202 |
||
203 |
#endif |