00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef UTAP_SYMBOLS_HH
00023 #define UTAP_SYMBOLS_HH
00024
00025 #include <inttypes.h>
00026 #include <exception>
00027
00028 namespace UTAP
00029 {
00030 class frame_t;
00031 class type_t;
00032 class expression_t;
00033
00034 class NoParentException : public std::exception {};
00035
00038 class range_t {
00039 public:
00040 int lower, upper;
00041
00043 range_t();
00044
00046 range_t(int);
00047
00049 range_t(int,int);
00050
00052 range_t(const std::pair<int,int> &);
00053
00055 range_t intersect(const range_t &) const;
00056
00058 range_t join(const range_t &) const;
00059
00061 bool contains(const range_t &) const;
00062
00064 bool contains(int32_t) const;
00065
00067 bool operator == (const range_t &) const;
00068
00070 bool operator != (const range_t &) const;
00071
00073 range_t operator| (const range_t &) const;
00074
00076 range_t operator& (const range_t &) const;
00077
00079 bool isEmpty() const;
00080
00081 uint32_t size() const;
00082 };
00083
00084
00104 class symbol_t
00105 {
00106 private:
00107 struct symbol_data;
00108 symbol_data *data;
00109 protected:
00110 friend class frame_t;
00111 symbol_t(void *frame, type_t &type, std::string name, void *user);
00112 public:
00114 symbol_t();
00115
00117 symbol_t(const symbol_t &);
00118
00120 ~symbol_t();
00121
00123 const symbol_t &operator = (const symbol_t &);
00124
00126 bool operator == (const symbol_t &) const;
00127
00129 bool operator != (const symbol_t &) const;
00130
00132 bool operator < (const symbol_t &) const;
00133
00135 frame_t getFrame();
00136
00138 type_t getType() const;
00139
00141 void setType(type_t);
00142
00144 void *getData();
00145
00147 const void *getData() const;
00148
00150 std::string getName() const;
00151
00153 void setData(void *);
00154 };
00155
00177 class frame_t
00178 {
00179 private:
00180 struct frame_data;
00181 frame_data *data;
00182 protected:
00183 friend class symbol_t;
00184 frame_t(void *);
00185 public:
00187 frame_t();
00188
00190 frame_t(const frame_t &);
00191
00193 ~frame_t();
00194
00196 const frame_t &operator = (const frame_t &);
00197
00199 bool operator == (const frame_t &) const;
00200
00202 bool operator != (const frame_t &) const;
00203
00205 uint32_t getSize() const;
00206
00208 symbol_t getSymbol(int32_t);
00209
00211 int32_t getIndexOf(std::string name) const;
00212
00214 symbol_t operator[] (int32_t);
00215
00217 const symbol_t operator[] (int32_t) const;
00218
00220 symbol_t addSymbol(std::string name, type_t, void *user = NULL);
00221
00223 void add(frame_t);
00224
00226 bool resolve(std::string name, symbol_t &symbol);
00227
00229 frame_t getParent() throw (NoParentException);
00230
00232 bool hasParent() const;
00233
00235 static frame_t createFrame();
00236
00238 static frame_t createFrame(const frame_t &parent);
00239 };
00240
00241 namespace prefix {
00242 enum prefix_t {
00243 URGENT = 1,
00244 COMMITTED = 2,
00245 CONSTANT = 4,
00246 BROADCAST = 8,
00247 REFERENCE = 16,
00248 META = 32,
00249 WINNING = 64,
00250 LOSING = 128
00251 };
00252 }
00253
00281 class type_t
00282 {
00283 private:
00284 struct type_data;
00285 type_data *data;
00286 type_t(void *);
00287 public:
00289 type_t();
00290
00292 type_t(const type_t &);
00293
00295 ~type_t();
00296
00298 const type_t &operator = (const type_t &);
00299
00301 bool operator == (const type_t &) const;
00302
00304 bool operator != (const type_t &) const;
00305
00307 type_t getBase() const;
00308
00310 frame_t getRecordFields() const;
00311
00313 frame_t getParameters() const;
00314
00316 frame_t getFrame() const;
00317
00319 type_t getSub();
00320
00322 type_t getReturnType();
00323
00325 bool hasPrefix(prefix::prefix_t) const;
00326
00328 type_t setPrefix(bool set, prefix::prefix_t) const;
00329
00331 type_t getArraySize() const;
00332
00334 std::pair<expression_t, expression_t> getRange() const;
00335
00337 std::string toString();
00338
00340 bool isInteger() const {
00341 return getBase() == type_t::INT;
00342 }
00343
00345 bool isValue() const {
00346 return getBase() == type_t::INT || getBase() == type_t::BOOL;
00347 }
00348
00350 bool isScalar() const {
00351 return getBase() == type_t::SCALAR || isInteger();
00352 }
00353
00355 bool isClock() const {
00356 return getBase() == type_t::CLOCK;
00357 }
00358
00360 bool isRecord() const {
00361 return getBase() == type_t::RECORD;
00362 }
00363
00365 bool isDiff() const {
00366 return getBase() == type_t::DIFF;
00367 }
00368
00369
00371 bool isVoid() const {
00372 return getBase() == type_t::VOID_TYPE;
00373 }
00374
00375
00376 bool isInvariant() const {
00377 return getBase() == type_t::INVARIANT || isValue();
00378 }
00379
00380
00381 bool isGuard() const {
00382 return getBase() == type_t::GUARD || isInvariant();
00383 }
00384
00385
00386
00387
00388 bool isConstraint() const {
00389 return getBase() == type_t::CONSTRAINT || isGuard();
00390 }
00391
00392 bool isArray() const {
00393 return getBase() == type_t::ARRAY;
00394 }
00395
00397 static type_t createInteger(expression_t, expression_t);
00398
00400 static type_t createScalarSet(expression_t, expression_t);
00401
00403 static type_t createRecord(frame_t);
00404
00406 static type_t createFunction(frame_t, type_t);
00407
00409 static type_t createArray(type_t, type_t);
00410
00412 static type_t createTypeName(type_t);
00413
00415 static type_t createTemplate(frame_t);
00416
00418 static type_t createProcess(frame_t);
00419
00421 static type_t createBase();
00422
00423 static type_t UNKNOWN;
00424 static type_t VOID_TYPE;
00425 static type_t CLOCK;
00426 static type_t INT;
00427 static type_t BOOL;
00428 static type_t SCALAR;
00429 static type_t LOCATION;
00430 static type_t CHANNEL;
00431 static type_t TEMPLATE;
00432 static type_t INSTANCE;
00433 static type_t FUNCTION;
00434 static type_t ARRAY;
00435 static type_t RECORD;
00436 static type_t PROCESS;
00437 static type_t NTYPE;
00438 static type_t INVARIANT;
00439 static type_t INVARIANT_WR;
00440 static type_t GUARD;
00441 static type_t DIFF;
00442 static type_t CONSTRAINT;
00443 static type_t COST;
00444 static type_t RATE;
00445 };
00446 }
00447
00448 std::ostream &operator << (std::ostream &o, UTAP::type_t t);
00449
00450 #endif