Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions include/Compiler/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
namespace clice {

struct CommandOptions {
/// Ignore unknown commands.
bool ignore_unknown = true;

/// The commands that you want to remove from original commands list.
llvm::ArrayRef<std::string> remove;

/// The commands that you want to add to original commands list.
llvm::ArrayRef<std::string> append;

/// Attach resource directory to the command.
bool resource_dir = false;

Expand All @@ -19,7 +28,7 @@ struct CommandOptions {

/// Suppress the warning log if failed to query driver info.
/// Set true in unittests to avoid cluttering test output.
bool suppress_log = false;
bool suppress_logging = false;
};

class CompilationDatabase {
Expand All @@ -39,6 +48,12 @@ class CompilationDatabase {

/// The canonical command list.
llvm::ArrayRef<const char*> arguments;

/// The extra command @...
llvm::StringRef response_file;

/// The original index of the response file argument in the command list.
std::uint32_t response_file_index = 0;
};

struct DriverInfo {
Expand Down Expand Up @@ -81,6 +96,12 @@ class CompilationDatabase {

CompilationDatabase();

CompilationDatabase(CompilationDatabase&& other);

CompilationDatabase& operator= (CompilationDatabase&& other);

~CompilationDatabase();

auto save_string(this Self& self, llvm::StringRef string) -> llvm::StringRef;

auto save_cstring_list(this Self& self, llvm::ArrayRef<const char*> arguments)
Expand All @@ -95,20 +116,25 @@ class CompilationDatabase {

/// Update with arguments.
auto update_command(this Self& self,
llvm::StringRef dictionary,
llvm::StringRef directory,
llvm::StringRef file,
llvm::ArrayRef<const char*> arguments) -> UpdateInfo;

/// Update with full command.
auto update_command(this Self& self,
llvm::StringRef dictionary,
llvm::StringRef directory,
llvm::StringRef file,
llvm::StringRef command) -> UpdateInfo;

/// Update commands from json file and return all updated file.
auto load_commands(this Self& self, llvm::StringRef json_content, llvm::StringRef workspace)
-> std::expected<std::vector<UpdateInfo>, std::string>;

auto process_command(this Self& self,
llvm::StringRef file,
const CommandInfo& info,
const CommandOptions& options) -> std::vector<const char*>;

/// Get compile command from database. `file` should has relative path of workspace.
auto get_command(this Self& self, llvm::StringRef file, CommandOptions options = {})
-> LookupInfo;
Expand All @@ -124,6 +150,9 @@ class CompilationDatabase {
auto guess_or_fallback(this Self& self, llvm::StringRef file) -> LookupInfo;

private:
/// The opaque handle of `ArgumentParser`.
void* parser;

/// The memory pool to hold all cstring and command list.
llvm::BumpPtrAllocator allocator;

Expand Down
4 changes: 2 additions & 2 deletions include/Test/Tester.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct Tester {
CommandOptions options;
options.resource_dir = true;
options.query_driver = true;
options.suppress_log = true;
options.suppress_logging = true;
params.arguments = database.get_command(src_path, options).arguments;

for(auto& [file, source]: sources.all_files) {
Expand Down Expand Up @@ -76,7 +76,7 @@ struct Tester {
CommandOptions options;
options.resource_dir = true;
options.query_driver = true;
options.suppress_log = true;
options.suppress_logging = true;
params.arguments = database.get_command(src_path, options).arguments;

auto path = fs::createTemporaryFile("clice", "pch");
Expand Down
Loading