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.hh"
00030
#include "utap/symbols.hh"
00031
00032
namespace UTAP
00033 {
00067 class expression_t
00068 {
00069
private:
00070
expression_t(Constants::kind_t,
const position_t &);
00071
public:
00073
expression_t();
00074
00076
expression_t(
const expression_t &);
00077
00079
~expression_t();
00080
00082 Constants::kind_t
getKind()
const;
00083
00085 uint32_t
getSize()
const;
00086
00088
const position_t &
getPosition()
const;
00089
00091
type_t getType()
const;
00092
00094
void setType(
type_t);
00095
00098 int32_t
getValue()
const;
00099
00101 int32_t
getIndex()
const;
00102
00104
bool empty()
const;
00105
00107 Constants::synchronisation_t
getSync()
const;
00108
00110
char *
toString(
bool old =
false)
const;
00111
00113
expression_t &
operator[](uint32_t);
00114
00116
const expression_t operator[](uint32_t)
const;
00117
00119
expression_t &
get(uint32_t);
00120
00122
const expression_t &get(uint32_t)
const;
00123
00125
expression_t &
operator=(
const expression_t &);
00126
00128
bool equal(
const expression_t &)
const;
00129
00132
symbol_t getSymbol();
00133
00136
const symbol_t getSymbol()
const;
00137
00140
bool isReferenceTo(
const std::set<symbol_t> &)
const;
00141
00144
bool changesVariable(
const std::set<symbol_t> &)
const;
00145
00148
bool dependsOn(
const std::set<symbol_t> &)
const;
00149
00150
void collectPossibleWrites(std::set<symbol_t> &)
const;
00151
00153
static expression_t createConstant(
const position_t &, int32_t);
00154
00156
static expression_t createIdentifier(
const position_t &,
symbol_t);
00157
00159
static expression_t createUnary(
const position_t &, Constants::kind_t,
00160
expression_t,
type_t = type_t::UNKNOWN);
00162
static expression_t createBinary(
const position_t &, Constants::kind_t,
00163
expression_t,
expression_t,
00164
type_t = type_t::UNKNOWN);
00165
00167
static expression_t createTernary(
const position_t &,
00168 Constants::kind_t,
expression_t,
00169
expression_t,
expression_t,
00170
type_t = type_t::UNKNOWN);
00171
00173
static expression_t createNary(
const position_t &, Constants::kind_t,
00174
const std::vector<expression_t> &,
00175
type_t = type_t::UNKNOWN);
00176
00178
static expression_t createDot(
const position_t &,
expression_t,
00179 int32_t = -1,
type_t = type_t::UNKNOWN);
00180
00182
static expression_t createSync(
const position_t &,
expression_t,
00183 Constants::synchronisation_t);
00184
00186
static expression_t createDeadlock(
const position_t &);
00187
00188
private:
00189
struct expression_data;
00190 expression_data *data;
00191
int getPrecedence()
const;
00192
void toString(
bool,
char *&str,
char *&end,
int &size)
const;
00193 };
00194
00195 class InterpreterException :
public std::exception
00196 {
00197
public:
00198 const char *
what() const throw() {
return "InterpreterException"; }
00199 };
00200
00201 class Interpreter
00202 {
00203
private:
00204 std::map<symbol_t, expression_t> valuation;
00205 int32_t evaluateBinary(int32_t left, Constants::kind_t, int32_t right)
const;
00206
public:
00207
Interpreter();
00208
Interpreter(
const std::map<symbol_t, expression_t> &);
00209
00210
void addValuation(
const std::map<symbol_t, expression_t> &);
00211
00212
const std::map<symbol_t, expression_t> &
getValuation()
const;
00213
00214 int32_t
evaluate(
const expression_t)
const
00215
throw (
InterpreterException);
00216
void evaluate(
const expression_t, std::vector<int32_t> &)
const
00217
throw (
InterpreterException);
00218
range_t evaluate(
00219 std::pair<expression_t, expression_t>)
const
00220
throw (
InterpreterException);
00221
00222 int32_t
sizeOfType(
type_t)
const;
00223
00224 };
00225
00226 }
00227
00228
#endif
00229
00230
00231