libutap
expression.h
Go to the documentation of this file.
1 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 
3 /* libutap - Uppaal Timed Automata Parser.
4  Copyright (C) 2002-2006 Uppsala University and Aalborg University.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public License
8  as published by the Free Software Foundation; either version 2.1 of
9  the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  USA
20 */
21 
22 #ifndef UTAP_EXPRESSION_HH
23 #define UTAP_EXPRESSION_HH
24 
25 #include <vector>
26 #include <set>
27 #include <map>
28 
29 #include "utap/common.h"
30 #include "utap/symbols.h"
31 #include "utap/position.h"
32 
33 namespace UTAP
34 {
68  class expression_t
69  {
70  private:
72  public:
74  expression_t();
75 
77  expression_t(const expression_t &);
78 
80  ~expression_t();
81 
82  bool usesFP() const;
83  bool usesClock() const;
84  bool isDynamic() const;
85  bool hasDynamicSub() const;
87  expression_t clone() const;
88 
90  expression_t deeperClone() const;
91 
94  expression_t deeperClone(symbol_t from, symbol_t to) const;
95 
98  expression_t deeperClone(frame_t frame, frame_t select = frame_t()) const;
99 
101  Constants::kind_t getKind() const;
102 
104  size_t getSize() const;
105 
107  const position_t &getPosition() const;
108 
110  type_t getType() const;
111 
113  void setType(type_t);
114 
117  int32_t getValue() const;
118 
120  int32_t getIndex() const;
121 
124  double getDoubleValue() const;
125 
127  bool empty() const;
128 
131 
133  std::string toString(bool old = false) const;
134 
136  expression_t &operator[](uint32_t);
137 
139  const expression_t operator[](uint32_t) const;
140 
142  expression_t &get(uint32_t);
143 
145  const expression_t &get(uint32_t) const;
146 
149 
151  bool equal(const expression_t &) const;
152 
164 
175  void getSymbols(std::set<symbol_t> &symbols) const;
176 
179  const symbol_t getSymbol() const;
180 
183  bool isReferenceTo(const std::set<symbol_t> &) const;
184 
187  bool changesVariable(const std::set<symbol_t> &) const;
188 
190  bool changesAnyVariable() const;
191 
194  bool dependsOn(const std::set<symbol_t> &) const;
195 
196  void collectPossibleWrites(std::set<symbol_t> &) const;
197  void collectPossibleReads(std::set<symbol_t> &, bool collectRandom = false) const;
198 
201  bool operator < (const expression_t) const;
202 
205  bool operator == (const expression_t) const;
206 
208 
209  static int getPrecedence(Constants::kind_t);
210 
212  static expression_t createConstant(int32_t, position_t = position_t());
213 
214  static expression_t createDouble(double, position_t = position_t());
215 
218 
222  type_t = type_t());
223 
228  type_t = type_t());
229 
234  type_t = type_t());
235 
238  const std::vector<expression_t> &,
240  type_t = type_t());
241 
243  static expression_t createDot(expression_t, int32_t = -1,
244  position_t = position_t(),
245  type_t = type_t());
246 
250  position_t = position_t());
251 
254 
256 
257  // true if empty or equal to 1.
258  bool isTrue() const;
259 
260  private:
261  struct expression_data;
262  expression_data *data;
263  int getPrecedence() const;
264  void toString(bool, char *&str, char *&end, int &size) const;
265  void appendBoundType(char *&str, char*&end, int &size, expression_t e) const;
266  };
267 }
268 
269 std::ostream &operator<< (std::ostream &o, const UTAP::expression_t &e);
270 
271 #endif
272 
273 
274 
bool isTrue() const
Definition: expression.cpp:561
static expression_t createBinary(Constants::kind_t, expression_t, expression_t, position_t=position_t(), type_t=type_t())
Create a binary expression.
Definition: expression.cpp:2061
A reference to a symbol.
Definition: symbols.h:107
bool equal(const expression_t &) const
Equality operator.
Definition: expression.cpp:570
Constants::synchronisation_t getSync() const
Returns the synchronisation type of SYNC operations.
Definition: expression.cpp:526
expression_t deeperClone() const
Makes a deep clone of the expression.
Definition: expression.cpp:101
bool isDynamic() const
Definition: expression.cpp:278
size_t getSize() const
Returns the number of subexpression.
Definition: expression.cpp:328
bool dependsOn(const std::set< symbol_t > &) const
True if the evaluation of this expression depends on any of the symbols in the given set...
Definition: expression.cpp:763
double getDoubleValue() const
Returns the value field of this expression.
Definition: expression.cpp:514
Definition: lexer.cc:585
bool hasDynamicSub() const
Definition: expression.cpp:302
kind_t
Definition: common.h:37
static expression_t createDeadlock(position_t=position_t())
Create a DEADLOCK expression.
Definition: expression.cpp:2107
A reference to a frame.
Definition: symbols.h:183
bool empty() const
Returns true if this is an empty expression.
Definition: expression.cpp:556
void collectPossibleWrites(std::set< symbol_t > &) const
Definition: expression.cpp:1891
int32_t getIndex() const
Returns the index field of this expression.
Definition: expression.cpp:520
expression_t subst(symbol_t, expression_t) const
Definition: expression.cpp:167
synchronisation_t
Definition: common.h:263
static expression_t createDouble(double, position_t=position_t())
Definition: expression.cpp:2014
bool isReferenceTo(const std::set< symbol_t > &) const
Returns true if this expression is a reference to a symbol in the given set.
Definition: expression.cpp:740
bool operator==(const expression_t) const
Equality operator.
Definition: expression.cpp:1863
static expression_t createIdentifier(symbol_t, position_t=position_t())
Create an IDENTIFIER expression.
Definition: expression.cpp:2022
A reference to an expression.
Definition: expression.h:68
type_t
Definition: tracer.cpp:51
static expression_t createSync(expression_t, Constants::synchronisation_t, position_t=position_t())
Create a SYNC expression.
Definition: expression.cpp:2097
static expression_t createExit(position_t=position_t())
Definition: expression.cpp:2006
int32_t getValue() const
Returns the value field of this expression.
Definition: expression.cpp:508
static expression_t createConstant(int32_t, position_t=position_t())
Create a CONSTANT expression.
Definition: expression.cpp:1998
static int getPrecedence(Constants::kind_t)
Definition: expression.cpp:777
Definition: position.h:42
static expression_t createTernary(Constants::kind_t, expression_t, expression_t, expression_t, position_t=position_t(), type_t=type_t())
Create a ternary expression.
Definition: expression.cpp:2073
bool changesVariable(const std::set< symbol_t > &) const
True if this expression can change any of the variables identified by the given symbols.
Definition: expression.cpp:748
bool usesFP() const
Definition: expression.cpp:217
const position_t & getPosition() const
Returns the position of this expression.
Definition: expression.cpp:211
bool usesClock() const
Definition: expression.cpp:257
bool operator<(const expression_t) const
Less-than operator.
Definition: expression.cpp:1858
expression_t()
Default constructor.
Definition: expression.cpp:63
A reference to a type.
Definition: type.h:92
Constants::kind_t getKind() const
Returns the kind of the expression.
Definition: expression.cpp:205
bool changesAnyVariable() const
True if this expression can change any variable at all.
Definition: expression.cpp:756
std::ostream & operator<<(std::ostream &o, const UTAP::expression_t &e)
void setType(type_t)
Sets the type of the expression.
Definition: expression.cpp:502
std::string toString(bool old=false) const
Returns a string representation of the expression.
Definition: expression.cpp:1872
expression_t & operator[](uint32_t)
Returns the ith subexpression.
Definition: expression.cpp:532
static expression_t createUnary(Constants::kind_t, expression_t, position_t=position_t(), type_t=type_t())
Create a unary expression.
Definition: expression.cpp:2051
expression_t & operator=(const expression_t &)
Assignment operator.
Definition: expression.cpp:596
static expression_t createDot(expression_t, int32_t=-1, position_t=position_t(), type_t=type_t())
Create a DOT expression.
Definition: expression.cpp:2086
symbol_t getSymbol()
Returns the symbol of a variable reference.
Definition: expression.cpp:622
static expression_t createNary(Constants::kind_t, const std::vector< expression_t > &, position_t=position_t(), type_t=type_t())
Create an n-ary expression.
Definition: expression.cpp:2037
expression_t clone() const
Make a shallow clone of the expression.
Definition: expression.cpp:87
void collectPossibleReads(std::set< symbol_t > &, bool collectRandom=false) const
Definition: expression.cpp:1953
void getSymbols(std::set< symbol_t > &symbols) const
Returns the set of symbols this expression might resolve into.
Definition: expression.cpp:679
type_t getType() const
Returns the type of the expression.
Definition: expression.cpp:496
~expression_t()
Destructor.
Definition: expression.cpp:192