]> rtime.felk.cvut.cz Git - boost-statechart-viewer.git/blobdiff - src/visualizer.cpp
Add support for deferred events
[boost-statechart-viewer.git] / src / visualizer.cpp
index 503ebaf72cdf79ec3baca4e90964cbfcf8b12987..5b7827643e1cc72069e78a6c896e7e510c19cad8 100644 (file)
@@ -61,10 +61,12 @@ namespace Model
     class State : public Context
     {
        string initialInnerState;
+       list<string> defferedEvents;
     public:
        const string name;
        explicit State(string name) : name(name) {}
        void setInitialInnerState(string name) { initialInnerState = name; }
+       void addDeferredEvent(const string &name) { defferedEvents.push_back(name); }
        friend ostream& operator<<(ostream& os, const State& s);
     };
 
@@ -88,12 +90,14 @@ namespace Model
        return 0;
     }
 
-
     ostream& operator<<(ostream& os, const Context& c);
 
     ostream& operator<<(ostream& os, const State& s)
     {
-       os << indent << "" << s.name << "\n";
+       string label = s.name;
+       for (list<string>::const_iterator i = s.defferedEvents.begin(), e = s.defferedEvents.end(); i != e; ++i)
+           label.append("<br />").append(*i).append(" / defer");
+       os << indent << s.name << " [label=<" << label << ">]\n";
        if (s.size()) {
            os << indent << s.name << " -> " << s.initialInnerState << " [style = dashed]\n";
            os << indent << "subgraph cluster_" << s.name << " {\n" << indent_inc;
@@ -154,7 +158,7 @@ namespace Model
 
     class Model : public map<string, Machine>
     {
-       Context unknown;        // For forward-declared state classes
+       Context undefined;      // For forward-declared state classes
     public:
        list< Transition*> transitions;
 
@@ -166,14 +170,14 @@ namespace Model
 
        void addUndefinedState(State *m)
        {
-           unknown[m->name] = m;
+           undefined[m->name] = m;
        }
 
 
        Context *findContext(const string &name)
        {
-           Context::iterator ci = unknown.find(name);
-           if (ci != unknown.end())
+           Context::iterator ci = undefined.find(name);
+           if (ci != undefined.end())
                return ci->second;
            iterator i = find(name), e;
            if (i != end())
@@ -186,12 +190,23 @@ namespace Model
            return 0;
        }
 
+       State *findState(const string &name)
+       {
+           for (iterator i = begin(), e = end(); i != e; ++i) {
+               Context *c = i->second.findContext(name);
+               if (c)
+                   return static_cast<State*>(c);
+           }
+           return 0;
+       }
+
+
        State *removeFromUndefinedContexts(const string &name)
        {
-           Context::iterator ci = unknown.find(name);
-           if (ci == unknown.end())
+           Context::iterator ci = undefined.find(name);
+           if (ci == undefined.end())
                return 0;
-           unknown.erase(ci);
+           undefined.erase(ci);
            return ci->second;
        }
 
@@ -324,8 +339,9 @@ public:
                const Type *EventType = TST->getArg(0).getAsType().getTypePtr();
                CXXRecordDecl *Event = EventType->getAsCXXRecordDecl();
 
-               Model::Transition *T = new Model::Transition(SrcState->getName(), "\"??? deferral\"", Event->getName());
-               model.transitions.push_back(T);
+               Model::State *s = model.findState(SrcState->getName());
+               assert(s);
+               s->addDeferredEvent(Event->getName());
            } else if (name == "boost::mpl::list") {
                for (TemplateSpecializationType::iterator Arg = TST->begin(), End = TST->end(); Arg != End; ++Arg)
                    HandleReaction(Arg->getAsType().getTypePtr(), Loc, SrcState);
@@ -360,6 +376,8 @@ public:
     {
        if (!Declaration->isCompleteDefinition())
            return true;
+       if (Declaration->getQualifiedNameAsString() == "boost::statechart::state")
+           return true; // This is an "abstract class" not a real state
 
        MyCXXRecordDecl *RecordDecl = static_cast<MyCXXRecordDecl*>(Declaration);
        const CXXBaseSpecifier *Base;
@@ -373,7 +391,6 @@ public:
            // Either we saw a reference to forward declared state
            // before, or we create a new state.
            if (!(state = model.removeFromUndefinedContexts(name)))
-               // TODO: Fix the value of name
                state = new Model::State(name);
 
            CXXRecordDecl *Context = getTemplateArgDecl(Base->getType().getTypePtr(), 1);