]> rtime.felk.cvut.cz Git - boost-statechart-viewer.git/commitdiff
Added function for working with command line. (-I, -o) Multiple transitions using...
authorsilhape2 <silhape2@postel.local>
Mon, 21 Feb 2011 13:56:11 +0000 (14:56 +0100)
committersilhape2 <silhape2@postel.local>
Mon, 21 Feb 2011 13:56:11 +0000 (14:56 +0100)
commandlineopt.h [new file with mode: 0644]
stringoper.h
visualizer.cpp

diff --git a/commandlineopt.h b/commandlineopt.h
new file mode 100644 (file)
index 0000000..7a3bef0
--- /dev/null
@@ -0,0 +1,8 @@
+#include "llvm/Support/CommandLine.h"
+
+using namespace std;
+
+llvm::cl::opt<string> outputFile("o", llvm::cl::desc("Specify output filename"), llvm::cl::value_desc("filename"), llvm::cl::init("Graph")); //option -o is not required. implicit filename is Graph
+
+llvm::cl::list<string> includeFiles("I", llvm::cl::desc("Specify the location of include files"),  llvm::cl::value_desc("Source location"), llvm::cl::OneOrMore); //option -I must be there at least once
+
index dbe9e6300a887d911f1d216c175d587dd731ff8f..99b19a0b1085432ea93e779a6264e8df530fdfab 100644 (file)
@@ -133,6 +133,52 @@ int count(std::string line) //count all < in string
        return number;
 }
 
+bool is_list(const std::string line)
+{
+       int pos = line.find("::");
+       if(pos==10)
+       {
+               if(line.compare(0,9,"mpl::list")==0)
+               {
+                       return true;    
+               }
+               else
+               {
+                       std::string str = line.substr(pos+2);
+                       if(str.compare(0,4,"list")==0)return true;
+               }
+       }
+       else
+       {
+               std::string str = line.substr(pos+2);
+               //std::cout<<str;
+               if(str.compare(0,4,"list")==0)return true;
+       }
+       return false;
+}
+
+std::string get_inner_part(const std::string line)
+{
+       std::string str;
+       int i, pos = 0;
+       for(i = 0;i<line.length();i++)
+       {
+               if(line[i]=='<') break;
+       }
+       str = line.substr(i+1);
+       for(i = 0;i<str.length();i++)
+       {
+               if(str[i]=='<') pos+=1;
+               if(str[i]=='>')
+               { 
+                       if(pos==0) break;
+                       else pos-=1;
+               }
+       }
+       //std::cout<<str.substr(0,i);
+       return str.substr(0,i);
+}
+
 bool is_transition(const std::string line)
 {
        int pos = line.find("::");
index ef02cb56894794d1ee295508c4a21bf2c405c28d..b781be350bb2ff356406bc6d8fc9ba759e1330b1 100644 (file)
 #include "clang/Parse/ParseAST.h"
 #include "clang/Basic/Version.h"
 
+#include "llvm/Support/CommandLine.h"
+
 //my own header files
 #include "stringoper.h"
+#include "commandlineopt.h"
 
 using namespace clang;
 
@@ -175,28 +178,46 @@ class FindStates : public ASTConsumer
 
        void find_transitions (const std::string name_of_state,const DeclContext *declCont) // traverse all methods for finding declarations of transitions
        {       
-               std::string output, line, event, dest, params;  
+               std::string output, line, event, dest, params, base;    
                llvm::raw_string_ostream x(output);
-               int pos;                
+               int pos;
+               int num;                
                for (DeclContext::decl_iterator i = declCont->decls_begin(), e = declCont->decls_end(); i != e; ++i) 
                {
                        const Decl *decl = *i;
-                       //decl->dump();
                        
                        if (const TypedefDecl *typeDecl = dyn_cast<TypedefDecl>(decl)) 
                        {
-                               const NamedDecl *namedDecl = dyn_cast<NamedDecl>(decl);
-                               decl->print(x);
-                               output = x.str();
-                               if(count(output)==1)
-                               {
+                                       decl->print(x);
+                                       output = x.str();
                                        line = clean_spaces(cut_typedef(output));
-                                       params = get_transition_params(line);
-                                       pos = params.find(",");
-                                       event = params.substr(0,pos);
-                                       dest = params.substr(pos+1);
-                                       if(is_transition(line)) std::cout << "New transition: " << name_of_state<<" -> "<<event<<" -> "<< dest<<"\n";
-                               }
+                                       num = count(output);                                    
+                                       if(num>1)
+                                       {
+                                               num-=1;
+                                               if(is_list(line))
+                                               {
+                                                       line = get_inner_part(line);
+                                               }
+                                       }
+                                       for(int j = 0;j<num;j++)
+                                       {
+                                               if(j!=num-1) base = get_first_base(line);                       
+                                               else base = line;
+                                               if(is_transition(base))
+                                               {
+                                                       params = get_transition_params(line);
+                                                       pos = params.find(",");
+                                                       event = params.substr(0,pos);
+                                                       dest = params.substr(pos+1);
+                                                       std::cout << "New transition: " << name_of_state<<" -> "<<event<<" -> "<< dest<<"\n";
+                                                       line = get_next_base(line);
+                                               }
+                                               else
+                                               {
+                                                       line = get_next_base(line);
+                                               }
+                                       }
                        }
                }       
        }       
@@ -204,6 +225,7 @@ class FindStates : public ASTConsumer
 
 int main(int argc, char *argv[])
 {
+       llvm::cl::ParseCommandLineOptions(argc, argv);  
        DiagnosticOptions diagnosticOptions;
        TextDiagnosticPrinter *tdp = new TextDiagnosticPrinter(llvm::nulls(), diagnosticOptions);
        llvm::IntrusiveRefCntPtr<DiagnosticIDs> dis(new DiagnosticIDs());
@@ -220,11 +242,14 @@ int main(int argc, char *argv[])
 
        HeaderSearchOptions hsopts;
        hsopts.ResourceDir=LLVM_PREFIX "/lib/clang/" CLANG_VERSION_STRING;
-       hsopts.AddPath("/home/petr/Dokumenty/BOOST/boost_1_44_0",
-                       clang::frontend::Angled,
-                       false,
-                       false,
-                       true);
+       for(int i = 0; i<includeFiles.size();i++)
+       {       
+               hsopts.AddPath(includeFiles[i],
+                               clang::frontend::Angled,
+                               false,
+                               false,
+                               true);
+       }
        TargetOptions to;
        to.Triple = llvm::sys::getHostTriple();
        TargetInfo *ti = TargetInfo::CreateTargetInfo(diag, to);