Skip to content

Commit

Permalink
Variable renaming and other small refactorings.
Browse files Browse the repository at this point in the history
  • Loading branch information
intjftw committed Apr 7, 2024
1 parent 0936a19 commit e09e8ff
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
33 changes: 11 additions & 22 deletions plugins/cpp_metrics/service/cxxmetrics.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,28 @@ struct CppModuleMetricsTypeName
2:string name
}

struct CppMetricsAstNode
struct CppMetricsAstNodeSingle
{
1:CppAstNodeMetricsType type,
2:double value
}

struct CppAllMetricsAstNode
struct CppMetricsAstNodeAll
{
1:common.AstNodeId id,
2:list<CppMetricsAstNode> metrics
2:list<CppMetricsAstNodeSingle> metrics
}

struct CppMetricsModule
struct CppMetricsModuleSingle
{
1:CppModuleMetricsType type,
2:double value
}

struct CppAllMetricsModule
struct CppMetricsModuleAll
{
1:common.FileId id,
2:list<CppMetricsModule> metrics
}

// Thrift does not provide a union type,
// the ids can remain empty.
struct CppMetricsPath
{
1:CppUnitType type
2:common.AstNodeId astNodeId
3:list<CppMetricsAstNode> astNodeIdMetrics
4:common.FileId fileId
5:list<CppMetricsModule> fileMetrics
2:list<CppMetricsModuleSingle> metrics
}

service CppMetricsService
Expand All @@ -84,28 +73,28 @@ service CppMetricsService
* This function returns all available C++ metrics
* for a particular AST node.
*/
list<CppMetricsAstNode> getCppMetricsForAstNode(
list<CppMetricsAstNodeSingle> getCppMetricsForAstNode(
1:common.AstNodeId astNodeId)

/**
* This function returns all available C++ metrics
* for a particular module.
*/
list<CppMetricsModule> getCppMetricsForModule(
list<CppMetricsModuleSingle> getCppMetricsForModule(
1:common.FileId fileId)

/**
* This function returns all available C++ metrics
* (AST node-level) for a particular path.
*/
list<CppAllMetricsAstNode> getCppAstNodeMetricsForPath(
list<CppMetricsAstNodeAll> getCppAstNodeMetricsForPath(
1:string path)

/**
* This function returns all available C++ metrics
* (file-level) for a particular path.
*/
list<CppAllMetricsModule> getCppFileMetricsForPath(
list<CppMetricsModuleAll> getCppFileMetricsForPath(
1:string path)

/**
Expand All @@ -116,5 +105,5 @@ service CppMetricsService
/**
* This function returns the names of module-level metrics.
*/
list<CppModuleMetricsTypeName> getCppModuleMetricsTypeNames()
list<CppModuleMetricsTypeName> getCppModuleMetricsTypeNames()
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ class CppMetricsServiceHandler : virtual public CppMetricsServiceIf
CppAstNodeMetricsType::type metric_) override;

void getCppMetricsForAstNode(
std::vector<CppMetricsAstNode>& _return,
std::vector<CppMetricsAstNodeSingle>& _return,
const core::AstNodeId& astNodeId_) override;

void getCppMetricsForModule(
std::vector<CppMetricsModule>& _return,
std::vector<CppMetricsModuleSingle>& _return,
const core::FileId& fileId_) override;

void getCppAstNodeMetricsForPath(
std::vector<CppAllMetricsAstNode>& _return,
std::vector<CppMetricsAstNodeAll>& _return,
const std::string& path_) override;

void getCppFileMetricsForPath(
std::vector<CppAllMetricsModule>& _return,
std::vector<CppMetricsModuleAll>& _return,
const std::string& path_) override;

void getCppAstNodeMetricsTypeNames(
Expand Down
24 changes: 12 additions & 12 deletions plugins/cpp_metrics/service/src/cppmetricsservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ void CppMetricsServiceHandler::getCppModuleMetricsTypeNames(
}

void CppMetricsServiceHandler::getCppMetricsForAstNode(
std::vector<CppMetricsAstNode>& _return,
std::vector<CppMetricsAstNodeSingle>& _return,
const core::AstNodeId& astNodeId_)
{
CppMetricsAstNode metric;
CppMetricsAstNodeSingle metric;

_transaction([&, this](){
typedef odb::query<model::CppAstNodeMetrics> CppAstNodeMetricsQuery;
Expand Down Expand Up @@ -97,10 +97,10 @@ double CppMetricsServiceHandler::getSingleCppMetricForAstNode(
}

void CppMetricsServiceHandler::getCppMetricsForModule(
std::vector<CppMetricsModule>& _return,
std::vector<CppMetricsModuleSingle>& _return,
const core::FileId& fileId_)
{
CppMetricsModule metric;
CppMetricsModuleSingle metric;

_transaction([&, this](){
typedef odb::query<model::CppFileMetrics> CppModuleMetricsQuery;
Expand All @@ -118,7 +118,7 @@ void CppMetricsServiceHandler::getCppMetricsForModule(
}

void CppMetricsServiceHandler::getCppAstNodeMetricsForPath(
std::vector<CppAllMetricsAstNode>& _return,
std::vector<CppMetricsAstNodeAll>& _return,
const std::string& path_)
{
_transaction([&, this]()
Expand All @@ -142,9 +142,9 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath(
{
auto metricsQuery = _db->query<model::CppAstNodeMetrics>(
CppAstNodeMetricsQuery::astNodeId == node.id);
std::vector<CppMetricsAstNode> metrics;
std::vector<CppMetricsAstNodeSingle> metrics;

CppMetricsAstNode metricsAstNode;
CppMetricsAstNodeSingle metricsAstNode;
for (const auto& metric : metricsQuery)
{
metricsAstNode.type = static_cast<CppAstNodeMetricsType::type>(metric.type);
Expand All @@ -155,7 +155,7 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath(
if (metrics.empty())
continue;

CppAllMetricsAstNode nodeMetric;
CppMetricsAstNodeAll nodeMetric;
nodeMetric.id = std::to_string(node.id);
nodeMetric.metrics = metrics;
_return.push_back(nodeMetric);
Expand All @@ -164,7 +164,7 @@ void CppMetricsServiceHandler::getCppAstNodeMetricsForPath(
}

void CppMetricsServiceHandler::getCppFileMetricsForPath(
std::vector<CppAllMetricsModule>& _return,
std::vector<CppMetricsModuleAll>& _return,
const std::string& path_)
{
_transaction([&, this]()
Expand All @@ -188,9 +188,9 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath(
{
CppFileMetricsResult metricsQuery = _db->query<model::CppFileMetrics>(
CppFileMetricsQuery::file == file.id);
std::vector<CppMetricsModule> metrics;
std::vector<CppMetricsModuleSingle> metrics;

CppMetricsModule metricsModule;
CppMetricsModuleSingle metricsModule;
for (const auto& metric : metricsQuery)
{
metricsModule.type = static_cast<CppModuleMetricsType::type>(metric.type);
Expand All @@ -201,7 +201,7 @@ void CppMetricsServiceHandler::getCppFileMetricsForPath(
if (metrics.empty())
continue;

CppAllMetricsModule nodeMetric;
CppMetricsModuleAll nodeMetric;
nodeMetric.id = std::to_string(file.id);
nodeMetric.metrics = metrics;
_return.push_back(nodeMetric);
Expand Down

0 comments on commit e09e8ff

Please sign in to comment.