2018-02-16 22:15:55 +08:00
|
|
|
//===--- Headers.h - Include headers -----------------------------*- C++-*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_HEADERS_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_HEADERS_H
|
|
|
|
|
|
|
|
#include "Path.h"
|
2018-05-14 20:19:16 +08:00
|
|
|
#include "Protocol.h"
|
2018-02-16 22:15:55 +08:00
|
|
|
#include "clang/Basic/VirtualFileSystem.h"
|
2018-05-14 20:19:16 +08:00
|
|
|
#include "clang/Lex/PPCallbacks.h"
|
2018-02-16 22:15:55 +08:00
|
|
|
#include "clang/Tooling/CompilationDatabase.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/Support/Error.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
2018-02-20 02:48:44 +08:00
|
|
|
|
2018-02-26 16:32:13 +08:00
|
|
|
/// Returns true if \p Include is literal include like "path" or <path>.
|
|
|
|
bool isLiteralInclude(llvm::StringRef Include);
|
|
|
|
|
|
|
|
/// Represents a header file to be #include'd.
|
|
|
|
struct HeaderFile {
|
|
|
|
std::string File;
|
|
|
|
/// If this is true, `File` is a literal string quoted with <> or "" that
|
|
|
|
/// can be #included directly; otherwise, `File` is an absolute file path.
|
|
|
|
bool Verbatim;
|
|
|
|
|
|
|
|
bool valid() const;
|
|
|
|
};
|
|
|
|
|
2018-05-14 20:19:16 +08:00
|
|
|
// An #include directive that we found in the main file.
|
|
|
|
struct Inclusion {
|
|
|
|
Range R; // Inclusion range.
|
|
|
|
std::string Written; // Inclusion name as written e.g. <vector>.
|
|
|
|
Path Resolved; // Resolved path of included file. Empty if not resolved.
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Returns a PPCallback that visits all inclusions in the main file.
|
|
|
|
std::unique_ptr<PPCallbacks>
|
|
|
|
collectInclusionsInMainFileCallback(const SourceManager &SM,
|
|
|
|
std::function<void(Inclusion)> Callback);
|
|
|
|
|
2018-02-16 22:15:55 +08:00
|
|
|
/// Determines the preferred way to #include a file, taking into account the
|
|
|
|
/// search path. Usually this will prefer a shorter representation like
|
|
|
|
/// 'Foo/Bar.h' over a longer one like 'Baz/include/Foo/Bar.h'.
|
|
|
|
///
|
2018-02-20 02:48:44 +08:00
|
|
|
/// \param File is an absolute file path.
|
2018-02-26 16:32:13 +08:00
|
|
|
/// \param DeclaringHeader is the original header corresponding to \p
|
|
|
|
/// InsertedHeader e.g. the header that declares a symbol.
|
|
|
|
/// \param InsertedHeader The preferred header to be inserted. This could be the
|
|
|
|
/// same as DeclaringHeader but must be provided.
|
|
|
|
// \return A quoted "path" or <path>. This returns an empty string if:
|
|
|
|
/// - Either \p DeclaringHeader or \p InsertedHeader is already (directly)
|
|
|
|
/// included in the file (including those included via different paths).
|
|
|
|
/// - \p DeclaringHeader or \p InsertedHeader is the same as \p File.
|
2018-02-16 22:15:55 +08:00
|
|
|
llvm::Expected<std::string>
|
2018-02-26 16:32:13 +08:00
|
|
|
calculateIncludePath(PathRef File, llvm::StringRef Code,
|
|
|
|
const HeaderFile &DeclaringHeader,
|
|
|
|
const HeaderFile &InsertedHeader,
|
2018-02-20 02:48:44 +08:00
|
|
|
const tooling::CompileCommand &CompileCommand,
|
|
|
|
IntrusiveRefCntPtr<vfs::FileSystem> FS);
|
2018-02-16 22:15:55 +08:00
|
|
|
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_HEADERS_H
|