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 "symbols.hh"
00031 #include "utap/expression.hh"
00032 #include "statement.hh"
00033
00034 namespace UTAP
00035 {
00036
00041 struct variable_t {
00042 symbol_t uid;
00043 bool global;
00044 expression_t expr;
00045 };
00046
00051 struct state_t {
00052 symbol_t uid;
00053 expression_t invariant;
00054 int32_t locNr;
00055 };
00056
00062 struct transition_t {
00063 int nr;
00064 state_t *src;
00065 state_t *dst;
00066 expression_t guard;
00067 expression_t assign;
00068 expression_t sync;
00069 };
00070
00074 struct function_t {
00075 symbol_t uid;
00076 bool global;
00077 BlockStatement *body;
00078 function_t() : body(NULL) {}
00079 ~function_t() { delete body; }
00080 };
00081
00082 struct template_t;
00083
00084 struct instance_t {
00085 symbol_t uid;
00086 const template_t *templ;
00087 std::map<symbol_t, expression_t> mapping;
00088 };
00089
00093 struct template_t
00094 {
00095 symbol_t uid;
00096 frame_t frame;
00097 std::list<variable_t> variables;
00098 std::list<function_t> functions;
00099 std::list<instance_t> instances;
00100 int32_t nr;
00101 std::list<state_t> states;
00102 std::list<transition_t> transitions;
00103 symbol_t init;
00104 };
00105
00111 struct process_t : public instance_t
00112 {
00113 int32_t nr;
00114 };
00115
00116 class TimedAutomataSystem;
00117
00118 class SystemVisitor
00119 {
00120 public:
00121 virtual ~SystemVisitor() {}
00122 virtual void visitSystemBefore(TimedAutomataSystem *) {}
00123 virtual void visitSystemAfter(TimedAutomataSystem *) {}
00124 virtual void visitVariable(variable_t &) {}
00125 virtual bool visitTemplateBefore(template_t &) { return true; }
00126 virtual void visitTemplateAfter(template_t &) {}
00127 virtual void visitState(state_t &) {}
00128 virtual void visitTransition(transition_t &) {}
00129 virtual void visitInstance(instance_t &) {}
00130 virtual void visitProcess(process_t &) {}
00131 virtual void visitFunction(function_t &) {}
00132 };
00133
00134 class TimedAutomataSystem
00135 {
00136 public:
00137 TimedAutomataSystem();
00138 virtual ~TimedAutomataSystem();
00139
00140 std::list<template_t> &getTemplates();
00141 std::list<process_t> &getProcesses();
00142 template_t &getGlobals();
00143 template_t &getCurrentTemplate();
00144 void setCurrentTemplate(template_t &);
00145
00146 void addVariable(type_t type, const char *name,
00147 expression_t initial);
00148 function_t &addFunction(type_t type, const char *name);
00149
00150 template_t &addTemplate(const char *name, frame_t params);
00151 state_t &addLocation(const char *name, expression_t inv);
00152 transition_t &addTransition(symbol_t src, symbol_t dst);
00153 instance_t &addInstance(const char *name, const template_t *);
00154 process_t &addProcess(symbol_t uid);
00155 void accept(SystemVisitor &);
00156
00157 const std::set<symbol_t> &getConstants() const;
00158
00159 const std::map<symbol_t, expression_t> getConstantValuation() const;
00160
00161 protected:
00162
00163 std::list<template_t> templates;
00164
00165
00166 std::list<instance_t> instances;
00167
00168
00169 std::list<process_t> processes;
00170
00171
00172 std::set<symbol_t> constants;
00173
00174
00175 std::map<symbol_t, expression_t> constantValuation;
00176
00177
00178 template_t global;
00179
00180
00181 template_t *current_template;
00182 };
00183
00188 class ContextVisitor : public SystemVisitor, private XPath
00189 {
00190 private:
00191 int currentTemplate;
00192 char path[256];
00193 ErrorHandler *errorHandler;
00194 char *get() const;
00195 protected:
00196 void setContextNone();
00197 void setContextDeclaration();
00198 void setContextParameters();
00199 void setContextInvariant(state_t &);
00200 void setContextGuard(transition_t &);
00201 void setContextSync(transition_t &);
00202 void setContextAssignment(transition_t &);
00203 void setContextInstantiation();
00204
00205 void handleError(expression_t, const char *);
00206 void handleWarning(expression_t, const char *);
00207 public:
00208 ContextVisitor(ErrorHandler *);
00209 virtual bool visitTemplateBefore(template_t &);
00210 virtual void visitTemplateAfter(template_t &);
00211 };
00212
00213 }
00214 #endif