Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

expression.hh

Go to the documentation of this file.
00001 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; -*- 00002 00003 /* libutap - Uppaal Timed Automata Parser. 00004 Copyright (C) 2002-2003 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_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

Generated on Sat May 15 12:33:41 2004 for libutap by doxygen 1.3.7