]> rtime.felk.cvut.cz Git - boost-statechart-viewer.git/commitdiff
Add first part of support for orthogonal states.
authorpetr000 <silhavik.p@gmail.com>
Fri, 5 Aug 2011 09:01:21 +0000 (11:01 +0200)
committerpetr000 <silhavik.p@gmail.com>
Fri, 5 Aug 2011 09:01:21 +0000 (11:01 +0200)
For visualization the printing methods must be changed to be able to print orthogonal states.

src/stringoper.h
src/visualizer.cpp

index abf4d56fd91e9eb5e750fedd2c6617d63720d48b..e2727da893836a8d873b8a165442f943db295c86 100644 (file)
@@ -72,15 +72,26 @@ string get_return(const string code) /** Return return statement. */
 
 string cut_namespaces(string line) /** Cut namespaces from the declarations. */
 {
-       int i = line.rfind("::");
-       if(i==-1) return line;
-       return line.substr(i+2);
+       int i;
+       int brackets = 0;
+       for(i = line.length()-1;i>0;i--)
+       {
+               if(line[i]=='<') brackets+=1;
+               if(line[i]=='>') brackets-=1;
+               if(line[i]==':' && line[i-1]==':')
+               {
+                       if(brackets == 0) break;
+                       else i--;
+               }
+       }
+       if(i==0) return line;
+       return line.substr(i+1);
 }
 
 bool is_derived(const string line) /** Test whether this struct or class is derived */
 {
        unsigned i;
-       for(i = 0;i<line.length()-1;i++)
+       for(i = 0;i<line.length()-2;i++)
        {
                if(line[i]==':')
                {
@@ -133,6 +144,7 @@ string get_first_base(const string line) /** Get the first super class of this d
 
 bool is_state(const string line) /** Test if this declaration is a state. It is used to test the base classes. */
 {
+       cout<<cut_namespaces(line)<<endl;
        if(cut_namespaces(line).compare(0,12,"simple_state")==0)
        {
                return true;    
@@ -228,9 +240,10 @@ string get_params(string line) /** Return parameters of the specified transition
        
 string find_states(const CXXRecordDecl *cRecDecl, string line) /** test if the struct/class is he state (must be derived from simple_state or state). */
 {      
-       string super_class = get_super_class(line), base, params;               
+       string super_class = get_super_class(line), base, params;
        if(cRecDecl->getNumBases()>1)
        {
+               
                for(unsigned i = 0; i<cRecDecl->getNumBases();i++ )
                {
                        if(i!=cRecDecl->getNumBases()-1) base = get_first_base(super_class);
@@ -246,9 +259,9 @@ string find_states(const CXXRecordDecl *cRecDecl, string line) /** test if the s
                }
        }
        else
-       { 
+       {               
                if(is_state(super_class)) 
-               {
+               {                       
                        params = get_params(super_class);
                }
                else params = "";
index 721ef1a2ceea6f56e9d9ae1f018cef91488b9ac9..0a034896a3f165f2e4061fe004ab1b2046b763d6 100644 (file)
@@ -242,6 +242,7 @@ class FindStates : public ASTConsumer
                llvm::raw_string_ostream x(output);
                decl->print(x);
                line = get_line_of_code(x.str());
+               
                output = "";
                int pos;
                const NamedDecl *namedDecl = dyn_cast<NamedDecl>(decl);