Skip to content

Commit

Permalink
Removing C++ metrics plugin and related C++ plugin changes from Gersw…
Browse files Browse the repository at this point in the history
…hin release.
  • Loading branch information
mcserep committed Apr 1, 2024
1 parent 1a1209e commit 953d5ba
Show file tree
Hide file tree
Showing 26 changed files with 3 additions and 2,006 deletions.
5 changes: 0 additions & 5 deletions Functions.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# Generate ODB files from sources
# @return ODB_CXX_SOURCES - odb cxx source files
function(generate_odb_files _src)
set(DEPENDENCY_PLUGIN_INCLUDE_DIRS ${ARGN})
list(TRANSFORM DEPENDENCY_PLUGIN_INCLUDE_DIRS PREPEND "-I${CMAKE_SOURCE_DIR}/plugins/")
list(TRANSFORM DEPENDENCY_PLUGIN_INCLUDE_DIRS APPEND "/model/include")

foreach(_file ${_src})
get_filename_component(_dir ${_file} DIRECTORY)
get_filename_component(_name ${_file} NAME)
Expand All @@ -29,7 +25,6 @@ function(generate_odb_files _src)
-I ${CMAKE_SOURCE_DIR}/model/include
-I ${CMAKE_SOURCE_DIR}/util/include
-I ${ODB_INCLUDE_DIRS}
${DEPENDENCY_PLUGIN_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/${_file}
COMMAND
mv ${CMAKE_CURRENT_BINARY_DIR}/include/model/${_cxx}
Expand Down
35 changes: 0 additions & 35 deletions plugins/cpp/model/include/model/cppfunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ struct CppFunction : CppTypedEntity
std::vector<odb::lazy_shared_ptr<CppVariable>> parameters;
#pragma db on_delete(cascade)
std::vector<odb::lazy_shared_ptr<CppVariable>> locals;
unsigned int mccabe;

std::string toString() const
{
Expand All @@ -40,24 +39,6 @@ struct CppFunctionParamCount
std::size_t count;
};

#pragma db view \
object(CppFunction) \
object(CppVariable = Parameters : CppFunction::parameters) \
object(CppAstNode : CppFunction::astNodeId == CppAstNode::id) \
object(File : CppAstNode::location.file) \
query((?) + "GROUP BY" + cc::model::CppEntity::astNodeId + "," + cc::model::File::path)
struct CppFunctionParamCountWithId
{
#pragma db column(CppEntity::astNodeId)
CppAstNodeId id;

#pragma db column("count(" + Parameters::id + ")")
std::size_t count;

#pragma db column(File::path)
std::string filePath;
};

#pragma db view \
object(CppFunction) object(CppVariable = Locals : CppFunction::locals)
struct CppFunctionLocalCount
Expand All @@ -66,22 +47,6 @@ struct CppFunctionLocalCount
std::size_t count;
};

#pragma db view \
object(CppFunction) \
object(CppAstNode : CppFunction::astNodeId == CppAstNode::id) \
object(File : CppAstNode::location.file)
struct CppFunctionMcCabe
{
#pragma db column(CppEntity::astNodeId)
CppAstNodeId astNodeId;

#pragma db column(CppFunction::mccabe)
unsigned int mccabe;

#pragma db column(File::path)
std::string filePath;
};

}
}

Expand Down
217 changes: 3 additions & 214 deletions plugins/cpp/parser/src/clangastvisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <mutex>
#include <type_traits>
#include <stack>
#include <functional>

#include <clang/Basic/SourceLocation.h>
#include <clang/Basic/SourceManager.h>
Expand Down Expand Up @@ -153,9 +152,6 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>

bool TraverseFunctionDecl(clang::FunctionDecl* fd_)
{
if (fd_->doesThisDeclarationHaveABody())
return TraverseFunctionDeclWithBody(fd_);

_functionStack.push(std::make_shared<model::CppFunction>());

bool b = Base::TraverseFunctionDecl(fd_);
Expand All @@ -167,30 +163,8 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
return b;
}

bool TraverseFunctionDeclWithBody(clang::FunctionDecl* fd_)
{
_functionStack.push(std::make_shared<model::CppFunction>());
_mcCabeStack.push(1);

bool b = Base::TraverseFunctionDecl(fd_);

model::CppFunctionPtr top = _functionStack.top();
if (top->astNodeId)
{
top->mccabe = _mcCabeStack.top();
_functions.push_back(top);
}
_mcCabeStack.pop();
_functionStack.pop();

return b;
}

bool TraverseCXXDeductionGuideDecl(clang::CXXDeductionGuideDecl* fd_)
{
if (fd_->doesThisDeclarationHaveABody())
return TraverseCXXDeductionGuideDeclWithBody(fd_);

_functionStack.push(std::make_shared<model::CppFunction>());

bool b = Base::TraverseCXXDeductionGuideDecl(fd_);
Expand All @@ -202,30 +176,8 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
return b;
}

