Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/cpp/model/include/model/cppfunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ struct CppFunction : CppTypedEntity
unsigned int mccabe;
unsigned int bumpiness;
unsigned int statementCount;
bool inLambdaObject = false;

// Hash of the record (e.g. class or struct) in which this function is declared
// recordHash = 0 means this is a global function
Expand Down
1 change: 1 addition & 0 deletions plugins/cpp/parser/src/clangastvisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
if (const clang::CXXRecordDecl* parent = md->getParent())
{
cppFunction->recordHash = util::fnvHash(getUSR(parent));
cppFunction->inLambdaObject = parent->isLambda();
}

if (md->isVirtual())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ class CppMetricsParser : public AbstractParser
// Returns cohesion record query based on parser configuration.
odb::query<model::CohesionCppRecordView> getCohesionRecordQuery();

// Returns metric function query based on parser configuration.
template<typename TQueryParam>
odb::query<TQueryParam> getFunctionQuery() const
{
odb::query<TQueryParam> query = getFilterPathsQuery<TQueryParam>();

if (_ctx.options.count("cppmetrics-ignore-lambdas")) {
query = query && odb::query<model::CppFunction>::inLambdaObject == false;
}

return query;
}

/// @brief Constructs an ODB query that you can use to filter only
/// the database records of the given parameter type whose path
/// is rooted under any of this parser's input paths.
Expand Down
24 changes: 8 additions & 16 deletions plugins/cpp_metrics/parser/src/cppmetricsparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void CppMetricsParser::functionMcCabe()
parallelCalcMetric<model::CppFunctionMcCabe>(
"Function-level McCabe",
_threadCount * functionMcCabePartitionMultiplier,// number of jobs; adjust for granularity
getFilterPathsQuery<model::CppFunctionMcCabe>(),
getFunctionQuery<model::CppFunctionMcCabe>(),
[&, this](const MetricsTasks<model::CppFunctionMcCabe>& tasks)
{
util::OdbTransaction {_ctx.db} ([&, this]
Expand All @@ -155,7 +155,7 @@ void CppMetricsParser::functionBumpyRoad()
parallelCalcMetric<model::CppFunctionBumpyRoad>(
"Bumpy road complexity",
_threadCount * functionBumpyRoadPartitionMultiplier,// number of jobs; adjust for granularity
getFilterPathsQuery<model::CppFunctionBumpyRoad>(),
getFunctionQuery<model::CppFunctionBumpyRoad>(),
[&, this](const MetricsTasks<model::CppFunctionBumpyRoad>& tasks)
{
util::OdbTransaction {_ctx.db} ([&, this]
Expand Down Expand Up @@ -184,27 +184,19 @@ void CppMetricsParser::typeMcCabe()
using AstNodeMet = model::CppAstNodeMetrics;

// Calculate type level McCabe metric for all types on parallel threads.
parallelCalcMetric<AstNode>(
parallelCalcMetric<model::CohesionCppRecordView>(
"Type-level McCabe",
_threadCount * typeMcCabePartitionMultiplier,// number of jobs; adjust for granularity
odb::query<AstNode>::symbolType == AstNode::SymbolType::Type &&
odb::query<AstNode>::astType == AstNode::AstType::Definition,
[&, this](const MetricsTasks<AstNode>& tasks)
getCohesionRecordQuery(),
[&, this](const MetricsTasks<model::CohesionCppRecordView>& tasks)
{
util::OdbTransaction {_ctx.db} ([&, this]
{
for (const AstNode& type : tasks)
for (const model::CohesionCppRecordView& type : tasks)
{
// Skip if class is included from external library
type.location.file.load();
const auto typeFile = _ctx.db->query_one<model::File>(
odb::query<model::File>::id == type.location.file->id);
if (!typeFile || !cc::util::isRootedUnderAnyOf(_inputPaths, typeFile->path))
continue;

// Skip if its a template instantiation
const auto typeEntity = _ctx.db->query_one<Entity>(
odb::query<Entity>::astNodeId == type.id);
odb::query<Entity>::astNodeId == type.astNodeId);
if (typeEntity && typeEntity->tags.find(model::Tag::TemplateInstantiation)
!= typeEntity->tags.cend())
continue;
Expand Down Expand Up @@ -256,7 +248,7 @@ void CppMetricsParser::typeMcCabe()
}

model::CppAstNodeMetrics typeMcMetric;
typeMcMetric.astNodeId = type.id;
typeMcMetric.astNodeId = type.astNodeId;
typeMcMetric.type = model::CppAstNodeMetrics::Type::MCCABE_TYPE;
typeMcMetric.value = value;
_ctx.db->persist(typeMcMetric);
Expand Down
Loading