Qt 4.8
Public Types | Public Functions | Static Public Functions | Public Variables | Properties | Related Functions | List of all members
QPatternist::VariableDeclaration Class Reference

Represents a declared variable. Only used at the compilation stage. More...

#include <qvariabledeclaration_p.h>

Inheritance diagram for QPatternist::VariableDeclaration:
QSharedData

Public Types

typedef QHash< QXmlName, VariableDeclaration::PtrHash
 The key is the variable name. More...
 
typedef QList< VariableDeclaration::PtrList
 
typedef QExplicitlySharedDataPointer< VariableDeclarationPtr
 
typedef QStack< VariableDeclaration::PtrStack
 
enum  Type {
  RangeVariable, ExpressionVariable, FunctionArgument, PositionalVariable,
  TemplateParameter, GlobalVariable, ExternalVariable
}
 

Public Functions

const Expression::Ptrexpression () const
 
bool isUsed () const
 
void setExpression (const Expression::Ptr &expr)
 
bool usedByMany () const
 Returns how many times this variable is used. More...
 
 VariableDeclaration (const QXmlName n, const VariableSlotID varSlot, const Type t, const SequenceType::Ptr &seqType)
 
- 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...
 

Static Public Functions

static bool contains (const VariableDeclaration::List &list, const QXmlName &lookup)
 Returns true if list contains lookup. More...
 

Public Variables

bool canSourceRewrite
 Whether a reference can rewrite itself to expression(). More...
 
const QXmlName name
 
VariableReference::List references
 
const SequenceType::Ptr sequenceType
 
const VariableSlotID slot
 
const Type type
 
- Public Variables inherited from QSharedData
QAtomicInt ref
 

Properties

Expression::Ptr m_expression
 

Related Functions

(Note that these are not member functions.)

static QString formatKeyword (const VariableDeclaration::Ptr &var, const NamePool::Ptr &np)
 Formats var appropriately for display. More...
 

Detailed Description

Represents a declared variable. Only used at the compilation stage.

See also
FunctionArgument
Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 77 of file qvariabledeclaration_p.h.

Typedefs

◆ Hash

The key is the variable name.

Definition at line 87 of file qvariabledeclaration_p.h.

◆ List

Definition at line 82 of file qvariabledeclaration_p.h.

◆ Ptr

Definition at line 80 of file qvariabledeclaration_p.h.

◆ Stack

Definition at line 81 of file qvariabledeclaration_p.h.

Enumerations

◆ Type

Enumerator
RangeVariable 
ExpressionVariable 
FunctionArgument 
PositionalVariable 
TemplateParameter 
GlobalVariable 

A global variable is always an external variable, but it is cached differently.

See also
DynamicContext::globalItemCacheCell()
ExternalVariable 

External variables doesn't use slots, that's a big difference compared to the other types.

Definition at line 89 of file qvariabledeclaration_p.h.

Constructors and Destructors

◆ VariableDeclaration()

QPatternist::VariableDeclaration::VariableDeclaration ( const QXmlName  n,
const VariableSlotID  varSlot,
const Type  t,
const SequenceType::Ptr seqType 
)
inline

Creates a VariableDeclaration.

sourceExpr and seqType may be null.

Definition at line 117 of file qvariabledeclaration_p.h.

120  : 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  }
bool canSourceRewrite
Whether a reference can rewrite itself to expression().
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isNull() const
Returns true if this QXmlName is not initialized with a valid combination of {namespace URI}...
Definition: qxmlname.cpp:224

Functions

◆ contains()

bool VariableDeclaration::contains ( const VariableDeclaration::List list,
const QXmlName lookup 
)
static

Returns true if list contains lookup.

Definition at line 48 of file qvariabledeclaration.cpp.

Referenced by QPatternist::CallTemplate::typeCheck(), usedByMany(), and QPatternist::yyparse().

50 {
53 
54  for(; it != end; ++it)
55  {
56  if((*it)->name == lookup)
57  return true;
58  }
59 
60  return false;
61 }
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
static const KeyPair *const end
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ expression()

const Expression::Ptr& QPatternist::VariableDeclaration::expression ( ) const
inline

◆ isUsed()

bool QPatternist::VariableDeclaration::isUsed ( ) const
inline

Definition at line 130 of file qvariabledeclaration_p.h.

131  {
132  return !references.isEmpty();
133  }
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152

◆ setExpression()

void QPatternist::VariableDeclaration::setExpression ( const Expression::Ptr expr)
inline

Definition at line 140 of file qvariabledeclaration_p.h.

141  {
142  m_expression = expr;
143  }

◆ usedByMany()

bool QPatternist::VariableDeclaration::usedByMany ( ) const
inline

Returns how many times this variable is used.

Definition at line 148 of file qvariabledeclaration_p.h.

149  {
150  return references.count() > 1;
151  }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891

Friends and Related Functions

◆ formatKeyword()

static QString formatKeyword ( const VariableDeclaration::Ptr var,
const NamePool::Ptr np 
)
related

Formats var appropriately for display.

Definition at line 189 of file qvariabledeclaration_p.h.

Referenced by QPatternist::AbstractFloatMathematician< isDouble >::calculate(), and QPatternist::ComparisonPlatform< IndexOfIterator, false >::fetchComparator().

191  {
192  Q_ASSERT(var);
193  Q_ASSERT(np);
194  return formatKeyword(np->displayName(var->name));
195  }
static QString formatKeyword(const VariableDeclaration::Ptr &var, const NamePool::Ptr &np)
Formats var appropriately for display.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

Properties

◆ canSourceRewrite

bool QPatternist::VariableDeclaration::canSourceRewrite

Whether a reference can rewrite itself to expression().

The default value is true.

Definition at line 177 of file qvariabledeclaration_p.h.

Referenced by QPatternist::ExpressionVariableReference::typeCheck().

◆ m_expression

Expression::Ptr QPatternist::VariableDeclaration::m_expression
private

Definition at line 180 of file qvariabledeclaration_p.h.

Referenced by expression(), and setExpression().

◆ name

const QXmlName QPatternist::VariableDeclaration::name

◆ references

VariableReference::List QPatternist::VariableDeclaration::references

Definition at line 170 of file qvariabledeclaration_p.h.

Referenced by isUsed(), and usedByMany().

◆ sequenceType

const SequenceType::Ptr QPatternist::VariableDeclaration::sequenceType

The declared type of the variable. What the value might be, depends on the context which VariableDeclaration is used in. Note that sequenceType is hence not in anyway obligated to the type of expression().

Definition at line 169 of file qvariabledeclaration_p.h.

Referenced by QPatternist::TemplateParameterReference::staticType().

◆ slot

const VariableSlotID QPatternist::VariableDeclaration::slot

Definition at line 160 of file qvariabledeclaration_p.h.

◆ type

const Type QPatternist::VariableDeclaration::type

Definition at line 161 of file qvariabledeclaration_p.h.

Referenced by QPatternist::checkVariableCircularity().


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