bool TraverseCXXDeductionGuideDeclWithBody(clang::CXXDeductionGuideDecl* fd_)
{
_functionStack.push(std::make_shared<model::CppFunction>());
_mcCabeStack.push(1);

bool b = Base::TraverseCXXDeductionGuideDecl(fd_);

model::CppFunctionPtr top = _functionStack.top();
if (top->astNodeId)
{
top->mccabe = _mcCabeStack.top();
_functions.push_back(top);
}
_mcCabeStack.pop();
_functionStack.pop();

return b;
}

bool TraverseCXXMethodDecl(clang::CXXMethodDecl* fd_)
{
if (fd_->doesThisDeclarationHaveABody())
return TraverseCXXMethodDeclWithBody(fd_);

_functionStack.push(std::make_shared<model::CppFunction>());

bool b = Base::TraverseCXXMethodDecl(fd_);
Expand All @@ -237,30 +189,8 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
return b;
}

bool TraverseCXXMethodDeclWithBody(clang::CXXMethodDecl* fd_)
{
_functionStack.push(std::make_shared<model::CppFunction>());
_mcCabeStack.push(1);

bool b = Base::TraverseCXXMethodDecl(fd_);

model::CppFunctionPtr top = _functionStack.top();
if (top->astNodeId)
{
top->mccabe = _mcCabeStack.top();
_functions.push_back(top);
}
_mcCabeStack.pop();
_functionStack.pop();

return b;
}

bool TraverseCXXConstructorDecl(clang::CXXConstructorDecl* fd_)
{
if (fd_->doesThisDeclarationHaveABody())
return TraverseCXXConstructorDeclWithBody(fd_);

_functionStack.push(std::make_shared<model::CppFunction>());

bool b = Base::TraverseCXXConstructorDecl(fd_);
Expand All @@ -272,30 +202,8 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
return b;
}

bool TraverseCXXConstructorDeclWithBody(clang::CXXConstructorDecl* fd_)
{
_functionStack.push(std::make_shared<model::CppFunction>());
_mcCabeStack.push(1);

bool b = Base::TraverseCXXConstructorDecl(fd_);

model::CppFunctionPtr top = _functionStack.top();
if (top->astNodeId)
{
top->mccabe = _mcCabeStack.top();
_functions.push_back(top);
}
_mcCabeStack.pop();
_functionStack.pop();

return b;
}

bool TraverseCXXDestructorDecl(clang::CXXDestructorDecl* fd_)
{
if (fd_->doesThisDeclarationHaveABody())
return TraverseCXXDestructorDeclWithBody(fd_);

_functionStack.push(std::make_shared<model::CppFunction>());

bool b = Base::TraverseCXXDestructorDecl(fd_);
Expand All @@ -307,30 +215,8 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
return b;
}

bool TraverseCXXDestructorDeclWithBody(clang::CXXDestructorDecl* fd_)
{
_functionStack.push(std::make_shared<model::CppFunction>());
_mcCabeStack.push(1);

bool b = Base::TraverseCXXDestructorDecl(fd_);

model::CppFunctionPtr top = _functionStack.top();
if (top->astNodeId)
{
top->mccabe = _mcCabeStack.top();
_functions.push_back(top);
}
_mcCabeStack.pop();
_functionStack.pop();

return b;
}

bool TraverseCXXConversionDecl(clang::CXXConversionDecl* fd_)
{
if (fd_->doesThisDeclarationHaveABody())
return TraverseCXXConversionDeclWithBody(fd_);

_functionStack.push(std::make_shared<model::CppFunction>());

bool b = Base::TraverseCXXConversionDecl(fd_);
Expand All @@ -342,25 +228,6 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
return b;
}

bool TraverseCXXConversionDeclWithBody(clang::CXXConversionDecl* fd_)
{
_functionStack.push(std::make_shared<model::CppFunction>());
_mcCabeStack.push(1);

bool b = Base::TraverseCXXConversionDecl(fd_);

model::CppFunctionPtr top = _functionStack.top();
if (top->astNodeId)
{
top->mccabe = _mcCabeStack.top();
_functions.push_back(top);
}
_mcCabeStack.pop();
_functionStack.pop();

return b;
}

