Skip to content

Commit

Permalink
Resolve lifetime issues related to macro dependencies (part 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Feb 6, 2023
1 parent bdbb68d commit 4ba42b1
Show file tree
Hide file tree
Showing 72 changed files with 763 additions and 708 deletions.
11 changes: 4 additions & 7 deletions parser_library/fuzzer/fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using namespace hlasm_plugin::parser_library::workspaces;

class fuzzer_lib_provider : public parse_lib_provider
{
std::optional<size_t> read_library_name(const std::string& library) const
std::optional<size_t> read_library_name(std::string_view library) const
{
if (library.size() < 2 || library.size() > 8 || library[0] != '@'
|| std::any_of(library.begin() + 1, library.end(), [](unsigned char c) { return !isdigit(c); }))
Expand All @@ -50,7 +50,7 @@ class fuzzer_lib_provider : public parse_lib_provider
}

public:
parse_result parse_library(const std::string& library, analyzing_context ctx, library_data data) override
parse_result parse_library(std::string_view library, analyzing_context ctx, library_data data) override
{
auto lib = read_library_name(library);
if (!lib.has_value())
Expand All @@ -63,13 +63,10 @@ class fuzzer_lib_provider : public parse_lib_provider
return true;
}

bool has_library(const std::string& library, const hlasm_plugin::utils::resource::resource_location&) const override
{
return read_library_name(library).has_value();
}
bool has_library(std::string_view library) const override { return read_library_name(library).has_value(); }

std::optional<std::pair<std::string, hlasm_plugin::utils::resource::resource_location>> get_library(
const std::string& library, const hlasm_plugin::utils::resource::resource_location&) const override
std::string_view library) const override
{
auto lib = read_library_name(library);
if (!lib.has_value())
Expand Down
4 changes: 2 additions & 2 deletions parser_library/src/analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "analyzer.h"

#include "hlasmparser_multiline.h"
#include "lsp/lsp_context.h"
#include "processing/opencode_provider.h"
#include "processing/preprocessor.h"

Expand Down Expand Up @@ -114,8 +115,7 @@ analyzer::analyzer(std::string_view text, analyzer_options opts)
src_proc_,
*this,
opts.get_preprocessor(
[libs = &opts.get_lib_provider(), program = opts.file_loc](
std::string_view library) { return libs->get_library(std::string(library), program); },
[libs = &opts.get_lib_provider()](std::string_view library) { return libs->get_library(library); },
*this,
src_proc_),
opts.parsing_opencode == file_is_opencode::yes ? processing::opencode_provider_options { true, 10 }
Expand Down
10 changes: 7 additions & 3 deletions parser_library/src/analyzing_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
#ifndef HLASMPARSER_PARSERLIBRARY_ANALYZING_CONTEXT_H
#define HLASMPARSER_PARSERLIBRARY_ANALYZING_CONTEXT_H

#include "context/hlasm_context.h"
#include "lsp/lsp_context.h"
#include <memory>

namespace hlasm_plugin::parser_library {

namespace context {
class hlasm_context;
} // namespace context
namespace lsp {
class lsp_context;
} // namespace lsp

struct analyzing_context
{
Expand Down
3 changes: 2 additions & 1 deletion parser_library/src/checking/asm_instr_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "context/common_types.h"
#include "diagnostic_collector.h"
#include "lexing/tools.h"
#include "utils/string_operations.h"

namespace {
const std::vector<std::string_view> rmode_options = { "24", "31", "64", "ANY" };
Expand Down Expand Up @@ -662,7 +663,7 @@ bool external::check(const std::vector<const asm_operand*>& to_check,
if (auto complex_op = get_complex_operand(operand); complex_op)
{
// check PART operand
if (context::to_upper_copy(complex_op->operand_identifier) != "PART")
if (utils::to_upper_copy(complex_op->operand_identifier) != "PART")
{
add_diagnostic(diagnostic_op::error_A129_EXTRN_format(operand->operand_range));
return false;
Expand Down
11 changes: 3 additions & 8 deletions parser_library/src/config/assembler_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "compiler_options.h"
#include "nlohmann/json.hpp"
#include "utils/string_operations.h"

namespace hlasm_plugin::parser_library::config {

Expand Down Expand Up @@ -129,16 +130,10 @@ static_assert(std::is_sorted(std::begin(instr_set_machine_equivalents),
[](const auto& l, const auto& r) { return l.first < r.first; }));
#endif

void to_upper(std::string& s)
{
for (auto& c : s)
c = static_cast<char>(std::toupper((unsigned char)c));
}

bool instr_set_equivalent_valid(
std::string instr_set_name, std::span<const instr_set_equivalent_pair> equivalents) noexcept
{
to_upper(instr_set_name);
utils::to_upper(instr_set_name);

#ifdef __cpp_lib_ranges
return instr_set_name.size() == 0
Expand Down Expand Up @@ -169,7 +164,7 @@ namespace {
std::optional<instruction_set_version> find_instruction_set(
std::string instr_set_name, const std::span<const instr_set_equivalent_pair> equivalents)
{
to_upper(instr_set_name);
utils::to_upper(instr_set_name);

#ifdef __cpp_lib_ranges
auto it = std::ranges::lower_bound(equivalents, instr_set_name, {}, [](const auto& instr) { return instr.first; });
Expand Down
14 changes: 0 additions & 14 deletions parser_library/src/context/common_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@

namespace hlasm_plugin::parser_library::context {

std::string& to_upper(std::string& s)
{
for (auto& c : s)
c = static_cast<char>(std::toupper((unsigned char)c));
return s;
}

std::string to_upper_copy(std::string s)
{
for (auto& c : s)
c = static_cast<char>(std::toupper((unsigned char)c));
return s;
}

SET_t::SET_t(context::A_t value)
: a_value(value)
, b_value(value)
Expand Down
4 changes: 0 additions & 4 deletions parser_library/src/context/common_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,5 @@ struct SET_t
bool operator==(const SET_t& r) const noexcept;
};

// just mock method for now, will be implemented later with respect to UTF/EBCDIC
std::string& to_upper(std::string& s);
std::string to_upper_copy(std::string s);

} // namespace hlasm_plugin::parser_library::context
#endif
7 changes: 4 additions & 3 deletions parser_library/src/context/id_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <memory>

#include "common_types.h"
#include "utils/string_operations.h"

using namespace hlasm_plugin::parser_library::context;

Expand All @@ -36,7 +37,7 @@ std::optional<id_index> id_storage::find(std::string_view value) const
if (value.size() < id_index::buffer_size)
return small_id(value);

if (auto tmp = lit_.find(to_upper_copy(std::string(value))); tmp != lit_.end())
if (auto tmp = lit_.find(utils::to_upper_copy(std::string(value))); tmp != lit_.end())
return id_index(std::to_address(tmp));
else
return std::nullopt;
Expand All @@ -47,15 +48,15 @@ id_index id_storage::add(std::string_view value)
if (value.size() < id_index::buffer_size)
return small_id(value);

return id_index(std::to_address(lit_.insert(to_upper_copy(std::string(value))).first));
return id_index(std::to_address(lit_.insert(utils::to_upper_copy(std::string(value))).first));
}

id_index id_storage::add(std::string&& value)
{
if (value.size() < id_index::buffer_size)
return small_id(value);

to_upper(value);
utils::to_upper(value);

return id_index(std::to_address(lit_.insert(std::move(value)).first));
}
6 changes: 3 additions & 3 deletions parser_library/src/debugging/debug_lib_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ debug_lib_provider::debug_lib_provider(std::vector<std::shared_ptr<workspaces::l
{}

workspaces::parse_result debug_lib_provider::parse_library(
const std::string& library, analyzing_context ctx, workspaces::library_data data)
std::string_view library, analyzing_context ctx, workspaces::library_data data)
{
utils::resource::resource_location url;
for (const auto& lib : m_libraries)
Expand Down Expand Up @@ -58,7 +58,7 @@ workspaces::parse_result debug_lib_provider::parse_library(
return false;
}

bool debug_lib_provider::has_library(const std::string& library, const utils::resource::resource_location&) const
bool debug_lib_provider::has_library(std::string_view library) const
{
for (const auto& lib : m_libraries)
if (lib->has_file(library))
Expand All @@ -67,7 +67,7 @@ bool debug_lib_provider::has_library(const std::string& library, const utils::re
}

std::optional<std::pair<std::string, utils::resource::resource_location>> debug_lib_provider::get_library(
const std::string& library, const utils::resource::resource_location&) const
std::string_view library) const
{
utils::resource::resource_location url;
for (const auto& lib : m_libraries)
Expand Down
6 changes: 3 additions & 3 deletions parser_library/src/debugging/debug_lib_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class debug_lib_provider final : public workspaces::parse_lib_provider
std::atomic<bool>* cancel);

workspaces::parse_result parse_library(
const std::string& library, analyzing_context ctx, workspaces::library_data data) override;
std::string_view library, analyzing_context ctx, workspaces::library_data data) override;

bool has_library(const std::string& library, const utils::resource::resource_location& program) const override;
bool has_library(std::string_view library) const override;

std::optional<std::pair<std::string, utils::resource::resource_location>> get_library(
const std::string& library, const utils::resource::resource_location& program) const override;
std::string_view library) const override;
};

} // namespace hlasm_plugin::parser_library::debugging
Expand Down
3 changes: 1 addition & 2 deletions parser_library/src/library_info_transitional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ namespace hlasm_plugin::parser_library {

bool library_info_transitional::has_library(std::string_view member) const
{
return m_lib_provider->has_library(
std::string(member), m_hlasm_ctx ? m_hlasm_ctx->opencode_location() : empty_location);
return m_lib_provider->has_library(member);
}

const library_info_transitional library_info_transitional::empty(workspaces::empty_parse_lib_provider::instance);
Expand Down
9 changes: 1 addition & 8 deletions parser_library/src/library_info_transitional.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,12 @@ class parse_lib_provider;
class library_info_transitional final : public library_info
{
workspaces::parse_lib_provider* m_lib_provider;
const context::hlasm_context* m_hlasm_ctx = nullptr;

explicit library_info_transitional(workspaces::parse_lib_provider& lib_provider)
: m_lib_provider(&lib_provider)
{}

public:
bool has_library(std::string_view member) const override;

explicit library_info_transitional(
workspaces::parse_lib_provider& lib_provider, const context::hlasm_context& hlasm_ctx)
explicit library_info_transitional(workspaces::parse_lib_provider& lib_provider)
: m_lib_provider(&lib_provider)
, m_hlasm_ctx(&hlasm_ctx)
{}

static const library_info_transitional empty;
Expand Down
1 change: 1 addition & 0 deletions parser_library/src/lsp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
target_sources(parser_library PRIVATE
completion_item.cpp
completion_item.h
completion_list_source.h
document_symbol_item.cpp
document_symbol_item.h
file_info.cpp
Expand Down
54 changes: 54 additions & 0 deletions parser_library/src/lsp/completion_list_source.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2023 Broadcom.
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*/

#ifndef HLASMPLUGIN_PARSERLIBRARY_LSP_COMPLETION_LIST_SOURCE_H
#define HLASMPLUGIN_PARSERLIBRARY_LSP_COMPLETION_LIST_SOURCE_H

#include <memory>
#include <string_view>
#include <unordered_map>
#include <variant>
#include <vector>

namespace hlasm_plugin::parser_library {
namespace context {
class id_index;
class macro_definition;
struct sequence_symbol;
class symbol;
} // namespace context
} // namespace hlasm_plugin::parser_library

namespace hlasm_plugin::parser_library::lsp {

class lsp_context;
struct macro_info;
struct variable_symbol_definition;

struct completion_list_instructions
{
std::string_view completed_text;
size_t completed_text_start_column;
const std::unordered_map<std::shared_ptr<context::macro_definition>, std::shared_ptr<macro_info>>* macros;
const lsp_context* lsp_ctx;
};

using completion_list_source = std::variant<std::monostate,
const std::vector<variable_symbol_definition>*,
const std::unordered_map<context::id_index, std::unique_ptr<context::sequence_symbol>>*,
completion_list_instructions>;

} // namespace hlasm_plugin::parser_library::lsp

#endif
Loading

0 comments on commit 4ba42b1

Please sign in to comment.