;
57using namespacetooling;
63std::unique_ptr<CompilationDatabase>
65std::string &ErrorMessage) {
66llvm::raw_string_ostream ErrorStream(ErrorMessage);
67 for(
constCompilationDatabasePluginRegistry::entry &Database :
68CompilationDatabasePluginRegistry::entries()) {
69std::string DatabaseErrorMessage;
70std::unique_ptr<CompilationDatabasePlugin> Plugin(Database.instantiate());
71 if(std::unique_ptr<CompilationDatabase> DB =
72Plugin->loadFromDirectory(BuildDirectory, DatabaseErrorMessage))
74ErrorStream << Database.getName() <<
": "<< DatabaseErrorMessage <<
"\n";
79staticstd::unique_ptr<CompilationDatabase>
81std::string &ErrorMessage) {
82std::stringstream ErrorStream;
83 boolHasErrorMessage =
false;
84 while(!Directory.empty()) {
85std::string LoadErrorMessage;
87 if(std::unique_ptr<CompilationDatabase> DB =
91 if(!HasErrorMessage) {
92ErrorStream <<
"No compilation database found in "<< Directory.str()
93<<
" or any parent directory\n"<< LoadErrorMessage;
94HasErrorMessage =
true;
97Directory = llvm::sys::path::parent_path(Directory);
99ErrorMessage = ErrorStream.str();
103std::unique_ptr<CompilationDatabase>
105std::string &ErrorMessage) {
107StringRef Directory = llvm::sys::path::parent_path(AbsolutePath);
109std::unique_ptr<CompilationDatabase> DB =
113ErrorMessage = (
"Could not auto-detect compilation database for file \""+
114SourceFile +
"\"\n"+ ErrorMessage).str();
118std::unique_ptr<CompilationDatabase>
120std::string &ErrorMessage) {
123std::unique_ptr<CompilationDatabase> DB =
127ErrorMessage = (
"Could not auto-detect compilation database from directory \""+
128SourceDir +
"\"\n"+ ErrorMessage).str();
133std::vector<CompileCommand>
Result;
136std::move(
C.begin(),
C.end(), std::back_inserter(
Result));
147structCompileJobAnalyzer {
156 boolCollectChildren = Collect;
160CollectChildren =
true;
165 const auto*IA = cast<driver::InputAction>(A);
166Inputs.push_back(std::string(IA->getInputArg().getSpelling()));
176runImpl(AI, CollectChildren);
189 if(Info.
getID() == diag::warn_drv_input_file_unused) {
195 Other.HandleDiagnostic(DiagLevel, Info);
206structFilterUnusedFlags {
207 booloperator() (StringRef S) {
208 return(S ==
"-no-integrated-as") || S.starts_with(
"-Wa,");
212std::string GetClangToolCommand() {
214std::string ClangExecutable =
215llvm::sys::fs::getMainExecutable(
"clang", (
void*)&Dummy);
217ClangToolPath = llvm::sys::path::parent_path(ClangExecutable);
218llvm::sys::path::append(ClangToolPath,
"clang-tool");
219 returnstd::string(ClangToolPath);
244std::vector<std::string> &
Result,
245std::string &ErrorMsg) {
247llvm::raw_string_ostream Output(ErrorMsg);
249UnusedInputDiagConsumer DiagClient(DiagnosticPrinter);
252&*DiagOpts, &DiagClient,
false);
257 "", llvm::sys::getDefaultTargetTriple(),
259NewDriver->setCheckInputsExist(
false);
263std::string Argv0 = GetClangToolCommand();
264Args.insert(Args.begin(), Argv0.c_str());
272Args.push_back(
"-c");
278Args.push_back(
"placeholder.cpp");
280llvm::erase_if(Args, FilterUnusedFlags());
282 conststd::unique_ptr<driver::Compilation> Compilation(
283NewDriver->BuildCompilation(Args));
289CompileJobAnalyzer CompileAnalyzer;
291 for(
const auto&
Cmd: Jobs) {
299CompileAnalyzer.run(&
Cmd.getSource());
303 if(CompileAnalyzer.Inputs.empty()) {
304ErrorMsg =
"warning: no compile jobs found\n";
311std::vector<const char *>::iterator End =
312llvm::remove_if(Args, [&](StringRef S) {
313 returnllvm::is_contained(CompileAnalyzer.Inputs, S) ||
314llvm::is_contained(DiagClient.UnusedInputs, S);
317assert(strcmp(*(End - 1),
"-c") == 0);
320 Result= std::vector<std::string>(Args.begin() + 1, End);
324std::unique_ptr<FixedCompilationDatabase>
326 const char*
const*Argv,
327std::string &ErrorMsg,
328 constTwine &Directory) {
332 const char*
const*DoubleDash = std::find(Argv, Argv + Argc, StringRef(
"--"));
333 if(DoubleDash == Argv + Argc)
335std::vector<const char *> CommandLine(DoubleDash + 1, Argv + Argc);
336Argc = DoubleDash - Argv;
338std::vector<std::string> StrippedArgs;
341 returnstd::make_unique<FixedCompilationDatabase>(Directory, StrippedArgs);
344std::unique_ptr<FixedCompilationDatabase>
347llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
File=
348llvm::MemoryBuffer::getFile(
Path);
349 if(std::error_code
Result=
File.getError()) {
350ErrorMsg =
"Error while opening fixed database: "+
Result.message();
354(*File)->getBuffer(), ErrorMsg);
357std::unique_ptr<FixedCompilationDatabase>
359std::string &ErrorMsg) {
361std::vector<std::string> Args;
363 while(!
Data.empty()) {
368Args.push_back(
Line.str());
370 returnstd::make_unique<FixedCompilationDatabase>(Directory, std::move(Args));
375std::vector<std::string> ToolCommandLine(1, GetClangToolCommand());
376ToolCommandLine.insert(ToolCommandLine.end(),
377CommandLine.begin(), CommandLine.end());
378CompileCommands.emplace_back(Directory, StringRef(),
379std::move(ToolCommandLine),
383std::vector<CompileCommand>
385std::vector<CompileCommand>
Result(CompileCommands);
386 Result[0].CommandLine.push_back(std::string(FilePath));
387 Result[0].Filename = std::string(FilePath);
394std::unique_ptr<CompilationDatabase>
395loadFromDirectory(StringRef Directory, std::string &ErrorMessage)
override{
397llvm::sys::path::append(DatabasePath,
"compile_flags.txt");
404staticCompilationDatabasePluginRegistry::Add<FixedCompilationDatabasePlugin>
405X(
"fixed-compilation-database",
"Reads plain-text flags file");
Defines the Diagnostic-related interfaces.
static std::unique_ptr< CompilationDatabase > findCompilationDatabaseFromDirectory(StringRef Directory, std::string &ErrorMessage)
static bool stripPositionalArgs(std::vector< const char * > Args, std::vector< std::string > &Result, std::string &ErrorMsg)
Strips any positional args and possible argv[0] from a command-line provided by the user to construct...
Defines the Diagnostic IDs-related interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Abstract interface, implemented by clients of the front-end, which formats and prints fully processed...
Used for handling and querying diagnostic IDs.
Options for controlling the compiler diagnostics engine.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine a...
const std::string & getArgStdStr(unsigned Idx) const
Return the provided argument string specified by Idx.
Concrete class used by the front-end to report problems and issues.
Level
The level of the diagnostic, after it has been through mapping.
Action - Represent an abstract compilation step to perform.
ActionClass getKind() const
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
JobList - A sequence of jobs to perform.
const list_type & getJobs() const
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
@ Other
Other implicit parameter.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4