data: don't parse lambda calls to avoid subnodes within functions
This commit is contained in:
@@ -19,7 +19,7 @@ public:
|
||||
template <template<class, class> class ContainerType>
|
||||
static ContainerType<Range, std::allocator<Range>> mergeAdjacent(ContainerType<Range, std::allocator<Range>> ranges, int rowDifference = 1)
|
||||
{
|
||||
for (size_t i = 0; i < ranges.size() - 1; i++)
|
||||
for (size_t i = 0; i + 1 < ranges.size(); i++)
|
||||
{
|
||||
const Range first = ranges[i];
|
||||
const Range second = ranges[i + 1];
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "data/parser/cxx/ASTBodyVisitor.h"
|
||||
|
||||
#include "clang/AST/DeclCXX.h"
|
||||
|
||||
ASTBodyVisitor::ASTBodyVisitor(ASTBodyVisitorClient* client, clang::FunctionDecl* functionDecl)
|
||||
: m_client(client)
|
||||
, m_functionDecl(functionDecl)
|
||||
@@ -36,13 +38,30 @@ void ASTBodyVisitor::VisitChildren(clang::Stmt* stmt)
|
||||
|
||||
void ASTBodyVisitor::VisitCallExpr(clang::CallExpr* expr)
|
||||
{
|
||||
if (m_functionDecl)
|
||||
bool ignore = false;
|
||||
|
||||
// check if lambda call
|
||||
if (clang::isa<clang::CXXOperatorCallExpr>(expr))
|
||||
{
|
||||
m_client->VisitCallExprInDeclBody(m_functionDecl, expr);
|
||||
clang::Decl* calleeDecl = expr->getCalleeDecl();
|
||||
|
||||
if (clang::isa<clang::CXXMethodDecl>(calleeDecl))
|
||||
{
|
||||
clang::CXXRecordDecl* recordDecl = clang::dyn_cast<clang::CXXMethodDecl>(calleeDecl)->getParent();
|
||||
ignore = recordDecl->isLambda();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (!ignore)
|
||||
{
|
||||
m_client->VisitCallExprInDeclBody(m_varDecl, expr);
|
||||
if (m_functionDecl)
|
||||
{
|
||||
m_client->VisitCallExprInDeclBody(m_functionDecl, expr);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_client->VisitCallExprInDeclBody(m_varDecl, expr);
|
||||
}
|
||||
}
|
||||
|
||||
VisitStmt(expr);
|
||||
|
||||
@@ -543,20 +543,6 @@ bool ASTVisitor::VisitFunctionTemplateDecl(clang::FunctionTemplateDecl *declarat
|
||||
|
||||
void ASTVisitor::VisitCallExprInDeclBody(clang::FunctionDecl* 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;
|
||||
|
||||
if (!expr->getDirectCallee())
|
||||
{
|
||||
// TODO: Save error at location.
|
||||
|
||||
@@ -2449,6 +2449,39 @@ public:
|
||||
"A<typename T> -> test<template<typename> typename T>::T<typename> <4:40 4:40>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_ignores_lambda_in_function()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"void lambdaCaller()\n"
|
||||
"{\n"
|
||||
" [](){}();\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->functions.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->functions[0], "void lambdaCaller() <1:1 <1:6 1:17> 4:1>");
|
||||
TS_ASSERT_EQUALS(client->calls.size(), 0);
|
||||
}
|
||||
|
||||
void test_cxx_parser_ignores_lambda_in_function_but_still_finds_call_within()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"void func() {}\n"
|
||||
"void lambdaCaller()\n"
|
||||
"{\n"
|
||||
" []()\n"
|
||||
" {\n"
|
||||
" func();\n"
|
||||
" }();\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->functions.size(), 2);
|
||||
TS_ASSERT_EQUALS(client->functions[0], "void func() <1:1 <1:6 1:9> 1:14>");
|
||||
TS_ASSERT_EQUALS(client->functions[1], "void lambdaCaller() <2:1 <2:6 2:17> 8:1>");
|
||||
TS_ASSERT_EQUALS(client->calls.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->calls[0], "void lambdaCaller() -> void func() <6:3 6:8>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_parses_multiple_files()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user