Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound 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 
00151         static expression_t createConstant(const position_t &, int32_t);
00152 
00154         static expression_t createIdentifier(const position_t &, symbol_t);
00155 
00157         static expression_t createUnary(const position_t &, Constants::kind_t,
00158                                         expression_t, type_t = type_t::UNKNOWN);
00160         static expression_t createBinary(const position_t &, Constants::kind_t,
00161                                          expression_t, expression_t,
00162                                          type_t = type_t::UNKNOWN);
00163 
00165         static expression_t createTernary(const position_t &,
00166                                           Constants::kind_t, expression_t, 
00167                                           expression_t, expression_t,
00168                                           type_t = type_t::UNKNOWN);
00169 
00171         static expression_t createNary(const position_t &, Constants::kind_t, 
00172                                        const std::vector<expression_t> &,
00173                                        type_t = type_t::UNKNOWN);
00174 
00176         static expression_t createDot(const position_t &, expression_t,
00177                                       int32_t = -1, type_t = type_t::UNKNOWN);
00178 
00180         static expression_t createSync(const position_t &, expression_t, 
00181                                        Constants::synchronisation_t);
00182 
00184         static expression_t createDeadlock(const position_t &);
00185 
00186     private:
00187         struct expression_data;
00188         expression_data *data;
00189         int getPrecedence() const;
00190         std::pair<int, char*> toString_(bool) const;
00191     };
00192 
00193     class InterpreterException : public std::exception
00194     {
00195     public:
00196         const char *what() const throw() { return "InterpreterException"; }
00197     };
00198 
00199     class Interpreter
00200     {
00201     private:
00202         std::map<symbol_t, expression_t> valuation;
00203         int32_t evaluateBinary(int32_t left, Constants::kind_t, int32_t right) const;
00204     public:
00205         Interpreter();
00206         Interpreter(const std::map<symbol_t, expression_t> &);
00207 
00208         void addValuation(const std::map<symbol_t, expression_t> &);
00209 
00210         const std::map<symbol_t, expression_t> &getValuation() const;
00211 
00212         int32_t evaluate(const expression_t) const
00213             throw (InterpreterException);
00214         void evaluate(const expression_t, std::vector<int32_t> &) const
00215             throw (InterpreterException);
00216         range_t evaluate(
00217             std::pair<expression_t, expression_t>) const
00218             throw (InterpreterException);
00219 
00220         int32_t sizeOfType(type_t) const;
00221 
00222     };
00223 
00224 }
00225 
00226 #endif
00227 
00228 
00229 

Generated on Wed Jul 2 12:08:18 2003 for libutap by doxygen 1.3.2