diff options
Diffstat (limited to 'src/checkbase.h')
-rw-r--r-- | src/checkbase.h | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/checkbase.h b/src/checkbase.h index d6d84698..463667a3 100644 --- a/src/checkbase.h +++ b/src/checkbase.h @@ -28,6 +28,7 @@ #include "clazy_export.h" #include "clazy_stl.h" +#include "SourceCompatibilityHelpers.h" #include <clang/Basic/SourceManager.h> #include <clang/Frontend/CompilerInstance.h> @@ -53,13 +54,13 @@ class PreprocessorOptions; class CheckBase; class ClazyContext; -enum CheckLevel { +enum CheckLevel { // See README.md for what each level does CheckLevelUndefined = -1, - CheckLevel0 = 0, // 100% safe, no false-positives, very useful - CheckLevel1, // Similar to CheckLevel0, but sometimes (rarely) there might be some false positive - CheckLevel2, // Sometimes has false-positives (20-30%) - CheckLevel3 = 3, // Not always correct, possibly very noisy, requires a knowledgeable developer to review, might have a very big rate of false-positives - HiddenCheckLevel, // The check is hidden and must be explicitly enabled + CheckLevel0 = 0, + CheckLevel1, + CheckLevel2, + CheckLevel3 = 3, + ManualCheckLevel, MaxCheckLevel = CheckLevel3, DefaultCheckLevel = CheckLevel1 }; @@ -93,23 +94,23 @@ class CLAZYLIB_EXPORT CheckBase public: enum Option { - Option_None = 0 + Option_None = 0, + Option_CanIgnoreIncludes = 1 }; typedef int Options; typedef std::vector<CheckBase*> List; - explicit CheckBase(const std::string &name, const ClazyContext *context, Options = Option_None); + explicit CheckBase(const std::string &name, const ClazyContext *context, + Options = Option_None); CheckBase(const CheckBase &other) = delete; virtual ~CheckBase(); - void VisitStatement(clang::Stmt *stm); - void VisitDeclaration(clang::Decl *stm); - std::string name() const { return m_name; } void setEnabledFixits(int); bool isFixitEnabled(int fixit) const; + bool isFixitEnabled() const; void emitWarning(const clang::Decl *, const std::string &error, bool printWarningTag = true); void emitWarning(const clang::Stmt *, const std::string &error, bool printWarningTag = true); @@ -119,10 +120,15 @@ public: virtual void registerASTMatchers(clang::ast_matchers::MatchFinder &) {}; -protected: + bool canIgnoreIncludes() const + { + return m_options & Option_CanIgnoreIncludes; + } + virtual void VisitStmt(clang::Stmt *stm); virtual void VisitDecl(clang::Decl *decl); - virtual void VisitMacroExpands(const clang::Token ¯oNameTok, const clang::SourceRange &); +protected: + virtual void VisitMacroExpands(const clang::Token ¯oNameTok, const clang::SourceRange &, const clang::MacroInfo *minfo = nullptr); virtual void VisitMacroDefined(const clang::Token ¯oNameTok); virtual void VisitDefined(const clang::Token ¯oNameTok, const clang::SourceRange &); virtual void VisitIfdef(clang::SourceLocation, const clang::Token ¯oNameTok); @@ -133,10 +139,9 @@ protected: bool shouldIgnoreFile(clang::SourceLocation) const; void reallyEmitWarning(clang::SourceLocation loc, const std::string &error, const std::vector<clang::FixItHint> &fixits); - void queueManualFixitWarning(clang::SourceLocation loc, int fixitType, const std::string &message = {}); + void queueManualFixitWarning(clang::SourceLocation loc, const std::string &message = {}, int fixitType = 1); bool warningAlreadyEmitted(clang::SourceLocation loc) const; bool manualFixitAlreadyQueued(clang::SourceLocation loc) const; - virtual std::vector<std::string> supportedOptions() const; bool isOptionSet(const std::string &optionName) const; // 3 shortcuts for stuff that litter the codebase all over. @@ -147,12 +152,6 @@ protected: const std::string m_name; const ClazyContext *const m_context; clang::ASTContext &m_astContext; - const clang::PreprocessorOptions &m_preprocessorOpts; - clang::TranslationUnitDecl *const m_tu; - - clang::CXXMethodDecl *m_lastMethodDecl = nullptr; - clang::Decl *m_lastDecl = nullptr; - clang::Stmt *m_lastStmt = nullptr; std::vector<std::string> m_filesToIgnore; private: friend class ClazyPreprocessorCallbacks; @@ -162,6 +161,8 @@ private: std::vector<unsigned int> m_emittedManualFixItsWarningsInMacro; std::vector<std::pair<clang::SourceLocation, std::string>> m_queuedManualInterventionWarnings; int m_enabledFixits = 0; + const Options m_options; + const std::string m_tag; }; #endif |