00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef UTAP_EXPRESSION_HH
00023 #define UTAP_EXPRESSION_HH
00024
00025 #include <vector>
00026 #include <set>
00027 #include <map>
00028
00029 #include "utap/common.h"
00030 #include "utap/symbols.h"
00031 #include "utap/position.h"
00032
00033 namespace UTAP
00034 {
00068 class expression_t
00069 {
00070 private:
00071 expression_t(Constants::kind_t, const position_t &);
00072 public:
00074 expression_t();
00075
00077 expression_t(const expression_t &);
00078
00080 ~expression_t();
00081
00083 expression_t clone() const;
00084
00086 Constants::kind_t getKind() const;
00087
00089 size_t getSize() const;
00090
00092 const position_t &getPosition() const;
00093
00095 type_t getType() const;
00096
00098 void setType(type_t);
00099
00102 int32_t getValue() const;
00103
00105 int32_t getIndex() const;
00106
00108 bool empty() const;
00109
00111 Constants::synchronisation_t getSync() const;
00112
00114 std::string toString(bool old = false) const;
00115
00117 expression_t &operator[](uint32_t);
00118
00120 const expression_t operator[](uint32_t) const;
00121
00123 expression_t &get(uint32_t);
00124
00126 const expression_t &get(uint32_t) const;
00127
00129 expression_t &operator=(const expression_t &);
00130
00132 bool equal(const expression_t &) const;
00133
00144 symbol_t getSymbol();
00145
00156 void getSymbols(std::set<symbol_t> &symbols) const;
00157
00160 const symbol_t getSymbol() const;
00161
00164 bool isReferenceTo(const std::set<symbol_t> &) const;
00165
00168 bool changesVariable(const std::set<symbol_t> &) const;
00169
00171 bool changesAnyVariable() const;
00172
00175 bool dependsOn(const std::set<symbol_t> &) const;
00176
00177 void collectPossibleWrites(std::set<symbol_t> &) const;
00178 void collectPossibleReads(std::set<symbol_t> &) const;
00179
00182 bool operator < (const expression_t) const;
00183
00186 bool operator == (const expression_t) const;
00187
00188 expression_t subst(symbol_t, expression_t) const;
00189
00190 static int getPrecedence(Constants::kind_t);
00191
00193 static expression_t createConstant(int32_t, position_t = position_t());
00194
00196 static expression_t createIdentifier(symbol_t, position_t = position_t());
00197
00199 static expression_t createUnary(Constants::kind_t, expression_t,
00200 position_t = position_t(),
00201 type_t = type_t());
00203 static expression_t createBinary(Constants::kind_t,
00204 expression_t, expression_t,
00205 position_t = position_t(),
00206 type_t = type_t());
00207
00209 static expression_t createTernary(Constants::kind_t, expression_t,
00210 expression_t, expression_t,
00211 position_t = position_t(),
00212 type_t = type_t());
00213
00215 static expression_t createNary(Constants::kind_t,
00216 const std::vector<expression_t> &,
00217 position_t = position_t(),
00218 type_t = type_t());
00219
00221 static expression_t createDot(expression_t, int32_t = -1,
00222 position_t = position_t(),
00223 type_t = type_t());
00224
00226 static expression_t createSync(expression_t,
00227 Constants::synchronisation_t,
00228 position_t = position_t());
00229
00231 static expression_t createDeadlock(position_t = position_t());
00232
00233 private:
00234 struct expression_data;
00235 expression_data *data;
00236 int getPrecedence() const;
00237 void toString(bool, char *&str, char *&end, int &size) const;
00238 };
00239 }
00240
00241 std::ostream &operator<< (std::ostream &o, const UTAP::expression_t &e);
00242
00243 #endif
00244
00245
00246