xref: /llvm-project/clang-tools-extra/include-cleaner/lib/AnalysisInternal.h (revision ec6c3448d31056db5d63d7aed3e9f207edb49321)
141ac245cSSam McCall //===--- AnalysisInternal.h - Analysis building blocks ------------- C++-*-===//
241ac245cSSam McCall //
341ac245cSSam McCall // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
441ac245cSSam McCall // See https://llvm.org/LICENSE.txt for license information.
541ac245cSSam McCall // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
641ac245cSSam McCall //
741ac245cSSam McCall //===----------------------------------------------------------------------===//
841ac245cSSam McCall //
941ac245cSSam McCall // This file provides smaller, testable pieces of the used-header analysis.
1041ac245cSSam McCall // We find the headers by chaining together several mappings.
1141ac245cSSam McCall //
1241ac245cSSam McCall // AST => AST node => Symbol => Location => Header
1341ac245cSSam McCall //                   /
1441ac245cSSam McCall // Macro expansion =>
1541ac245cSSam McCall //
1641ac245cSSam McCall // The individual steps are declared here.
1741ac245cSSam McCall // (AST => AST Node => Symbol is one API to avoid materializing DynTypedNodes).
1841ac245cSSam McCall //
1941ac245cSSam McCall //===----------------------------------------------------------------------===//
2041ac245cSSam McCall 
2141ac245cSSam McCall #ifndef CLANG_INCLUDE_CLEANER_ANALYSISINTERNAL_H
2241ac245cSSam McCall #define CLANG_INCLUDE_CLEANER_ANALYSISINTERNAL_H
2341ac245cSSam McCall 
24749c6a70SKadir Cetinkaya #include "TypesInternal.h"
252bececb8SViktoriia Bakalova #include "clang-include-cleaner/Analysis.h"
2677955480SHaojian Wu #include "clang-include-cleaner/Record.h"
27d19ba74dSKadir Cetinkaya #include "clang-include-cleaner/Types.h"
28*ec6c3448Skadir çetinkaya #include "clang/Basic/LangOptions.h"
29*ec6c3448Skadir çetinkaya #include "clang/Lex/Preprocessor.h"
3041ac245cSSam McCall #include "llvm/ADT/STLFunctionalExtras.h"
31f82f5b05SKadir Cetinkaya #include <vector>
3241ac245cSSam McCall 
3341ac245cSSam McCall namespace clang {
346fa0e026SSam McCall class ASTContext;
3541ac245cSSam McCall class Decl;
366a95e673SSam McCall class HeaderSearch;
3741ac245cSSam McCall class NamedDecl;
38749c6a70SKadir Cetinkaya class SourceLocation;
3941ac245cSSam McCall namespace include_cleaner {
4041ac245cSSam McCall 
4141ac245cSSam McCall /// Traverses part of the AST from \p Root, finding uses of symbols.
4241ac245cSSam McCall ///
4341ac245cSSam McCall /// Each use is reported to the callback:
4441ac245cSSam McCall /// - the SourceLocation describes where the symbol was used. This is usually
4541ac245cSSam McCall ///   the primary location of the AST node found under Root.
4641ac245cSSam McCall /// - the NamedDecl is the symbol referenced. It is canonical, rather than e.g.
4741ac245cSSam McCall ///   the redecl actually found by lookup.
48d19ba74dSKadir Cetinkaya /// - the RefType describes the relation between the SourceLocation and the
49d19ba74dSKadir Cetinkaya ///   NamedDecl.
5041ac245cSSam McCall ///
5141ac245cSSam McCall /// walkAST is typically called once per top-level declaration in the file
5241ac245cSSam McCall /// being analyzed, in order to find all references within it.
53d19ba74dSKadir Cetinkaya void walkAST(Decl &Root,
54d19ba74dSKadir Cetinkaya              llvm::function_ref<void(SourceLocation, NamedDecl &, RefType)>);
5541ac245cSSam McCall 
5677955480SHaojian Wu /// Finds the headers that provide the symbol location.
57749c6a70SKadir Cetinkaya llvm::SmallVector<Hinted<Header>> findHeaders(const SymbolLocation &Loc,
58749c6a70SKadir Cetinkaya                                               const SourceManager &SM,
59749c6a70SKadir Cetinkaya                                               const PragmaIncludes *PI);
60749c6a70SKadir Cetinkaya 
61749c6a70SKadir Cetinkaya /// A set of locations that provides the declaration.
62*ec6c3448Skadir çetinkaya std::vector<Hinted<SymbolLocation>> locateSymbol(const Symbol &S,
63*ec6c3448Skadir çetinkaya                                                  const LangOptions &LO);
64749c6a70SKadir Cetinkaya 
656fa0e026SSam McCall /// Write an HTML summary of the analysis to the given stream.
66d3714c2bSSam McCall void writeHTMLReport(FileID File, const Includes &,
6719ab2a67SSam McCall                      llvm::ArrayRef<Decl *> Roots,
6826757732SSam McCall                      llvm::ArrayRef<SymbolReference> MacroRefs, ASTContext &Ctx,
69*ec6c3448Skadir çetinkaya                      const Preprocessor &PP, PragmaIncludes *PI,
706a95e673SSam McCall                      llvm::raw_ostream &OS);
716fa0e026SSam McCall 
7241ac245cSSam McCall } // namespace include_cleaner
7341ac245cSSam McCall } // namespace clang
7441ac245cSSam McCall 
7541ac245cSSam McCall #endif
76