9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_HEADERS_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_HEADERS_H
16#include "clang/Basic/FileEntry.h"
17#include "clang/Basic/TokenKinds.h"
18#include "clang/Format/Format.h"
19#include "clang/Frontend/CompilerInstance.h"
20#include "clang/Lex/HeaderSearch.h"
21#include "clang/Lex/Preprocessor.h"
22#include "clang/Tooling/Inclusions/HeaderIncludes.h"
23#include "clang/Tooling/Inclusions/StandardLibrary.h"
24#include "llvm/ADT/ArrayRef.h"
25#include "llvm/ADT/DenseSet.h"
26#include "llvm/ADT/StringRef.h"
27#include "llvm/ADT/StringSet.h"
28#include "llvm/Support/Error.h"
29#include "llvm/Support/FileSystem/UniqueID.h"
36using HeaderFilter = llvm::ArrayRef<std::function<bool(llvm::StringRef)>>;
62llvm::Expected<HeaderFile>
toHeaderFile(llvm::StringRef Header,
63 llvm::StringRef HintPath);
76 SrcMgr::CharacteristicKind
FileKind = SrcMgr::C_User;
108 static_cast<uint8_t
>(B));
113 return static_cast<uint8_t
>(A) &
static_cast<uint8_t
>(B);
134 RealPathNames.emplace_back();
140 void collect(
const CompilerInstance &
CI);
147 std::optional<HeaderID>
getID(
const FileEntry *
Entry)
const;
151 assert(
static_cast<unsigned>(
ID) <= RealPathNames.size());
152 return RealPathNames[
static_cast<unsigned>(
ID)];
156 llvm::ArrayRef<std::string>
allHeaders()
const {
return RealPathNames; }
160 llvm::SmallVector<const Inclusion *>
167 llvm::DenseMap<HeaderID, unsigned>
173 llvm::DenseMap<tooling::stdlib::Header, llvm::SmallVector<HeaderID>>
193 const FileEntry *MainFileEntry =
nullptr;
195 std::vector<std::string> RealPathNames;
201 llvm::DenseMap<llvm::sys::fs::UniqueID, HeaderID> UIDToIndex;
205 llvm::StringMap<llvm::SmallVector<unsigned>> MainFileIncludesBySpelling;
215 const format::FormatStyle &Style, StringRef BuildDir,
216 HeaderSearch *HeaderSearchInfo,
HeaderFilter QuotedHeaders,
219 HeaderSearchInfo(HeaderSearchInfo),
220 Inserter(
FileName, Code, Style.IncludeStyle),
249 std::optional<std::string>
251 llvm::StringRef IncludingFile)
const;
255 std::optional<TextEdit>
insert(llvm::StringRef VerbatimHeader,
256 tooling::IncludeDirective
Directive)
const;
262 HeaderSearch *HeaderSearchInfo =
nullptr;
263 llvm::StringSet<> IncludedHeaders;
264 tooling::HeaderIncludes Inserter;
275template <>
struct DenseMapInfo<
clang::clangd::IncludeStructure::HeaderID> {
286 return hash_value(
static_cast<unsigned>(
Tag));
const MacroDirective * Directive
std::unique_ptr< CompilerInvocation > CI
void addExisting(const Inclusion &Inc)
std::optional< std::string > calculateIncludePath(const HeaderFile &InsertedHeader, llvm::StringRef IncludingFile) const
Determines the preferred way to #include a file, taking into account the search path.
IncludeInserter(StringRef FileName, StringRef Code, const format::FormatStyle &Style, StringRef BuildDir, HeaderSearch *HeaderSearchInfo, HeaderFilter QuotedHeaders, HeaderFilter AngledHeaders)
bool shouldInsertInclude(PathRef DeclaringHeader, const HeaderFile &InsertedHeader) const
Checks whether to add an #include of the header into File.
std::optional< TextEdit > insert(llvm::StringRef VerbatimHeader, tooling::IncludeDirective Directive) const
Calculates an edit that inserts VerbatimHeader into code.
llvm::SmallVector< const Inclusion * > mainFileIncludesWithSpelling(llvm::StringRef Spelling) const
static const HeaderID MainFileID
llvm::DenseMap< HeaderID, unsigned > includeDepth(HeaderID Root=MainFileID) const
std::vector< Inclusion > MainFileIncludes
StringRef getRealPath(HeaderID ID) const
std::vector< std::string > SearchPathsCanonical
llvm::DenseMap< tooling::stdlib::Header, llvm::SmallVector< HeaderID > > StdlibHeaders
HeaderID getOrCreateID(FileEntryRef Entry)
llvm::ArrayRef< std::string > allHeaders() const
void collect(const CompilerInstance &CI)
std::optional< HeaderID > getID(const FileEntry *Entry) const
llvm::DenseMap< HeaderID, SmallVector< HeaderID > > IncludeChildren
bool isLiteralInclude(llvm::StringRef Include)
Returns true if Include is literal include like "path" or <path>.
std::string Path
A typedef to represent a file path.
DeclRelationSet operator&(DeclRelation L, DeclRelation R)
bool operator==(const Inclusion &LHS, const Inclusion &RHS)
std::array< uint8_t, 8 > FileDigest
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
DeclRelationSet operator|(DeclRelation L, DeclRelation R)
llvm::Expected< HeaderFile > toHeaderFile(llvm::StringRef Header, llvm::StringRef HintPath)
Creates a HeaderFile from Header which can be either a URI or a literal include.
llvm::StringMap< IncludeGraphNode > IncludeGraph
llvm::SmallVector< SymbolInclude, 1 > getRankedIncludes(const Symbol &Sym)
llvm::ArrayRef< std::function< bool(llvm::StringRef)> > HeaderFilter
llvm::StringRef PathRef
A typedef to represent a ref to file path.
IncludeGraphNode::SourceFlag & operator|=(IncludeGraphNode::SourceFlag &A, IncludeGraphNode::SourceFlag B)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Some operations such as code completion produce a set of candidates.
std::vector< llvm::StringRef > DirectIncludes
tok::PPKeywordKind Directive
SrcMgr::CharacteristicKind FileKind
std::optional< unsigned > HeaderID
A header and directives as stored in a Symbol.
Symbol::IncludeDirective Directive
The include directive(s) that can be used, e.g. #import and/or #include.
llvm::StringRef Header
The header to include.
The class presents a C++ symbol, e.g.