Go to the documentation of this file.
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"
50 llvm::Expected<HeaderFile>
toHeaderFile(llvm::StringRef Header,
51 llvm::StringRef HintPath);
64 SrcMgr::CharacteristicKind
FileKind = SrcMgr::C_User;
97 static_cast<uint8_t
>(
B));
102 return static_cast<uint8_t
>(
A) &
static_cast<uint8_t
>(
B);
123 RealPathNames.emplace_back();
129 void collect(
const CompilerInstance &
CI);
136 llvm::Optional<HeaderID>
getID(
const FileEntry *
Entry)
const;
140 assert(
static_cast<unsigned>(
ID) <= RealPathNames.size());
141 return RealPathNames[
static_cast<unsigned>(
ID)];
145 return !NonSelfContained.contains(
ID);
149 return HasIWYUExport.contains(
ID);
153 llvm::ArrayRef<std::string>
allHeaders()
const {
return RealPathNames; }
159 llvm::DenseMap<HeaderID, unsigned>
165 llvm::DenseMap<tooling::stdlib::Header, llvm::SmallVector<HeaderID>>
180 const FileEntry *MainFileEntry =
nullptr;
182 std::vector<std::string> RealPathNames;
188 llvm::DenseMap<llvm::sys::fs::UniqueID, HeaderID> UIDToIndex;
191 llvm::DenseSet<HeaderID> NonSelfContained;
194 llvm::DenseSet<HeaderID> HasIWYUExport;
205 HeaderSearch *HeaderSearchInfo)
207 HeaderSearchInfo(HeaderSearchInfo),
236 llvm::Optional<std::string>
238 llvm::StringRef IncludingFile)
const;
242 llvm::Optional<TextEdit>
insert(llvm::StringRef VerbatimHeader)
const;
248 HeaderSearch *HeaderSearchInfo =
nullptr;
249 llvm::StringSet<> IncludedHeaders;
250 tooling::HeaderIncludes Inserter;
259 template <>
struct DenseMapInfo<
clang::clangd::IncludeStructure::HeaderID> {
281 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_HEADERS_H
void collect(const CompilerInstance &CI)
Some operations such as code completion produce a set of candidates.
llvm::Optional< unsigned > HeaderID
IncludeInserter(StringRef FileName, StringRef Code, const format::FormatStyle &Style, StringRef BuildDir, HeaderSearch *HeaderSearchInfo)
std::string Path
A typedef to represent a file path.
StringRef getRealPath(HeaderID ID) const
static cl::opt< std::string > FormatStyle("format-style", cl::desc(R"(
Style for formatting code around applied fixes:
- 'none' (default) turns off formatting
- 'file' (literally 'file', not a placeholder)
uses .clang-format file in the closest parent
directory
- '{ <json> }' specifies options inline, e.g.
-format-style='{BasedOnStyle: llvm, IndentWidth: 8}'
- 'llvm', 'google', 'webkit', 'mozilla'
See clang-format documentation for the up-to-date
information about formatting styles and options.
This option overrides the 'FormatStyle` option in
.clang-tidy file, if any.
)"), cl::init("none"), cl::cat(ClangTidyCategory))
llvm::Optional< HeaderID > getID(const FileEntry *Entry) const
std::unique_ptr< CompilerInvocation > CI
llvm::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.
std::vector< Inclusion > MainFileIncludes
DeclRelationSet operator&(DeclRelation L, DeclRelation R)
bool shouldInsertInclude(PathRef DeclaringHeader, const HeaderFile &InsertedHeader) const
Checks whether to add an #include of the header into File.
llvm::SmallVector< llvm::StringRef, 1 > getRankedIncludes(const Symbol &Sym)
llvm::hash_code hash_value(const SymbolID &ID)
tok::PPKeywordKind Directive
IncludeGraphNode::SourceFlag & operator|=(IncludeGraphNode::SourceFlag &A, IncludeGraphNode::SourceFlag B)
The class presents a C++ symbol, e.g.
bool hasIWYUExport(HeaderID ID) const
std::vector< llvm::StringRef > DirectIncludes
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::DenseMap< tooling::stdlib::Header, llvm::SmallVector< HeaderID > > StdlibHeaders
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const CodeCompletion &C)
llvm::DenseMap< HeaderID, unsigned > includeDepth(HeaderID Root=MainFileID) const
bool isLiteralInclude(llvm::StringRef Include)
Returns true if Include is literal include like "path" or <path>.
void addExisting(const Inclusion &Inc)
llvm::StringRef PathRef
A typedef to represent a ref to file path.
static const HeaderID MainFileID
HeaderID getOrCreateID(FileEntryRef Entry)
llvm::Optional< TextEdit > insert(llvm::StringRef VerbatimHeader) const
Calculates an edit that inserts VerbatimHeader into code.
SrcMgr::CharacteristicKind FileKind
std::array< uint8_t, 8 > FileDigest
DeclRelationSet operator|(DeclRelation L, DeclRelation R)
llvm::ArrayRef< std::string > allHeaders() const
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
llvm::StringMap< IncludeGraphNode > IncludeGraph
bool operator==(const Inclusion &LHS, const Inclusion &RHS)
bool isSelfContained(HeaderID ID) const
llvm::DenseMap< HeaderID, SmallVector< HeaderID > > IncludeChildren