#include "clang/Tooling/Tooling.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticIDs.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/FileSystemOptions.h"
#include "clang/Basic/LLVM.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "clang/Driver/Job.h"
#include "clang/Driver/Options.h"
#include "clang/Driver/Tool.h"
#include "clang/Driver/ToolChain.h"
#include "clang/Frontend/ASTUnit.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/FrontendDiagnostic.h"
#include "clang/Frontend/FrontendOptions.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Tooling/ArgumentsAdjusters.h"
#include "clang/Tooling/CompilationDatabase.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/OptTable.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Host.h"
#include <cassert>
#include <cstring>
#include <memory>
#include <string>
#include <system_error>
#include <utility>
#include <vector>
#define DEBUG_TYPE …
usingnamespaceclang;
usingnamespacetooling;
ToolAction::~ToolAction() = default;
FrontendActionFactory::~FrontendActionFactory() = default;
static driver::Driver *
newDriver(DiagnosticsEngine *Diagnostics, const char *BinaryName,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) { … }
static bool ignoreExtraCC1Commands(const driver::Compilation *Compilation) { … }
namespace clang {
namespace tooling {
const llvm::opt::ArgStringList *
getCC1Arguments(DiagnosticsEngine *Diagnostics,
driver::Compilation *Compilation) { … }
CompilerInvocation *newInvocation(DiagnosticsEngine *Diagnostics,
ArrayRef<const char *> CC1Args,
const char *const BinaryName) { … }
bool runToolOnCode(std::unique_ptr<FrontendAction> ToolAction,
const Twine &Code, const Twine &FileName,
std::shared_ptr<PCHContainerOperations> PCHContainerOps) { … }
}
}
static std::vector<std::string>
getSyntaxOnlyToolArgs(const Twine &ToolName,
const std::vector<std::string> &ExtraArgs,
StringRef FileName) { … }
namespace clang {
namespace tooling {
bool runToolOnCodeWithArgs(
std::unique_ptr<FrontendAction> ToolAction, const Twine &Code,
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
const std::vector<std::string> &Args, const Twine &FileName,
const Twine &ToolName,
std::shared_ptr<PCHContainerOperations> PCHContainerOps) { … }
bool runToolOnCodeWithArgs(
std::unique_ptr<FrontendAction> ToolAction, const Twine &Code,
const std::vector<std::string> &Args, const Twine &FileName,
const Twine &ToolName,
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
const FileContentMappings &VirtualMappedFiles) { … }
llvm::Expected<std::string> getAbsolutePath(llvm::vfs::FileSystem &FS,
StringRef File) { … }
std::string getAbsolutePath(StringRef File) { … }
void addTargetAndModeForProgramName(std::vector<std::string> &CommandLine,
StringRef InvokedAs) { … }
void addExpandedResponseFiles(std::vector<std::string> &CommandLine,
llvm::StringRef WorkingDir,
llvm::cl::TokenizerCallback Tokenizer,
llvm::vfs::FileSystem &FS) { … }
}
}
namespace {
class SingleFrontendActionFactory : public FrontendActionFactory { … };
}
ToolInvocation::ToolInvocation(
std::vector<std::string> CommandLine, ToolAction *Action,
FileManager *Files, std::shared_ptr<PCHContainerOperations> PCHContainerOps)
: … { … }
ToolInvocation::ToolInvocation(
std::vector<std::string> CommandLine,
std::unique_ptr<FrontendAction> FAction, FileManager *Files,
std::shared_ptr<PCHContainerOperations> PCHContainerOps)
: … { … }
ToolInvocation::~ToolInvocation() { … }
bool ToolInvocation::run() { … }
bool ToolInvocation::runInvocation(
const char *BinaryName, driver::Compilation *Compilation,
std::shared_ptr<CompilerInvocation> Invocation,
std::shared_ptr<PCHContainerOperations> PCHContainerOps) { … }
bool FrontendActionFactory::runInvocation(
std::shared_ptr<CompilerInvocation> Invocation, FileManager *Files,
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
DiagnosticConsumer *DiagConsumer) { … }
ClangTool::ClangTool(const CompilationDatabase &Compilations,
ArrayRef<std::string> SourcePaths,
std::shared_ptr<PCHContainerOperations> PCHContainerOps,
IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS,
IntrusiveRefCntPtr<FileManager> Files)
: … { … }
ClangTool::~ClangTool() = default;
void ClangTool::mapVirtualFile(StringRef FilePath, StringRef Content) { … }
void ClangTool::appendArgumentsAdjuster(ArgumentsAdjuster Adjuster) { … }
void ClangTool::clearArgumentsAdjusters() { … }
static void injectResourceDir(CommandLineArguments &Args, const char *Argv0,
void *MainAddr) { … }
int ClangTool::run(ToolAction *Action) { … }
namespace {
class ASTBuilderAction : public ToolAction { … };
}
int ClangTool::buildASTs(std::vector<std::unique_ptr<ASTUnit>> &ASTs) { … }
void ClangTool::setPrintErrorMessage(bool PrintErrorMessage) { … }
namespace clang {
namespace tooling {
std::unique_ptr<ASTUnit>
buildASTFromCode(StringRef Code, StringRef FileName,
std::shared_ptr<PCHContainerOperations> PCHContainerOps) { … }
std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs(
StringRef Code, const std::vector<std::string> &Args, StringRef FileName,
StringRef ToolName, std::shared_ptr<PCHContainerOperations> PCHContainerOps,
ArgumentsAdjuster Adjuster, const FileContentMappings &VirtualMappedFiles,
DiagnosticConsumer *DiagConsumer) { … }
}
}