Skip to content

Commit

Permalink
refactor: Hide diagnostic collection details
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Apr 12, 2024
1 parent b8119f4 commit 7c5d260
Show file tree
Hide file tree
Showing 70 changed files with 194 additions and 1,009 deletions.
1 change: 0 additions & 1 deletion parser_library/fuzzer/fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class fuzzer_lib_provider : public parse_lib_provider
analyzer a(
files[lib.value()], analyzer_options(resource_location(std::move(library)), this, std::move(ctx), data));
co_await a.co_analyze();
a.collect_diags();
co_return true;
}

Expand Down
33 changes: 19 additions & 14 deletions parser_library/src/analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "analyzer.h"

#include "context/id_storage.h"
#include "diagnosable_ctx.h"
#include "lsp/lsp_context.h"
#include "processing/opencode_provider.h"
#include "processing/preprocessor.h"
Expand Down Expand Up @@ -105,10 +107,11 @@ std::unique_ptr<processing::preprocessor> analyzer_options::get_preprocessor(pro
return std::make_unique<combined_preprocessor>(std::move(tmp));
}

struct analyzer::impl
struct analyzer::impl : public diagnosable_ctx
{
impl(std::string_view text, analyzer_options&& opts, diagnosable_ctx& diag_consumer)
: ctx(std::move(opts.get_context()))
impl(std::string_view text, analyzer_options&& opts)
: diagnosable_ctx(opts.get_hlasm_context())
, ctx(std::move(opts.get_context()))
, src_proc(opts.collect_hl_info == collect_highlighting_info::yes)
, field_parser(ctx.hlasm_ctx.get())
, mngr(std::make_unique<processing::opencode_provider>(text,
Expand All @@ -117,10 +120,9 @@ struct analyzer::impl
mngr,
mngr,
src_proc,
diag_consumer,
opts.get_preprocessor(std::bind_front(&parse_lib_provider::get_library, &opts.get_lib_provider()),
diag_consumer,
src_proc),
*this,
opts.get_preprocessor(
std::bind_front(&parse_lib_provider::get_library, &opts.get_lib_provider()), *this, src_proc),
opts.parsing_opencode == file_is_opencode::yes ? processing::opencode_provider_options { true, 10 }
: processing::opencode_provider_options {},
opts.vf_monitor,
Expand All @@ -144,11 +146,16 @@ struct analyzer::impl
std::vector<std::pair<virtual_file_handle, utils::resource::resource_location>> vf_handles;

processing::processing_manager mngr;

void collect_diags() const override
{
collect_diags_from_child(mngr);
collect_diags_from_child(field_parser);
}
};

analyzer::analyzer(std::string_view text, analyzer_options opts)
: diagnosable_ctx(opts.get_hlasm_context())
, m_impl(std::make_unique<impl>(text, std::move(opts), *this))
: m_impl(std::make_unique<impl>(text, std::move(opts)))
{}

analyzer::~analyzer() = default;
Expand All @@ -173,16 +180,14 @@ hlasm_plugin::utils::task analyzer::co_analyze() &
co_await m_impl->mngr.co_step();

m_impl->src_proc.finish();
}

void analyzer::collect_diags() const
{
collect_diags_from_child(m_impl->mngr);
collect_diags_from_child(m_impl->field_parser);
m_impl->collect_diags();
}

const performance_metrics& analyzer::get_metrics() const { return m_impl->ctx.hlasm_ctx->metrics; }

std::span<diagnostic_s> analyzer::diags() const noexcept { return m_impl->diags(); }

void analyzer::register_stmt_analyzer(processing::statement_analyzer* stmt_analyzer)
{
m_impl->mngr.register_stmt_analyzer(stmt_analyzer);
Expand Down
16 changes: 10 additions & 6 deletions parser_library/src/analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@
#ifndef HLASMPARSER_PARSERLIBRARY_ANALYZER_H
#define HLASMPARSER_PARSERLIBRARY_ANALYZER_H

#include <atomic>
#include <memory>
#include <optional>
#include <span>
#include <string_view>
#include <utility>
#include <variant>
#include <vector>

#include "analyzing_context.h"
#include "compiler_options.h"
#include "diagnosable_ctx.h"
#include "preprocessor_options.h"
#include "processing/preprocessor.h"
#include "protocol.h"
Expand All @@ -38,6 +36,7 @@ class task;

namespace hlasm_plugin::parser_library::context {
class hlasm_context;
class id_storage;
} // namespace hlasm_plugin::parser_library::context

namespace hlasm_plugin::parser_library::parsing {
Expand All @@ -58,6 +57,10 @@ class output_handler;
class virtual_file_monitor;
class virtual_file_handle;

template<typename T>
class diagnostic_consumer;
struct diagnostic_op;

enum class collect_highlighting_info : bool
{
no,
Expand Down Expand Up @@ -102,7 +105,7 @@ class analyzer_options
analyzing_context& get_context();
workspaces::parse_lib_provider& get_lib_provider() const;
std::unique_ptr<processing::preprocessor> get_preprocessor(
processing::library_fetcher, diagnostic_op_consumer&, semantics::source_info_processor&) const;
processing::library_fetcher, diagnostic_consumer<diagnostic_op>&, semantics::source_info_processor&) const;

friend class analyzer;

Expand Down Expand Up @@ -152,7 +155,7 @@ class analyzer_options
};

// this class analyzes provided text and produces diagnostics and highlighting info with respect to provided context
class analyzer : public diagnosable_ctx
class analyzer
{
struct impl;

Expand All @@ -171,9 +174,10 @@ class analyzer : public diagnosable_ctx
void analyze();
[[nodiscard]] utils::task co_analyze() &;

void collect_diags() const override;
const performance_metrics& get_metrics() const;

std::span<diagnostic_s> diags() const noexcept;

void register_stmt_analyzer(processing::statement_analyzer* stmt_analyzer);

parsing::hlasmparser_multiline& parser(); // for testing only
Expand Down
4 changes: 0 additions & 4 deletions parser_library/src/instruction_set_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
#ifndef HLASMPARSER_PARSERLIBRARY_INSTRUCTION_SET_VERSION_H
#define HLASMPARSER_PARSERLIBRARY_INSTRUCTION_SET_VERSION_H

#include <algorithm>
#include <array>
#include <string>

// Available instruction sets versions
namespace hlasm_plugin::parser_library {
enum class instruction_set_version
Expand Down
5 changes: 4 additions & 1 deletion parser_library/src/processing/opencode_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,10 @@ utils::task opencode_provider::start_nested_parser(
{
analyzer a(text, std::move(opts));
co_await a.co_analyze();
m_diagnoser->collect_diags_from_child(a);

for (auto&& d : a.diags())
m_diagnoser->add_diagnostic(std::move(d));

m_ctx.hlasm_ctx->enter_copy_member(vf_name);
}

Expand Down
19 changes: 13 additions & 6 deletions parser_library/src/processing/preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <utility>
#include <vector>

#include "diagnostic_consumer.h"
#include "document.h"
#include "utils/resource_location.h"

Expand All @@ -33,6 +32,10 @@ struct cics_preprocessor_options;
struct db2_preprocessor_options;
struct endevor_preprocessor_options;

template<typename T>
class diagnostic_consumer;
struct diagnostic_op;

namespace lexing {
template<typename It>
struct logical_line;
Expand Down Expand Up @@ -72,15 +75,19 @@ class preprocessor

[[nodiscard]] virtual utils::value_task<document> generate_replacement(document doc) = 0;

static std::unique_ptr<preprocessor> create(
const cics_preprocessor_options&, library_fetcher, diagnostic_op_consumer*, semantics::source_info_processor&);
static std::unique_ptr<preprocessor> create(const cics_preprocessor_options&,
library_fetcher,
diagnostic_consumer<diagnostic_op>*,
semantics::source_info_processor&);

static std::unique_ptr<preprocessor> create(
const db2_preprocessor_options&, library_fetcher, diagnostic_op_consumer*, semantics::source_info_processor&);
static std::unique_ptr<preprocessor> create(const db2_preprocessor_options&,
library_fetcher,
diagnostic_consumer<diagnostic_op>*,
semantics::source_info_processor&);

static std::unique_ptr<preprocessor> create(const endevor_preprocessor_options&,
library_fetcher,
diagnostic_op_consumer*,
diagnostic_consumer<diagnostic_op>*,
semantics::source_info_processor&);

virtual std::vector<std::shared_ptr<semantics::preprocessor_statement_si>> take_statements();
Expand Down
2 changes: 1 addition & 1 deletion parser_library/src/workspaces/parse_lib_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <utility>

#include "analyzing_context.h"
#include "context/id_storage.h"
#include "context/id_index.h"
#include "processing/processing_format.h"
#include "utils/resource_location.h"
#include "utils/task.h"
Expand Down
10 changes: 5 additions & 5 deletions parser_library/src/workspaces/workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ struct parsing_results
a.register_stmt_analyzer(&hc_analyzer);

co_await a.co_analyze();

a.collect_diags();
auto d = a.diags();

parsing_results result;
result.opencode_diagnostics = std::move(a.diags());
result.opencode_diagnostics.assign(std::make_move_iterator(d.begin()), std::make_move_iterator(d.end()));
result.hl_info = a.take_semantic_tokens();
result.lsp_context = a.context().lsp_ctx;
result.fade_messages = std::move(fms);
Expand Down Expand Up @@ -231,9 +230,10 @@ struct workspace_parse_lib_provider final : public parse_lib_provider
a.register_stmt_analyzer(&hc_analyzer);

co_await a.co_analyze();
a.collect_diags();
auto d = a.diags();

macro_pfc.m_last_results->macro_diagnostics = std::move(a.diags());
macro_pfc.m_last_results->macro_diagnostics.assign(
std::make_move_iterator(d.begin()), std::make_move_iterator(d.end()));

mc.save_macro(cache_key, a);
macro_pfc.m_last_macro_analyzer_with_lsp = collect_hl;
Expand Down
Loading

0 comments on commit 7c5d260

Please sign in to comment.