Skip to content

Commit

Permalink
refactor: Cleanup std::bind
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Jul 13, 2023
1 parent e06c31d commit fd86c3a
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 125 deletions.
45 changes: 22 additions & 23 deletions language_server/src/dap/dap_feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "dap_feature.h"

#include <functional>

#include "nlohmann/json.hpp"
#include "utils/path.h"
#include "utils/path_conversions.h"
Expand Down Expand Up @@ -76,30 +78,27 @@ dap_feature::dap_feature(parser_library::debugger_configuration_provider& dc_pro

void dap_feature::register_methods(std::map<std::string, method>& methods)
{
const auto this_bind = [this](void (dap_feature::*func)(const request_id&, const nlohmann::json&),
telemetry_log_level telem = telemetry_log_level::NO_TELEMETRY) {
return method {
[this, func](
const request_id& requested_seq, const nlohmann::json& args) { (this->*func)(requested_seq, args); },
telem,
};
using enum telemetry_log_level;
const auto add_method = [this, &methods](std::string_view name,
auto func,
telemetry_log_level telem = telemetry_log_level::NO_TELEMETRY) {
methods.try_emplace(std::string(name), method { std::bind_front(func, this), telem });
};
methods.try_emplace("initialize", this_bind(&dap_feature::on_initialize));
methods.try_emplace("disconnect", this_bind(&dap_feature::on_disconnect, telemetry_log_level::LOG_EVENT));
methods.try_emplace("launch", this_bind(&dap_feature::on_launch, telemetry_log_level::LOG_EVENT));
methods.try_emplace("setBreakpoints", this_bind(&dap_feature::on_set_breakpoints, telemetry_log_level::LOG_EVENT));
methods.try_emplace("setExceptionBreakpoints",
this_bind(&dap_feature::on_set_exception_breakpoints, telemetry_log_level::LOG_EVENT));
methods.try_emplace("configurationDone", this_bind(&dap_feature::on_configuration_done));
methods.try_emplace("threads", this_bind(&dap_feature::on_threads));
methods.try_emplace("stackTrace", this_bind(&dap_feature::on_stack_trace));
methods.try_emplace("scopes", this_bind(&dap_feature::on_scopes));
methods.try_emplace("next", this_bind(&dap_feature::on_next, telemetry_log_level::LOG_EVENT));
methods.try_emplace("stepIn", this_bind(&dap_feature::on_step_in, telemetry_log_level::LOG_EVENT));
methods.try_emplace("stepOut", this_bind(&dap_feature::on_step_out, telemetry_log_level::LOG_EVENT));
methods.try_emplace("variables", this_bind(&dap_feature::on_variables));
methods.try_emplace("continue", this_bind(&dap_feature::on_continue, telemetry_log_level::LOG_EVENT));
methods.try_emplace("pause", this_bind(&dap_feature::on_pause, telemetry_log_level::LOG_EVENT));
add_method("initialize", &dap_feature::on_initialize);
add_method("disconnect", &dap_feature::on_disconnect, LOG_EVENT);
add_method("launch", &dap_feature::on_launch, LOG_EVENT);
add_method("setBreakpoints", &dap_feature::on_set_breakpoints, LOG_EVENT);
add_method("setExceptionBreakpoints", &dap_feature::on_set_exception_breakpoints, LOG_EVENT);
add_method("configurationDone", &dap_feature::on_configuration_done);
add_method("threads", &dap_feature::on_threads);
add_method("stackTrace", &dap_feature::on_stack_trace);
add_method("scopes", &dap_feature::on_scopes);
add_method("next", &dap_feature::on_next, LOG_EVENT);
add_method("stepIn", &dap_feature::on_step_in, LOG_EVENT);
add_method("stepOut", &dap_feature::on_step_out, LOG_EVENT);
add_method("variables", &dap_feature::on_variables);
add_method("continue", &dap_feature::on_continue, LOG_EVENT);
add_method("pause", &dap_feature::on_pause, LOG_EVENT);
}
nlohmann::json dap_feature::register_capabilities() { return nlohmann::json(); }

Expand Down
31 changes: 12 additions & 19 deletions language_server/src/lsp/feature_language_features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,27 +233,20 @@ feature_language_features::feature_language_features(

void feature_language_features::register_methods(std::map<std::string, method>& methods)
{
const auto this_bind = [this](void (feature_language_features::*func)(const request_id& id, const nlohmann::json&),
telemetry_log_level telem) {
return method {
[this, func](const request_id& id, const nlohmann::json& args) { (this->*func)(id, args); },
telem,
};
using enum telemetry_log_level;
const auto add_method = [this, &methods](std::string_view name,
auto func,
telemetry_log_level telem = telemetry_log_level::NO_TELEMETRY) {
methods.try_emplace(std::string(name), method { std::bind_front(func, this), telem });
};

methods.emplace(
"textDocument/definition", this_bind(&feature_language_features::definition, telemetry_log_level::LOG_EVENT));
methods.emplace(
"textDocument/references", this_bind(&feature_language_features::references, telemetry_log_level::LOG_EVENT));
methods.emplace("textDocument/hover", this_bind(&feature_language_features::hover, telemetry_log_level::LOG_EVENT));
methods.emplace(
"textDocument/completion", this_bind(&feature_language_features::completion, telemetry_log_level::LOG_EVENT));
methods.emplace("textDocument/semanticTokens/full",
this_bind(&feature_language_features::semantic_tokens, telemetry_log_level::NO_TELEMETRY));
methods.emplace("textDocument/documentSymbol",
this_bind(&feature_language_features::document_symbol, telemetry_log_level::NO_TELEMETRY));
methods.try_emplace("textDocument/$/opcode_suggestion",
this_bind(&feature_language_features::opcode_suggestion, telemetry_log_level::LOG_EVENT));
add_method("textDocument/definition", &feature_language_features::definition, LOG_EVENT);
add_method("textDocument/references", &feature_language_features::references, LOG_EVENT);
add_method("textDocument/hover", &feature_language_features::hover, LOG_EVENT);
add_method("textDocument/completion", &feature_language_features::completion, LOG_EVENT);
add_method("textDocument/semanticTokens/full", &feature_language_features::semantic_tokens);
add_method("textDocument/documentSymbol", &feature_language_features::document_symbol);
add_method("textDocument/$/opcode_suggestion", &feature_language_features::opcode_suggestion);
}

nlohmann::json feature_language_features::register_capabilities()
Expand Down
36 changes: 16 additions & 20 deletions language_server/src/lsp/lsp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,26 +221,16 @@ void server::register_cancellable_request(const request_id& id, request_invalida

void server::register_methods()
{
methods_.try_emplace("initialize",
method { [this](const request_id& id, const nlohmann::json& params) { on_initialize(id, params); },
telemetry_log_level::LOG_EVENT });
methods_.try_emplace("initialized",
method { [this](const nlohmann::json&) {
for (const auto& f : features_)
f->initialized();
},
telemetry_log_level::NO_TELEMETRY });
methods_.try_emplace("shutdown",
method { [this](const request_id& id, const nlohmann::json& params) { on_shutdown(id, params); },
telemetry_log_level::NO_TELEMETRY });
methods_.try_emplace("exit",
method { [this](const nlohmann::json& params) { on_exit(params); }, telemetry_log_level::NO_TELEMETRY });
methods_.try_emplace("$/cancelRequest",
method {
[this](const nlohmann::json& args) { cancel_request_handler(args); }, telemetry_log_level::NO_TELEMETRY });
methods_.try_emplace("invalidate_external_configuration",
method {
std::bind_front(&server::invalidate_external_configuration, this), telemetry_log_level::NO_TELEMETRY });
const auto add_method =
[this](std::string_view name, auto func, telemetry_log_level telem = telemetry_log_level::NO_TELEMETRY) {
methods_.try_emplace(std::string(name), method { std::bind_front(func, this), telem });
};
add_method("initialize", &server::on_initialize, telemetry_log_level::LOG_EVENT);
add_method("initialized", &server::on_initialized);
add_method("shutdown", &server::on_shutdown);
add_method("exit", &server::on_exit);
add_method("$/cancelRequest", &server::cancel_request_handler);
add_method("invalidate_external_configuration", &server::invalidate_external_configuration);
}

void server::send_telemetry(const telemetry_message& message) { notify("telemetry/event", nlohmann::json(message)); }
Expand Down Expand Up @@ -300,6 +290,12 @@ void server::on_initialize(const request_id& id, const nlohmann::json& param)
}
}

void server::on_initialized(const nlohmann::json&)
{
for (const auto& f : features_)
f->initialized();
}

void server::on_shutdown(const request_id& id, const nlohmann::json&)
{
shutdown_request_received_ = true;
Expand Down
2 changes: 2 additions & 0 deletions language_server/src/lsp/lsp_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class server final : public hlasm_plugin::language_server::server,
// requests
// Implements initialize request.
void on_initialize(const request_id& id, const nlohmann::json& param);
// Implements initialized notification.
void on_initialized(const nlohmann::json&);
// Implements the LSP shutdown request.
void on_shutdown(const request_id& id, const nlohmann::json& param);

Expand Down
63 changes: 22 additions & 41 deletions parser_library/src/processing/instruction_sets/ca_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,48 +45,29 @@ void ca_processor::process(std::shared_ptr<const processing::resolved_statement>

ca_processor::process_table_t ca_processor::create_table()
{
using wk = context::id_storage::well_known;
process_table_t table;
table.emplace(context::id_storage::well_known::SETA,
std::bind(&ca_processor::process_SET<context::A_t>, this, std::placeholders::_1));
table.emplace(context::id_storage::well_known::SETB,
std::bind(&ca_processor::process_SET<context::B_t>, this, std::placeholders::_1));
table.emplace(context::id_storage::well_known::SETC,
std::bind(&ca_processor::process_SET<context::C_t>, this, std::placeholders::_1));
table.emplace(context::id_storage::well_known::LCLA,
std::bind(&ca_processor::process_GBL_LCL<context::A_t, false>, this, std::placeholders::_1));
table.emplace(context::id_storage::well_known::LCLB,
std::bind(&ca_processor::process_GBL_LCL<context::B_t, false>, this, std::placeholders::_1));
table.emplace(context::id_storage::well_known::LCLC,
std::bind(&ca_processor::process_GBL_LCL<context::C_t, false>, this, std::placeholders::_1));
table.emplace(context::id_storage::well_known::GBLA,
std::bind(&ca_processor::process_GBL_LCL<context::A_t, true>, this, std::placeholders::_1));
table.emplace(context::id_storage::well_known::GBLB,
std::bind(&ca_processor::process_GBL_LCL<context::B_t, true>, this, std::placeholders::_1));
table.emplace(context::id_storage::well_known::GBLC,
std::bind(&ca_processor::process_GBL_LCL<context::C_t, true>, this, std::placeholders::_1));
table.emplace(
context::id_storage::well_known::ANOP, std::bind(&ca_processor::process_ANOP, this, std::placeholders::_1));
table.emplace(
context::id_storage::well_known::ACTR, std::bind(&ca_processor::process_ACTR, this, std::placeholders::_1));
table.emplace(
context::id_storage::well_known::AGO, std::bind(&ca_processor::process_AGO, this, std::placeholders::_1));
table.emplace(
context::id_storage::well_known::AIF, std::bind(&ca_processor::process_AIF, this, std::placeholders::_1));
table.emplace(context::id_index(), std::bind(&ca_processor::process_empty, this, std::placeholders::_1));
table.emplace(
context::id_storage::well_known::MACRO, std::bind(&ca_processor::process_MACRO, this, std::placeholders::_1));
table.emplace(
context::id_storage::well_known::MEND, std::bind(&ca_processor::process_MEND, this, std::placeholders::_1));
table.emplace(
context::id_storage::well_known::MEXIT, std::bind(&ca_processor::process_MEXIT, this, std::placeholders::_1));
table.emplace(
context::id_storage::well_known::AREAD, std::bind(&ca_processor::process_AREAD, this, std::placeholders::_1));
table.emplace(
context::id_storage::well_known::ASPACE, std::bind(&ca_processor::process_ASPACE, this, std::placeholders::_1));
table.emplace(
context::id_storage::well_known::AEJECT, std::bind(&ca_processor::process_AEJECT, this, std::placeholders::_1));
table.emplace(context::id_storage::well_known::MHELP,
[this](const semantics::complete_statement& stmt) { process_MHELP(stmt); });
table.try_emplace(wk::SETA, std::bind_front(&ca_processor::process_SET<context::A_t>, this));
table.try_emplace(wk::SETB, std::bind_front(&ca_processor::process_SET<context::B_t>, this));
table.try_emplace(wk::SETC, std::bind_front(&ca_processor::process_SET<context::C_t>, this));
table.try_emplace(wk::LCLA, std::bind_front(&ca_processor::process_GBL_LCL<context::A_t, false>, this));
table.try_emplace(wk::LCLB, std::bind_front(&ca_processor::process_GBL_LCL<context::B_t, false>, this));
table.try_emplace(wk::LCLC, std::bind_front(&ca_processor::process_GBL_LCL<context::C_t, false>, this));
table.try_emplace(wk::GBLA, std::bind_front(&ca_processor::process_GBL_LCL<context::A_t, true>, this));
table.try_emplace(wk::GBLB, std::bind_front(&ca_processor::process_GBL_LCL<context::B_t, true>, this));
table.try_emplace(wk::GBLC, std::bind_front(&ca_processor::process_GBL_LCL<context::C_t, true>, this));
table.try_emplace(wk::ANOP, std::bind_front(&ca_processor::process_ANOP, this));
table.try_emplace(wk::ACTR, std::bind_front(&ca_processor::process_ACTR, this));
table.try_emplace(wk::AGO, std::bind_front(&ca_processor::process_AGO, this));
table.try_emplace(wk::AIF, std::bind_front(&ca_processor::process_AIF, this));
table.try_emplace(context::id_index(), std::bind_front(&ca_processor::process_empty, this));
table.try_emplace(wk::MACRO, std::bind_front(&ca_processor::process_MACRO, this));
table.try_emplace(wk::MEND, std::bind_front(&ca_processor::process_MEND, this));
table.try_emplace(wk::MEXIT, std::bind_front(&ca_processor::process_MEXIT, this));
table.try_emplace(wk::AREAD, std::bind_front(&ca_processor::process_AREAD, this));
table.try_emplace(wk::ASPACE, std::bind_front(&ca_processor::process_ASPACE, this));
table.try_emplace(wk::AEJECT, std::bind_front(&ca_processor::process_AEJECT, this));
table.try_emplace(wk::MHELP, std::bind_front(&ca_processor::process_MHELP, this));

return table;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,28 +142,17 @@ void lookahead_processor::process_COPY(const resolved_statement& statement)
lookahead_processor::process_table_t lookahead_processor::create_table()
{
process_table_t table;
table.emplace(context::id_index("CSECT"),
std::bind(&lookahead_processor::assign_section_attributes, this, std::placeholders::_1, std::placeholders::_2));
table.emplace(context::id_index("DSECT"),
std::bind(&lookahead_processor::assign_section_attributes, this, std::placeholders::_1, std::placeholders::_2));
table.emplace(context::id_index("RSECT"),
std::bind(&lookahead_processor::assign_section_attributes, this, std::placeholders::_1, std::placeholders::_2));
table.emplace(context::id_index("COM"),
std::bind(&lookahead_processor::assign_section_attributes, this, std::placeholders::_1, std::placeholders::_2));
table.emplace(context::id_index("DXD"),
std::bind(&lookahead_processor::assign_section_attributes, this, std::placeholders::_1, std::placeholders::_2));
table.emplace(context::id_index("LOCTR"),
std::bind(&lookahead_processor::assign_section_attributes, this, std::placeholders::_1, std::placeholders::_2));
table.emplace(context::id_index("EQU"),
std::bind(&lookahead_processor::assign_EQU_attributes, this, std::placeholders::_1, std::placeholders::_2));
table.emplace(context::id_index("DC"),
std::bind(
&lookahead_processor::assign_data_def_attributes, this, std::placeholders::_1, std::placeholders::_2));
table.emplace(context::id_index("DS"),
std::bind(
&lookahead_processor::assign_data_def_attributes, this, std::placeholders::_1, std::placeholders::_2));
table.emplace(context::id_index("CXD"),
std::bind(&lookahead_processor::assign_cxd_attributes, this, std::placeholders::_1, std::placeholders::_2));
using context::id_index;
table.try_emplace(id_index("CSECT"), std::bind_front(&lookahead_processor::assign_section_attributes, this));
table.try_emplace(id_index("DSECT"), std::bind_front(&lookahead_processor::assign_section_attributes, this));
table.try_emplace(id_index("RSECT"), std::bind_front(&lookahead_processor::assign_section_attributes, this));
table.try_emplace(id_index("COM"), std::bind_front(&lookahead_processor::assign_section_attributes, this));
table.try_emplace(id_index("DXD"), std::bind_front(&lookahead_processor::assign_section_attributes, this));
table.try_emplace(id_index("LOCTR"), std::bind_front(&lookahead_processor::assign_section_attributes, this));
table.try_emplace(id_index("EQU"), std::bind_front(&lookahead_processor::assign_EQU_attributes, this));
table.try_emplace(id_index("DC"), std::bind_front(&lookahead_processor::assign_data_def_attributes, this));
table.try_emplace(id_index("DS"), std::bind_front(&lookahead_processor::assign_data_def_attributes, this));
table.try_emplace(id_index("CXD"), std::bind_front(&lookahead_processor::assign_cxd_attributes, this));

return table;
}
Expand Down

0 comments on commit fd86c3a

Please sign in to comment.