Skip to content

Commit

Permalink
refactor: use span in ca variable functions
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Oct 11, 2022
1 parent af0eeb5 commit a7b4880
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 99 deletions.
12 changes: 6 additions & 6 deletions clients/vscode-hlasmplugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,6 @@
"key": "shift+alt+delete",
"when": "editorLangId == hlasm && editorTextFocus && !editorReadonly"
},
{
"command": "extension.hlasm-plugin.commentEditorCommands",
"key": "ctrl+/",
"mac": "cmd+/",
"when": "editorLangId == hlasm && editorTextFocus && !editorReadonly"
},
{
"command": "extension.hlasm-plugin.commentEditorCommands",
"key": "ctrl+k ctrl+c",
Expand All @@ -299,6 +293,12 @@
"args": "CommentOption.remove",
"when": "editorLangId == hlasm && editorTextFocus && !editorReadonly"
},
{
"command": "extension.hlasm-plugin.commentEditorCommands",
"key": "ctrl+/",
"mac": "cmd+/",
"when": "editorLangId == hlasm && editorTextFocus && !editorReadonly"
},
{
"command": "extension.hlasm-plugin.blockCommentEditorCommands",
"key": "alt+shift+a",
Expand Down
4 changes: 2 additions & 2 deletions parser_library/src/context/hlasm_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ hlasm_context::name_result hlasm_context::try_get_symbol_name(const std::string&

SET_t get_var_sym_value(const hlasm_context& hlasm_ctx,
id_index name,
const std::vector<A_t>& subscript,
std::span<const context::A_t> subscript,
range symbol_range,
diagnostic_op_consumer& diags)
{
Expand Down Expand Up @@ -1131,7 +1131,7 @@ SET_t get_var_sym_value(const hlasm_context& hlasm_ctx,
}

bool test_symbol_for_read(const var_sym_ptr& var,
const std::vector<A_t>& subscript,
std::span<const context::A_t> subscript,
range symbol_range,
diagnostic_op_consumer& diags,
std::string_view var_name)
Expand Down
5 changes: 3 additions & 2 deletions parser_library/src/context/hlasm_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <map>
#include <memory>
#include <set>
#include <span>
#include <string>
#include <unordered_set>
#include <vector>
Expand Down Expand Up @@ -345,14 +346,14 @@ class hlasm_context
};

bool test_symbol_for_read(const var_sym_ptr& var,
const std::vector<A_t>& subscript,
std::span<const A_t> subscript,
range symbol_range,
diagnostic_op_consumer& diags,
std::string_view var_name);

SET_t get_var_sym_value(const hlasm_context& hlasm_ctx,
id_index name,
const std::vector<A_t>& subscript,
std::span<const A_t> subscript,
range symbol_range,
diagnostic_op_consumer& diags);

Expand Down
12 changes: 6 additions & 6 deletions parser_library/src/context/variables/macro_param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ macro_param_base::macro_param_base(macro_param_type param_type, id_index name, b
, param_type(param_type)
{}

C_t macro_param_base::get_value(const std::vector<size_t>& offset) const
C_t macro_param_base::get_value(std::span<const size_t> offset) const
{
const macro_param_data_component* tmp = real_data();

Expand All @@ -57,7 +57,7 @@ C_t macro_param_base::get_value(size_t idx) const { return real_data()->get_ith(

C_t macro_param_base::get_value() const { return real_data()->get_value(); }

const macro_param_data_component* macro_param_base::get_data(const std::vector<size_t>& offset) const
const macro_param_data_component* macro_param_base::get_data(std::span<const size_t> offset) const
{
auto data = real_data();
for (auto idx : offset)
Expand All @@ -67,7 +67,7 @@ const macro_param_data_component* macro_param_base::get_data(const std::vector<s
return data;
}

A_t macro_param_base::number(std::vector<size_t> offset) const
A_t macro_param_base::number(std::span<const size_t> offset) const
{
const macro_param_data_component* tmp = real_data();

Expand All @@ -78,7 +78,7 @@ A_t macro_param_base::number(std::vector<size_t> offset) const
return (A_t)tmp->number;
}

A_t macro_param_base::count(std::vector<size_t> offset) const
A_t macro_param_base::count(std::span<const size_t> offset) const
{
const macro_param_data_component* tmp = real_data();

Expand All @@ -90,7 +90,7 @@ A_t macro_param_base::count(std::vector<size_t> offset) const
}

bool macro_param_base::can_read(
const std::vector<context::A_t>& subscript, range symbol_range, diagnostic_consumer<diagnostic_op>& diags) const
std::span<const A_t> subscript, range symbol_range, diagnostic_consumer<diagnostic_op>& diags) const
{
if (subscript.empty())
{
Expand Down Expand Up @@ -119,7 +119,7 @@ bool macro_param_base::can_read(
return true;
}

size_t macro_param_base::size(std::vector<size_t> offset) const
size_t macro_param_base::size(std::span<const size_t> offset) const
{
const macro_param_data_component* tmp = real_data();

Expand Down
15 changes: 7 additions & 8 deletions parser_library/src/context/variables/macro_param.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,24 @@ class macro_param_base : public variable_symbol
const system_variable* access_system_variable() const;

// gets value of data where parameter is list of nested data offsets
virtual C_t get_value(const std::vector<size_t>& offset) const;
virtual C_t get_value(std::span<const size_t> offset) const;
// gets value of data where parameter is offset to data field
virtual C_t get_value(size_t idx) const;
// gets value of whole macro parameter
virtual C_t get_value() const;

// gets param struct
virtual const macro_param_data_component* get_data(const std::vector<size_t>& offset) const;
virtual const macro_param_data_component* get_data(std::span<const size_t> offset) const;

// N' attribute of the symbol
A_t number(std::vector<size_t> offset) const override;
A_t number(std::span<const size_t> offset) const override;
// K' attribute of the symbol
A_t count(std::vector<size_t> offset) const override;
A_t count(std::span<const size_t> offset) const override;

bool can_read(const std::vector<context::A_t>& subscript,
range symbol_range,
diagnostic_consumer<diagnostic_op>& diags) const override;
bool can_read(
std::span<const A_t> subscript, range symbol_range, diagnostic_consumer<diagnostic_op>& diags) const override;

virtual size_t size(std::vector<size_t> offset) const;
virtual size_t size(std::span<const size_t> offset) const;

protected:
macro_param_base(macro_param_type param_type, id_index name, bool is_global);
Expand Down
12 changes: 6 additions & 6 deletions parser_library/src/context/variables/set_symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace hlasm_plugin::parser_library::context {

bool set_symbol_base::can_read(
const std::vector<context::A_t>& subscript, range symbol_range, diagnostic_consumer<diagnostic_op>& diags) const
std::span<const A_t> subscript, range symbol_range, diagnostic_consumer<diagnostic_op>& diags) const
{
if (subscript.size() > 1)
{
Expand Down Expand Up @@ -54,22 +54,22 @@ set_symbol_base::set_symbol_base(id_index name, bool is_scalar, bool is_global,
{}

template<>
A_t set_symbol<A_t>::count(std::vector<size_t> offset) const
A_t set_symbol<A_t>::count(std::span<const size_t> offset) const
{
auto tmp = get_data(std::move(offset));
auto tmp = get_data(offset);
return tmp ? (A_t)utils::length_utf32_no_validation(std::to_string(*tmp)) : (A_t)1;
}

template<>
A_t set_symbol<B_t>::count(std::vector<size_t>) const
A_t set_symbol<B_t>::count(std::span<const size_t>) const
{
return (A_t)1;
}

template<>
A_t set_symbol<C_t>::count(std::vector<size_t> offset) const
A_t set_symbol<C_t>::count(std::span<const size_t> offset) const
{
auto tmp = get_data(std::move(offset));
auto tmp = get_data(offset);
return tmp ? (A_t)utils::length_utf32_no_validation(*tmp) : (A_t)0;
}
} // namespace hlasm_plugin::parser_library::context
11 changes: 5 additions & 6 deletions parser_library/src/context/variables/set_symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ class set_symbol_base : public variable_symbol
virtual std::vector<size_t> keys() const = 0;
virtual size_t size() const = 0;

bool can_read(const std::vector<context::A_t>& subscript,
range symbol_range,
diagnostic_consumer<diagnostic_op>& diags) const override;
bool can_read(
std::span<const A_t> subscript, range symbol_range, diagnostic_consumer<diagnostic_op>& diags) const override;

protected:
set_symbol_base(id_index name, bool is_scalar, bool is_global, SET_t_enum type);
Expand Down Expand Up @@ -128,13 +127,13 @@ class set_symbol : public set_symbol_base
}

// N' attribute of the symbol
A_t number(std::vector<size_t>) const override
A_t number(std::span<const size_t>) const override
{
return (A_t)(is_scalar || data.empty() ? 0 : data.rbegin()->first + 1);
}

// K' attribute of the symbol
A_t count(std::vector<size_t> offset) const override;
A_t count(std::span<const size_t> offset) const override;

size_t size() const override { return data.size(); };

Expand All @@ -148,7 +147,7 @@ class set_symbol : public set_symbol_base
}

private:
const T* get_data(std::vector<size_t> offset) const
const T* get_data(std::span<const size_t> offset) const
{
if ((is_scalar && !offset.empty()) || (!is_scalar && offset.size() != 1))
return nullptr;
Expand Down
36 changes: 22 additions & 14 deletions parser_library/src/context/variables/system_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ system_variable::system_variable(id_index name, macro_data_ptr value, bool is_gl
, data_(std::move(value))
{}

C_t system_variable::get_value(const std::vector<size_t>& offset) const { return get_data(offset)->get_value(); }
C_t system_variable::get_value(std::span<const size_t> offset) const { return get_data(offset)->get_value(); }

C_t system_variable::get_value(size_t idx) const { return macro_param_base::get_value(idx); }

C_t system_variable::get_value() const { return macro_param_base::get_value(0); }

const macro_param_data_component* system_variable::get_data(const std::vector<size_t>& offset) const
const macro_param_data_component* system_variable::get_data(std::span<const size_t> offset) const
{
for (auto subscript : offset)
{
Expand All @@ -46,18 +46,27 @@ const macro_param_data_component* system_variable::get_data(const std::vector<si
return data_->get_ith(0);
}

A_t system_variable::number(std::vector<size_t> offset) const
A_t system_variable::number(std::span<const size_t> offset) const
{
static constexpr const size_t inline_limit = 16;
if (offset.empty())
return (A_t)data_->number - 1;
else if (offset.size() <= inline_limit)
{
std::array<size_t, inline_limit> copy_offset;
std::copy(offset.begin(), offset.end(), copy_offset.begin());
++copy_offset.front();
return (A_t)macro_param_base::number(std::span<const size_t>(copy_offset.data(), offset.size()));
}
else
{
++offset.front();
return (A_t)macro_param_base::number(std::move(offset));
std::vector<size_t> copy_offset(offset.begin(), offset.end());
++copy_offset.front();
return (A_t)macro_param_base::number(copy_offset);
}
}

A_t system_variable::count(std::vector<size_t> offset) const
A_t system_variable::count(std::span<const size_t> offset) const
{
if (offset.empty())
return (A_t)utils::length_utf32_no_validation(data_->get_ith(0)->get_value());
Expand All @@ -70,7 +79,7 @@ A_t system_variable::count(std::vector<size_t> offset) const
return (A_t)utils::length_utf32_no_validation(tmp->get_value());
}

size_t system_variable::size(std::vector<size_t> offset) const
size_t system_variable::size(std::span<const size_t> offset) const
{
const macro_param_data_component* tmp = real_data();

Expand All @@ -84,19 +93,19 @@ size_t system_variable::size(std::vector<size_t> offset) const

const macro_param_data_component* system_variable::real_data() const { return &*data_; }

C_t system_variable_sysmac::get_value(const std::vector<size_t>& offset) const
C_t system_variable_sysmac::get_value(std::span<const size_t> offset) const
{
if (!offset.empty())
return get_data(offset)->get_value();
else
return get_data({ 0 })->get_value();
return get_data(std::array<size_t, 1> { 0 })->get_value();
}

C_t system_variable_sysmac::get_value(size_t idx) const { return system_variable::get_value(idx); }

C_t system_variable_sysmac::get_value() const { return system_variable::get_value(); }

const macro_param_data_component* system_variable_sysmac::get_data(const std::vector<size_t>& offset) const
const macro_param_data_component* system_variable_sysmac::get_data(std::span<const size_t> offset) const
{
const macro_param_data_component* tmp = real_data();

Expand All @@ -106,13 +115,12 @@ const macro_param_data_component* system_variable_sysmac::get_data(const std::ve
return tmp;
}

bool system_variable_sysmac::can_read(
const std::vector<context::A_t>&, range, diagnostic_consumer<diagnostic_op>&) const
bool system_variable_sysmac::can_read(std::span<const A_t>, range, diagnostic_consumer<diagnostic_op>&) const
{
return true;
}

const macro_param_data_component* system_variable_syslist::get_data(const std::vector<size_t>& offset) const
const macro_param_data_component* system_variable_syslist::get_data(std::span<const size_t> offset) const
{
const macro_param_data_component* tmp = real_data();

Expand All @@ -132,7 +140,7 @@ const macro_param_data_component* system_variable_syslist::get_data(const std::v
}

bool system_variable_syslist::can_read(
const std::vector<context::A_t>& subscript, range symbol_range, diagnostic_consumer<diagnostic_op>& diags) const
std::span<const A_t> subscript, range symbol_range, diagnostic_consumer<diagnostic_op>& diags) const
{
if (subscript.empty())
{
Expand Down
26 changes: 12 additions & 14 deletions parser_library/src/context/variables/system_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ class system_variable : public macro_param_base
system_variable(id_index name, macro_data_ptr value, bool is_global);

// gets value of data where parameter is list of nested data offsets
C_t get_value(const std::vector<size_t>& offset) const override;
C_t get_value(std::span<const size_t> offset) const override;
// gets value of data where parameter is offset to data field
C_t get_value(size_t idx) const override;
// gets value of whole macro parameter
C_t get_value() const override;

// gets param struct
const macro_param_data_component* get_data(const std::vector<size_t>& offset) const override;
const macro_param_data_component* get_data(std::span<const size_t> offset) const override;

// N' attribute of the symbol
A_t number(std::vector<size_t> offset) const override;
A_t number(std::span<const size_t> offset) const override;
// K' attribute of the symbol
A_t count(std::vector<size_t> offset) const override;
A_t count(std::span<const size_t> offset) const override;

size_t size(std::vector<size_t> offset) const override;
size_t size(std::span<const size_t> offset) const override;

protected:
const macro_param_data_component* real_data() const override;
Expand All @@ -58,13 +58,12 @@ class system_variable_sysmac final : public system_variable
using system_variable::system_variable;

// SYSMAC special behavior
C_t get_value(const std::vector<size_t>& offset) const override;
C_t get_value(std::span<const size_t> offset) const override;
C_t get_value(size_t idx) const override;
C_t get_value() const override;
const macro_param_data_component* get_data(const std::vector<size_t>& offset) const override;
bool can_read(const std::vector<context::A_t>& subscript,
range symbol_range,
diagnostic_consumer<diagnostic_op>& diags) const override;
const macro_param_data_component* get_data(std::span<const size_t> offset) const override;
bool can_read(
std::span<const A_t> subscript, range symbol_range, diagnostic_consumer<diagnostic_op>& diags) const override;
};

// SYSLIST extras
Expand All @@ -74,10 +73,9 @@ class system_variable_syslist final : public system_variable
using system_variable::system_variable;

// SYSLIST special behavior
const macro_param_data_component* get_data(const std::vector<size_t>& offset) const override;
bool can_read(const std::vector<context::A_t>& subscript,
range symbol_range,
diagnostic_consumer<diagnostic_op>& diags) const override;
const macro_param_data_component* get_data(std::span<const size_t> offset) const override;
bool can_read(
std::span<const A_t> subscript, range symbol_range, diagnostic_consumer<diagnostic_op>& diags) const override;
};

} // namespace hlasm_plugin::parser_library::context
Expand Down
Loading

0 comments on commit a7b4880

Please sign in to comment.