clang-tools  3.8.0
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
29 public:
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
VirtualNearMissCheck(StringRef Name, ClangTidyContext *Context)
StringHandle Name
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:188
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Checks for near miss of virtual methods.
Base class for all clang-tidy checks.
Definition: ClangTidy.h:102
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register ASTMatchers with Finder.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
const NamedDecl * Result
Definition: USRFinder.cpp:121