]> rtime.felk.cvut.cz Git - boost-statechart-viewer.git/commitdiff
The states now can be derived from more than one classes. They can also be outside...
authorsilhape2 <silhape2@postel.local>
Thu, 17 Feb 2011 09:38:17 +0000 (10:38 +0100)
committersilhape2 <silhape2@postel.local>
Thu, 17 Feb 2011 09:38:17 +0000 (10:38 +0100)
stringoper.h
visualizer.cpp

index 29dcec69bf5b87e6030c187fd726e87e3fcd2528..dbe9e6300a887d911f1d216c175d587dd731ff8f 100644 (file)
@@ -6,7 +6,7 @@ std::string get_line_of_code(const char* code) //return the line of code
        int i;  
        for(i = 0;i<ret.length();i++)
        {
-               if(ret[i]=='\n') break;
+               if(ret[i]=='\n'||ret[i]=='{') break;
        }       
        return ret.substr(0,i);
 } 
@@ -51,6 +51,33 @@ std::string get_super_class(const std::string line) // get the super class of th
        return line.substr(i+1);
 }
 
+std::string get_next_base(const std::string line) // get the super class of this declarations
+{
+       int i = 0;
+       int brackets = 0;
+       for(i = 0;i<line.length()-1;i++)
+       {
+               if(line[i]=='<') brackets+=1;
+               if(line[i]=='>') brackets-=1;
+               if(line[i]==',' && brackets == 0) break;
+       }
+       return line.substr(i+1);
+}  
+
+std::string get_first_base(const std::string line) // get the super class of this declarations
+{
+       int i = 0;
+       int brackets = 0;
+       for(i = 0;i<line.length()-1;i++)
+       {
+               if(line[i]=='<') brackets+=1;
+               if(line[i]=='>') brackets-=1;
+               if(line[i]==',' && brackets == 0) break;
+       }
+       return line.substr(0,i);
+}  
+
+
 std::string clean_spaces(const std::string line)
 {
        int i;
index 5d7e942615c0e0353e2639d11e411d1c4a39ea86..c99f605f296d73551e43db9772adb18b90f00d88 100644 (file)
@@ -68,37 +68,53 @@ class FindStates : public ASTConsumer
                SourceLocation loc;
                const SourceManager &sman = fSloc->getManager();
                std::string line;
-               std::string super_class;
+               std::string super_class, output;
+               llvm::raw_string_ostream x(output);
                for (DeclGroupRef::iterator i = DGR.begin(), e = DGR.end(); i != e; ++i) 
                {
                        const Decl *decl = *i;
                        loc = decl->getLocation();
-                               
-                       if(sman.isFromMainFile(loc)) //only declaration in Main file interested us
+                       const NamedDecl *namedDecl = dyn_cast<NamedDecl>(decl);
+                       if (const TagDecl *tagDecl = dyn_cast<TagDecl>(decl))
                        {
-                               const NamedDecl *namedDecl = dyn_cast<NamedDecl>(decl);
-                               if (const TagDecl *tagDecl = dyn_cast<TagDecl>(decl))
+                               if(tagDecl->isStruct() || tagDecl->isClass()) //is it a structure or class      
                                {
-                                       if(tagDecl->isStruct() || tagDecl->isClass()) //is it a structure or class      
+                                       const CXXRecordDecl *cRecDecl = dyn_cast<CXXRecordDecl>(decl);
+                                       line = cut_commentary(clean_spaces(get_line_of_code(sman.getCharacterData(loc))));
+                                       if(is_derived(line))
                                        {
-                                               line = cut_commentary(clean_spaces(get_line_of_code(sman.getCharacterData(loc))));
-                                               if(is_derived(line))
-                                               {
-                                                       super_class = get_super_class(line);
-                                                       if(is_state(super_class))
-                                                       {                               
-                                                               const CXXRecordDecl *cRecDecl = dyn_cast<CXXRecordDecl>(decl);
-                                                               if(cRecDecl->getNumBases()==1) //state is derived from one base class simple_state              
-                                                               {       
-                                                                       const DeclContext *declCont = tagDecl->castToDeclContext(tagDecl);                                              
-                                                                       std::cout << "New state: " << namedDecl->getNameAsString() << "\n";
-                                                                       find_transitions(namedDecl->getNameAsString(), declCont);
-                                                               }
-                                                       }
+                                               if(find_states(cRecDecl, line))
+                                               {                               
+                                                       const DeclContext *declCont = tagDecl->castToDeclContext(tagDecl);                                      
+                                                       std::cout << "New state: " << namedDecl->getNameAsString() << "\n";
+                                                       find_transitions(namedDecl->getNameAsString(), declCont);
                                                }
-                                       }       
+                                       }
+                               }       
+                       }
+               }
+       }
+       bool find_states(const CXXRecordDecl *cRecDecl, std::string line)
+       {       
+               std::string super_class = get_super_class(line), base;
+               if(cRecDecl->getNumBases()>1)
+               {
+                       for(int i = 0; i<cRecDecl->getNumBases();i++ )
+                       {
+                               if(i!=cRecDecl->getNumBases()-1) base = get_first_base(super_class);
+                               else base = super_class;
+                               if(is_state(base)) return true;
+                               else
+                               {
+                                       super_class = get_next_base(super_class);
                                }
                        }
+                       return false;
+               }
+               else
+               { 
+                       if(is_state(super_class)) return true;
+                       else return false;
                }
        }
 
@@ -112,7 +128,7 @@ class FindStates : public ASTConsumer
                        const Decl *decl = *i;
                        //decl->dump();
                        
-                       if (const TypedefDecl *typeDecl = llvm::dyn_cast<TypedefDecl>(decl)) 
+                       if (const TypedefDecl *typeDecl = dyn_cast<TypedefDecl>(decl)) 
                        {
                                const NamedDecl *namedDecl = dyn_cast<NamedDecl>(decl);
                                decl->print(x);
@@ -127,7 +143,6 @@ class FindStates : public ASTConsumer
                                        if(is_transition(line)) std::cout << "New transition: " << name_of_state<<" -> "<<event<<" -> "<< dest<<"\n";
                                }
                        }
-                       /* TODO else test na projiti*/
                }       
        }       
 };