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-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_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 
00033 namespace UTAP
00034 {
00039     struct variable_t 
00040     {
00041         symbol_t uid;      
00042         expression_t expr; 
00043     };
00044 
00049     struct state_t 
00050     {
00051         symbol_t uid;           
00052         expression_t invariant; 
00053         int32_t locNr;          
00054     };
00055 
00060     struct edge_t 
00061     {
00062         int nr;                 
00063         state_t *src;           
00064         state_t *dst;           
00065         expression_t guard;     
00066         expression_t assign;    
00067         expression_t sync;      
00068     };
00069 
00070     class BlockStatement; // Forward declaration
00071 
00075     struct function_t
00076     {
00077         symbol_t uid;                
00078         std::set<symbol_t> changes;  
00079         std::list<variable_t> variables;
00080         BlockStatement *body;        
00081         function_t() : body(NULL) {}
00082         ~function_t();
00083     };
00084 
00085     struct template_t;
00086         
00087     struct instance_t 
00088     {
00089         symbol_t uid;
00090         const template_t *templ;
00091         std::map<symbol_t, expression_t> mapping;
00092     };
00093 
00094     struct progress_t
00095     {
00096         expression_t guard;
00097         expression_t measure;
00098     };
00099 
00104     struct declarations_t 
00105     {
00106         frame_t frame;
00107         std::list<variable_t> variables;        
00108         std::list<function_t> functions;        
00109         std::list<progress_t> progress;         
00112         bool addFunction(type_t type, std::string, function_t *&);
00113     };
00114 
00119     struct template_t : public declarations_t
00120     {
00121         symbol_t uid;                           
00122         int32_t nr;                             
00123         symbol_t init;                          
00124         frame_t parameters;                     
00125         std::list<state_t> states;              
00126         std::list<edge_t> edges;                
00129         state_t &addLocation(std::string, expression_t inv);
00130 
00132         edge_t &addEdge(symbol_t src, symbol_t dst);
00133     };
00134 
00140     struct process_t : public instance_t 
00141     {
00142         int32_t nr;             
00143     };
00144 
00145     class TimedAutomataSystem;
00146     
00147     class SystemVisitor
00148     {
00149     public:
00150         virtual ~SystemVisitor() {}
00151         virtual void visitSystemBefore(TimedAutomataSystem *) {}
00152         virtual void visitSystemAfter(TimedAutomataSystem *) {}
00153         virtual void visitVariable(variable_t &) {}
00154         virtual bool visitTemplateBefore(template_t &) { return true; }
00155         virtual void visitTemplateAfter(template_t &) {}
00156         virtual void visitState(state_t &) {}
00157         virtual void visitEdge(edge_t &) {}
00158         virtual void visitInstance(instance_t &) {}
00159         virtual void visitProcess(process_t &) {}
00160         virtual void visitFunction(function_t &) {}
00161     };
00162 
00163     class TimedAutomataSystem
00164     {
00165     public:
00166         TimedAutomataSystem();
00167         virtual ~TimedAutomataSystem();
00168 
00170         declarations_t &getGlobals();
00171 
00173         std::list<template_t> &getTemplates();
00174 
00176         std::list<process_t> &getProcesses();
00177 
00178         variable_t *addVariableToFunction(
00179             function_t *, frame_t, type_t, std::string, expression_t initital);
00180         variable_t *addVariable(
00181             declarations_t *, type_t type, std::string, expression_t initial);
00182         void addProgressMeasure(
00183             declarations_t *, expression_t guard, expression_t measure);
00184 
00185         template_t &addTemplate(std::string, frame_t params);
00186         instance_t &addInstance(std::string name, const template_t *);
00187         process_t &addProcess(symbol_t uid);
00188         void accept(SystemVisitor &);
00189 
00191         const std::set<symbol_t> &getConstants() const;
00192 
00199         const std::map<symbol_t, expression_t> &getConstantValuation() const;
00200 
00207         std::map<symbol_t, expression_t> &getConstantValuation();       
00208 
00209         void setBeforeUpdate(expression_t);
00210         expression_t getBeforeUpdate();
00211         void setAfterUpdate(expression_t);
00212         expression_t getAfterUpdate();
00213 
00214 #ifdef ENABLE_PRIORITY
00215 
00216         /* Set priorities for channels and processes. */
00217         void setChanPriority(symbol_t uid, int32_t prio);
00218         void setProcPriority(symbol_t uid, int32_t prio);
00219 
00220         /* Get priorities for channels and processes. */
00221         int32_t getChanPriority(symbol_t uid);
00222         int32_t getProcPriority(symbol_t uid);
00223 
00224         /* Returns true if system has some priority declaration. */
00225         bool hasPriorityDeclaration() const;
00226 
00227     protected:
00228         bool hasPriority;
00229         std::map<symbol_t, int32_t> chanPriority;
00230         std::map<symbol_t, int32_t> procPriority;
00231 
00232 #endif /* ENABLE_PRIORITY */
00233         
00234     protected:
00235         // The list of templates.
00236         std::list<template_t> templates;
00237 
00238         // The list of template instances.
00239         std::list<instance_t> instances;
00240         
00241         // List of processes used in the system line
00242         std::list<process_t> processes;
00243 
00244         // The set of all constants
00245         std::set<symbol_t> constants;   
00246 
00247         // Maps constans to their values
00248         std::map<symbol_t, expression_t> constantValuation;
00249         
00250         // Global declarations
00251         declarations_t global;
00252 
00253         expression_t beforeUpdate;
00254         expression_t afterUpdate;
00255 
00256         variable_t *addVariable(
00257             std::list<variable_t> &variables, frame_t frame, 
00258             type_t type, std::string);
00259     };
00260 
00265     class ContextVisitor : public SystemVisitor, private XPath
00266     {
00267     private:
00268         int currentTemplate;
00269         std::string path;
00270         ErrorHandler *errorHandler;
00271         virtual std::string get() const;
00272     protected:
00273         void setContextNone();
00274         void setContextDeclaration();
00275         void setContextParameters();
00276         void setContextInvariant(state_t &);
00277         void setContextGuard(edge_t &);
00278         void setContextSync(edge_t &);
00279         void setContextAssignment(edge_t &);
00280         void setContextInstantiation();
00281         
00282         void handleError(expression_t, std::string);
00283         void handleWarning(expression_t, std::string);
00284     public:
00285         ContextVisitor(ErrorHandler *);
00286         virtual bool visitTemplateBefore(template_t &);
00287         virtual void visitTemplateAfter(template_t &);
00288     };
00289 
00290 }
00291 #endif

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