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

expression.h

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.h"
00030 #include "utap/symbols.h"
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         std::string 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 
00154         bool operator < (const expression_t) const;
00155  
00158         bool operator == (const expression_t) const;
00159  
00160         static int getPrecedence(Constants::kind_t); 
00161 
00163         static expression_t createConstant(const position_t &, int32_t);
00164 
00166         static expression_t createIdentifier(const position_t &, symbol_t);
00167 
00169         static expression_t createUnary(const position_t &, Constants::kind_t,
00170                                         expression_t, type_t = type_t::UNKNOWN);
00172         static expression_t createBinary(const position_t &, Constants::kind_t,
00173                                          expression_t, expression_t,
00174                                          type_t = type_t::UNKNOWN);
00175 
00177         static expression_t createTernary(const position_t &,
00178                                           Constants::kind_t, expression_t, 
00179                                           expression_t, expression_t,
00180                                           type_t = type_t::UNKNOWN);
00181 
00183         static expression_t createNary(const position_t &, Constants::kind_t, 
00184                                        const std::vector<expression_t> &,
00185                                        type_t = type_t::UNKNOWN);
00186 
00188         static expression_t createDot(const position_t &, expression_t,
00189                                       int32_t = -1, type_t = type_t::UNKNOWN);
00190 
00192         static expression_t createSync(const position_t &, expression_t, 
00193                                        Constants::synchronisation_t);
00194 
00196         static expression_t createDeadlock(const position_t &);
00197 
00198     private:
00199         struct expression_data;
00200         expression_data *data;
00201         int getPrecedence() const;
00202         void toString(bool, char *&str, char *&end, int &size) const;
00203     };
00204 
00205     class InterpreterException : public std::exception
00206     {
00207     public:
00208         const char *what() const throw() { return "InterpreterException"; }
00209     };
00210 
00211     class Interpreter
00212     {
00213     private:
00214         std::map<symbol_t, expression_t> valuation;
00215         int32_t evaluateBinary(int32_t left, Constants::kind_t, int32_t right) const;
00216     public:
00217         Interpreter();
00218         Interpreter(const std::map<symbol_t, expression_t> &);
00219 
00220         void addValuation(const std::map<symbol_t, expression_t> &);
00221 
00222         const std::map<symbol_t, expression_t> &getValuation() const;
00223 
00224         int32_t evaluate(const expression_t) const
00225             throw (InterpreterException);
00226         void evaluate(const expression_t, std::vector<int32_t> &) const
00227             throw (InterpreterException);
00228         range_t evaluate(
00229             std::pair<expression_t, expression_t>) const
00230             throw (InterpreterException);
00231 
00232         size_t sizeOfType(type_t) const;
00233 
00234     };
00235 
00236 }
00237 
00238 std::ostream &operator<< (std::ostream &o, const UTAP::expression_t &e);
00239 
00240 #endif
00241 
00242 
00243 

Generated on Thu Feb 17 15:20:58 2005 for libutap by  doxygen 1.4.1