Skip to content

Commit

Permalink
fix: TITLE instruction name field support
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Oct 7, 2022
1 parent 2cb627c commit 1df0fa2
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 3 deletions.
1 change: 1 addition & 0 deletions clients/vscode-hlasmplugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Implement rest of the changes introduced by APAR PH46868
- Evaluation of subscripted expressions in CA statements
- Detection of re-declared global variables with inconsistent types
- TITLE instruction name field support

## [1.4.0](https://github.com/eclipse/che-che4z-lsp-for-hlasm/compare/1.3.0...1.4.0) (2022-08-30)

Expand Down
6 changes: 6 additions & 0 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 <string>
#include <unordered_set>
#include <vector>

Expand Down Expand Up @@ -115,6 +116,8 @@ class hlasm_context

processing_frame_tree m_stack_tree;

std::string m_title_name;

public:
hlasm_context(utils::resource::resource_location file_loc = utils::resource::resource_location(""),
asm_option asm_opts = {},
Expand Down Expand Up @@ -331,6 +334,9 @@ class hlasm_context
const opcode_t* find_opcode_mnemo(id_index name, opcode_generation gen) const;

opcode_generation current_opcode_generation() const { return m_current_opcode_generation; }

const std::string& get_title_name() const { return m_title_name; }
void set_title_name(std::string name) { m_title_name = std::move(name); }
};

bool test_symbol_for_read(const var_sym_ptr& var,
Expand Down
8 changes: 7 additions & 1 deletion parser_library/src/diagnostic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1980,7 +1980,7 @@ diagnostic_op diagnostic_op::error_E056(const range& range)

diagnostic_op diagnostic_op::error_E057(const range& range)
{
return diagnostic_op(diagnostic_severity::error, "E057", "Symbol not an ordinary or sequence symbol", range);
return diagnostic_op(diagnostic_severity::error, "E057", "Symbol is not an ordinary or a sequence symbol", range);
}

diagnostic_op diagnostic_op::error_E058(const range& range)
Expand Down Expand Up @@ -2143,6 +2143,12 @@ diagnostic_op diagnostic_op::warning_W015(const range& range)
diagnostic_severity::warning, "W015", "End of source input reached, batch mode is not supported yet", range);
}

diagnostic_op diagnostic_op::warning_W016(const range& range)
{
return diagnostic_op(
diagnostic_severity::warning, "W016", "Multiple TITLE instructions with a non-empty name field", range);
}

diagnostic_op diagnostic_op::error_EQU1(const range& range)
{
return diagnostic_op(diagnostic_severity::error, "EQU1", "Constant redefinition", range);
Expand Down
2 changes: 2 additions & 0 deletions parser_library/src/diagnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ struct diagnostic_op

static diagnostic_op warning_W015(const range& range);

static diagnostic_op warning_W016(const range& range);

static diagnostic_op error_EQU1(const range& range);

static diagnostic_op error_EQU2(const range& range);
Expand Down
29 changes: 29 additions & 0 deletions parser_library/src/processing/instruction_sets/asm_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ asm_processor::process_table_t asm_processor::create_table(context::hlasm_contex
table.emplace(h_ctx.ids().add("POP"), [this](rebuilt_statement stmt) { process_POP(std::move(stmt)); });
table.emplace(h_ctx.ids().add("MNOTE"), [this](rebuilt_statement stmt) { process_MNOTE(std::move(stmt)); });
table.emplace(h_ctx.ids().add("CXD"), [this](rebuilt_statement stmt) { process_CXD(std::move(stmt)); });
table.emplace(h_ctx.ids().add("TITLE"), [this](rebuilt_statement stmt) { process_TITLE(std::move(stmt)); });

return table;
}
Expand Down Expand Up @@ -1315,4 +1316,32 @@ void asm_processor::process_CXD(rebuilt_statement stmt)
hlasm_ctx.ord_ctx.reserve_storage_area(cxd_length, context::no_align, lib_info);
}

struct title_label_visitor
{
std::string operator()(const std::string& v) const { return v; }
std::string operator()(const semantics::ord_symbol_string& v) const { return v.mixed_case; }
std::string operator()(const semantics::concat_chain&) const { return {}; }
std::string operator()(const semantics::seq_sym&) const { return {}; }
std::string operator()(const semantics::vs_ptr&) const { return {}; }
};

void asm_processor::process_TITLE(rebuilt_statement stmt)
{
const auto& label = stmt.label_ref();

if (auto label_text = std::visit(title_label_visitor(), label.value); !label_text.empty())
{
if (hlasm_ctx.get_title_name().empty())
hlasm_ctx.set_title_name(std::move(label_text));
else
add_diagnostic(diagnostic_op::warning_W016(label.field_range));
}

hlasm_ctx.ord_ctx.symbol_dependencies.add_dependency(
std::make_unique<postponed_statement_impl>(std::move(stmt), hlasm_ctx.processing_stack()),
context::ordinary_assembly_dependency_solver(hlasm_ctx.ord_ctx, lib_info)
.derive_current_dependency_evaluation_context(),
lib_info);
}

} // namespace hlasm_plugin::parser_library::processing
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class asm_processor : public low_language_processor
void process_POP(rebuilt_statement stmt);
void process_MNOTE(rebuilt_statement stmt);
void process_CXD(rebuilt_statement stmt);
void process_TITLE(rebuilt_statement stmt);

template<checking::data_instr_type instr_type>
void process_data_instruction(rebuilt_statement stmt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ low_language_processor::preprocessed_part low_language_processor::preprocess_inn
}
break;
case label_si_type::MAC:
add_diagnostic(diagnostic_op::error_E057(label_ref.field_range));
if (*stmt.opcode_ref().value != "TITLE")
add_diagnostic(diagnostic_op::error_E057(label_ref.field_range));
break;
case label_si_type::SEQ:
branch_provider.register_sequence_symbol(
Expand Down
2 changes: 1 addition & 1 deletion parser_library/src/semantics/collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void collector::set_label_field(
// otherwise it is macro label parameter
else
{
lbl_.emplace(symbol_range, *label, label_si::mac_flag());
lbl_.emplace(symbol_range, mixed_case_label, label_si::mac_flag());
}
}

Expand Down
47 changes: 47 additions & 0 deletions parser_library/test/processing/asm_instr_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,50 @@ C CXD
EXPECT_EQ(get_var_value<A_t>(a.hlasm_ctx(), "S"), 0);
EXPECT_EQ(get_var_value<A_t>(a.hlasm_ctx(), "I"), 0);
}

TEST(asm_instr_processing, TITLE_text_label)
{
std::string input = R"(
0a0 TITLE 'aaa'
)";

analyzer a(input);
a.analyze();
a.collect_diags();

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

EXPECT_EQ(a.hlasm_ctx().get_title_name(), "0a0");
}

TEST(asm_instr_processing, TITLE_multiple_labels)
{
std::string input = R"(
000 TITLE 'aaa'
0b0 TITLE 'aaa'
)";

analyzer a(input);
a.analyze();
a.collect_diags();

EXPECT_TRUE(matches_message_codes(a.diags(), { "W016" }));

EXPECT_EQ(a.hlasm_ctx().get_title_name(), "000");
}

TEST(asm_instr_processing, TITLE_sequence_does_not_count)
{
std::string input = R"(
0a0 TITLE 'aaa'
.A TITLE 'aaa'
)";

analyzer a(input);
a.analyze();
a.collect_diags();

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

EXPECT_EQ(a.hlasm_ctx().get_title_name(), "0a0");
}

0 comments on commit 1df0fa2

Please sign in to comment.