aboutsummaryrefslogtreecommitdiffstats
path: root/src/checkbase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/checkbase.cpp')
-rw-r--r--src/checkbase.cpp59
1 files changed, 23 insertions, 36 deletions
diff --git a/src/checkbase.cpp b/src/checkbase.cpp
index bafebb8c..f423ec83 100644
--- a/src/checkbase.cpp
+++ b/src/checkbase.cpp
@@ -44,10 +44,10 @@ ClazyPreprocessorCallbacks::ClazyPreprocessorCallbacks(CheckBase *check)
{
}
-void ClazyPreprocessorCallbacks::MacroExpands(const Token &macroNameTok, const MacroDefinition &,
+void ClazyPreprocessorCallbacks::MacroExpands(const Token &macroNameTok, const MacroDefinition &md,
SourceRange range, const MacroArgs *)
{
- check->VisitMacroExpands(macroNameTok, range);
+ check->VisitMacroExpands(macroNameTok, range, md.getMacroInfo());
}
void ClazyPreprocessorCallbacks::Defined(const Token &macroNameTok, const MacroDefinition &, SourceRange range)
@@ -65,14 +65,14 @@ void ClazyPreprocessorCallbacks::MacroDefined(const Token &macroNameTok, const M
check->VisitMacroDefined(macroNameTok);
}
-CheckBase::CheckBase(const string &name, const ClazyContext *context, Options)
+CheckBase::CheckBase(const string &name, const ClazyContext *context, Options options)
: m_sm(context->ci.getSourceManager())
, m_name(name)
, m_context(context)
, m_astContext(context->astContext)
- , m_preprocessorOpts(context->ci.getPreprocessorOpts())
- , m_tu(m_astContext.getTranslationUnitDecl())
, m_preprocessorCallbacks(new ClazyPreprocessorCallbacks(this))
+ , m_options(options)
+ , m_tag(" [-Wclazy-" + m_name + ']')
{
}
@@ -80,21 +80,6 @@ CheckBase::~CheckBase()
{
}
-void CheckBase::VisitStatement(Stmt *stm)
-{
- m_lastStmt = stm;
- VisitStmt(stm);
-}
-
-void CheckBase::VisitDeclaration(Decl *decl)
-{
- m_lastDecl = decl;
- if (auto mdecl = dyn_cast<CXXMethodDecl>(decl))
- m_lastMethodDecl = mdecl;
-
- VisitDecl(decl);
-}
-
void CheckBase::VisitStmt(Stmt *)
{
// Overriden in derived classes
@@ -105,7 +90,7 @@ void CheckBase::VisitDecl(Decl *)
// Overriden in derived classes
}
-void CheckBase::VisitMacroExpands(const Token &, const SourceRange &)
+void CheckBase::VisitMacroExpands(const Token &, const SourceRange &, const clang::MacroInfo *)
{
// Overriden in derived classes
}
@@ -141,19 +126,19 @@ bool CheckBase::shouldIgnoreFile(SourceLocation loc) const
string filename = sm().getFilename(loc);
- return clazy_std::any_of(m_filesToIgnore, [filename](const std::string &ignored) {
- return clazy_std::contains(filename, ignored);
+ return clazy::any_of(m_filesToIgnore, [filename](const std::string &ignored) {
+ return clazy::contains(filename, ignored);
});
}
void CheckBase::emitWarning(const clang::Decl *d, const std::string &error, bool printWarningTag)
{
- emitWarning(d->getLocStart(), error, printWarningTag);
+ emitWarning(getLocStart(d), error, printWarningTag);
}
void CheckBase::emitWarning(const clang::Stmt *s, const std::string &error, bool printWarningTag)
{
- emitWarning(s->getLocStart(), error, printWarningTag);
+ emitWarning(getLocStart(s), error, printWarningTag);
}
void CheckBase::emitWarning(clang::SourceLocation loc, const std::string &error, bool printWarningTag)
@@ -167,15 +152,17 @@ void CheckBase::emitWarning(clang::SourceLocation loc, std::string error,
if (m_context->suppressionManager.isSuppressed(m_name, loc, sm(), lo()))
return;
+ if (m_context->shouldIgnoreFile(loc))
+ return;
+
if (loc.isMacroID()) {
if (warningAlreadyEmitted(loc))
return; // For warnings in macro arguments we get a warning in each place the argument is used within the expanded macro, so filter all the dups
m_emittedWarningsInMacro.push_back(loc.getRawEncoding());
}
- const string tag = " [-Wclazy-" + name() + ']';
if (printWarningTag)
- error += tag;
+ error += m_tag;
reallyEmitWarning(loc, error, fixits);
@@ -184,7 +171,7 @@ void CheckBase::emitWarning(clang::SourceLocation loc, std::string error,
if (!l.second.empty())
msg += ' ' + l.second;
- reallyEmitWarning(l.first, msg + tag, {});
+ reallyEmitWarning(l.first, msg + m_tag, {});
}
m_queuedManualInterventionWarnings.clear();
@@ -192,8 +179,7 @@ void CheckBase::emitWarning(clang::SourceLocation loc, std::string error,
void CheckBase::emitInternalError(SourceLocation loc, string error)
{
- const string tag = " [-Wclazy-" + name() + ']';
- llvm::errs() << tag << ": internal error: " << error
+ llvm::errs() << m_tag << ": internal error: " << error
<< " at " << loc.printToString(sm()) << "\n";
}
@@ -211,7 +197,7 @@ void CheckBase::reallyEmitWarning(clang::SourceLocation loc, const std::string &
}
}
-void CheckBase::queueManualFixitWarning(clang::SourceLocation loc, int fixitType, const string &message)
+void CheckBase::queueManualFixitWarning(clang::SourceLocation loc, const string &message, int fixitType)
{
if (isFixitEnabled(fixitType) && !manualFixitAlreadyQueued(loc)) {
m_queuedManualInterventionWarnings.push_back({loc, message});
@@ -245,11 +231,6 @@ bool CheckBase::manualFixitAlreadyQueued(SourceLocation loc) const
return false;
}
-std::vector<string> CheckBase::supportedOptions() const
-{
- return {};
-}
-
bool CheckBase::isOptionSet(const std::string &optionName) const
{
const string qualifiedName = name() + '-' + optionName;
@@ -266,6 +247,12 @@ bool CheckBase::isFixitEnabled(int fixit) const
return (m_enabledFixits & fixit) || (m_context->options & ClazyContext::ClazyOption_AllFixitsEnabled);
}
+bool CheckBase::isFixitEnabled() const
+{
+ // Checks with only 1 fixit (which is most of them) don't need to pass fixit id
+ return isFixitEnabled(1);
+}
+
ClazyAstMatcherCallback::ClazyAstMatcherCallback(CheckBase *check)
: MatchFinder::MatchCallback()
, m_check(check)