Skip to content

Commit

Permalink
fix: &SYSMAC should contain only the macro name (fixes #168)
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Aug 20, 2021
1 parent 200b769 commit 4e2fddc
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
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 @@ -147,9 +147,9 @@ void hlasm_context::add_system_vars_to_scope()

macro_data_ptr mac_data = std::make_unique<macro_param_data_composite>(std::move(data));

auto var = std::make_shared<system_variable>(SYSMAC, std::move(mac_data), false);
sys_sym_ptr var = std::make_shared<system_variable_sysmac>(SYSMAC, std::move(mac_data), false);

curr_scope()->system_variables.insert({ SYSMAC, var });
curr_scope()->system_variables.insert({ SYSMAC, std::move(var) });
}
}
add_global_system_vars();
Expand Down
22 changes: 22 additions & 0 deletions parser_library/src/context/variables/system_variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,25 @@ size_t system_variable::size(std::vector<size_t> offset) const
}

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

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

const C_t& system_variable_sysmac::get_value(size_t idx) const { return get_data({ idx })->get_value(); }

const C_t& system_variable_sysmac::get_value() const { return get_data({ 0 })->get_value(); }

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

if (!offset.empty())
tmp = tmp->get_ith(offset.back()); // what the original seems to do

return tmp;
}
13 changes: 13 additions & 0 deletions parser_library/src/context/variables/system_variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ class system_variable : public macro_param_base
const macro_param_data_component* real_data() const override;
};

// SYSMAC extras
class system_variable_sysmac final : public system_variable
{
public:
using system_variable::system_variable;

// SYSMAC special behavior
const C_t& get_value(const std::vector<size_t>& offset) const override;
const C_t& get_value(size_t idx) const override;
const C_t& get_value() const override;
const macro_param_data_component* get_data(const std::vector<size_t>& offset) const override;
};

} // namespace hlasm_plugin::parser_library::context

#endif
26 changes: 24 additions & 2 deletions parser_library/test/context/context_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,21 @@ TEST(context_system_variables, SYSNEST_SYSMAC)
MACRO
M1
GBLA V1
GBLC V2,V3,V5
GBLC V2,V3,V5,V6,V7
GBLC T1,T2,T3
GBLA K1,K2,K3
&V1 SETA &SYSNEST
&V2 SETC '&SYSMAC(&SYSNEST)'
&V3 SETC '&SYSMAC(1)'
&V5 SETC '&SYSMAC(0)'
&V6 SETC '&SYSMAC'
&V7 SETC '&SYSMAC(0,1,2,3,4,5,6,7,8,9,1)'
&T1 SETC T'&SYSMAC
&T2 SETC T'&SYSMAC(0)
&T3 SETC T'&SYSMAC(10)
&K1 SETA K'&SYSMAC
&K2 SETA K'&SYSMAC(0)
&K3 SETA K'&SYSMAC(10)
MEND
MACRO
Expand All @@ -581,7 +591,9 @@ TEST(context_system_variables, SYSNEST_SYSMAC)
MEND
GBLA V1,V4
GBLC V2,V3,V5
GBLC V2,V3,V5,V6,V7
GBLC T1,T2,T3
GBLA K1,K2,K3
M2
)";
Expand All @@ -597,4 +609,14 @@ TEST(context_system_variables, SYSNEST_SYSMAC)
EXPECT_EQ(get_var_value<context::C_t>(a.hlasm_ctx(), "v3"), "M2");
EXPECT_EQ(get_var_value<context::A_t>(a.hlasm_ctx(), "v4"), 1);
EXPECT_EQ(get_var_value<context::C_t>(a.hlasm_ctx(), "v5"), "M1");
EXPECT_EQ(get_var_value<context::C_t>(a.hlasm_ctx(), "v6"), "M1");
EXPECT_EQ(get_var_value<context::C_t>(a.hlasm_ctx(), "v7"), "M2");

EXPECT_EQ(get_var_value<context::C_t>(a.hlasm_ctx(), "t1"), "U");
EXPECT_EQ(get_var_value<context::C_t>(a.hlasm_ctx(), "t2"), "U");
EXPECT_EQ(get_var_value<context::C_t>(a.hlasm_ctx(), "t3"), "O");

EXPECT_EQ(get_var_value<context::A_t>(a.hlasm_ctx(), "k1"), 2);
EXPECT_EQ(get_var_value<context::A_t>(a.hlasm_ctx(), "k2"), 2);
EXPECT_EQ(get_var_value<context::A_t>(a.hlasm_ctx(), "k3"), 0);
}

0 comments on commit 4e2fddc

Please sign in to comment.