Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement SYSTEM_ID system variable #182

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clients/vscode-hlasmplugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- CNOP instruction implementation (limited)
- START, MHELP instructions
- Wildcard support in library specification
- Support for SYSTEM_ID system variable.

#### Fixed
- Preserve mixed-case labels on macro calls
Expand All @@ -20,6 +21,8 @@
- Lookahead mode does not work correctly when triggered from AINSERTed code
- Incorrect relative immediate operand validation
- Remove ALIAS operand parsing limitation
- Attribute expressions ending with dot are not parsed correctly
- Improve evaluation and diagnostics of conditional assembler expressions

## [0.14.0](https://github.com/eclipse/che-che4z-lsp-for-hlasm/compare/0.13.0...0.14.0) (2021-08-18)

Expand Down
2 changes: 1 addition & 1 deletion clients/vscode-hlasmplugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Breakpoints can be set before or during the debugging session.
### External Macro Libraries and COPY Members
The HLASM Language Support extension looks for locally stored members when a macro or COPY instruction is evaluated. The paths of these members are specified in two configuration files in the `.hlasmplugin` folder of the currently open workspace:

- `proc_grps.json` defines _processor groups_ by assigning a group name to a list of directories. Hence, the group name serves as a unique identifier of a set of HLASM libraries defined by a list of directories (some of which can be optional). Additionaly, the _SYSPARM_ option can be specified in the `asm_options` section.
- `proc_grps.json` defines _processor groups_ by assigning a group name to a list of directories. Hence, the group name serves as a unique identifier of a set of HLASM libraries defined by a list of directories (some of which can be optional). Additionaly, the _SYSPARM_ and _SYSTEM_ID_ options can be specified in the `asm_options` section.

- `pgm_conf.json` provides a mapping between _programs_ (open-code files) and processor groups. It specifies which list of directories is used with which source file. If a relative source file path is specified, it is relative to the current workspace.

Expand Down
4 changes: 4 additions & 0 deletions clients/vscode-hlasmplugin/proc_grps_schema
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
"PROFILE": {
"type": "string",
"description": "Profile Member to be copied into the source program."
},
"SYSTEM_ID": {
"type": "string",
"description": "Provides the value for the SYSTEM_ID system variable. Defaults to 'z/OS 02.04.00' when omitted."
}
}
},
Expand Down
1 change: 1 addition & 0 deletions parser_library/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ target_sources(parser_library PRIVATE
analyzer.cpp
analyzer.h
analyzing_context.h
compiler_options.cpp
compiler_options.h
diagnosable.h
diagnosable_ctx.cpp
Expand Down
19 changes: 19 additions & 0 deletions parser_library/src/compiler_options.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2021 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
*/

#include "compiler_options.h"

namespace hlasm_plugin::parser_library {
const std::string asm_option::system_id_default = "z/OS 02.04.00";
} // namespace hlasm_plugin::parser_library
4 changes: 3 additions & 1 deletion parser_library/src/compiler_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

namespace hlasm_plugin::parser_library {
struct asm_option

{
std::string sysparm;
std::string profile;

static const std::string system_id_default;
std::string system_id = system_id_default;
};
} // namespace hlasm_plugin::parser_library
#endif
4 changes: 4 additions & 0 deletions parser_library/src/config/proc_grps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ void to_json(nlohmann::json& j, const assembler_options& p)
j["PROFILE"] = p.profile;
if (p.sysparm.size())
j["SYSPARM"] = p.sysparm;
if (p.system_id.size())
j["SYSTEM_ID"] = p.system_id;
}
void from_json(const nlohmann::json& j, assembler_options& p)
{
Expand All @@ -57,6 +59,8 @@ void from_json(const nlohmann::json& j, assembler_options& p)
it->get_to(p.profile);
if (auto it = j.find("SYSPARM"); it != j.end())
it->get_to(p.sysparm);
if (auto it = j.find("SYSTEM_ID"); it != j.end())
it->get_to(p.system_id);
}

void to_json(nlohmann::json& j, const db2_preprocessor&) { j = "DB2"; }
Expand Down
1 change: 1 addition & 0 deletions parser_library/src/config/proc_grps.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct assembler_options
{
std::string sysparm;
std::string profile;
std::string system_id;

bool valid() const noexcept { return sysparm.size() < 256; }
};
Expand Down
10 changes: 10 additions & 0 deletions parser_library/src/context/hlasm_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ void hlasm_context::add_global_system_vars()
auto SYSTIME = ids().add("SYSTIME");
auto SYSPARM = ids().add("SYSPARM");
auto SYSOPT_RENT = ids().add("SYSOPT_RENT");
auto SYSTEM_ID = ids().add("SYSTEM_ID");

if (!is_in_macro())
{
Expand Down Expand Up @@ -231,6 +232,13 @@ void hlasm_context::add_global_system_vars()
auto val = std::make_shared<set_symbol<B_t>>(SYSOPT_RENT, true, true);
globals_.insert({ SYSOPT_RENT, std::move(val) });
}
{
auto val = std::make_shared<set_symbol<C_t>>(SYSTEM_ID, true, true);

val->set_value(asm_options_.system_id);

globals_.insert({ SYSTEM_ID, std::move(val) });
}
}

auto glob = globals_.find(SYSDATC);
Expand All @@ -243,6 +251,8 @@ void hlasm_context::add_global_system_vars()
curr_scope()->variables.insert({ glob->second->id, glob->second });
glob = globals_.find(SYSOPT_RENT);
curr_scope()->variables.insert({ glob->second->id, glob->second });
glob = globals_.find(SYSTEM_ID);
curr_scope()->variables.insert({ glob->second->id, glob->second });
}

