xref: /llvm-project/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.h (revision 4718da506091a37ca4863d979bc541e359b79b10)
1587deb45SJulie Hockett //===--- MultipleInheritanceCheck.h - clang-tidy-----------------*- C++ -*-===//
2587deb45SJulie Hockett //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6587deb45SJulie Hockett //
7587deb45SJulie Hockett //===----------------------------------------------------------------------===//
8587deb45SJulie Hockett 
9587deb45SJulie Hockett #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLE_INHERITANCE_H
10587deb45SJulie Hockett #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLE_INHERITANCE_H
11587deb45SJulie Hockett 
12478fc5c8SAlexander Kornienko #include "../ClangTidyCheck.h"
13587deb45SJulie Hockett 
14*4718da50SCarlos Galvez namespace clang::tidy::fuchsia {
15587deb45SJulie Hockett 
16dd5571d5SKazuaki Ishizaki /// Multiple implementation inheritance is discouraged.
17587deb45SJulie Hockett ///
18587deb45SJulie Hockett /// For the user-facing documentation see:
196e566bc5SRichard /// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia/multiple-inheritance.html
20587deb45SJulie Hockett class MultipleInheritanceCheck : public ClangTidyCheck {
21587deb45SJulie Hockett public:
MultipleInheritanceCheck(StringRef Name,ClangTidyContext * Context)22587deb45SJulie Hockett   MultipleInheritanceCheck(StringRef Name, ClangTidyContext *Context)
23587deb45SJulie Hockett       : ClangTidyCheck(Name, Context) {}
isLanguageVersionSupported(const LangOptions & LangOpts)24e40a742aSNathan James   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
25e40a742aSNathan James     return LangOpts.CPlusPlus;
26e40a742aSNathan James   }
27587deb45SJulie Hockett   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
28587deb45SJulie Hockett   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
29587deb45SJulie Hockett 
onEndOfTranslationUnit()30587deb45SJulie Hockett   void onEndOfTranslationUnit() override { InterfaceMap.clear(); }
31587deb45SJulie Hockett 
32587deb45SJulie Hockett private:
33ade0662cSSalman Javed   void addNodeToInterfaceMap(const CXXRecordDecl *Node, bool IsInterface);
34ade0662cSSalman Javed   bool getInterfaceStatus(const CXXRecordDecl *Node, bool &IsInterface) const;
35587deb45SJulie Hockett   bool isCurrentClassInterface(const CXXRecordDecl *Node) const;
36587deb45SJulie Hockett   bool isInterface(const CXXRecordDecl *Node);
37587deb45SJulie Hockett 
38587deb45SJulie Hockett   // Contains the identity of each named CXXRecord as an interface.  This is
39587deb45SJulie Hockett   // used to memoize lookup speeds and improve performance from O(N^2) to O(N),
40587deb45SJulie Hockett   // where N is the number of classes.
41587deb45SJulie Hockett   llvm::StringMap<bool> InterfaceMap;
42587deb45SJulie Hockett };
43587deb45SJulie Hockett 
44*4718da50SCarlos Galvez } // namespace clang::tidy::fuchsia
45587deb45SJulie Hockett 
46587deb45SJulie Hockett #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLE_INHERITANCE_H
47