bool TraverseRecordDecl(clang::RecordDecl* rd_)
{
_typeStack.push(std::make_shared<model::CppRecord>());
Expand Down Expand Up @@ -462,8 +329,6 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>

bool TraverseBinaryOperator(clang::BinaryOperator* bo_)
{
if (bo_->isLogicalOp() && !_mcCabeStack.empty())
++_mcCabeStack.top();
_contextStatementStack.push(bo_);
bool b = Base::TraverseBinaryOperator(bo_);
_contextStatementStack.pop();
Expand All @@ -486,88 +351,14 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
return b;
}

template<typename T>
bool StatementStackDecorator(T* stmt_, const std::function<bool(T*)>& func_)
bool TraverseStmt(clang::Stmt* s_)
{
_statements.push(stmt_);
bool b = func_(stmt_);
_statements.push(s_);
bool b = Base::TraverseStmt(s_);
_statements.pop();
return b;
}

template<typename T>
bool McCabeDecorator(T* stmt_, const std::function<bool(T*)>& func_)
{
if(!_mcCabeStack.empty())
++_mcCabeStack.top();
return StatementStackDecorator(stmt_, func_);
}

bool TraverseIfStmt(clang::IfStmt* stmt_)
{
return McCabeDecorator<clang::IfStmt>(stmt_, [this] (clang::IfStmt* s) { return Base::TraverseIfStmt(s); });
}

bool TraverseWhileStmt(clang::WhileStmt* stmt_)
{
return McCabeDecorator<clang::WhileStmt>(stmt_, [this] (clang::WhileStmt* s) { return Base::TraverseWhileStmt(s); });
}

bool TraverseDoStmt(clang::DoStmt* stmt_)
{
return McCabeDecorator<clang::DoStmt>(stmt_, [this] (clang::DoStmt* s) { return Base::TraverseDoStmt(s); });
}

bool TraverseForStmt(clang::ForStmt* stmt_)
{
return McCabeDecorator<clang::ForStmt>(stmt_, [this] (clang::ForStmt* s) { return Base::TraverseForStmt(s); });
}

bool TraverseCXXForRangeStmt(clang::CXXForRangeStmt* stmt_)
{
return McCabeDecorator<clang::CXXForRangeStmt>(stmt_, [this] (clang::CXXForRangeStmt* s) { return Base::TraverseCXXForRangeStmt(s); });
}

bool TraverseCaseStmt(clang::CaseStmt* stmt_)
{
return McCabeDecorator<clang::CaseStmt>(stmt_, [this] (clang::CaseStmt* s) { return Base::TraverseCaseStmt(s); });
}

bool TraverseDefaultStmt(clang::DefaultStmt* stmt_)
{
return McCabeDecorator<clang::DefaultStmt>(stmt_, [this] (clang::DefaultStmt* s) { return Base::TraverseDefaultStmt(s); });
}

bool TraverseContinueStmt(clang::ContinueStmt* stmt_)
{
return McCabeDecorator<clang::ContinueStmt>(stmt_, [this] (clang::ContinueStmt* s) { return Base::TraverseContinueStmt(s); });
}

bool TraverseGotoStmt(clang::GotoStmt* stmt_)
{
return McCabeDecorator<clang::GotoStmt>(stmt_, [this] (clang::GotoStmt* s) { return Base::TraverseGotoStmt(s); });
}

bool TraverseCXXCatchStmt(clang::CXXCatchStmt* stmt_)
{
return McCabeDecorator<clang::CXXCatchStmt>(stmt_, [this] (clang::CXXCatchStmt* s) { return Base::TraverseCXXCatchStmt(s); });
}

bool TraverseConditionalOperator(clang::ConditionalOperator* op_)
{
return McCabeDecorator<clang::ConditionalOperator>(op_, [this] (clang::ConditionalOperator* s) { return Base::TraverseConditionalOperator(s); });
}

bool TraverseBinaryConditionalOperator(clang::BinaryConditionalOperator* op_)
{
return McCabeDecorator<clang::BinaryConditionalOperator>(op_, [this] (clang::BinaryConditionalOperator* s) { return Base::TraverseBinaryConditionalOperator(s); });
}

bool TraverseStmt(clang::Stmt* stmt_)
{
return StatementStackDecorator<clang::Stmt>(stmt_, [this] (clang::Stmt* s) { return Base::TraverseStmt(s); });
}

bool VisitTypedefTypeLoc(clang::TypedefTypeLoc tl_)
{
const clang::TypedefType* type = tl_.getTypePtr();
Expand Down Expand Up @@ -932,7 +723,6 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
cppFunction->qualifiedName = fn_->getQualifiedNameAsString();
cppFunction->typeHash = util::fnvHash(getUSR(qualType, _astContext));
cppFunction->qualifiedType = qualType.getAsString();
cppFunction->mccabe = 1;

//--- Tags ---//

Expand Down Expand Up @@ -1870,7 +1660,6 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
std::stack<model::CppFunctionPtr> _functionStack;
std::stack<model::CppRecordPtr> _typeStack;
std::stack<model::CppEnumPtr> _enumStack;
std::stack<unsigned int> _mcCabeStack;

bool _isImplicit;
ParserContext& _ctx;
Expand Down
Loading

0 comments on commit 953d5ba

Please sign in to comment.