00001 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; indent-tabs-mode: nil; -*- 00002 00003 /* libutap - Uppaal Timed Automata Parser. 00004 Copyright (C) 2002-2006 Uppsala University and Aalborg University. 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public License 00008 as published by the Free Software Foundation; either version 2.1 of 00009 the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, but 00012 WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00019 USA 00020 */ 00021 00022 #ifndef UTAP_SYMBOLS_HH 00023 #define UTAP_SYMBOLS_HH 00024 00025 #include <inttypes.h> 00026 #include <exception> 00027 00028 #include "utap/common.h" 00029 #include "utap/position.h" 00030 #include "utap/type.h" 00031 00032 namespace UTAP 00033 { 00034 class frame_t; 00035 class expression_t; 00036 00037 class NoParentException : public std::exception {}; 00038 00041 class range_t 00042 { 00043 public: 00044 int lower, upper; 00045 00047 range_t(); 00048 00050 range_t(int); 00051 00053 range_t(int,int); 00054 00056 range_t(const std::pair<int,int> &); 00057 00059 range_t intersect(const range_t &) const; 00060 00062 range_t join(const range_t &) const; 00063 00065 bool contains(const range_t &) const; 00066 00068 bool contains(int32_t) const; 00069 00071 bool operator == (const range_t &) const; 00072 00074 bool operator != (const range_t &) const; 00075 00077 range_t operator| (const range_t &) const; 00078 00080 range_t operator& (const range_t &) const; 00081 00083 bool isEmpty() const; 00084 00085 uint32_t size() const; 00086 }; 00087 00107 class symbol_t 00108 { 00109 private: 00110 struct symbol_data; 00111 symbol_data *data; 00112 protected: 00113 friend class frame_t; 00114 symbol_t(void *frame, type_t type, std::string name, void *user); 00115 public: 00117 symbol_t(); 00118 00120 symbol_t(const symbol_t &); 00121 00123 ~symbol_t(); 00124 00126 const symbol_t &operator = (const symbol_t &); 00127 00129 bool operator == (const symbol_t &) const; 00130 00132 bool operator != (const symbol_t &) const; 00133 00135 bool operator < (const symbol_t &) const; 00136 00138 frame_t getFrame(); 00139 00141 type_t getType() const; 00142 00144 void setType(type_t); 00145 00147 void *getData(); 00148 00150 const void *getData() const; 00151 00153 std::string getName() const; 00154 00156 void setData(void *); 00157 }; 00158 00180 class frame_t 00181 { 00182 private: 00183 struct frame_data; 00184 frame_data *data; 00185 protected: 00186 friend class symbol_t; 00187 frame_t(void *); 00188 public: 00190 frame_t(); 00191 00193 frame_t(const frame_t &); 00194 00196 ~frame_t(); 00197 00199 const frame_t &operator = (const frame_t &); 00200 00202 bool operator == (const frame_t &) const; 00203 00205 bool operator != (const frame_t &) const; 00206 00208 uint32_t getSize() const; 00209 00211 symbol_t getSymbol(int32_t); 00212 00214 int32_t getIndexOf(std::string name) const; 00215 00217 symbol_t operator[] (int32_t); 00218 00220 const symbol_t operator[] (int32_t) const; 00221 00223 symbol_t addSymbol(std::string name, type_t, void *user = NULL); 00224 00226 void add(symbol_t); 00227 00229 void add(frame_t); 00230 00232 bool resolve(std::string name, symbol_t &symbol); 00233 00235 frame_t getParent() throw (NoParentException); 00236 00238 bool hasParent() const; 00239 00241 static frame_t createFrame(); 00242 00244 static frame_t createFrame(const frame_t &parent); 00245 }; 00246 } 00247 00248 #endif