comparison clang-tools-extra/clang-tidy/readability/RedundantPreprocessorCheck.cpp @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 79ff65ed7e25
children 1f2b6ac9f198
comparison
equal deleted inserted replaced
232:70dce7da266c 236:c4bab56944e8
22 SourceLocation Loc; 22 SourceLocation Loc;
23 /// Condition used after the preprocessor directive. 23 /// Condition used after the preprocessor directive.
24 std::string Condition; 24 std::string Condition;
25 }; 25 };
26 26
27 const char WarningDescription[] =
28 "nested redundant %select{#if|#ifdef|#ifndef}0; consider removing it";
29 const char NoteDescription[] = "previous %select{#if|#ifdef|#ifndef}0 was here";
30
27 class RedundantPreprocessorCallbacks : public PPCallbacks { 31 class RedundantPreprocessorCallbacks : public PPCallbacks {
28 enum DirectiveKind { DK_If = 0, DK_Ifdef = 1, DK_Ifndef = 2 }; 32 enum DirectiveKind { DK_If = 0, DK_Ifdef = 1, DK_Ifndef = 2 };
29 33
30 public: 34 public:
31 explicit RedundantPreprocessorCallbacks(ClangTidyCheck &Check, 35 explicit RedundantPreprocessorCallbacks(ClangTidyCheck &Check,
32 Preprocessor &PP) 36 Preprocessor &PP)
33 : Check(Check), PP(PP), 37 : Check(Check), PP(PP) {}
34 WarningDescription("nested redundant %select{#if|#ifdef|#ifndef}0; "
35 "consider removing it"),
36 NoteDescription("previous %select{#if|#ifdef|#ifndef}0 was here") {}
37 38
38 void If(SourceLocation Loc, SourceRange ConditionRange, 39 void If(SourceLocation Loc, SourceRange ConditionRange,
39 ConditionValueKind ConditionValue) override { 40 ConditionValueKind ConditionValue) override {
40 StringRef Condition = 41 StringRef Condition =
41 Lexer::getSourceText(CharSourceRange::getTokenRange(ConditionRange), 42 Lexer::getSourceText(CharSourceRange::getTokenRange(ConditionRange),
92 ClangTidyCheck &Check; 93 ClangTidyCheck &Check;
93 Preprocessor &PP; 94 Preprocessor &PP;
94 SmallVector<PreprocessorEntry, 4> IfStack; 95 SmallVector<PreprocessorEntry, 4> IfStack;
95 SmallVector<PreprocessorEntry, 4> IfdefStack; 96 SmallVector<PreprocessorEntry, 4> IfdefStack;
96 SmallVector<PreprocessorEntry, 4> IfndefStack; 97 SmallVector<PreprocessorEntry, 4> IfndefStack;
97 const std::string WarningDescription;
98 const std::string NoteDescription;
99 }; 98 };
100 } // namespace 99 } // namespace
101 100
102 void RedundantPreprocessorCheck::registerPPCallbacks( 101 void RedundantPreprocessorCheck::registerPPCallbacks(
103 const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) { 102 const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {