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

system.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-2006 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_INTERMEDIATE_HH
00023 #define UTAP_INTERMEDIATE_HH
00024 
00025 #include <list>
00026 #include <vector>
00027 #include <map>
00028 #include <exception>
00029 
00030 #include "utap/symbols.h"
00031 #include "utap/expression.h"
00032 #include "utap/position.h"
00033 
00034 namespace UTAP
00035 {
00040     struct variable_t
00041     {
00042         symbol_t uid;      
00043         expression_t expr; 
00044     };
00045 
00052     struct state_t
00053     {
00054         symbol_t uid;           
00055         expression_t invariant; 
00056         expression_t costrate;  
00057         int32_t locNr;          
00058     };
00059 
00064     struct edge_t
00065     {
00066         int nr;                 
00067         bool control;           
00068         state_t *src;           
00069         state_t *dst;           
00070         frame_t select;         
00071         expression_t guard;     
00072         expression_t assign;    
00073         expression_t sync;      
00074     };
00075 
00076     class BlockStatement; // Forward declaration
00077 
00081     struct function_t
00082     {
00083         symbol_t uid;                
00084         std::set<symbol_t> changes;  
00085         std::set<symbol_t> depends;  
00086         std::list<variable_t> variables; 
00087         BlockStatement *body;        
00088         function_t() : body(NULL) {}
00089         ~function_t();
00090     };
00091 
00092     struct progress_t
00093     {
00094         expression_t guard;
00095         expression_t measure;
00096     };
00097 
00102     struct declarations_t
00103     {
00104         frame_t frame;
00105         std::list<variable_t> variables;        
00106         std::list<function_t> functions;        
00107         std::list<progress_t> progress;         
00110         bool addFunction(type_t type, std::string, function_t *&);
00111     };
00112 
00142     struct instance_t
00143     {
00144         symbol_t uid;                             
00145         frame_t parameters;                       
00146         std::map<symbol_t, expression_t> mapping; 
00147         size_t arguments;
00148         size_t unbound;
00149         struct template_t *templ;
00150         std::set<symbol_t> restricted;          
00151     };
00152 
00157     struct template_t : public instance_t, declarations_t
00158     {
00159         symbol_t init;                          
00160         frame_t templateset;                    
00161         std::list<state_t> states;              
00162         std::list<edge_t> edges;                
00165         state_t &addLocation(std::string, expression_t inv);
00166 
00168         edge_t &addEdge(symbol_t src, symbol_t dst, bool type);
00169     };
00170 
00171 
00176     struct chan_priority_t
00177     {
00178         expression_t chanElement;
00179         int chanPriority;
00180     };
00181 
00182     class TimedAutomataSystem;
00183 
00184     class SystemVisitor
00185     {
00186     public:
00187         virtual ~SystemVisitor() {}
00188         virtual void visitSystemBefore(TimedAutomataSystem *) {}
00189         virtual void visitSystemAfter(TimedAutomataSystem *) {}
00190         virtual void visitVariable(variable_t &) {}
00191         virtual bool visitTemplateBefore(template_t &) { return true; }
00192         virtual void visitTemplateAfter(template_t &) {}
00193         virtual void visitState(state_t &) {}
00194         virtual void visitEdge(edge_t &) {}
00195         virtual void visitInstance(instance_t &) {}
00196         virtual void visitProcess(instance_t &) {}
00197         virtual void visitFunction(function_t &) {}
00198         virtual void visitTypeDef(symbol_t) {}
00199         virtual void visitProgressMeasure(progress_t &) {}
00200     };
00201 
00202     class TimedAutomataSystem
00203     {
00204     public:
00205         TimedAutomataSystem();
00206         virtual ~TimedAutomataSystem();
00207 
00209         declarations_t &getGlobals();
00210 
00212         std::list<template_t> &getTemplates();
00213 
00215         std::list<instance_t> &getProcesses();
00216 
00217         void addPosition(
00218             uint32_t position, uint32_t offset, uint32_t line, std::string path);
00219         const Positions::line_t &findPosition(uint32_t position) const;
00220 
00221         variable_t *addVariableToFunction(
00222             function_t *, frame_t, type_t, std::string, expression_t initital);
00223         variable_t *addVariable(
00224             declarations_t *, type_t type, std::string, expression_t initial);
00225         void addProgressMeasure(
00226             declarations_t *, expression_t guard, expression_t measure);
00227 
00228         template_t &addTemplate(std::string, frame_t params);
00229         instance_t &addInstance(
00230             std::string name, instance_t &instance, frame_t params, 
00231             const std::vector<expression_t> &arguments);
00232         void addProcess(instance_t &instance);
00233         void accept(SystemVisitor &);
00234 
00235         void setBeforeUpdate(expression_t);
00236         expression_t getBeforeUpdate();
00237         void setAfterUpdate(expression_t);
00238         expression_t getAfterUpdate();
00239 
00240         /* The default priority for channels is also used for
00241          * 'tau transitions' (i.e. non-synchronizing transitions).
00242          */
00243         void setChanPriority(expression_t chan, int priority);
00244         const std::list<chan_priority_t>& getChanPriorities() const;
00245         std::list<chan_priority_t>& getMutableChanPriorities();
00246         void setDefaultChanPriority(int priority);
00247         int getTauPriority() const;
00248 
00249         /* Process priorities. */
00250         void setProcPriority(const char* name, int priority);
00251         int getProcPriority(const char* name) const;
00252 
00253         /* Returns true if system has some priority declaration. */
00254         bool hasPriorityDeclaration() const;
00255 
00256     protected:
00257         bool hasPriorities;
00258         int defaultChanPriority;
00259         std::list<chan_priority_t> chanPriorities;
00260         std::map<std::string,int> procPriority;
00261 
00262     protected:
00263         // The list of templates.
00264         std::list<template_t> templates;
00265 
00266         // The list of template instances.
00267         std::list<instance_t> instances;
00268 
00269         // List of processes.
00270         std::list<instance_t> processes;
00271 
00272         // Global declarations
00273         declarations_t global;
00274 
00275         expression_t beforeUpdate;
00276         expression_t afterUpdate;
00277 
00278         variable_t *addVariable(
00279             std::list<variable_t> &variables, frame_t frame,
00280             type_t type, std::string);
00281 
00282     public:
00283         void addError(position_t, std::string);
00284         void addWarning(position_t, std::string);
00285         bool hasErrors() const;
00286         bool hasWarnings() const;
00287         const std::vector<error_t> &getErrors() const;
00288         const std::vector<error_t> &getWarnings() const;
00289         void clearErrors();
00290         void clearWarnings();
00291 
00292     private:
00293         std::vector<error_t> errors;
00294         std::vector<error_t> warnings;
00295         Positions positions;
00296     };
00297 }
00298 
00299 #endif

Generated on Sat Apr 29 21:02:14 2006 for libutap by  doxygen 1.4.2