libutap  0.93
Uppaal Timed Automata Parser
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) 2011-2018 Aalborg University.
5  Copyright (C) 2002-2006 Uppsala University and Aalborg University.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public License
9  as published by the Free Software Foundation; either version 2.1 of
10  the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful, but
13  WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20  USA
21 */
22 
23 #ifndef UTAP_EXPRESSION_HH
24 #define UTAP_EXPRESSION_HH
25 
26 #include "utap/common.h"
27 #include "utap/symbols.h"
28 #include "utap/position.h"
29 
30 #include <vector>
31 #include <set>
32 #include <map>
33 #include <memory>
34 
35 namespace UTAP
36 {
71  {
72  private:
74  public:
77 
79  expression_t(const expression_t &);
80 
83 
85  ~expression_t();
86 
87  bool usesFP() const;
88  bool usesClock() const;
89  bool isDynamic() const;
90  bool hasDynamicSub() const;
92  expression_t clone() const;
93 
95  expression_t deeperClone() const;
96 
99  expression_t deeperClone(symbol_t from, symbol_t to) const;
100 
103  expression_t deeperClone(frame_t frame, frame_t select = frame_t()) const;
104 
106  Constants::kind_t getKind() const;
107 
109  size_t getSize() const;
110 
112  const position_t &getPosition() const;
113 
115  type_t getType() const;
116 
118  void setType(type_t);
119 
122  int32_t getValue() const;
123 
125  int32_t getIndex() const;
126 
129  double getDoubleValue() const;
130 
132  bool empty() const;
133 
136 
138  std::string toString(bool old = false) const;
139 
141  expression_t &operator[](uint32_t);
142 
144  const expression_t operator[](uint32_t) const;
145 
147  expression_t &get(uint32_t);
148 
150  const expression_t &get(uint32_t) const;
151 
153  bool equal(const expression_t &) const;
154 
166 
177  void getSymbols(std::set<symbol_t> &symbols) const;
178 
181  const symbol_t getSymbol() const;
182 
185  bool isReferenceTo(const std::set<symbol_t> &) const;
186 
189  bool changesVariable(const std::set<symbol_t> &) const;
190 
192  bool changesAnyVariable() const;
193 
196  bool dependsOn(const std::set<symbol_t> &) const;
197 
198  void collectPossibleWrites(std::set<symbol_t> &) const;
199  void collectPossibleReads(std::set<symbol_t> &, bool collectRandom = false) const;
200 
203  bool operator < (const expression_t) const;
204 
207  bool operator == (const expression_t) const;
208 
210 
211  static int getPrecedence(Constants::kind_t);
212 
214  static expression_t createConstant(int32_t, position_t = position_t());
215 
216  static expression_t createDouble(double, position_t = position_t());
217 
220 
224  type_t = type_t());
225 
230  type_t = type_t());
231 
236  type_t = type_t());
237 
240  const std::vector<expression_t> &,
242  type_t = type_t());
243 
245  static expression_t createDot(expression_t, int32_t = -1,
247  type_t = type_t());
248 
252  position_t = position_t());
253 
256 
258 
259  // true if empty or equal to 1.
260  bool isTrue() const;
261 
262  private:
263  struct expression_data;
264  std::shared_ptr<expression_data> data;
265  int getPrecedence() const;
266  void toString(bool, char *&str, char *&end, int &size) const;
267  void appendBoundType(char *&str, char*&end, int &size, expression_t e) const;
268  };
269 }
270 
271 std::ostream &operator<< (std::ostream &o, const UTAP::expression_t &e);
272 
273 #endif
static expression_t createDouble(double, position_t=position_t())
expression_t()
Default constructor.
Definition: expression.h:76
Constants::kind_t getKind() const
Returns the kind of the expression.
Definition: expression.cpp:182
void getSymbols(std::set< symbol_t > &symbols) const
Returns the set of symbols this expression might resolve into.
Definition: expression.cpp:775
static expression_t createExit(position_t=position_t())
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:844
int32_t getIndex() const
Returns the index field of this expression.
Definition: expression.cpp:635
bool empty() const
Returns true if this is an empty expression.
Definition: expression.cpp:671
expression_t clone() const
Make a shallow clone of the expression.
Definition: expression.cpp:81
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.
A reference to a symbol.
Definition: symbols.h:107
symbol_t getSymbol()
Returns the symbol of a variable reference.
Definition: expression.cpp:718
bool usesClock() const
Definition: expression.cpp:308
double getDoubleValue() const
Returns the value field of this expression.
Definition: expression.cpp:629
bool usesFP() const
Definition: expression.cpp:211
expression_t & operator=(const expression_t &)
Assignment operator.
Definition: expression.cpp:75
expression_t & operator[](uint32_t)
Returns the ith subexpression.
Definition: expression.cpp:647
static expression_t createDot(expression_t, int32_t=-1, position_t=position_t(), type_t=type_t())
Create a DOT expression.
expression_t subst(symbol_t, expression_t) const
Definition: expression.cpp:153
static expression_t createUnary(Constants::kind_t, expression_t, position_t=position_t(), type_t=type_t())
Create a unary expression.
std::ostream & operator<<(std::ostream &os, const SignalFlow::strs_t &s)
Definition: signalflow.h:189
const position_t & getPosition() const
Returns the position of this expression.
Definition: expression.cpp:188
std::string toString(bool old=false) const
Returns a string representation of the expression.
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.
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:859
A reference to a frame.
Definition: symbols.h:183
void collectPossibleWrites(std::set< symbol_t > &) const
A reference to a type.
Definition: type.h:93
static expression_t createDeadlock(position_t=position_t())
Create a DEADLOCK expression.
static int getPrecedence(Constants::kind_t)
Definition: expression.cpp:873
expression_t deeperClone() const
Makes a deep clone of the expression.
Definition: expression.cpp:92
A reference to an expression.
Definition: expression.h:70
bool hasDynamicSub() const
Definition: expression.cpp:353
bool isDynamic() const
Definition: expression.cpp:329
type_t getType() const
Returns the type of the expression.
Definition: expression.cpp:611
int32_t getValue() const
Returns the value field of this expression.
Definition: expression.cpp:623
size_t getSize() const
Returns the number of subexpression.
Definition: expression.cpp:379
~expression_t()
Destructor.
Definition: expression.cpp:178
Definition: lexer.cc:817
static expression_t createSync(expression_t, Constants::synchronisation_t, position_t=position_t())
Create a SYNC expression.
bool isTrue() const
Definition: expression.cpp:676
static expression_t createConstant(int32_t, position_t=position_t())
Create a CONSTANT expression.
void setType(type_t)
Sets the type of the expression.
Definition: expression.cpp:617
Constants::synchronisation_t getSync() const
Returns the synchronisation type of SYNC operations.
Definition: expression.cpp:641
static expression_t createBinary(Constants::kind_t, expression_t, expression_t, position_t=position_t(), type_t=type_t())
Create a binary expression.
void collectPossibleReads(std::set< symbol_t > &, bool collectRandom=false) const
bool operator<(const expression_t) const
Less-than operator.
static expression_t createIdentifier(symbol_t, position_t=position_t())
Create an IDENTIFIER expression.
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:836
bool operator==(const expression_t) const
Equality operator.
bool equal(const expression_t &) const
Equality operator.
Definition: expression.cpp:685
bool changesAnyVariable() const
True if this expression can change any variable at all.
Definition: expression.cpp:852