data: token locations for constructor calls
* fixed token locations for implicit constructor calls. * removed error line from test code.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "data/parser/cxx/ASTVisitor.h"
|
||||
|
||||
#include <clang/AST/ParentMap.h>
|
||||
#include <clang/Lex/Lexer.h>
|
||||
|
||||
#include "data/parser/cxx/ASTBodyVisitor.h"
|
||||
@@ -424,8 +425,47 @@ void ASTVisitor::VisitCallExprInDeclBody(clang::VarDecl* decl, clang::CallExpr*
|
||||
|
||||
void ASTVisitor::VisitCXXConstructExprInDeclBody(clang::FunctionDecl* decl, clang::CXXConstructExpr* expr)
|
||||
{
|
||||
std::string caller = decl->getNameAsString();
|
||||
std::string callee = expr->getConstructor()->getNameAsString();
|
||||
clang::SourceRange sourceRange = expr->getSourceRange();
|
||||
// expr->getParenOrBraceRange(); // is null when no parens found (for implicit constructor calls; maybe we will have to use this in the future)
|
||||
// expr->getNumArgs(); // and maybe we will need this one, too.. for same reasons as above.
|
||||
|
||||
const clang::SourceManager& sourceManager = m_context->getSourceManager();
|
||||
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(sourceRange.getBegin(), false);
|
||||
const clang::PresumedLoc& presumedEnd = sourceManager.getPresumedLoc(sourceRange.getEnd(), false);
|
||||
int endLocationOffset = 0;
|
||||
|
||||
bool oneCharacterLocation = (
|
||||
presumedBegin.getLine() == presumedEnd.getLine() && presumedBegin.getColumn() == presumedEnd.getColumn()
|
||||
);
|
||||
if (oneCharacterLocation) // get the exact range of name of declard variable
|
||||
{
|
||||
clang::ParentMap pm(decl->getBody());
|
||||
clang::Stmt* parentStmt = pm.getParent(expr);
|
||||
if (parentStmt && parentStmt->getStmtClass() == clang::Stmt::DeclStmtClass)
|
||||
{
|
||||
clang::DeclStmt* declStmt = clang::dyn_cast<clang::DeclStmt>(parentStmt);
|
||||
clang::Decl* decl = declStmt->getSingleDecl();
|
||||
if (clang::isa<clang::NamedDecl>(decl))
|
||||
{
|
||||
clang::NamedDecl* namedDecl = clang::dyn_cast<clang::NamedDecl>(decl);
|
||||
int variableNameLength = namedDecl->getName().size();
|
||||
endLocationOffset = variableNameLength - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ParseLocation location(
|
||||
presumedBegin.getFilename(),
|
||||
presumedBegin.getLine(),
|
||||
presumedBegin.getColumn(),
|
||||
presumedEnd.getLine(),
|
||||
presumedEnd.getColumn() + endLocationOffset
|
||||
);
|
||||
|
||||
m_client->onCallParsed(
|
||||
getParseLocation(expr->getSourceRange()),
|
||||
location,
|
||||
getParseFunction(decl),
|
||||
getParseFunction(expr->getConstructor())
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user