{
if(type == 1)
{
- for(unsigned i = 3;i<events.size()+3;i++)
+ for(int i = 3;i<cols;i++)
{
if(model.compare(0,model.size(),table[i])==0) return i;
}
}
else
{
- for(unsigned i = 1;i<states.size()+1;i++)
+ for(int i = 1;i<rows;i++)
if(model.compare(0,model.size(),table[i*cols+2])==0) return i;
}
return -1;
unsigned * len = new unsigned[cols];
len[0] = 1;
string line = "-|---|-";
- for(unsigned i = 1; i<cols; i++)
+ for(int i = 1; i<cols; i++)
{
len[i] = 0;
- for(unsigned j = 0;j<rows;j++)
+ for(int j = 0;j<rows;j++)
{
if(len[i]<table[j*cols+i].length()) len[i] = table[j*cols+i].length();
}
line.append("-|-");
}
cout<<line<<"\n";
- for(unsigned i = 0; i<rows; i++)
+ for(int i = 0; i<rows; i++)
{
cout<<" | ";
- for(unsigned j = 0;j<cols;j++)
+ for(int j = 0;j<cols;j++)
{
cout.width(len[j]);
cout<<left<<table[i*cols+j]<<" | ";
using namespace clang::driver;
using namespace std;
-class MyDiagnosticClient : public TextDiagnosticPrinter // My diagnostic Client
+class MyDiagnosticClient : public TextDiagnosticPrinter // Diagnostic Client
{
int nwarnings;
int nnotes;
}
virtual void HandleDiagnostic(Diagnostic::Level DiagLevel, const DiagnosticInfo &Info)
{
- TextDiagnosticPrinter::HandleDiagnostic(DiagLevel, Info); // print diagnostic information
- switch (DiagLevel)
+ TextDiagnosticPrinter::HandleDiagnostic(DiagLevel, Info); // print diagnostic information using library implementation
+ switch (DiagLevel) // count number of all diagnostic information
{
case 0 : nignored+=1; break;
case 1 : nnotes+=1; break;
}
}
- void print_stats()
+ void print_stats() // print statistics about diagnostic
{
cout<<"\n--Diagnostic Info--\n";
cout<<"Number of ignored: "<<nignored<<"\n";
cout<<"Number of errors and fatal errors: "<<nerrors<<"\n";
}
- int getNbrOfWarnings()
+ int getNbrOfWarnings() // get number of warnings
{
return nwarnings;
}
- int getNbrOfNotes()
+ int getNbrOfNotes() // get number of notes
{
return nnotes;
}
- int getNbrOfIgnored()
+ int getNbrOfIgnored() // get number of ignored
{
return nignored;
}
};
-class FindStates : public ASTConsumer
+class FindStates : public ASTConsumer // AST Consumer interface for traversing AST
{
+ // lists for saving information about state machine
list<string> transitions;
list<string> cReactions;
list<string> events;
string name_of_machine;
string name_of_start;
FullSourceLoc *fsloc;
-
public:
list<string> getStates()
name_of_machine = "";
}
+/*
+ Traverse global decls using DeclGroupRef for handling all global decls.
+*/
virtual void HandleTopLevelDecl(DeclGroupRef DGR)// traverse all top level declarations
{
SourceLocation loc;
output = "";
}
}
+
+/*
+ It is used to recursive traverse decls in namespaces.
+*/
void recursive_visit(const DeclContext *declCont) //recursively visit all decls hidden inside namespaces
{
string line, output, event;
}
}
+/*
+ This function works with class or struct. It splits the decl into 3 interesting parts.
+ The state machine decl, state decl and event decl.
+*/
void struct_class(const Decl *decl) // works with struct or class decl
{
string output, line, ret, trans, event;
}
else
{
- ret = find_states(cRecDecl, line);
+ ret = find_states(cRecDecl, line);
if(!ret.empty())
{
cout << "New state: " << namedDecl->getNameAsString() << "\n";
}
}
- void methods_in_class(const Decl *decl, const string state)
+/*
+ This function provides traversing all methods and other context indide class. If
+ typedef or classic method decl is found. Transitions inside it are beiing founded.
+*/
+ void methods_in_class(const Decl *decl, const string state) // traverse context inside one class
{
string output, line, ret, trans, event;
llvm::raw_string_ostream x(output);
int pos, num;
const TagDecl *tagDecl = dyn_cast<TagDecl>(decl);
- const DeclContext *declCont = tagDecl->castToDeclContext(tagDecl);
- //states.push_back(namedDecl->getNameAsString());
-
+ const DeclContext *declCont = tagDecl->castToDeclContext(tagDecl);
output="";
for (DeclContext::decl_iterator i = declCont->decls_begin(), e = declCont->decls_end(); i != e; ++i)
{
- if (i->getKind()==26)
+ if (i->getKind()==26) // typedefs
{
i->print(x);
output = x.str();
if(pos==-1) transitions.push_back(ret);
else transitions.push_back(ret.substr(0,pos));
}
- //cout<<ret<<"\n";
if(i!=num-1) ret = ret.substr(pos+1);
}
output="";
}
}
- if(i->getKind()==35) method_decl(decl);
+ if(i->getKind()==35) method_decl(decl);// C++ method
}
}
- void method_decl(const Decl *decl)
+ void method_decl(const Decl *decl) // method decl traverse. Using Stmt
{
string output, line, event;
llvm::raw_string_ostream x(output);
line.append(",");
line.append(event);
find_return_stmt(decl->getBody(),line);
- for(list<string>::iterator i = cReactions.begin();i!=cReactions.end();i++)
+ for(list<string>::iterator i = cReactions.begin();i!=cReactions.end();i++) // erase info about it from list of custom reactions
{
event = *i;
if(line.compare(event)==0)
}
}
- void find_return_stmt(Stmt *statemt,string event)
+ void find_return_stmt(Stmt *statemt,string event) // traverse all statements in function for finding return Statement
{
if(statemt->getStmtClass() == 99) test_stmt(dyn_cast<CaseStmt>(statemt)->getSubStmt(), event);
else
}
}
- void test_stmt(Stmt *stmt, string event)
+ void test_stmt(Stmt *stmt, string event) // test statement
{
const SourceManager &sman = fsloc->getManager();
int type;