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

expressionbuilder.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_EXPRESSIONBUILDER_HH
00023 #define UTAP_EXPRESSIONBUILDER_HH
00024 
00025 #include <stack>
00026 #include <vector>
00027 #include <cassert>
00028 
00029 #include "abstractbuilder.h"
00030 #include "utap.h"
00031 
00032 namespace UTAP
00033 {
00034     class ExpressionBuilder : public AbstractBuilder 
00035     {
00036     public:
00037         class ExpressionFragments 
00038         {
00039         private:
00040             std::vector<expression_t> data;
00041         public:
00042             expression_t &operator[] (int idx)
00043                 { return data[data.size() - idx - 1]; }
00044             void push(expression_t e)
00045                 { data.push_back(e); }
00046             void pop()
00047                 { data.pop_back(); }
00048             void pop(uint32_t n);
00049             uint32_t size() { return data.size(); }
00050         };
00051 
00052     protected:
00053         /* Expression stack */
00054         ExpressionFragments fragments;
00055 
00056         /* Pointer to the intermediate system under construction */
00057         TimedAutomataSystem *system;
00058 
00059         /* The stack of type fragments. A type fragment is a pair
00060          * consiting of a type and an optional name (the name is used
00061          * for fields of a structure).
00062          */
00063         class TypeFragments 
00064         {
00065         private:
00066             std::vector<std::pair<type_t, char *> > data;
00067         public:
00068             ~TypeFragments() 
00069                 { while (!data.empty()) pop(); }
00070             std::pair<type_t, char *> &operator[] (int idx)
00071                 { return data[data.size() - idx - 1]; }
00072             void push(type_t value)
00073                 { data.push_back(std::make_pair(value, (char*)NULL)); }
00074             void pop()
00075                 { assert(!data.empty()); free(data.back().second); data.pop_back(); }
00076         } typeFragments;
00077 
00078         /* Current frame */
00079         std::stack<frame_t> frames;
00080 
00081         /* Push a new frame. */
00082         void pushFrame(frame_t);
00083         
00084         /* Pop the topmost frame. */
00085         void popFrame();
00086 
00087         bool resolve(std::string, symbol_t &);
00088 
00089         expression_t makeConstant(int value);
00090 
00096         type_t applyPrefix(int32_t prefix, type_t type);
00097 
00106         virtual bool allowProcessReferences() { return false; }
00107 
00108     public:
00109         ExpressionBuilder(TimedAutomataSystem *);
00110         ExpressionFragments &getExpressions();
00111 
00112         /************************************************************
00113          * Types
00114          */
00115         virtual void typeName(int32_t prefix, const char* name, int range);
00116 
00117         /************************************************************
00118          * Query functions
00119          */
00120         virtual bool isType(const char*);
00121         virtual bool isLocation(const char*);
00122 
00123         /************************************************************
00124          * Expressions
00125          */
00126         virtual void exprTrue();
00127         virtual void exprFalse();
00128         virtual void exprId(const char * varName);
00129         virtual void exprNat(int32_t); // natural number
00130         virtual void exprCallBegin();
00131         virtual void exprCallEnd(uint32_t n); // n exprs as arguments
00132         virtual void exprArg(uint32_t n); // 1 exprs as n-th argument for fn-call
00133         virtual void exprArray(); // 2 expr 
00134         virtual void exprPostIncrement(); // 1 expr
00135         virtual void exprPreIncrement(); // 1 expr
00136         virtual void exprPostDecrement(); // 1 expr
00137         virtual void exprPreDecrement(); // 1 expr
00138         virtual void exprAssignment(Constants::kind_t op); // 2 expr
00139         virtual void exprUnary(Constants::kind_t unaryop); // 1 expr
00140         virtual void exprBinary(Constants::kind_t binaryop); // 2 expr
00141         virtual void exprInlineIf(); // 3 expr
00142         virtual void exprComma(); // 2 expr
00143         virtual void exprDot(const char *); // 1 expr
00144         virtual void exprDeadlock();
00145         virtual void exprForAllBegin(const char *name);
00146         virtual void exprForAllEnd(const char *name);
00147 
00148     };
00149 }
00150 
00151 #endif

Generated on Thu Nov 10 13:16:12 2005 for libutap by  doxygen 1.4.2