Skip to content

Commit

Permalink
Adding inheritance to the efferent coupling of types.
Browse files Browse the repository at this point in the history
  • Loading branch information
intjftw committed Jul 1, 2024
1 parent 11f6e7a commit 63481da
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct CppAstNodeMetrics
BUMPY_ROAD = 4,
LACK_OF_COHESION = 5,
LACK_OF_COHESION_HS = 6,
EFFERENT_TYPE = 7
};

#pragma db id auto
Expand Down
1 change: 0 additions & 1 deletion plugins/cpp_metrics/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ include_directories(
${PLUGIN_DIR}/model/include)

add_library(cxxmetricsparser SHARED
src/efferent.cpp
src/cppmetricsparser.cpp)

target_link_libraries(cxxmetricsparser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class CppMetricsParser : public AbstractParser
// Calculate the lack of cohesion between member variables
// and member functions for every type.
void lackOfCohesion();
// Calculate the efferent coupling of types.
void efferentTypeLevel();


/// @brief Constructs an ODB query that you can use to filter only
Expand Down
60 changes: 56 additions & 4 deletions plugins/cpp_metrics/parser/src/cppmetricsparser.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include <cppmetricsparser/cppmetricsparser.h>
#include "efferent.h"

#include <model/cppastnodemetrics.h>
#include <model/cppastnodemetrics-odb.hxx>
#include <model/cppcohesionmetrics.h>
#include <model/cppcohesionmetrics-odb.hxx>
#include <model/cppfilemetrics.h>
#include <model/cppfilemetrics-odb.hxx>
#include <model/cppinheritance.h>
#include <model/cppinheritance-odb.hxx>

#include <model/cppastnode.h>
#include <model/cppastnode-odb.hxx>
Expand Down Expand Up @@ -365,6 +366,58 @@ void CppMetricsParser::lackOfCohesion()
});
}

void CppMetricsParser::efferentTypeLevel()
{
typedef odb::query<cc::model::CppMemberType> MemTypeQuery;
typedef odb::query<cc::model::CppInheritance> InheritanceQuery;

util::OdbTransaction{_ctx.db}([&, this]
{
std::set<std::uint64_t> dependentTypes;
for (const model::CohesionCppRecordView& type
: _ctx.db->query<model::CohesionCppRecordView>())
{
// Skip types that were included from external libraries.
/*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;*/
//if (!cc::util::isRootedUnderAnyOf(_inputPaths, type.filePath))
//continue;

dependentTypes.clear();
for (const model::CppMemberType& mem : _ctx.db->query<model::CppMemberType>(
MemTypeQuery::typeHash == type.entityHash &&
MemTypeQuery::kind == model::CppMemberType::Kind::Field))
{
LOG(warning) << "step 1";
dependentTypes.insert(mem.memberAstNode.load()->id);
}

for (const model::CppInheritance& inherit : _ctx.db->query<model::CppInheritance>(
InheritanceQuery::derived == type.astNodeId))
{
LOG(warning) << "step 2";
dependentTypes.insert(inherit.base);
}

/*for (const model::CppMemberType& mem : _ctx.db->query<model::CppMemberType>(
MemTypeQuery::typeHash == type.entityHash &&
MemTypeQuery::kind == model::CppMemberType::Kind::Method))
{
dependentTypes.insert(mem.memberAstNode->id);
}*/

model::CppAstNodeMetrics metric;
metric.astNodeId = type.astNodeId;
metric.type = model::CppAstNodeMetrics::Type::EFFERENT_TYPE;
metric.value = dependentTypes.size();
_ctx.db->persist(metric);
}
});
}

bool CppMetricsParser::parse()
{
LOG(info) << "[cppmetricsparser] Computing function parameter count metric.";
Expand All @@ -377,9 +430,8 @@ bool CppMetricsParser::parse()
typeMcCabe();
LOG(info) << "[cppmetricsparser] Computing Lack of Cohesion metric for types.";
lackOfCohesion();

EfferentCoupling efferent(_ctx, _inputPaths);
efferent.efferentTypeLevel();
LOG(info) << "[cppmetricsparser] Computing efferent coupling metric for types.";
efferentTypeLevel();
return true;
}

Expand Down
57 changes: 0 additions & 57 deletions plugins/cpp_metrics/parser/src/efferent.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions plugins/cpp_metrics/parser/src/efferent.h

This file was deleted.

0 comments on commit 63481da

Please sign in to comment.