src: added optional indexer AST logging
* removed old AstVisitor * added new implementation called CxxAstVisitor * added CxxVerboseAstVisitor that may wrap the CxxAstVisitor to log the AST while visiting * added the same structure for the Java visitors * removed all the logs that were fired when recording stuff * Added UI setting for verbose indexer logging. * implemented AST name obfuscation for Java and Cxx * unified test visitors for Java and Cxx * implemented recording using directive decl * removed most of the old onXxxParsed methods
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
#include "data/parser/cxx/CxxVerboseAstVisitor.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include <clang/Basic/SourceLocation.h>
|
||||
#include <clang/Basic/SourceManager.h>
|
||||
|
||||
#include "data/parser/ParseLocation.h"
|
||||
#include "data/parser/ParserClient.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/ScopedSwitcher.h"
|
||||
|
||||
CxxVerboseAstVisitor::CxxVerboseAstVisitor(clang::ASTContext* context, clang::Preprocessor* preprocessor, ParserClient* client, FileRegister* fileRegister)
|
||||
: base(context, preprocessor, client, fileRegister)
|
||||
, m_indentation(0)
|
||||
{
|
||||
}
|
||||
|
||||
CxxVerboseAstVisitor::~CxxVerboseAstVisitor()
|
||||
{
|
||||
}
|
||||
|
||||
bool CxxVerboseAstVisitor::TraverseDecl(clang::Decl *d)
|
||||
{
|
||||
if (d)
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << getIndentString() << d->getDeclKindName() << "Decl";
|
||||
if (clang::NamedDecl *namedDecl = clang::dyn_cast_or_null<clang::NamedDecl>(d))
|
||||
{
|
||||
stream << " [" << obfuscateName(namedDecl->getNameAsString()) << "]";
|
||||
}
|
||||
|
||||
ParseLocation loc = getParseLocation(d->getSourceRange());
|
||||
stream << " <" << loc.startLineNumber << ":" << loc.startColumnNumber << ", " << loc.endLineNumber << ":" << loc.endColumnNumber << ">";
|
||||
|
||||
LOG_INFO_STREAM_BARE(<< "Indexer - " << stream.str());
|
||||
|
||||
{
|
||||
ScopedSwitcher<unsigned int> switcher(m_indentation, m_indentation + 1);
|
||||
return base::TraverseDecl(d);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CxxVerboseAstVisitor::TraverseStmt(clang::Stmt *stmt)
|
||||
{
|
||||
if (stmt)
|
||||
{
|
||||
ParseLocation loc = getParseLocation(stmt->getSourceRange());
|
||||
LOG_INFO_STREAM_BARE(
|
||||
<< "Indexer - "
|
||||
<< getIndentString() << stmt->getStmtClassName()
|
||||
<< " <" << loc.startLineNumber << ":" << loc.startColumnNumber
|
||||
<< ", " << loc.endLineNumber << ":" << loc.endColumnNumber << ">"
|
||||
);
|
||||
|
||||
{
|
||||
ScopedSwitcher<unsigned int> switcher(m_indentation, m_indentation + 1);
|
||||
return base::TraverseStmt(stmt);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CxxVerboseAstVisitor::TraverseType(clang::QualType t)
|
||||
{
|
||||
LOG_INFO_STREAM_BARE(<< "Indexer - " << getIndentString() << t->getTypeClassName() << "Type");
|
||||
{
|
||||
ScopedSwitcher<unsigned int> switcher(m_indentation, m_indentation + 1);
|
||||
return base::TraverseType(t);
|
||||
}
|
||||
}
|
||||
|
||||
bool CxxVerboseAstVisitor::TraverseTypeLoc(clang::TypeLoc tl)
|
||||
{
|
||||
ParseLocation loc = getParseLocation(tl.getSourceRange());
|
||||
LOG_INFO_STREAM_BARE(
|
||||
<< "Indexer - "
|
||||
<< getIndentString() << typeLocClassToString(tl)
|
||||
<< "TypeLoc <" << loc.startLineNumber << ":" << loc.startColumnNumber
|
||||
<< ", " << loc.endLineNumber << ":" << loc.endColumnNumber << ">"
|
||||
);
|
||||
{
|
||||
ScopedSwitcher<unsigned int> switcher(m_indentation, m_indentation + 1);
|
||||
return base::TraverseTypeLoc(tl);
|
||||
}
|
||||
}
|
||||
|
||||
std::string CxxVerboseAstVisitor::getIndentString() const
|
||||
{
|
||||
std::string indentString = "";
|
||||
for (unsigned int i = 0; i < m_indentation; i++)
|
||||
{
|
||||
indentString += "| ";
|
||||
}
|
||||
return indentString;
|
||||
}
|
||||
|
||||
std::string CxxVerboseAstVisitor::obfuscateName(const std::string& name) const
|
||||
{
|
||||
if (name.length() <= 2)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
return name.substr(0, 1) + ".." + name.substr(name.length() - 1);
|
||||
}
|
||||
Reference in New Issue
Block a user