From: Michal Sojka Date: Mon, 27 Aug 2012 17:27:56 +0000 (+0200) Subject: Add handling of the initial state X-Git-Url: https://rtime.felk.cvut.cz/gitweb/boost-statechart-viewer.git/commitdiff_plain/6711f42e73ff964075d55b14b48b060b0b317c11?hp=fe48c26b343be09fea18e3974891fd39bf9b9c63 Add handling of the initial state --- diff --git a/src/visualizer.cpp b/src/visualizer.cpp index 4d19a3f..f3ccf55 100644 --- a/src/visualizer.cpp +++ b/src/visualizer.cpp @@ -55,6 +55,7 @@ public: { ofstream f(fn.c_str()); f << "digraph " << name << " {\n"; + f << " " << name_of_start << " [peripheries=2]\n"; for (string& s : states) { f << " " << s << "\n"; } @@ -74,18 +75,22 @@ class MyCXXRecordDecl : public CXXRecordDecl CXXBasePath &Path, void *qualName) { - string qn(static_cast(qualName)); - const RecordType *rt = Specifier->getType()->getAs(); - assert(rt); - TagDecl *canon = rt->getDecl()->getCanonicalDecl(); - return canon->getQualifiedNameAsString() == qn; + string qn(static_cast(qualName)); + const RecordType *rt = Specifier->getType()->getAs(); + assert(rt); + TagDecl *canon = rt->getDecl()->getCanonicalDecl(); + return canon->getQualifiedNameAsString() == qn; } public: - bool isDerivedFrom(const char *baseStr) const { - CXXBasePaths Paths(/*FindAmbiguities=*/false, /*RecordPaths=*/false, /*DetectVirtual=*/false); + bool isDerivedFrom(const char *baseStr, CXXBaseSpecifier const **Base = 0) const { + CXXBasePaths Paths(/*FindAmbiguities=*/false, /*RecordPaths=*/!!Base, /*DetectVirtual=*/false); Paths.setOrigin(const_cast(this)); - return lookupInBases(&FindBaseClassString, const_cast(baseStr), Paths); + if (!lookupInBases(&FindBaseClassString, const_cast(baseStr), Paths)) + return false; + if (Base) + *Base = Paths.front().back().Base; + return true; } }; @@ -155,6 +160,7 @@ public: return true; MyCXXRecordDecl *RecordDecl = static_cast(Declaration); + const CXXBaseSpecifier *Base; if (RecordDecl->isDerivedFrom("boost::statechart::simple_state")) { @@ -167,11 +173,16 @@ public: Reactions.first != Reactions.second; ++Reactions.first) HandleReaction(*Reactions.first, RecordDecl); } - else if (RecordDecl->isDerivedFrom("boost::statechart::state_machine")) + else if (RecordDecl->isDerivedFrom("boost::statechart::state_machine", &Base)) { sc.name = RecordDecl->getQualifiedNameAsString(); - sc.name_of_start = "tmp"; //RecordDecl->getStateMachineInitialStateAsString() Diag(RecordDecl->getLocStart(), diag_found_statemachine) << sc.name; + + if (const ElaboratedType *ET = dyn_cast(Base->getType())) { + if (const TemplateSpecializationType *TST = dyn_cast(ET->getNamedType())) { + sc.name_of_start = TST->getArg(1).getAsType()->getAsCXXRecordDecl()->getName(); + } + } } else if (RecordDecl->isDerivedFrom("boost::statechart::event")) {