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

system.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_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.hh" 00031 #include "utap/expression.hh" 00032 00033 namespace UTAP 00034 { 00039 struct variable_t { 00040 symbol_t uid; 00041 bool global; 00042 expression_t expr; 00043 }; 00044 00049 struct state_t { 00050 symbol_t uid; 00051 expression_t invariant; 00052 int32_t locNr; 00053 }; 00054 00060 struct transition_t { 00061 int nr; 00062 state_t *src; 00063 state_t *dst; 00064 expression_t guard; 00065 expression_t assign; 00066 expression_t sync; 00067 }; 00068 00069 class BlockStatement; // Forward declaration 00070 00074 struct function_t 00075 { 00076 symbol_t uid; 00077 bool global; 00078 std::set<symbol_t> changes; 00079 BlockStatement *body; 00080 function_t() : body(NULL) {} 00081 ~function_t(); 00082 }; 00083 00084 struct template_t; 00085 00086 struct instance_t { 00087 symbol_t uid; 00088 const template_t *templ; 00089 std::map<symbol_t, expression_t> mapping; 00090 }; 00091 00096 struct declarations_t 00097 { 00098 frame_t frame; 00099 std::list<variable_t> variables; 00100 std::list<function_t> functions; 00101 std::list<instance_t> instances; 00102 std::list<state_t> states; 00103 std::list<transition_t> transitions; 00104 }; 00105 00109 struct template_t : public declarations_t 00110 { 00111 symbol_t uid; 00112 int32_t nr; 00113 symbol_t init; 00114 }; 00115 00121 struct process_t : public instance_t 00122 { 00123 int32_t nr; 00124 }; 00125 00126 class TimedAutomataSystem; 00127 00128 class SystemVisitor 00129 { 00130 public: 00131 virtual ~SystemVisitor() {} 00132 virtual void visitSystemBefore(TimedAutomataSystem *) {} 00133 virtual void visitSystemAfter(TimedAutomataSystem *) {} 00134 virtual void visitVariable(variable_t &) {} 00135 virtual bool visitTemplateBefore(template_t &) { return true; } 00136 virtual void visitTemplateAfter(template_t &) {} 00137 virtual void visitState(state_t &) {} 00138 virtual void visitTransition(transition_t &) {} 00139 virtual void visitInstance(instance_t &) {} 00140 virtual void visitProcess(process_t &) {} 00141 virtual void visitFunction(function_t &) {} 00142 }; 00143 00144 class TimedAutomataSystem 00145 { 00146 public: 00147 TimedAutomataSystem(); 00148 virtual ~TimedAutomataSystem(); 00149 00150 std::list<template_t> &getTemplates(); 00151 std::list<process_t> &getProcesses(); 00152 template_t &getGlobals(); 00153 00154 void setDeclarationBlock(declarations_t *); 00155 00156 variable_t *addVariable(type_t type, const char *name, 00157 expression_t initial); 00158 bool addFunction(type_t type, const char *name, function_t *&); 00159 00160 template_t &addTemplate(const char *name, frame_t params); 00161 state_t &addLocation(const char *name, expression_t inv); 00162 transition_t &addTransition(symbol_t src, symbol_t dst); 00163 instance_t &addInstance(const char *name, const template_t *); 00164 process_t &addProcess(symbol_t uid); 00165 void accept(SystemVisitor &); 00166 00167 const std::set<symbol_t> &getConstants() const; 00168 00169 const std::map<symbol_t, expression_t> getConstantValuation() const; 00170 00171 protected: 00172 // The list of templates. 00173 std::list<template_t> templates; 00174 00175 // The list of template instances. 00176 std::list<instance_t> instances; 00177 00178 // List of processes used in the system line 00179 std::list<process_t> processes; 00180 00181 // The set of all constants 00182 std::set<symbol_t> constants; 00183 00184 // Maps constans to their values 00185 std::map<symbol_t, expression_t> constantValuation; 00186 00187 // Not really a template, only used to keep track of global variables 00188 template_t global; 00189 00190 // The current declaration block 00191 declarations_t *current; 00192 }; 00193 00198 class ContextVisitor : public SystemVisitor, private XPath 00199 { 00200 private: 00201 int currentTemplate; 00202 char path[256]; 00203 ErrorHandler *errorHandler; 00204 char *get() const; 00205 protected: 00206 void setContextNone(); 00207 void setContextDeclaration(); 00208 void setContextParameters(); 00209 void setContextInvariant(state_t &); 00210 void setContextGuard(transition_t &); 00211 void setContextSync(transition_t &); 00212 void setContextAssignment(transition_t &); 00213 void setContextInstantiation(); 00214 00215 void handleError(expression_t, const char *); 00216 void handleWarning(expression_t, const char *); 00217 public: 00218 ContextVisitor(ErrorHandler *); 00219 virtual bool visitTemplateBefore(template_t &); 00220 virtual void visitTemplateAfter(template_t &); 00221 }; 00222 00223 } 00224 #endif

Generated on Sat May 15 12:33:41 2004 for libutap by doxygen 1.3.7