00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00051 struct state_t
00052 {
00053 symbol_t uid;
00054 expression_t invariant;
00055 expression_t costrate;
00056 int32_t locNr;
00057 };
00058
00063 struct edge_t
00064 {
00065 int nr;
00066 bool control;
00067 state_t *src;
00068 state_t *dst;
00069 frame_t select;
00070 expression_t guard;
00071 expression_t assign;
00072 expression_t sync;
00073 };
00074
00075 class BlockStatement;
00076
00080 struct function_t
00081 {
00082 symbol_t uid;
00083 std::set<symbol_t> changes;
00084 std::set<symbol_t> depends;
00085 std::list<variable_t> variables;
00086 BlockStatement *body;
00087 function_t() : body(NULL) {}
00088 ~function_t();
00089 };
00090
00091 struct template_t;
00092
00093 struct instance_t
00094 {
00095 symbol_t uid;
00096 const template_t *templ;
00097 std::map<symbol_t, expression_t> mapping;
00098 };
00099
00100 struct progress_t
00101 {
00102 expression_t guard;
00103 expression_t measure;
00104 };
00105
00110 struct declarations_t
00111 {
00112 frame_t frame;
00113 std::list<variable_t> variables;
00114 std::list<function_t> functions;
00115 std::list<progress_t> progress;
00118 bool addFunction(type_t type, std::string, function_t *&);
00119 };
00120
00125 struct template_t : public declarations_t
00126 {
00127 symbol_t uid;
00128 int32_t nr;
00129 symbol_t init;
00130 frame_t templateset;
00131 frame_t parameters;
00132 std::list<state_t> states;
00133 std::list<edge_t> edges;
00136 state_t &addLocation(std::string, expression_t inv);
00137
00139 edge_t &addEdge(symbol_t src, symbol_t dst, bool type);
00140 };
00141
00147 struct process_t : public instance_t
00148 {
00149 int32_t nr;
00150 };
00151
00152 class TimedAutomataSystem;
00153
00154 class SystemVisitor
00155 {
00156 public:
00157 virtual ~SystemVisitor() {}
00158 virtual void visitSystemBefore(TimedAutomataSystem *) {}
00159 virtual void visitSystemAfter(TimedAutomataSystem *) {}
00160 virtual void visitVariable(variable_t &) {}
00161 virtual bool visitTemplateBefore(template_t &) { return true; }
00162 virtual void visitTemplateAfter(template_t &) {}
00163 virtual void visitState(state_t &) {}
00164 virtual void visitEdge(edge_t &) {}
00165 virtual void visitInstance(instance_t &) {}
00166 virtual void visitProcess(process_t &) {}
00167 virtual void visitFunction(function_t &) {}
00168 virtual void visitProgressMeasure(progress_t &) {}
00169 };
00170
00171 class TimedAutomataSystem
00172 {
00173 public:
00174 TimedAutomataSystem();
00175 virtual ~TimedAutomataSystem();
00176
00178 declarations_t &getGlobals();
00179
00181 std::list<template_t> &getTemplates();
00182
00184 std::list<process_t> &getProcesses();
00185
00186 variable_t *addVariableToFunction(
00187 function_t *, frame_t, type_t, std::string, expression_t initital);
00188 variable_t *addVariable(
00189 declarations_t *, type_t type, std::string, expression_t initial);
00190 void addProgressMeasure(
00191 declarations_t *, expression_t guard, expression_t measure);
00192
00193 template_t &addTemplate(std::string, frame_t templateset, frame_t params);
00194 instance_t &addInstance(std::string name, const template_t *);
00195 process_t &addProcess(symbol_t uid);
00196 void accept(SystemVisitor &);
00197
00199 const std::set<symbol_t> &getConstants() const;
00200
00207 const std::map<symbol_t, expression_t> &getConstantValuation() const;
00208
00215 std::map<symbol_t, expression_t> &getConstantValuation();
00216
00217 void setBeforeUpdate(expression_t);
00218 expression_t getBeforeUpdate();
00219 void setAfterUpdate(expression_t);
00220 expression_t getAfterUpdate();
00221
00222 #ifdef ENABLE_PRIORITY
00223
00224
00225 void setChanPriority(symbol_t uid, int32_t prio);
00226 void setProcPriority(symbol_t uid, int32_t prio);
00227
00228
00229 int32_t getChanPriority(symbol_t uid);
00230 int32_t getProcPriority(symbol_t uid);
00231
00232
00233 bool hasPriorityDeclaration() const;
00234
00235 protected:
00236 bool hasPriority;
00237 std::map<symbol_t, int32_t> chanPriority;
00238 std::map<symbol_t, int32_t> procPriority;
00239
00240 #endif
00241
00242 protected:
00243
00244 std::list<template_t> templates;
00245
00246
00247 std::list<instance_t> instances;
00248
00249
00250 std::list<process_t> processes;
00251
00252
00253 std::set<symbol_t> constants;
00254
00255
00256 std::map<symbol_t, expression_t> constantValuation;
00257
00258
00259 declarations_t global;
00260
00261 expression_t beforeUpdate;
00262 expression_t afterUpdate;
00263
00264 variable_t *addVariable(
00265 std::list<variable_t> &variables, frame_t frame,
00266 type_t type, std::string);
00267 };
00268
00273 class ContextVisitor : public SystemVisitor, private XPath
00274 {
00275 private:
00276 int currentTemplate;
00277 std::string path;
00278 ErrorHandler *errorHandler;
00279 virtual std::string get() const;
00280 protected:
00281 void setContextNone();
00282 void setContextDeclaration();
00283 void setContextParameters();
00284 void setContextInvariant(state_t &);
00285 void setContextSelect(edge_t &);
00286 void setContextGuard(edge_t &);
00287 void setContextSync(edge_t &);
00288 void setContextAssignment(edge_t &);
00289 void setContextInstantiation();
00290
00291 void handleError(expression_t, std::string);
00292 void handleWarning(expression_t, std::string);
00293 public:
00294 ContextVisitor(ErrorHandler *);
00295 virtual bool visitTemplateBefore(template_t &);
00296 virtual void visitTemplateAfter(template_t &);
00297 };
00298
00299 }
00300 #endif