Skip to content

Commit

Permalink
refactor: Reduce header dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Jun 3, 2022
1 parent 23f6b03 commit 2a7f8cb
Show file tree
Hide file tree
Showing 42 changed files with 143 additions and 59 deletions.
1 change: 1 addition & 0 deletions parser_library/src/checking/asm_instr_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <regex>

#include "context/common_types.h"
#include "diagnostic_collector.h"

namespace {
const std::vector<std::string_view> rmode_options = { "24", "31", "64", "ANY" };
Expand Down
4 changes: 4 additions & 0 deletions parser_library/src/checking/asm_instr_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include "asm_instr_class.h"
#include "data_definition/data_def_type_base.h"

namespace hlasm_plugin::parser_library {
class diagnostic_collector;
} // namespace hlasm_plugin::parser_library

namespace hlasm_plugin::parser_library::checking {
/*
TO DO - notes
Expand Down
2 changes: 2 additions & 0 deletions parser_library/src/checking/asm_instr_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include <array>

#include "diagnostic_collector.h"

using namespace hlasm_plugin::parser_library;
using namespace hlasm_plugin::parser_library::checking;

Expand Down
4 changes: 4 additions & 0 deletions parser_library/src/checking/asm_instr_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include "diagnosable.h"
#include "instr_operand.h"

namespace hlasm_plugin::parser_library {
class diagnostic_collector;
} // namespace hlasm_plugin::parser_library

namespace hlasm_plugin::parser_library::checking {

// defining label types before instruction, used as parameter in assembler_instruction class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <optional>

#include "checking/diagnostic_collector.h"
#include "checking/instr_operand.h"
#include "data_def_types.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@
#include <cstdint>
#include <functional>
#include <map>
#include <memory>
#include <set>
#include <variant>

#include "checking/diagnostic_collector.h"
#include "context/ordinary_assembly/alignment.h"
#include "data_def_fields.h"

namespace hlasm_plugin::parser_library {
class diagnostic_collector;
} // namespace hlasm_plugin::parser_library

namespace hlasm_plugin::parser_library::checking {

class data_definition_operand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// these types: A, Y, S, R, V, Q, J

#include "checking/checker_helper.h"
#include "checking/diagnostic_collector.h"
#include "data_def_types.h"

using namespace hlasm_plugin::parser_library::checking;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// these types: P, Z, H, F

#include "checking/checker_helper.h"
#include "checking/diagnostic_collector.h"
#include "data_def_types.h"

using namespace hlasm_plugin::parser_library::checking;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// floating point types: E, D, L

#include "checking/checker_helper.h"
#include "checking/diagnostic_collector.h"
#include "data_def_types.h"

using namespace hlasm_plugin::parser_library::checking;
Expand All @@ -40,10 +41,25 @@ data_def_type_E_D_L::data_def_type_E_D_L(char type,
implicit_length)
{}

std::map<char, std::set<std::string>> allowed_round_modes = {
{ 'B', { "1", "4", "5", "6", "7" } },
{ 'H', { "1", "4", "5", "6", "7" } },
{ 'D', { "8", "9", "10", "11", "12", "13", "14", "15" } },
const std::set<std::pair<char, std::string_view>> allowed_round_modes = {
{ 'B', "1" },
{ 'B', "4" },
{ 'B', "5" },
{ 'B', "6" },
{ 'B', "7" },
{ 'H', "1" },
{ 'H', "4" },
{ 'H', "5" },
{ 'H', "6" },
{ 'H', "7" },
{ 'D', "8" },
{ 'D', "9" },
{ 'D', "10" },
{ 'D', "11" },
{ 'D', "12" },
{ 'D', "13" },
{ 'D', "14" },
{ 'D', "15" },
};

class E_D_L_number_spec
Expand Down Expand Up @@ -104,7 +120,7 @@ bool data_def_type_E_D_L::check(
++i;
}

if (allowed_round_modes[extension].find(round_mode_s) == allowed_round_modes[extension].end())
if (!allowed_round_modes.contains(std::pair<char, std::string_view>(extension, round_mode_s)))
{
add_diagnostic(diagnostic_op::error_D026(op.nominal_value.rng));
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <concepts>

#include "checking/checker_helper.h"
#include "checking/diagnostic_collector.h"
#include "data_def_types.h"

using namespace hlasm_plugin::parser_library::checking;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "data_definition_operand.h"

#include "checking/diagnostic_collector.h"

using namespace hlasm_plugin::parser_library::checking;
using namespace hlasm_plugin::parser_library;

Expand Down Expand Up @@ -88,3 +90,39 @@ uint32_t data_definition_operand::get_integer_attribute() const
else
return 0;
}


template<data_instr_type instr_type>
uint64_t data_definition_operand::get_operands_length(const std::vector<const data_definition_operand*>& operands)
{
uint64_t operands_bit_length = 0;

for (auto op : operands)
{
if (!op->check<instr_type>(diagnostic_collector()))
return 0;

if (op->length.len_type != checking::data_def_length_t::BIT)
{
// align to whole byte
operands_bit_length = round_up(operands_bit_length, (uint64_t)8);

// enforce data def alignment
context::alignment al = op->get_alignment();

operands_bit_length = round_up(operands_bit_length, (uint64_t)al.boundary * 8);
}

operands_bit_length += op->get_length();
}
// align to whole byte
operands_bit_length = round_up(operands_bit_length, (uint64_t)8);

// returns the length in bytes
return operands_bit_length / 8;
}

template uint64_t data_definition_operand::get_operands_length<data_instr_type::DC>(
const std::vector<const data_definition_operand*>& operands);
template uint64_t data_definition_operand::get_operands_length<data_instr_type::DS>(
const std::vector<const data_definition_operand*>& operands);
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
#ifndef HLASMPLUGIN_PARSERLIBRARY_CHECKING_DATA_DEFINITION_OPERAND_H
#define HLASMPLUGIN_PARSERLIBRARY_CHECKING_DATA_DEFINITION_OPERAND_H

#include "checking/diagnostic_collector.h"
#include "checking/operand.h"
#include "data_def_fields.h"
#include "data_def_type_base.h"

namespace hlasm_plugin::parser_library {
class diagnostic_collector;
} // namespace hlasm_plugin::parser_library

namespace hlasm_plugin::parser_library::checking {
// Represents evaluated (resolved machine expressions) data definition operand suitable for checking.
class data_definition_operand final : public asm_operand
Expand Down Expand Up @@ -58,35 +61,6 @@ class data_definition_operand final : public asm_operand


//************************* template functions implementation ************************
template<data_instr_type instr_type>
uint64_t data_definition_operand::get_operands_length(const std::vector<const data_definition_operand*>& operands)
{
uint64_t operands_bit_length = 0;

for (auto op : operands)
{
if (!op->check<instr_type>(diagnostic_collector()))
return 0;

if (op->length.len_type != checking::data_def_length_t::BIT)
{
// align to whole byte
operands_bit_length = round_up(operands_bit_length, (uint64_t)8);

// enforce data def alignment
context::alignment al = op->get_alignment();

operands_bit_length = round_up(operands_bit_length, (uint64_t)al.boundary * 8);
}

operands_bit_length += op->get_length();
}
// align to whole byte
operands_bit_length = round_up(operands_bit_length, (uint64_t)8);

// returns the length in bytes
return operands_bit_length / 8;
}

template<data_instr_type instr_type>
bool data_definition_operand::check(const diagnostic_collector& add_diagnostic) const
Expand Down
1 change: 0 additions & 1 deletion parser_library/src/checking/instr_operand.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include "context/ordinary_assembly/alignment.h"
#include "diagnostic.h"
#include "diagnostic_collector.h"
#include "operand.h"

namespace hlasm_plugin::parser_library::checking {
Expand Down
1 change: 1 addition & 0 deletions parser_library/src/checking/using_label_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "using_label_checker.h"

#include "context/ordinary_assembly/section.h"
#include "context/ordinary_assembly/symbol.h"

namespace hlasm_plugin::parser_library::checking {

Expand Down
2 changes: 2 additions & 0 deletions parser_library/src/context/instruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <algorithm>
#include <limits>

#include "checking/diagnostic_collector.h"

using namespace hlasm_plugin::parser_library::context;
using namespace hlasm_plugin::parser_library::checking;
using namespace hlasm_plugin::parser_library;
Expand Down
4 changes: 4 additions & 0 deletions parser_library/src/context/instruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#include "id_storage.h"
#include "instruction_set_version.h"

namespace hlasm_plugin::parser_library {
class diagnostic_collector;
} // namespace hlasm_plugin::parser_library

namespace hlasm_plugin::parser_library::context {

enum class z_arch_affiliation : uint16_t
Expand Down
4 changes: 4 additions & 0 deletions parser_library/src/context/literal_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include "tagged_index.h"
#include "utils/similar.h"

namespace hlasm_plugin::parser_library {
class diagnosable_ctx;
} // namespace hlasm_plugin::parser_library

namespace hlasm_plugin::parser_library::context {
class hlasm_context;
class using_collection;
Expand Down
1 change: 1 addition & 0 deletions parser_library/src/context/macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <cassert>
#include <stdexcept>

#include "copy_member.h"
#include "variables/system_variable.h"

using namespace hlasm_plugin::parser_library;
Expand Down
5 changes: 2 additions & 3 deletions parser_library/src/context/macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <variant>

#include "common_types.h"
#include "copy_member.h"
#include "sequence_symbol.h"
#include "statement_cache.h"
#include "variables/macro_param.h"
Expand Down Expand Up @@ -84,7 +83,7 @@ class macro_definition
const label_storage labels;
// location of the macro definition in code
const location definition_location;
const std::unordered_set<copy_member_ptr> used_copy_members;
const std::unordered_set<std::shared_ptr<copy_member>> used_copy_members;
// initializes macro with its name and params - positional or keyword
macro_definition(id_index name,
id_index label_param_name,
Expand All @@ -93,7 +92,7 @@ class macro_definition
copy_nest_storage copy_nests,
label_storage labels,
location definition_location,
std::unordered_set<copy_member_ptr> used_copy_members);
std::unordered_set<std::shared_ptr<copy_member>> used_copy_members);

// returns object with parameters' data set to actual parameters in macro call
macro_invo_ptr call(macro_data_ptr label_param_data, std::vector<macro_arg> actual_params, id_index syslist_name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <algorithm>
#include <assert.h>

#include "symbol_value.h"

using namespace hlasm_plugin::parser_library::context;

address_resolver::address_resolver(address dependency_address_)
Expand Down
3 changes: 2 additions & 1 deletion parser_library/src/context/ordinary_assembly/dependable.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
#include <optional>

#include "dependency_collector.h"
#include "symbol.h"

namespace hlasm_plugin::parser_library::expressions {
struct data_definition;
} // namespace hlasm_plugin::parser_library::expressions

namespace hlasm_plugin::parser_library::context {

class symbol;
struct symbol_value;
struct using_evaluate_result;

// interface for obtaining symbol from its name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <optional>

#include "address.h"
#include "range.h"

namespace hlasm_plugin::parser_library::context {
struct dependency_evaluation_context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <string_view>

#include "../ca_expression.h"
#include "diagnosable_ctx.h"
#include "diagnostic_adder.h"

namespace hlasm_plugin::parser_library::expressions {
Expand Down
1 change: 1 addition & 0 deletions parser_library/src/expressions/data_definition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "checking/data_definition/data_def_fields.h"
#include "checking/data_definition/data_def_type_base.h"
#include "checking/diagnostic_collector.h"
#include "context/using.h"
#include "ebcdic_encoding.h"
#include "lexing/logical_line.h"
Expand Down
5 changes: 4 additions & 1 deletion parser_library/src/expressions/data_definition.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
#include <optional>

#include "checking/data_definition/data_def_fields.h"
#include "checking/diagnostic_collector.h"
#include "context/id_storage.h"
#include "context/ordinary_assembly/alignment.h"
#include "nominal_value.h"

namespace hlasm_plugin::parser_library {
class diagnostic_collector;
} // namespace hlasm_plugin::parser_library

namespace hlasm_plugin::parser_library::checking {
class data_def_type;
enum class data_instr_type;
Expand Down
2 changes: 2 additions & 0 deletions parser_library/src/expressions/mach_expr_term.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include "checking/checker_helper.h"
#include "conditional_assembly/terms/ca_constant.h"
#include "context/ordinary_assembly/symbol.h"
#include "context/ordinary_assembly/symbol_value.h"
#include "ebcdic_encoding.h"
#include "mach_expr_visitor.h"
#include "utils/similar.h"
Expand Down
Loading

0 comments on commit 2a7f8cb

Please sign in to comment.