Skip to content

Commit

Permalink
Change unsigned int to std::size_t.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarod42 committed Dec 22, 2023
1 parent 41d914c commit 1e021cb
Show file tree
Hide file tree
Showing 36 changed files with 167 additions and 152 deletions.
36 changes: 21 additions & 15 deletions src/app/feeddict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,24 @@ void feedDict(const ccccc::FuncStat& funcStat,
if (funcStat.isConst()) {
sectionDict.ShowSection("const");
}
sectionDict.SetIntValue("lineDefinition", funcStat.getLineDefinition());
sectionDict.SetIntValue("LOCphy", funcStat.getLineCount().getLineOfCode_physic());
sectionDict.SetIntValue("LOCpro", funcStat.getLineCount().getLineOfCode_program());
sectionDict.SetIntValue("LOCcom", funcStat.getLineCount().getLineOfCode_comment());
sectionDict.SetIntValue("LOCbl", funcStat.getLineCount().getLineOfCode_blank());
sectionDict.SetIntValue("MVG", funcStat.getMcCabeCyclomaticNumber());

sectionDict.SetIntValue("CallCount", funcStat.getCallCount());
sectionDict.SetIntValue("CallerCount", funcStat.getCallerCount());

sectionDict.SetIntValue("Halstead_n", funcStat.getHalsteadMetric().getVocabularySize());
sectionDict.SetIntValue("Halstead_N", funcStat.getHalsteadMetric().getProgramLength());
sectionDict.SetIntValue("lineDefinition", static_cast<int>(funcStat.getLineDefinition()));
sectionDict.SetIntValue("LOCphy",
static_cast<int>(funcStat.getLineCount().getLineOfCode_physic()));
sectionDict.SetIntValue("LOCpro",
static_cast<int>(funcStat.getLineCount().getLineOfCode_program()));
sectionDict.SetIntValue("LOCcom",
static_cast<int>(funcStat.getLineCount().getLineOfCode_comment()));
sectionDict.SetIntValue("LOCbl",
static_cast<int>(funcStat.getLineCount().getLineOfCode_blank()));
sectionDict.SetIntValue("MVG", static_cast<int>(funcStat.getMcCabeCyclomaticNumber()));

sectionDict.SetIntValue("CallCount", static_cast<int>(funcStat.getCallCount()));
sectionDict.SetIntValue("CallerCount", static_cast<int>(funcStat.getCallerCount()));

sectionDict.SetIntValue("Halstead_n",
static_cast<int>(funcStat.getHalsteadMetric().getVocabularySize()));
sectionDict.SetIntValue("Halstead_N",
static_cast<int>(funcStat.getHalsteadMetric().getProgramLength()));
SetDoubleValue(sectionDict, "Halstead_V", funcStat.getHalsteadMetric().getVolume());
SetDoubleValue(sectionDict, "Halstead_D", funcStat.getHalsteadMetric().getDifficulty());
SetDoubleValue(sectionDict, "Halstead_E", funcStat.getHalsteadMetric().getEffort());
Expand All @@ -76,7 +82,7 @@ void feedDict(const ccccc::FuncStat& funcStat,
funcStat.getMaintainabilityIndex().getMaintainabilityIndexCommentWeight());
SetDoubleValue(sectionDict, "MI", funcStat.getMaintainabilityIndex().getMaintainabilityIndex());

sectionDict.SetIntValue("NestedBlockCount", funcStat.getNestedBlockCount());
sectionDict.SetIntValue("NestedBlockCount", static_cast<int>(funcStat.getNestedBlockCount()));

sectionDict.SetValue("namespacesName", namespacesName);
sectionDict.SetValue("classesName", classesName);
Expand Down Expand Up @@ -112,7 +118,7 @@ void feedDict(const ccccc::NamespaceStat& namespaceStat,
} else {
namespacesName += namespaceStat.getName();
}
for (unsigned int i = 0; i != namespaceStat.getFunctionCount(); ++i) {
for (std::size_t i = 0; i != namespaceStat.getFunctionCount(); ++i) {
const ccccc::FuncStat& funcStat = namespaceStat.getFuncStat(i);
feedDict(funcStat, namespacesName, "", dict);
}
Expand All @@ -132,7 +138,7 @@ void feedDict(const ccccc::FileStat& fileStat,

sectionDict->SetValue("filename",
std::filesystem::relative(fileStat.getFilename(), root).string());
for (unsigned int i = 0; i != fileStat.getFunctionCount(); ++i) {
for (std::size_t i = 0; i != fileStat.getFunctionCount(); ++i) {
feedDict(fileStat.getFuncStat(i), "", "", sectionDict);
}
for (const auto& p : fileStat.getNamespaces()) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int main(int argc, char* argv[])
dict.SetValue("cccccRoot", cccccRoot.string());
dict.SetValue("Date", getLocalTime());
const std::filesystem::path root = std::filesystem::current_path();
for (unsigned int i = 0; i != allStat.getFileCount(); ++i) {
for (std::size_t i = 0; i != allStat.getFileCount(); ++i) {
const ccccc::FileStat& filestat = allStat.getFileStat(i);
std::cerr << "feed dict: " << filestat.getFilename() << std::endl;

Expand Down
6 changes: 3 additions & 3 deletions src/lib/allstat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ GetCompileArgumentsFromDatabase(CXCompilationDatabase compilationDatabase,
{
CXCompileCommands compileCommands = clang_CompilationDatabase_getCompileCommands(
compilationDatabase, filename.string().c_str());
const unsigned int compileCommandsCount = clang_CompileCommands_getSize(compileCommands);
const std::size_t compileCommandsCount = clang_CompileCommands_getSize(compileCommands);

if (compileCommandsCount == 0) { // No entries in database
clang_CompileCommands_dispose(compileCommands);
Expand Down Expand Up @@ -118,14 +118,14 @@ void AllStat::Compute(const Parameters& param)
tu = clang_parseTranslationUnit(index,
absFilename.string().c_str(),
argsFromCommandLine.data(),
argsFromCommandLine.size(),
static_cast<int>(argsFromCommandLine.size()),
0,
0,
0);
} else {
std::filesystem::current_path(workingDirectory);
auto args = CStringView(argsFromDatabase);
tu = clang_parseTranslationUnit(index, nullptr, args.data(), args.size(), 0, 0, 0);
tu = clang_parseTranslationUnit(index, nullptr, args.data(), static_cast<int>(args.size()), 0, 0, 0);
std::filesystem::current_path(currentWorkingDirectory);
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/allstat.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class AllStat

void Compute(const Parameters& param);

unsigned int getFileCount() const { return m_filesStat.size(); }
const FileStat& getFileStat(unsigned int index) const { return *m_filesStat[index]; }
auto getFileCount() const { return m_filesStat.size(); }
const FileStat& getFileStat(std::size_t index) const { return *m_filesStat[index]; }

private:
std::vector<std::unique_ptr<FileStat>> m_filesStat;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/classstat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ ClassStat& ClassStat::GetOrCreateClass(const std::string& className)
return *m_classes.insert(make_pair(className, std::move(classStat))).first->second;
}

FuncStat* ClassStat::AddMethodStat(const std::string& className, unsigned int line)
FuncStat* ClassStat::AddMethodStat(const std::string& className, std::size_t line)
{
auto stat = std::make_unique<FuncStat>(className, line);

Expand Down
8 changes: 4 additions & 4 deletions src/lib/classstat.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ class ClassStat
~ClassStat();

const std::string& getName() const { return m_name; }
unsigned int getMethodCount() const { return m_methodStats.size(); }
const FuncStat& getMethodStat(unsigned int index) const { return *m_methodStats[index]; }
auto getMethodCount() const { return m_methodStats.size(); }
const FuncStat& getMethodStat(std::size_t index) const { return *m_methodStats[index]; }
const FuncStat* getMethodStatByName(const char* funcNameId) const;

unsigned int getClassCount() const { return m_classes.size(); }
auto getClassCount() const { return m_classes.size(); }
const ClassMap& getInnerClasses() const { return m_classes; }
const ClassStat* getClassByName(const char* funcNameId) const;

private:
FuncStat* AddMethodStat(const std::string& funcname, unsigned int line);
FuncStat* AddMethodStat(const std::string& funcname, std::size_t line);
ClassStat& GetOrCreateClass(const std::string& funcname);

private:
Expand Down
2 changes: 1 addition & 1 deletion src/lib/filestat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ FileStat::~FileStat()
FuncStat* FileStat::AddFuncStat(const std::vector<std::string>& namespaceNames,
const std::vector<std::string>& classeNames,
const std::string& funcname,
unsigned int line)
std::size_t line)
{
NamespaceStat* namespaceStat = &m_root;
for (const auto& namespaceName : namespaceNames) {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/filestat.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,29 @@ class FileStat

const std::filesystem::path& getFilename() const { return m_filename; }
const LineCount& getLineCount() const { return m_lineCount; }
unsigned int getFunctionCount() const { return m_root.getFunctionCount(); }
const FuncStat& getFuncStat(unsigned int index) const { return m_root.getFuncStat(index); }
auto getFunctionCount() const { return m_root.getFunctionCount(); }
const FuncStat& getFuncStat(std::size_t index) const { return m_root.getFuncStat(index); }
const FuncStat* getFuncStatByName(const char* funcNameId) const
{
return m_root.getFuncStatByName(funcNameId);
}

unsigned int getNamespaceCount() const { return m_root.getNamespaceCount(); }
auto getNamespaceCount() const { return m_root.getNamespaceCount(); }
const NamespaceMap& getNamespaces() const { return m_root.getNamespaces(); }
const NamespaceStat* getNamespaceByName(const char* name) const
{
return m_root.getNamespaceByName(name);
}

unsigned int getClassCount() const { return m_root.getClassCount(); }
auto getClassCount() const { return m_root.getClassCount(); }
const ClassMap& getClasses() const { return m_root.getClasses(); }
const ClassStat* getClassByName(const char* name) const { return m_root.getClassByName(name); }

private:
FuncStat* AddFuncStat(const std::vector<std::string>& namespaceNames,
const std::vector<std::string>& classeNames,
const std::string& funcname,
unsigned int line);
std::size_t line);
NamespaceStat* AddNamespace(const std::string& name);

private:
Expand Down
2 changes: 1 addition & 1 deletion src/lib/funcstat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
namespace ccccc
{

FuncStat::FuncStat(const std::string& funcname, unsigned int line) :
FuncStat::FuncStat(const std::string& funcname, std::size_t line) :
m_name(funcname),
m_line(line),
m_mcCabeCyclomaticNumber(0),
Expand Down
22 changes: 11 additions & 11 deletions src/lib/funcstat.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,39 @@ class FuncStat
{
friend class use_clang::FuncStatTool;
public:
FuncStat(const std::string& funcname, unsigned int line);
FuncStat(const std::string& funcname, std::size_t line);

const std::string& getName() const { return m_name; }
bool isConst() const { return m_isConst; }
bool isStatic() const { return m_isStatic; }
bool isVirtual() const { return m_isVirtual; }
bool isOverriden() const { return m_isOverriden; }
const LineCount& getLineCount() const { return m_lineCount; }
unsigned int getMcCabeCyclomaticNumber() const { return m_mcCabeCyclomaticNumber; }
int getLineDefinition() const { return m_line; }
std::size_t getMcCabeCyclomaticNumber() const { return m_mcCabeCyclomaticNumber; }
std::size_t getLineDefinition() const { return m_line; }
const HalsteadMetric& getHalsteadMetric() const { return m_halsteadMetric; }
const MaintainabilityIndex& getMaintainabilityIndex() const { return m_maintainabilityIndex; }
unsigned int getNestedBlockCount() const { return m_nestedBlockCount; }
unsigned int getCallCount() const { return m_callCount; }
unsigned int getCallerCount() const { return m_callerCount; }
std::size_t getNestedBlockCount() const { return m_nestedBlockCount; }
std::size_t getCallCount() const { return m_callCount; }
std::size_t getCallerCount() const { return m_callerCount; }
private:
std::string m_name;
bool m_isConst = false;
bool m_isStatic = false;
bool m_isVirtual = false;
bool m_isOverriden = false;
LineCount m_lineCount;
int m_line;
unsigned int m_mcCabeCyclomaticNumber; // MVG
std::size_t m_line;
std::size_t m_mcCabeCyclomaticNumber; // MVG
HalsteadMetric m_halsteadMetric;
MaintainabilityIndex m_maintainabilityIndex;
unsigned int m_nestedBlockCount;
std::size_t m_nestedBlockCount;
// A Unified Symbol Resolution (USR) is a string
// that identifies a particular entity
std::string m_usr;
CXCursor m_cursor; // Identifier
unsigned int m_callCount = 0; // How many function this function call
unsigned int m_callerCount = 0; // How many time this function is called
std::size_t m_callCount = 0; // How many function this function call
std::size_t m_callerCount = 0; // How many time this function is called
};

} // namespace ccccc
Expand Down
30 changes: 15 additions & 15 deletions src/lib/halsteadmetric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@
namespace ccccc
{

HalsteadMetric::HalsteadMetric(unsigned int operatorCount,
unsigned int uniqueOperatorCount,
unsigned int operandCount,
unsigned int uniqueOperandCount)
HalsteadMetric::HalsteadMetric(std::size_t operatorCount,
std::size_t uniqueOperatorCount,
std::size_t operandCount,
std::size_t uniqueOperandCount)
{
set(operatorCount, uniqueOperatorCount, operandCount, uniqueOperandCount);
}

void HalsteadMetric::set(unsigned int operatorCount,
unsigned int uniqueOperatorCount,
unsigned int operandCount,
unsigned int uniqueOperandCount)
void HalsteadMetric::set(std::size_t operatorCount,
std::size_t uniqueOperatorCount,
std::size_t operandCount,
std::size_t uniqueOperandCount)
{
const unsigned int n1 = uniqueOperatorCount;
const unsigned int n2 = uniqueOperandCount;
const unsigned int N1 = operatorCount;
const unsigned int N2 = operandCount;
const unsigned int N = N1 + N2;
const unsigned int n = n1 + n2;
const double V = N * log2(n);
const std::size_t n1 = uniqueOperatorCount;
const std::size_t n2 = uniqueOperandCount;
const std::size_t N1 = operatorCount;
const std::size_t N2 = operandCount;
const std::size_t N = N1 + N2;
const std::size_t n = n1 + n2;
const double V = static_cast<double>(N) * log2(static_cast<double>(n));
const double D = (n1 * N2) / double(2 * n2); // n1 / 2. * double(N2) / n2
const double E = D * V;
const double T = E / 18;
Expand Down
30 changes: 16 additions & 14 deletions src/lib/halsteadmetric.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,36 @@
#ifndef HALSTEAD_METRIC_H
#define HALSTEAD_METRIC_H

#include <cstddef>

namespace ccccc
{

class HalsteadMetric
{
public:
HalsteadMetric() = default;
HalsteadMetric(unsigned int operatorCount,
unsigned int uniqueOperatorCount,
unsigned int operandCount,
unsigned int uniqueOperandCount);

void set(unsigned int operatorCount,
unsigned int uniqueOperatorCount,
unsigned int operandCount,
unsigned int uniqueOperandCount);

unsigned int getVocabularySize() const { return m_vocabularySize; }
unsigned int getProgramLength() const { return m_programLength; }
HalsteadMetric(std::size_t operatorCount,
std::size_t uniqueOperatorCount,
std::size_t operandCount,
std::size_t uniqueOperandCount);

void set(std::size_t operatorCount,
std::size_t uniqueOperatorCount,
std::size_t operandCount,
std::size_t uniqueOperandCount);

std::size_t getVocabularySize() const { return m_vocabularySize; }
std::size_t getProgramLength() const { return m_programLength; }
double getVolume() const { return m_volume; }
double getDifficulty() const { return m_difficulty; }
double getEffort() const { return m_effort; }
double getTimeToImplement() const { return m_timeToImplement; }
double getDeliveredBugCount() const { return m_deliveredBugCount; }

private:
unsigned int m_vocabularySize = 0;
unsigned int m_programLength = 0;
std::size_t m_vocabularySize = 0;
std::size_t m_programLength = 0;
double m_volume = 0.;
double m_difficulty = 0.;
double m_effort = 0.;
Expand Down
8 changes: 4 additions & 4 deletions src/lib/linecount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
namespace ccccc
{

LineCount::LineCount(unsigned int lineOfCode_physic,
unsigned int lineOfCode_program,
unsigned int lineOfCode_blank,
unsigned int lineOfCode_comment) :
LineCount::LineCount(std::size_t lineOfCode_physic,
std::size_t lineOfCode_program,
std::size_t lineOfCode_blank,
std::size_t lineOfCode_comment) :
lineOfCode_physic(lineOfCode_physic),
lineOfCode_program(lineOfCode_program),
lineOfCode_blank(lineOfCode_blank),
Expand Down
26 changes: 14 additions & 12 deletions src/lib/linecount.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#ifndef LINECOUNT_H
#define LINECOUNT_H

#include <cstddef>

namespace ccccc
{
namespace use_clang
Expand All @@ -35,23 +37,23 @@ class LineCount
friend class use_clang::FuncStatTool;

public:
unsigned int getLineOfCode_physic() const { return lineOfCode_physic; }
unsigned int getLineOfCode_program() const { return lineOfCode_program; }
unsigned int getLineOfCode_blank() const { return lineOfCode_blank; }
unsigned int getLineOfCode_comment() const { return lineOfCode_comment; }
std::size_t getLineOfCode_physic() const { return lineOfCode_physic; }
std::size_t getLineOfCode_program() const { return lineOfCode_program; }
std::size_t getLineOfCode_blank() const { return lineOfCode_blank; }
std::size_t getLineOfCode_comment() const { return lineOfCode_comment; }

//private:
LineCount() = default;
LineCount(unsigned int lineOfCode_physic,
unsigned int lineOfCode_program,
unsigned int lineOfCode_blank,
unsigned int lineOfCode_comment);
LineCount(std::size_t lineOfCode_physic,
std::size_t lineOfCode_program,
std::size_t lineOfCode_blank,
std::size_t lineOfCode_comment);

private:
unsigned int lineOfCode_physic = 0; // LOCphy
unsigned int lineOfCode_program = 0; // LOCpro
unsigned int lineOfCode_blank = 0; // LOCbl
unsigned int lineOfCode_comment = 0; // LOCcom
std::size_t lineOfCode_physic = 0; // LOCphy
std::size_t lineOfCode_program = 0; // LOCpro
std::size_t lineOfCode_blank = 0; // LOCbl
std::size_t lineOfCode_comment = 0; // LOCcom
};

} // namespace ccccc
Expand Down
Loading

0 comments on commit 1e021cb

Please sign in to comment.