From 1b0db9b3b74b2fa744f1828e68a05badedc222c8 Mon Sep 17 00:00:00 2001 From: ykiko Date: Fri, 4 Oct 2024 10:13:55 +0800 Subject: [PATCH] Remove `Command`. --- include/Compiler/Compiler.h | 11 +++++++++++ include/Compiler/Dependency.h | 13 +++++++++++++ include/Compiler/ParsedAST.h | 3 ++- include/Server/Command.h | 36 ----------------------------------- include/Server/Config.h | 2 +- include/Server/Server.h | 1 - src/Compiler/ParsedAST.cpp | 7 ++++++- src/Server/Command.cpp | 21 -------------------- src/Server/Config.cpp | 10 +++++++--- src/Server/Server.cpp | 7 ++++--- 10 files changed, 44 insertions(+), 67 deletions(-) create mode 100644 include/Compiler/Dependency.h delete mode 100644 include/Server/Command.h delete mode 100644 src/Server/Command.cpp diff --git a/include/Compiler/Compiler.h b/include/Compiler/Compiler.h index 83ca0bb3..2d824604 100644 --- a/include/Compiler/Compiler.h +++ b/include/Compiler/Compiler.h @@ -16,4 +16,15 @@ std::unique_ptr createInvocation(StringRef filename, std::unique_ptr createInstance(std::shared_ptr invocation); + + +/// - build AST +/// - build module +/// - build preamble +/// - build CodeCompletion +class Compiler { +public: + Compiler(); +}; + } // namespace clice diff --git a/include/Compiler/Dependency.h b/include/Compiler/Dependency.h new file mode 100644 index 00000000..43940bbf --- /dev/null +++ b/include/Compiler/Dependency.h @@ -0,0 +1,13 @@ +#pragma once + +namespace clice::dependency { + +/// Record the include graph of the translation unit. +struct IncludeGraph {}; + +/// Record the map between module name and file path. +struct ModuleMap {}; + +// TODO: + +} // namespace clice::dependency diff --git a/include/Compiler/ParsedAST.h b/include/Compiler/ParsedAST.h index a7b2e934..940f1ef5 100644 --- a/include/Compiler/ParsedAST.h +++ b/include/Compiler/ParsedAST.h @@ -18,7 +18,8 @@ struct ParsedAST { static std::unique_ptr build(llvm::StringRef filename, llvm::StringRef content, std::vector& args, - Preamble* preamble = nullptr); + Preamble* preamble = nullptr, + clang::CodeCompleteConsumer* consumer = nullptr); clang::FileID getFileID(llvm::StringRef filename) const { auto entry = fileManager.getFileRef(filename); diff --git a/include/Server/Command.h b/include/Server/Command.h deleted file mode 100644 index 01e6badb..00000000 --- a/include/Server/Command.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include - -namespace clice { - -namespace command { - -std::vector decorate(const clang::tooling::CompileCommand& command); - -class Command { -public: - /// according to config, decorate the input command. - /// e.g. add `resource-dir`, remove or transform unsupported flags like `/std:lastest`. - Command(const clang::tooling::CompileCommand& command); - - Command& append(llvm::StringRef arg) { - auto data = allocator.Allocate(arg.size() + 1); - if(!arg.empty()) { - std::memcpy(data, arg.data(), arg.size()); - } - data[arg.size()] = '\0'; - args.push_back(data); - return *this; - } - -private: - std::vector args; - llvm::BumpPtrAllocator allocator; -}; - -// TODO: compile database logic - -} // namespace command - -} // namespace clice diff --git a/include/Server/Config.h b/include/Server/Config.h index a71dfbc0..e752db90 100644 --- a/include/Server/Config.h +++ b/include/Server/Config.h @@ -9,7 +9,7 @@ int parse(int argc, const char** argv); /// initialize the config, replace all predefined variables in the config file. /// called in `Server::initialize`. -void initialize(std::string_view workplace); +void init(std::string_view workplace); struct ServerOption { std::string mode; diff --git a/include/Server/Server.h b/include/Server/Server.h index 01131daa..ecb35874 100644 --- a/include/Server/Server.h +++ b/include/Server/Server.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include diff --git a/src/Compiler/ParsedAST.cpp b/src/Compiler/ParsedAST.cpp index 2fc6ad74..4f369c51 100644 --- a/src/Compiler/ParsedAST.cpp +++ b/src/Compiler/ParsedAST.cpp @@ -6,7 +6,8 @@ namespace clice { std::unique_ptr ParsedAST::build(llvm::StringRef filename, llvm::StringRef content, std::vector& args, - Preamble* preamble) { + Preamble* preamble, + clang::CodeCompleteConsumer* consumer) { auto vfs = llvm::vfs::getRealFileSystem(); clang::CreateInvocationOptions options; @@ -28,6 +29,10 @@ std::unique_ptr ParsedAST::build(llvm::StringRef filename, preproc.addCommentHandler(directive->handler()); preproc.addPPCallbacks(directive->callback()); + if(consumer) { + instance->setCodeCompletionConsumer(consumer); + } + if(auto error = action->Execute()) { llvm::errs() << "Failed to execute action: " << error << "\n"; std::terminate(); diff --git a/src/Server/Command.cpp b/src/Server/Command.cpp deleted file mode 100644 index dbe04c1f..00000000 --- a/src/Server/Command.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include - -namespace clice { - -namespace command { - -Command::Command(const clang::tooling::CompileCommand& command) { - // FIXME: - for(auto& arg: command.CommandLine) { - append(arg); - } - - append("-resource-dir"); - append(config::frontend().resource_dictionary); -} - -} // namespace command - -} // namespace clice diff --git a/src/Server/Config.cpp b/src/Server/Config.cpp index 8bba1441..fa690839 100644 --- a/src/Server/Config.cpp +++ b/src/Server/Config.cpp @@ -80,7 +80,7 @@ int parse(int argc, const char** argv) { return 0; } -void initialize(std::string_view workplace) { +void init(std::string_view workplace) { predefined["workplace"] = workplace; refl::walk(config, [&](std::string_view name, Field& field) { @@ -91,8 +91,12 @@ void initialize(std::string_view workplace) { return; } -const ServerOption& server() { return config.server; } +const ServerOption& server() { + return config.server; +} -const FrontendOption& frontend() { return config.frontend; } +const FrontendOption& frontend() { + return config.frontend; +} } // namespace clice::config diff --git a/src/Server/Server.cpp b/src/Server/Server.cpp index 9411dd4a..243a8177 100644 --- a/src/Server/Server.cpp +++ b/src/Server/Server.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include @@ -17,7 +16,9 @@ class MessageBuffer { std::size_t max = 0; public: - void write(std::string_view message) { buffer.insert(buffer.end(), message.begin(), message.end()); } + void write(std::string_view message) { + buffer.insert(buffer.end(), message.begin(), message.end()); + } std::string_view read() { std::string_view view = std::string_view(buffer.data(), buffer.size()); @@ -145,7 +146,7 @@ void eventloop(uv_idle_t* handle) { } auto Server::initialize(protocol::InitializeParams params) -> protocol::InitializeResult { - config::initialize(URI::resolve(params.workspaceFolders[0].uri)); + config::init(URI::resolve(params.workspaceFolders[0].uri)); return protocol::InitializeResult(); }