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

systembuilder.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_SYSTEMBUILDER_HH
00023 #define UTAP_SYSTEMBUILDER_HH
00024 
00025 #include <cassert>
00026 #include <vector>
00027 #include <inttypes.h>
00028 
00029 #include "utap/builder.hh"
00030 #include "utap/utap.hh"
00031 
00032 namespace UTAP
00033 {
00034 
00073     class SystemBuilder : public ParserBuilder
00074     {
00075     protected:
00076         // Error message for unsupported features
00077         static const char *const unsupported;
00078         static const char *const invalid_type;
00079 
00080         /* Flag used to determine how strict we check for inclusion 
00081            between ranges of integers. TODO: Replace this with a
00082            system, which reports a warning if there is a potential
00083            overflow. */
00084         bool strict_range;
00085 
00086         /* Pointer to the intermediate system under construction */
00087         TimedAutomataSystem *system;
00088 
00089         /* A pointer to the error handler */
00090         ErrorHandler *errorHandler;
00091 
00092         position_t position;
00093         
00094     private:
00095         //
00096         // The stack of expression fragments.
00097         //
00098         class ExpressionFragments 
00099         {
00100         private:
00101             std::vector<expression_t> data;
00102         public:
00103             expression_t &operator[] (int idx)
00104                 { return data[data.size() - idx - 1]; }
00105             void push(expression_t e)
00106                 { data.push_back(e); }
00107             void pop()
00108                 { data.pop_back(); }
00109             void pop(int n);
00110             uint32_t size() { return data.size(); }
00111         } fragments;
00112 
00113         //
00114         // The stack of type fragments. A type fragment is a pair
00115         // consiting of a type and an optional name (the name is 
00116         // used for fields of a structure).
00117         //
00118         class TypeFragments 
00119         {
00120         private:
00121             std::vector<std::pair<type_t, char *> > data;
00122         public:
00123             ~TypeFragments() 
00124                 { while (!data.empty()) pop(); }
00125             std::pair<type_t, char *> &operator[] (int idx)
00126                 { return data[data.size() - idx - 1]; }
00127             void push(type_t value)
00128                 { data.push_back(std::make_pair(value, (char*)NULL)); }
00129             void pop()
00130                 { assert(!data.empty()); free(data.back().second); data.pop_back(); }
00131         } typeFragments;
00132 
00133         // 
00134         // Support for handling template and function parameters
00135         //
00136 
00137         /* The params vector is used temporarily during parameter parsing */
00138         frame_t params;
00139 
00140         /* Current frame */
00141         frame_t frame;
00142 
00143         /* current parsing function structure */
00144         function_t *currentFun;
00145 
00146         /* stack of function body statement blocks */
00147         std::vector<BlockStatement*> blocks; 
00148 
00149         //
00150         // Fields for handling transition labels
00151         //
00152         int32_t guard;
00153         int32_t sync;
00154         int32_t update;
00155 
00156         //
00157         // Fields for function call and template instantiation handling
00158         //
00159         
00160         /* list of expected arguments */
00161         std::list<std::vector<type_t> > expectedArguments;
00162 
00163         /* stack of function or template symbols */
00164         std::vector<symbol_t> identifierStack;
00165 
00166         //
00167         // Method for handling types
00168         //
00169 
00170         type_t buildArrayType(type_t type, uint32_t dim);
00171         type_t getElementTypeOfArray(type_t type);
00172         type_t applyPrefix(uint32_t prefix, type_t type);
00173 
00174         //
00175         // Methods for handling expressions
00176         //
00177 
00178         expression_t makeConstant(int value);
00179 
00180     protected:
00181 
00183         // allowProcessReferences()
00185         // If this method returns true, it is allowed to access the 
00186         // private identifiers of a process by prefixing the identifier
00187         // with the process name. 
00188         //
00189         // This is only interesting when parsing properties. In this case
00190         // the method should be overridden by a sub class.
00191         virtual bool allowProcessReferences() { return false; }
00192 
00194         // property()
00196         // This method is called once for each property, which has
00197         // been parsed. The default implementation does nothing, so
00198         // you need to override this in a subclass.
00199         virtual void property(Constants::kind_t, int line, expression_t) {};
00200 
00201     public:
00202 
00203         SystemBuilder(TimedAutomataSystem *);
00204 
00205         virtual void setErrorHandler(ErrorHandler *);
00206         virtual void setPosition(const position_t &);
00207 
00208         /************************************************************
00209          * Query functions
00210          */
00211         virtual bool isType(const char*);
00212         virtual bool isLocation(const char*);
00213 
00214         /************************************************************
00215          * Types
00216          */
00217         virtual void declType(uint32_t prefix, const char* name, bool range);
00218         // 2 expr if range==true
00219         virtual void declStruct(uint32_t prefix, uint32_t fields);
00220         virtual void declField(const char* name, uint32_t dim); 
00221         // 1 type and dim array sizes
00222         virtual void declFieldEnd();
00223         virtual void declTypeDef(const char* name, uint32_t dim); 
00224         // 1 type and dim array sizes
00225         virtual void declTypeDefEnd();
00226 
00227         /************************************************************
00228          * Variable declarations
00229          */
00230         virtual void declVar(const char* name, uint32_t dim, bool init); 
00231         // 1 type, dims, initializer if init==true
00232         virtual void declVarEnd();
00233         virtual void declInitialiserList(uint32_t num); // n initialisers
00234         virtual void declFieldInit(const char* name); // 1 initialiser
00235     
00236         /************************************************************
00237          * Function declarations
00238          */
00239         virtual void declParameter(const char* name, bool reference, uint32_t dim);
00240         // 1 type, dim array sizes
00241         virtual void declParameterEnd(); // pop parameter type
00242     
00243         virtual void declFuncBegin(const char* name, uint32_t n); // n paramaters
00244         virtual void declFuncEnd(); // 1 block
00245 
00246         /************************************************************
00247          * Process declarations
00248          */
00249         virtual void procBegin(const char* name, uint32_t n); // n parameters
00250         virtual void procEnd(); // 1 ProcBody
00251         virtual void procState(const char* name, bool hasInvariant); // 1 expr
00252         virtual void procStateCommit(const char* name); // mark previously decl. state
00253         virtual void procStateUrgent(const char* name); // mark previously decl. state
00254         virtual void procStateInit(const char* name); // mark previously decl. state
00255         virtual void procTransition(const char* from, const char* to); 
00256         // 1 epxr,1sync,1expr
00257         virtual void procGuard();
00258         virtual void procSync(Constants::synchronisation_t type); // 1 expr
00259         virtual void procUpdate();
00260     
00261         /************************************************************
00262          * Statements
00263          */
00264         virtual void blockBegin();
00265         virtual void blockEnd();
00266         virtual void emptyStatement();
00267         virtual void forBegin();
00268         virtual void forEnd(); // 3 expr, 1 stat
00269         virtual void whileBegin();
00270         virtual void whileEnd(); // 1 expr, 1 stat
00271         virtual void doWhileBegin();
00272         virtual void doWhileEnd(); // 1 stat, 1 expr
00273         virtual void ifBegin();
00274         virtual void ifElse();
00275         virtual void ifEnd(bool); // 1 expr, 1 or 2 statements
00276         virtual void breakStatement();
00277         virtual void continueStatement();
00278         virtual void switchBegin();
00279         virtual void switchEnd(); // 1 expr, 1+ case/default
00280         virtual void caseBegin();
00281         virtual void caseEnd();  // 1 expr, 0+ stat
00282         virtual void defaultBegin();
00283         virtual void defaultEnd(); // 0+ statements
00284         virtual void exprStatement(); // 1 expr
00285         virtual void returnStatement(bool); // 1 expr if argument is true
00286     
00287         /************************************************************
00288          * Expressions
00289          */
00290         virtual void exprTrue();
00291         virtual void exprFalse();
00292         virtual void exprId(const char * varName);
00293         virtual void exprNat(int32_t); // natural number
00294         virtual void exprCallBegin(const char * functionName);
00295         virtual void exprCallEnd(uint32_t n); // n exprs as arguments
00296         virtual void exprArg(uint32_t n); // 1 exprs as n-th argument for fn-call
00297         virtual void exprArray(); // 2 expr 
00298         virtual void exprPostIncrement(); // 1 expr
00299         virtual void exprPreIncrement(); // 1 expr
00300         virtual void exprPostDecrement(); // 1 expr
00301         virtual void exprPreDecrement(); // 1 expr
00302         virtual void exprAssignment(Constants::kind_t op); // 2 expr
00303         virtual void exprUnary(Constants::kind_t unaryop); // 1 expr
00304         virtual void exprBinary(Constants::kind_t binaryop); // 2 expr
00305         virtual void exprInlineIf(); // 3 expr
00306         virtual void exprComma(); // 2 expr
00307         virtual void exprDot(const char *); // 1 expr
00308         virtual void exprDeadlock();
00309     
00310         /************************************************************
00311          * System declaration
00312          */
00313         virtual void instantiationBegin(const char*, const char*);
00314         virtual void instantiationEnd(const char *, const char *, uint32_t n); // n arguments
00315         virtual void process(const char*);
00316 
00317         virtual void done();    
00318 
00319         virtual void property(Constants::kind_t, int line);
00320 
00321         /********************************************************************
00322          * Guiding
00323          */
00324 
00325         virtual void beforeUpdate();
00326         virtual void afterUpdate();
00327     };
00328 }
00329 #endif

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