bool hlasm_context::is_opcode(id_index symbol) const
Expand Down
11 changes: 10 additions & 1 deletion parser_library/src/workspaces/processor_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,21 @@ struct translate_pp_options
preprocessor_options operator()(const std::monostate&) const { return std::monostate {}; }
preprocessor_options operator()(const config::db2_preprocessor&) const { return db2_preprocessor_options {}; }
};

asm_option translate_assembler_options(const config::assembler_options& asm_options)
{
return asm_option {
asm_options.sysparm,
asm_options.profile,
asm_options.system_id.empty() ? asm_option::system_id_default : asm_options.system_id,
};
}
} // namespace

processor_group::processor_group(
const std::string& name, const config::assembler_options& asm_options, const config::preprocessor_options& pp)
: name_(name)
, asm_optns { asm_options.sysparm, asm_options.profile }
, asm_optns(translate_assembler_options(asm_options))
, prep_opts(std::visit(translate_pp_options {}, pp.options))
{}

Expand Down
1 change: 1 addition & 0 deletions parser_library/test/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
target_sources(library_test PRIVATE
pgm_conf_test.cpp
proc_grps_test.cpp
system_id_test.cpp
)
9 changes: 7 additions & 2 deletions parser_library/test/config/proc_grps_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@ TEST(proc_grps, assembler_options_read)
std::make_pair(R"({})"_json, assembler_options {}),
std::make_pair(R"({"PROFILE":"MAC"})"_json, assembler_options { "", "MAC" }),
std::make_pair(R"({"SYSPARM":"TESTPARM"})"_json, assembler_options { "TESTPARM", "" }),
std::make_pair(R"({"PROFILE":"MAC","SYSPARM":"TESTPARM"})"_json, assembler_options { "TESTPARM", "MAC" }),
std::make_pair(R"({"SYSTEM_ID":"VSE"})"_json, assembler_options { "", "", "VSE" }),
std::make_pair(R"({"PROFILE":"MAC","SYSPARM":"TESTPARM","SYSTEM_ID":"VSE"})"_json,
assembler_options { "TESTPARM", "MAC", "VSE" }),
};

for (const auto& [input, expected] : cases)
{
const auto ao = input.get<assembler_options>();
EXPECT_EQ(ao.profile, expected.profile);
EXPECT_EQ(ao.sysparm, expected.sysparm);
EXPECT_EQ(ao.system_id, expected.system_id);
}
}

Expand All @@ -70,7 +73,9 @@ TEST(proc_grps, assembler_options_write)
std::make_pair(R"({})"_json, assembler_options {}),
std::make_pair(R"({"PROFILE":"MAC"})"_json, assembler_options { "", "MAC" }),
std::make_pair(R"({"SYSPARM":"TESTPARM"})"_json, assembler_options { "TESTPARM", "" }),
std::make_pair(R"({"PROFILE":"MAC","SYSPARM":"TESTPARM"})"_json, assembler_options { "TESTPARM", "MAC" }),
std::make_pair(R"({"SYSTEM_ID":"VSE"})"_json, assembler_options { "", "", "VSE" }),
std::make_pair(R"({"PROFILE":"MAC","SYSPARM":"TESTPARM","SYSTEM_ID":"VSE"})"_json,
assembler_options { "TESTPARM", "MAC", "VSE" }),
};

for (const auto& [expected, input] : cases)
Expand Down
55 changes: 55 additions & 0 deletions parser_library/test/config/system_id_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2021 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
*/

#include "gtest/gtest.h"

#include "../common_testing.h"

TEST(system_id, basic_properties)
{
std::string input =
R"(
&A SETC '&SYSTEM_ID'
&B SETC T'&SYSTEM_ID
&C SETA K'&SYSTEM_ID
)";
analyzer a(input, analyzer_options { asm_option { "", "", "VSE" } });
a.analyze();

a.collect_diags();
EXPECT_TRUE(a.diags().empty());

EXPECT_EQ(get_var_value<C_t>(a.hlasm_ctx(), "A"), "VSE");
EXPECT_EQ(get_var_value<C_t>(a.hlasm_ctx(), "B"), "U");
EXPECT_EQ(get_var_value<A_t>(a.hlasm_ctx(), "C"), 3);
}

TEST(system_id, check_defaults)
{
std::string input =
R"(
&A SETC '&SYSTEM_ID'
&B SETC T'&SYSTEM_ID
&C SETA K'&SYSTEM_ID
)";
analyzer a(input);
a.analyze();

a.collect_diags();
EXPECT_TRUE(a.diags().empty());

EXPECT_EQ(get_var_value<C_t>(a.hlasm_ctx(), "A"), "z/OS 02.04.00");
EXPECT_EQ(get_var_value<C_t>(a.hlasm_ctx(), "B"), "U");
EXPECT_EQ(get_var_value<A_t>(a.hlasm_ctx(), "C"), 13);
}
3 changes: 2 additions & 1 deletion parser_library/test/debugging/debugger_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ TEST(debugger, stopped_on_entry)
EXPECT_EQ(std::string_view(sc.item(1).name), "Locals");
EXPECT_EQ(std::string_view(sc.item(2).name), "Ordinary symbols");
auto globs = d.variables(sc.item(0).variable_reference);
EXPECT_EQ(globs.size(), 5U);
EXPECT_EQ(globs.size(), 6U);
auto locs = d.variables(sc.item(1).variable_reference);
EXPECT_EQ(locs.size(), 0U);

Expand Down Expand Up @@ -178,6 +178,7 @@ struct frame_vars
this->globals["&SYSTIME"];
this->globals["&SYSPARM"];
this->globals["&SYSOPT_RENT"];
this->globals["&SYSTEM_ID"];
}
std::unordered_map<std::string, test_var_value> globals;
std::unordered_map<std::string, test_var_value> locals;
Expand Down