data: parsing and saving calls

This change parses calls in CxxParser by using the class ASTBodyVisitor which traverses the Stmts and Exprs in the body
of the function and method declarations.

The calls include:
* calls in functions
* calls in methods
* constructor calls
* constructor calls in initialization lists
* implicit constructor calls of fields
* calls to operators
* global constructor calls of global variables
* global function calls for global variables

The calls don't include:
* destructor calls
* some calls to implicit constructors and copy constructors

fortune cookie message = Don't be afraid to take that big step.
This commit is contained in:
Eberhard Graether
2014-07-08 16:38:40 +02:00
parent 0f60a9a556
commit af54da4ce4
13 changed files with 466 additions and 7 deletions
+73
View File
@@ -1,5 +1,6 @@
#include "data/parser/cxx/ASTVisitor.h"
#include "data/parser/cxx/ASTBodyVisitor.h"
#include "data/parser/ParseLocation.h"
#include "data/parser/ParseVariable.h"
@@ -13,6 +14,11 @@ ASTVisitor::~ASTVisitor()
{
}
bool ASTVisitor::VisitStmt(const clang::Stmt* statement)
{
return true;
}
bool ASTVisitor::VisitTypedefDecl(const clang::TypedefDecl* declaration)
{
if (hasValidLocation(declaration))
@@ -84,6 +90,12 @@ bool ASTVisitor::VisitVarDecl(clang::VarDecl* declaration)
getParseLocation(declaration->getSourceRange()),
getParseVariable(declaration)
);
if (declaration->getInit())
{
ASTBodyVisitor bodyVisitor(this, declaration);
bodyVisitor.Visit(declaration->getInit());
}
}
else
{
@@ -128,6 +140,12 @@ bool ASTVisitor::VisitFunctionDecl(clang::FunctionDecl* declaration)
getTypeName(declaration->getReturnType()),
getParameters(declaration)
);
if (declaration->hasBody())
{
ASTBodyVisitor bodyVisitor(this, declaration);
bodyVisitor.Visit(declaration->getBody());
}
}
return true;
@@ -157,6 +175,29 @@ bool ASTVisitor::VisitCXXMethodDecl(clang::CXXMethodDecl* declaration)
declaration->isConst(),
declaration->isStatic()
);
if (declaration->hasBody())
{
ASTBodyVisitor bodyVisitor(this, declaration);
bodyVisitor.Visit(declaration->getBody());
}
}
return true;
}
bool ASTVisitor::VisitCXXConstructorDecl(clang::CXXConstructorDecl* declaration)
{
if (hasValidLocation(declaration))
{
for (clang::CXXConstructorDecl::init_const_iterator it = declaration->init_begin(); it != declaration->init_end(); it++)
{
if ((*it)->getInit())
{
ASTBodyVisitor bodyVisitor(this, declaration);
bodyVisitor.Visit((*it)->getInit());
}
}
}
return true;
@@ -202,6 +243,38 @@ bool ASTVisitor::VisitEnumConstantDecl(clang::EnumConstantDecl* declaration)
return true;
}
void ASTVisitor::VisitCallExprInDeclBody(clang::NamedDecl* decl, clang::CallExpr* expr)
{
// if (clang::FunctionDecl *CalleeDecl = CE->getDirectCallee())
// {
// return CalleeDecl;
// }
// clang::Expr *CEE = CE->getCallee()->IgnoreParenImpCasts();
// if (clang::BlockExpr *Block = clang::dyn_cast<clang::BlockExpr>(CEE))
// {
// NumBlockCallEdges++;
// return Block->getBlockDecl();
// }
// return nullptr;
m_client->onCallParsed(
getParseLocation(expr->getSourceRange()),
decl->getQualifiedNameAsString(),
expr->getDirectCallee()->getQualifiedNameAsString()
);
}
void ASTVisitor::VisitCXXConstructExprInDeclBody(clang::NamedDecl* decl, clang::CXXConstructExpr* expr)
{
m_client->onCallParsed(
getParseLocation(expr->getSourceRange()),
decl->getQualifiedNameAsString(),
expr->getConstructor()->getQualifiedNameAsString()
);
}
bool ASTVisitor::hasValidLocation(const clang::Decl* declaration) const
{
const clang::SourceLocation& location = declaration->getLocStart();