| 1 |
//===--- AnalysisInternal.h - Analysis building blocks ------------- C++-*-===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
// |
| 9 |
// This file provides smaller, testable pieces of the used-header analysis. |
| 10 |
// We find the headers by chaining together several mappings. |
| 11 |
// |
| 12 |
// AST => AST node => Symbol => Location => Header |
| 13 |
// / |
| 14 |
// Macro expansion => |
| 15 |
// |
| 16 |
// The individual steps are declared here. |
| 17 |
// (AST => AST Node => Symbol is one API to avoid materializing DynTypedNodes). |
| 18 |
// |
| 19 |
//===----------------------------------------------------------------------===// |
| 20 |
|
| 21 |
#ifndef CLANG_INCLUDE_CLEANER_ANALYSISINTERNAL_H |
| 22 |
#define CLANG_INCLUDE_CLEANER_ANALYSISINTERNAL_H |
| 23 |
|
| 24 |
#include "TypesInternal.h" |
| 25 |
#include "clang-include-cleaner/Record.h" |
| 26 |
#include "clang-include-cleaner/Types.h" |
| 27 |
#include "llvm/ADT/STLFunctionalExtras.h" |
| 28 |
#include <vector> |
| 29 |
|
| 30 |
namespace clang { |
| 31 |
class ASTContext; |
| 32 |
class Decl; |
| 33 |
class HeaderSearch; |
| 34 |
class NamedDecl; |
| 35 |
class SourceLocation; |
| 36 |
namespace include_cleaner { |
| 37 |
|
| 38 |
/// Traverses part of the AST from \p Root, finding uses of symbols. |
| 39 |
/// |
| 40 |
/// Each use is reported to the callback: |
| 41 |
/// - the SourceLocation describes where the symbol was used. This is usually |
| 42 |
/// the primary location of the AST node found under Root. |
| 43 |
/// - the NamedDecl is the symbol referenced. It is canonical, rather than e.g. |
| 44 |
/// the redecl actually found by lookup. |
| 45 |
/// - the RefType describes the relation between the SourceLocation and the |
| 46 |
/// NamedDecl. |
| 47 |
/// |
| 48 |
/// walkAST is typically called once per top-level declaration in the file |
| 49 |
/// being analyzed, in order to find all references within it. |
| 50 |
void walkAST(Decl &Root, |
| 51 |
llvm::function_ref<void(SourceLocation, NamedDecl &, RefType)>); |
| 52 |
|
| 53 |
/// Finds the headers that provide the symbol location. |
| 54 |
llvm::SmallVector<Hinted<Header>> findHeaders(const SymbolLocation &Loc, |
| 55 |
const SourceManager &SM, |
| 56 |
const PragmaIncludes *PI); |
| 57 |
|
| 58 |
/// A set of locations that provides the declaration. |
| 59 |
std::vector<Hinted<SymbolLocation>> locateSymbol(const Symbol &S); |
| 60 |
|
| 61 |
/// Gets all the providers for a symbol by traversing each location. |
| 62 |
/// Returned headers are sorted by relevance, first element is the most |
| 63 |
/// likely provider for the symbol. |
| 64 |
llvm::SmallVector<Header> headersForSymbol(const Symbol &S, |
| 65 |
const SourceManager &SM, |
| 66 |
const PragmaIncludes *PI); |
| 67 |
|
| 68 |
/// Write an HTML summary of the analysis to the given stream. |
| 69 |
void writeHTMLReport(FileID File, const Includes &, |
| 70 |
llvm::ArrayRef<Decl *> Roots, |
| 71 |
llvm::ArrayRef<SymbolReference> MacroRefs, ASTContext &Ctx, |
| 72 |
HeaderSearch &HS, PragmaIncludes *PI, |
| 73 |
llvm::raw_ostream &OS); |
| 74 |
|
| 75 |
} // namespace include_cleaner |
| 76 |
} // namespace clang |
| 77 |
|
| 78 |
#endif |