clang-tools 3.8.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

VirtualNearMissCheck.h
Go to the documentation of this file.
1 //===--- VirtualNearMissCheck.h - clang-tidy---------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_VIRTUAL_NEAR_MISS_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_VIRTUAL_NEAR_MISS_H
12
13 #include "../ClangTidy.h"
14 #include <map>
15 #include <string>
16
17 namespace clang {
18 namespace tidy {
19 namespace misc {
20
21 /// \brief Checks for near miss of virtual methods.
22 ///
23 /// For a method in a derived class, this check looks for virtual method with a
24 /// very similar name and an identical signature defined in a base class.
25 ///
26 /// For the user-facing documentation see:
27 /// http://clang.llvm.org/extra/clang-tidy/checks/misc-virtual-near-miss.html
28 class VirtualNearMissCheck : public ClangTidyCheck {
29 public:
30 VirtualNearMissCheck(StringRef Name, ClangTidyContext *Context)
31 : ClangTidyCheck(Name, Context) {}
32 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
33 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
34
35 private:
36 /// Check if the given method is possible to be overridden by some other
37 /// method.
38 ///
39 /// Results are memoized in PossibleMap.
40 bool isPossibleToBeOverridden(const CXXMethodDecl *BaseMD);
41
42 /// Check if the given base method is overridden by some methods in the given
43 /// derived class.
44 ///
45 /// Results are memoized in OverriddenMap.
46 bool isOverriddenByDerivedClass(const CXXMethodDecl *BaseMD,
47 const CXXRecordDecl *DerivedRD);
48
49 /// key: the unique ID of a method;
50 /// value: whether the method is possible to be overridden.
51 std::map<std::string, bool> PossibleMap;
52
53 /// key: <unique ID of base method, name of derived class>
54 /// value: whether the base method is overridden by some method in the derived
55 /// class.
56 std::map<std::pair<std::string, std::string>, bool> OverriddenMap;
57
58 const unsigned EditDistanceThreshold = 1;
59 };
60
61 } // namespace misc
62 } // namespace tidy
63 } // namespace clang
64
65 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_VIRTUAL_NEAR_MISS_H
clang::tidy::misc::VirtualNearMissCheck::VirtualNearMissCheck
VirtualNearMissCheck(StringRef Name, ClangTidyContext *Context)
Definition: VirtualNearMissCheck.h:30
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
Finder
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:188
clang::tidy::misc::VirtualNearMissCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: VirtualNearMissCheck.cpp:227
clang::tidy::misc::VirtualNearMissCheck
Checks for near miss of virtual methods.
Definition: VirtualNearMissCheck.h:28
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:102
clang::tidy::misc::VirtualNearMissCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register ASTMatchers with Finder.
Definition: VirtualNearMissCheck.cpp:217
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:124
Result
const NamedDecl * Result
Definition: USRFinder.cpp:121