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

systembuilder.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-2004 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_SYSTEMBUILDER_H
00023 #define UTAP_SYSTEMBUILDER_H
00024 
00025 #include <cassert>
00026 #include <vector>
00027 #include <inttypes.h>
00028 
00029 #include "utap/expressionbuilder.h"
00030 #include "utap/utap.h"
00031 
00032 namespace UTAP
00033 {
00068     class SystemBuilder : public ExpressionBuilder
00069     {
00070     protected:
00071         // Error message for unsupported features
00072         static const char *const unsupported;
00073         static const char *const invalid_type;
00074 
00075         /* Flag used to determine how strict we check for inclusion 
00076            between ranges of integers. TODO: Replace this with a
00077            system, which reports a warning if there is a potential
00078            overflow. */
00079         bool strict_range;
00080 
00081         /* The current priority level, used when declaring process or
00082          * channel priorities.
00083          */
00084         int32_t currentPriority;
00085     private:
00086 
00087         //
00088         // The stack of type fragments. A type fragment is a pair
00089         // consiting of a type and an optional name (the name is 
00090         // used for fields of a structure).
00091         //
00092         class TypeFragments 
00093         {
00094         private:
00095             std::vector<std::pair<type_t, char *> > data;
00096         public:
00097             ~TypeFragments() 
00098                 { while (!data.empty()) pop(); }
00099             std::pair<type_t, char *> &operator[] (int idx)
00100                 { return data[data.size() - idx - 1]; }
00101             void push(type_t value)
00102                 { data.push_back(std::make_pair(value, (char*)NULL)); }
00103             void pop()
00104                 { assert(!data.empty()); free(data.back().second); data.pop_back(); }
00105         } typeFragments;
00106 
00107         // 
00108         // Support for handling template and function parameters
00109         //
00110 
00111         /* The params vector is used temporarily during parameter parsing */
00112         frame_t params;
00113 
00114         /* current parsing function structure */
00115         function_t *currentFun;
00116 
00117         template_t *currentTemplate;
00118 
00119         /* stack of function body statement blocks */
00120         std::vector<BlockStatement*> blocks; 
00121 
00122         //
00123         // Fields for handling edge labels
00124         //
00125         int32_t guard;
00126         int32_t sync;
00127         int32_t update;
00128 
00129         //
00130         // Method for handling types
00131         //
00132 
00133         type_t buildArrayType(type_t type, uint32_t dim);
00134         type_t getElementTypeOfArray(type_t type);
00135         type_t applyPrefix(int32_t prefix, type_t type);
00136         declarations_t *getCurrentDeclarationBlock();
00137 
00138     public:
00139 
00140         SystemBuilder(TimedAutomataSystem *);
00141 
00142         /************************************************************
00143          * Types
00144          */
00145         virtual void typeName(int32_t prefix, const char* name, int range);
00146         // 2 expr if range==true
00147         virtual void typeStruct(int32_t prefix, uint32_t fields);
00148 
00149         virtual void structField(const char* name, uint32_t dim); 
00150         // 1 type and dim array sizes
00151         virtual void structFieldEnd();
00152 
00153         virtual void declTypeDef(const char* name, uint32_t dim); 
00154         // 1 type and dim array sizes
00155         virtual void declTypeDefEnd();
00156 
00157         /************************************************************
00158          * Variable declarations
00159          */
00160         virtual void declVar(const char* name, uint32_t dim, bool init); 
00161         // 1 type, dims, initializer if init==true
00162         virtual void declVarEnd();
00163         virtual void declInitialiserList(uint32_t num); // n initialisers
00164         virtual void declFieldInit(const char* name); // 1 initialiser
00165 
00166         /************************************************************
00167          * Guarded progress measure
00168          */
00169         virtual void declProgress(bool);
00170     
00171         /************************************************************
00172          * Function declarations
00173          */
00174         virtual void declParameter(const char* name, bool reference, uint32_t dim);
00175         // 1 type, dim array sizes
00176         virtual void declParameterEnd(); // pop parameter type
00177     
00178         virtual void declFuncBegin(const char* name, uint32_t n); // n paramaters
00179         virtual void declFuncEnd(); // 1 block
00180 
00181         /************************************************************
00182          * Process declarations
00183          */
00184         virtual void procBegin(const char* name, uint32_t n); // n parameters
00185         virtual void procEnd(); // 1 ProcBody
00186         virtual void procState(const char* name, bool hasInvariant); // 1 expr
00187         virtual void procStateCommit(const char* name); // mark previously decl. state
00188         virtual void procStateUrgent(const char* name); // mark previously decl. state
00189         virtual void procStateInit(const char* name); // mark previously decl. state
00190         virtual void procEdge(const char* from, const char* to); 
00191         // 1 epxr,1sync,1expr
00192         virtual void procGuard();
00193         virtual void procSync(Constants::synchronisation_t type); // 1 expr
00194         virtual void procUpdate();
00195     
00196         /************************************************************
00197          * Statements
00198          */
00199         virtual void blockBegin();
00200         virtual void blockEnd();
00201         virtual void emptyStatement();
00202         virtual void forBegin();
00203         virtual void forEnd(); // 3 expr, 1 stat
00204         virtual void whileBegin();
00205         virtual void whileEnd(); // 1 expr, 1 stat
00206         virtual void doWhileBegin();
00207         virtual void doWhileEnd(); // 1 stat, 1 expr
00208         virtual void ifBegin();
00209         virtual void ifElse();
00210         virtual void ifEnd(bool); // 1 expr, 1 or 2 statements
00211         virtual void breakStatement();
00212         virtual void continueStatement();
00213         virtual void switchBegin();
00214         virtual void switchEnd(); // 1 expr, 1+ case/default
00215         virtual void caseBegin();
00216         virtual void caseEnd();  // 1 expr, 0+ stat
00217         virtual void defaultBegin();
00218         virtual void defaultEnd(); // 0+ statements
00219         virtual void exprStatement(); // 1 expr
00220         virtual void returnStatement(bool); // 1 expr if argument is true
00221 
00222         /************************************************************
00223          * Expressions
00224          */     
00225         virtual void exprCallBegin(const char *);
00226     
00227         /************************************************************
00228          * System declaration
00229          */
00230         virtual void instantiationBegin(const char*, const char*);
00231         virtual void instantiationEnd(const char *, const char *, uint32_t n); // n arguments
00232         virtual void process(const char*);
00233 
00234         virtual void done();    
00235 
00236         /********************************************************************
00237          * Guiding
00238          */
00239 
00240         virtual void beforeUpdate();
00241         virtual void afterUpdate();
00242 
00243         /********************************************************************
00244          * Priority
00245          */
00246 
00247         virtual void lowPriority(const char*);
00248         virtual void samePriority(const char*);
00249         virtual void higherPriority(const char*);
00250     };
00251 }
00252 #endif

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