2017-05-16 17:38:59 +08:00
|
|
|
//===--- GlobalCompilationDatabase.h ----------------------------*- 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_GLOBALCOMPILATIONDATABASE_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_GLOBALCOMPILATIONDATABASE_H
|
|
|
|
|
|
|
|
#include "Path.h"
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
2017-05-16 18:06:20 +08:00
|
|
|
#include <vector>
|
2017-05-16 17:38:59 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
namespace tooling {
|
|
|
|
class CompilationDatabase;
|
|
|
|
struct CompileCommand;
|
|
|
|
} // namespace tooling
|
|
|
|
|
|
|
|
namespace clangd {
|
|
|
|
|
2017-07-06 16:44:54 +08:00
|
|
|
/// Returns a default compile command to use for \p File.
|
|
|
|
tooling::CompileCommand getDefaultCompileCommand(PathRef File);
|
|
|
|
|
2017-08-01 23:51:38 +08:00
|
|
|
/// Provides compilation arguments used for parsing C and C++ files.
|
2017-05-16 17:38:59 +08:00
|
|
|
class GlobalCompilationDatabase {
|
|
|
|
public:
|
|
|
|
virtual ~GlobalCompilationDatabase() = default;
|
|
|
|
|
|
|
|
virtual std::vector<tooling::CompileCommand>
|
|
|
|
getCompileCommands(PathRef File) = 0;
|
|
|
|
|
|
|
|
/// FIXME(ibiryukov): add facilities to track changes to compilation flags of
|
|
|
|
/// existing targets.
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Gets compile args from tooling::CompilationDatabases built for parent
|
|
|
|
/// directories.
|
|
|
|
class DirectoryBasedGlobalCompilationDatabase
|
|
|
|
: public GlobalCompilationDatabase {
|
|
|
|
public:
|
|
|
|
std::vector<tooling::CompileCommand>
|
|
|
|
getCompileCommands(PathRef File) override;
|
|
|
|
|
2017-07-06 16:44:54 +08:00
|
|
|
void setExtraFlagsForFile(PathRef File, std::vector<std::string> ExtraFlags);
|
|
|
|
|
2017-05-16 17:38:59 +08:00
|
|
|
private:
|
|
|
|
tooling::CompilationDatabase *getCompilationDatabase(PathRef File);
|
|
|
|
|
|
|
|
std::mutex Mutex;
|
|
|
|
/// Caches compilation databases loaded from directories(keys are
|
|
|
|
/// directories).
|
|
|
|
llvm::StringMap<std::unique_ptr<clang::tooling::CompilationDatabase>>
|
|
|
|
CompilationDatabases;
|
2017-07-06 16:44:54 +08:00
|
|
|
|
|
|
|
/// Stores extra flags per file.
|
|
|
|
llvm::StringMap<std::vector<std::string>> ExtraFlagsForFile;
|
2017-05-16 17:38:59 +08:00
|
|
|
};
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif
|