File src/Finder.cpp changed (mode: 100644) (index ebec09e..f8f7ebb) |
... |
... |
public: |
47 |
47 |
private: |
private: |
48 |
48 |
Funcs::iterator registerFunc(const FunctionDecl &func, |
Funcs::iterator registerFunc(const FunctionDecl &func, |
49 |
49 |
const SourceManager &sm) const; |
const SourceManager &sm) const; |
50 |
|
void registerRef(const DeclRefExpr &ref, |
|
51 |
|
const SourceManager &sm) const; |
|
|
50 |
|
void registerRef(const DeclRefExpr &ref, const SourceManager &sm) const; |
52 |
51 |
|
|
53 |
52 |
Funcs &funcs; |
Funcs &funcs; |
54 |
53 |
}; |
}; |
55 |
54 |
|
|
56 |
|
MatchHelper::MatchHelper(Funcs &funcs) |
|
57 |
|
: funcs(funcs) {} |
|
|
55 |
|
MatchHelper::MatchHelper(Funcs &funcs) : funcs(funcs) {} |
58 |
56 |
|
|
59 |
57 |
void MatchHelper::run(const Result &result) { |
void MatchHelper::run(const Result &result) { |
60 |
58 |
using Func = FunctionDecl; |
using Func = FunctionDecl; |
|
... |
... |
void MatchHelper::registerRef(const DeclRefExpr &ref, |
93 |
91 |
} |
} |
94 |
92 |
} |
} |
95 |
93 |
|
|
96 |
|
} // namespace |
|
|
94 |
|
} // namespace |
97 |
95 |
|
|
98 |
96 |
class Finder::Impl { |
class Finder::Impl { |
99 |
97 |
public: |
public: |
|
... |
... |
Finder::Impl::Impl() : helper(funcs) { |
116 |
114 |
} |
} |
117 |
115 |
|
|
118 |
116 |
Finder::Impl::~Impl() { |
Finder::Impl::~Impl() { |
119 |
|
for (auto & func : funcs) { |
|
|
117 |
|
for (auto &func : funcs) { |
120 |
118 |
const auto &funcInfo = func.second; |
const auto &funcInfo = func.second; |
121 |
119 |
|
|
122 |
120 |
if (funcInfo.isFullyDeclared()) { |
if (funcInfo.isFullyDeclared()) { |
File src/FuncInfo.cpp changed (mode: 100644) (index 52c6596..e5a9a53) |
... |
... |
void FuncInfo::registerRef(const clang::DeclRefExpr &ref, |
52 |
52 |
bool FuncInfo::isUnused() const { return calls.empty(); } |
bool FuncInfo::isUnused() const { return calls.empty(); } |
53 |
53 |
|
|
54 |
54 |
bool FuncInfo::canBeMadeStatic() const { |
bool FuncInfo::canBeMadeStatic() const { |
55 |
|
for (const auto & call : calls) { |
|
|
55 |
|
for (const auto &call : calls) { |
56 |
56 |
if (!call.isInThisUnit(fileName)) { |
if (!call.isInThisUnit(fileName)) { |
57 |
57 |
return false; |
return false; |
58 |
58 |
} |
} |
File src/FuncInfo.hpp changed (mode: 100644) (index 22e1c3c..ada220e) |
28 |
28 |
|
|
29 |
29 |
#include "RefInfo.hpp" |
#include "RefInfo.hpp" |
30 |
30 |
|
|
31 |
|
|
|
32 |
31 |
namespace clang { |
namespace clang { |
33 |
32 |
class FunctionDecl; |
class FunctionDecl; |
34 |
33 |
class DeclRefExpr; |
class DeclRefExpr; |
35 |
34 |
class SourceManager; |
class SourceManager; |
36 |
35 |
} // namespace clang |
} // namespace clang |
37 |
36 |
|
|
38 |
|
|
|
39 |
37 |
class FuncInfo { |
class FuncInfo { |
40 |
|
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const FuncInfo &fi); |
|
|
38 |
|
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &os, |
|
39 |
|
const FuncInfo &fi); |
41 |
40 |
|
|
42 |
41 |
public: |
public: |
43 |
42 |
FuncInfo(const clang::FunctionDecl &func, const clang::SourceManager &sm); |
FuncInfo(const clang::FunctionDecl &func, const clang::SourceManager &sm); |
|
... |
... |
public: |
53 |
52 |
private: |
private: |
54 |
53 |
const std::string name; |
const std::string name; |
55 |
54 |
std::string fileName; |
std::string fileName; |
56 |
|
unsigned int lineNum {0}; |
|
|
55 |
|
unsigned int lineNum{0}; |
57 |
56 |
typedef std::vector<RefInfo> Refs; |
typedef std::vector<RefInfo> Refs; |
58 |
57 |
Refs calls; |
Refs calls; |
59 |
58 |
}; |
}; |
File src/RefInfo.cpp changed (mode: 100644) (index 1d1e2e2..985c3db) |
24 |
24 |
#include <clang/Basic/SourceLocation.h> |
#include <clang/Basic/SourceLocation.h> |
25 |
25 |
#include <clang/Basic/SourceManager.h> |
#include <clang/Basic/SourceManager.h> |
26 |
26 |
|
|
27 |
|
|
|
28 |
27 |
namespace { |
namespace { |
29 |
28 |
std::string getFilename(const clang::DeclRefExpr &ref, |
std::string getFilename(const clang::DeclRefExpr &ref, |
30 |
29 |
const clang::SourceManager &sm) { |
const clang::SourceManager &sm) { |
31 |
|
clang::FullSourceLoc fullLoc(ref.getExprLoc(), sm); |
|
32 |
|
return sm.getFilename(fullLoc); |
|
|
30 |
|
clang::FullSourceLoc fullLoc(ref.getExprLoc(), sm); |
|
31 |
|
return sm.getFilename(fullLoc); |
33 |
32 |
} |
} |
34 |
|
} // namespace |
|
35 |
|
|
|
|
33 |
|
} // namespace |
36 |
34 |
|
|
37 |
|
RefInfo::RefInfo(const clang::DeclRefExpr &ref, |
|
38 |
|
const clang::SourceManager &sm) |
|
39 |
|
: fileName(getFilename(ref, sm)) { |
|
40 |
|
} |
|
|
35 |
|
RefInfo::RefInfo(const clang::DeclRefExpr &ref, const clang::SourceManager &sm) |
|
36 |
|
: fileName(getFilename(ref, sm)) {} |
41 |
37 |
|
|
42 |
38 |
bool RefInfo::isInThisUnit(const std::string &other) const { |
bool RefInfo::isInThisUnit(const std::string &other) const { |
43 |
39 |
return other == fileName; |
return other == fileName; |
File src/unused-funcs.cpp changed (mode: 100644) (index 8fe71b0..03d9228) |
30 |
30 |
namespace ct = clang::tooling; |
namespace ct = clang::tooling; |
31 |
31 |
|
|
32 |
32 |
namespace { |
namespace { |
33 |
|
class CustomDiagnosticConsumer: public clang::DiagnosticConsumer { |
|
34 |
|
public: |
|
35 |
|
bool IncludeInDiagnosticCounts() const override { return false; } |
|
36 |
|
}; |
|
37 |
|
} // namespace |
|
|
33 |
|
class CustomDiagnosticConsumer : public clang::DiagnosticConsumer { |
|
34 |
|
public: |
|
35 |
|
bool IncludeInDiagnosticCounts() const override { return false; } |
|
36 |
|
}; |
|
37 |
|
} // namespace |
38 |
38 |
|
|
39 |
39 |
static llvm::cl::extrahelp commonHelp(ct::CommonOptionsParser::HelpMessage); |
static llvm::cl::extrahelp commonHelp(ct::CommonOptionsParser::HelpMessage); |
40 |
40 |
|
|