Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 5 additions & 4 deletions plugins/cpp_metrics/model/include/model/cppastnodemetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ struct CppAstNodeMetrics
{
enum Type
{
PARAMETER_COUNT = 1,
MCCABE = 2,
LACK_OF_COHESION = 3,
LACK_OF_COHESION_HS = 4,
PARAMETER_COUNT,
MCCABE,
LACK_OF_COHESION,
LACK_OF_COHESION_HS,
EFFERENT_TYPE
};

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

add_library(cxxmetricsparser SHARED
src/efferent.cpp
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

efferent.h should also be added here, so CMake can recognize that in case the header file changes, recompilation of the target is required.

src/cppmetricsparser.cpp)

target_link_libraries(cxxmetricsparser
Expand Down
4 changes: 4 additions & 0 deletions plugins/cpp_metrics/parser/src/cppmetricsparser.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <cppmetricsparser/cppmetricsparser.h>
#include "efferent.h"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect inclusion order. Please refer to the coding conventions.


#include <model/cppastnodemetrics.h>
#include <model/cppastnodemetrics-odb.hxx>
Expand Down Expand Up @@ -251,6 +252,9 @@ bool CppMetricsParser::parse()
functionParameters();
functionMcCabe();
lackOfCohesion();

EfferentCoupling efferent(_ctx, _inputPaths);
efferent.efferentTypeLevel();
return true;
}

Expand Down
57 changes: 57 additions & 0 deletions plugins/cpp_metrics/parser/src/efferent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include <model/cpprecord.h>
#include <model/cpprecord-odb.hxx>
#include <model/cppastnodemetrics.h>
#include <model/cppastnodemetrics-odb.hxx>
#include <model/cppcohesionmetrics.h>
#include <model/cppcohesionmetrics-odb.hxx>

#include <util/filesystem.h>
#include <util/odbtransaction.h>

#include "efferent.h"

namespace cc
{
namespace parser
{

EfferentCoupling::EfferentCoupling(
ParserContext& ctx_,
std::vector<std::string>& inputPaths_)
: _ctx(ctx_), _inputPaths(inputPaths_)
{
}

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

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

memberTypes.clear();
for (const model::CppMemberType& mem : _ctx.db->query<model::CppMemberType>(
MemTypeQuery::typeHash == type.entityHash &&
MemTypeQuery::kind == model::CppMemberType::Kind::Field))
{
memberTypes.insert(mem.memberTypeHash);
}

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

} // parser
} // cc
28 changes: 28 additions & 0 deletions plugins/cpp_metrics/parser/src/efferent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef CC_PARSER_EFFERENT_H
#define CC_PARSER_EFFERENT_H

#include "parser/parsercontext.h"

namespace cc
{
namespace parser
{

class EfferentCoupling
{
public:
EfferentCoupling(
ParserContext& ctx_,
std::vector<std::string>& inputPaths_);

void efferentTypeLevel();

private:
ParserContext _ctx;
std::vector<std::string> _inputPaths;
};

} // parser
} // cc

#endif // CC_PARSER_EFFERENT_H