diff options
Diffstat (limited to 'clangd/ClangdUnit.h')
-rw-r--r-- | clangd/ClangdUnit.h | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/clangd/ClangdUnit.h b/clangd/ClangdUnit.h index 15bf998d..d5d29981 100644 --- a/clangd/ClangdUnit.h +++ b/clangd/ClangdUnit.h @@ -1,21 +1,23 @@ //===--- ClangdUnit.h --------------------------------------------*- C++-*-===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDUNIT_H #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CLANGDUNIT_H +#include "Compiler.h" #include "Diagnostics.h" #include "FS.h" #include "Function.h" #include "Headers.h" #include "Path.h" #include "Protocol.h" +#include "index/CanonicalIncludes.h" +#include "index/Index.h" #include "clang/Frontend/FrontendAction.h" #include "clang/Frontend/PrecompiledPreamble.h" #include "clang/Lex/Preprocessor.h" @@ -31,15 +33,14 @@ class raw_ostream; namespace vfs { class FileSystem; -} +} // namespace vfs } // namespace llvm namespace clang { -class PCHContainerOperations; namespace tooling { struct CompileCommand; -} +} // namespace tooling namespace clangd { @@ -47,7 +48,9 @@ namespace clangd { struct PreambleData { PreambleData(PrecompiledPreamble Preamble, std::vector<Diag> Diags, IncludeStructure Includes, - std::unique_ptr<PreambleFileStatusCache> StatCache); + std::vector<std::string> MainFileMacros, + std::unique_ptr<PreambleFileStatusCache> StatCache, + CanonicalIncludes CanonIncludes); tooling::CompileCommand CompileCommand; PrecompiledPreamble Preamble; @@ -55,16 +58,14 @@ struct PreambleData { // Processes like code completions and go-to-definitions will need #include // information, and their compile action skips preamble range. IncludeStructure Includes; + // Macros defined in the preamble section of the main file. + // Users care about headers vs main-file, not preamble vs non-preamble. + // These should be treated as main-file entities e.g. for code completion. + std::vector<std::string> MainFileMacros; // Cache of FS operations performed when building the preamble. // When reusing a preamble, this cache can be consumed to save IO. std::unique_ptr<PreambleFileStatusCache> StatCache; -}; - -/// Information required to run clang, e.g. to parse AST or do code completion. -struct ParseInputs { - tooling::CompileCommand CompileCommand; - IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS; - std::string Contents; + CanonicalIncludes CanonIncludes; }; /// Stores and provides access to parsed AST. @@ -76,8 +77,8 @@ public: build(std::unique_ptr<clang::CompilerInvocation> CI, std::shared_ptr<const PreambleData> Preamble, std::unique_ptr<llvm::MemoryBuffer> Buffer, - std::shared_ptr<PCHContainerOperations> PCHs, - IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS); + IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, const SymbolIndex *Index, + const ParseOptions &Opts); ParsedAST(ParsedAST &&Other); ParsedAST &operator=(ParsedAST &&Other); @@ -105,13 +106,14 @@ public: /// bytes. Does not include the size of the preamble. std::size_t getUsedBytes() const; const IncludeStructure &getIncludeStructure() const; + const CanonicalIncludes &getCanonicalIncludes() const; private: ParsedAST(std::shared_ptr<const PreambleData> Preamble, std::unique_ptr<CompilerInstance> Clang, std::unique_ptr<FrontendAction> Action, std::vector<Decl *> LocalTopLevelDecls, std::vector<Diag> Diags, - IncludeStructure Includes); + IncludeStructure Includes, CanonicalIncludes CanonIncludes); // In-memory preambles must outlive the AST, it is important that this member // goes before Clang and Action. @@ -130,14 +132,12 @@ private: // top-level decls from the preamble. std::vector<Decl *> LocalTopLevelDecls; IncludeStructure Includes; + CanonicalIncludes CanonIncludes; }; using PreambleParsedCallback = - std::function<void(ASTContext &, std::shared_ptr<clang::Preprocessor>)>; - -/// Builds compiler invocation that could be used to build AST or preamble. -std::unique_ptr<CompilerInvocation> -buildCompilerInvocation(const ParseInputs &Inputs); + std::function<void(ASTContext &, std::shared_ptr<clang::Preprocessor>, + const CanonicalIncludes &)>; /// Rebuild the preamble for the new inputs unless the old one can be reused. /// If \p OldPreamble can be reused, it is returned unchanged. @@ -149,8 +149,7 @@ std::shared_ptr<const PreambleData> buildPreamble(PathRef FileName, CompilerInvocation &CI, std::shared_ptr<const PreambleData> OldPreamble, const tooling::CompileCommand &OldCompileCommand, - const ParseInputs &Inputs, - std::shared_ptr<PCHContainerOperations> PCHs, bool StoreInMemory, + const ParseInputs &Inputs, bool StoreInMemory, PreambleParsedCallback PreambleCallback); /// Build an AST from provided user inputs. This function does not check if @@ -159,8 +158,7 @@ buildPreamble(PathRef FileName, CompilerInvocation &CI, llvm::Optional<ParsedAST> buildAST(PathRef FileName, std::unique_ptr<CompilerInvocation> Invocation, const ParseInputs &Inputs, - std::shared_ptr<const PreambleData> Preamble, - std::shared_ptr<PCHContainerOperations> PCHs); + std::shared_ptr<const PreambleData> Preamble); /// Get the beginning SourceLocation at a specified \p Pos. /// May be invalid if Pos is, or if there's no identifier. |