Skip to content

Commit

Permalink
refactor: Remove redundant arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera authored Jul 31, 2024
1 parent ff3ad99 commit bad80a8
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 140 deletions.
86 changes: 29 additions & 57 deletions parser_library/src/context/hlasm_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,41 +483,6 @@ processing_stack_t hlasm_context::processing_stack()
return result;
}

processing_frame hlasm_context::processing_stack_top(bool consider_macros)
{
// this is an inverted version of the loop from processing_stack()
// terminating after finding the first (originally last) element

assert(!source_stack_.empty());

if (consider_macros && source_stack_.size() == 1 && scope_stack_.size() > 1)
{
if (const auto& nest = scope_stack_.back().this_macro->get_current_copy_nest(); !nest.empty())
{
const auto& last_copy = nest.back();
return processing_frame(last_copy.loc.pos,
shared_resource_location(last_copy.loc.resource_loc),
last_copy.member_name,
nest.size() == 1 ? file_processing_type::MACRO : file_processing_type::COPY);
}
}

const auto& last_source = source_stack_.back();
if (!last_source.copy_stack.empty())
{
const auto& last_member = last_source.copy_stack.back();
return processing_frame(last_member.current_statement_position(),
shared_resource_location(last_member.definition_location()->resource_loc),
last_member.name(),
file_processing_type::COPY);
}

return processing_frame(last_source.current_instruction.pos,
shared_resource_location(last_source.current_instruction.resource_loc),
id_index(),
file_processing_type::OPENCODE);
}

processing_stack_details_t hlasm_context::processing_stack_details()
{
std::vector<processing_frame_details> res;
Expand Down Expand Up @@ -560,40 +525,47 @@ processing_stack_details_t hlasm_context::processing_stack_details()
return res;
}

location hlasm_context::current_statement_location(bool consider_macros) const
position hlasm_context::current_statement_position(bool consider_macros)
{
if (!consider_macros || source_stack_.size() > 1 || scope_stack_.size() == 1)
{
if (source_stack_.back().copy_stack.size())
{
const auto& member = source_stack_.back().copy_stack.back();

return location(member.current_statement_position(), member.definition_location()->resource_loc);
}
else
return source_stack_.back().current_instruction;
}
if (consider_macros && source_stack_.size() == 1 && scope_stack_.size() > 1)
return scope_stack_.back().this_macro->get_current_copy_nest().back().loc.pos;
else if (!source_stack_.back().copy_stack.empty())
return source_stack_.back().copy_stack.back().current_statement_position();
else
{
return scope_stack_.back().this_macro->get_current_copy_nest().back().loc;
}
return source_stack_.back().current_instruction.pos;
}

const utils::resource::resource_location& hlasm_context::current_statement_source(bool consider_macros) const
location hlasm_context::current_statement_location(bool consider_macros)
{
if (!consider_macros || source_stack_.size() > 1 || scope_stack_.size() == 1)
if (consider_macros && source_stack_.size() == 1 && scope_stack_.size() > 1)
{
if (source_stack_.back().copy_stack.size())
return source_stack_.back().copy_stack.back().definition_location()->resource_loc;
else
return source_stack_.back().current_instruction.resource_loc;
const auto& [p, r] = scope_stack_.back().this_macro->get_current_copy_nest().back().loc;
return location(p, *shared_resource_location(r));
}
else if (!source_stack_.back().copy_stack.empty())
{
const auto& member = source_stack_.back().copy_stack.back();
return location(
member.current_statement_position(), *shared_resource_location(member.definition_location()->resource_loc));
}
else
{
return scope_stack_.back().this_macro->get_current_copy_nest().back().loc.resource_loc;
const auto& [p, r] = source_stack_.back().current_instruction;
return location(p, *shared_resource_location(r));
}
}

const utils::resource::resource_location& hlasm_context::current_statement_source(bool consider_macros)
{
if (consider_macros && source_stack_.size() == 1 && scope_stack_.size() > 1)
return *shared_resource_location(
scope_stack_.back().this_macro->get_current_copy_nest().back().loc.resource_loc);
else if (source_stack_.back().copy_stack.size())
return *shared_resource_location(source_stack_.back().copy_stack.back().definition_location()->resource_loc);
else
return *shared_resource_location(source_stack_.back().current_instruction.resource_loc);
}

const std::deque<code_scope>& hlasm_context::scope_stack() const { return scope_stack_; }

const source_context& hlasm_context::current_source() const { return source_stack_.back(); }
Expand Down
6 changes: 3 additions & 3 deletions parser_library/src/context/hlasm_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ class hlasm_context

// gets stack of locations of all currently processed files
processing_stack_t processing_stack();
processing_frame processing_stack_top(bool consider_macros = true);
processing_stack_details_t processing_stack_details();
location current_statement_location(bool consider_macros = true) const;
const utils::resource::resource_location& current_statement_source(bool consider_macros = true) const;
position current_statement_position(bool consider_macros = true);
location current_statement_location(bool consider_macros = true);
const utils::resource::resource_location& current_statement_source(bool consider_macros = true);

// gets macro nest
const std::deque<code_scope>& scope_stack() const;
Expand Down
1 change: 0 additions & 1 deletion parser_library/src/context/literal_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ void literal_pool::generate_pool(diagnosable_ctx& diags, index_t<using_collectio
symbol_attributes(symbol_origin::DAT,
ebcdic_encoding::to_ebcdic((unsigned char)lit->get_type_attribute()),
lit->get_length_attribute(solver, diags)),
{},
li);

if (size == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,16 @@ location_counter& ordinary_assembly_context::loctr()
}

bool ordinary_assembly_context::create_symbol(
id_index name, symbol_value value, symbol_attributes attributes, location symbol_location, const library_info& li)
id_index name, symbol_value value, symbol_attributes attributes, const library_info& li)
{
assert(symbol_can_be_assigned(symbols_, name));

const auto value_kind = value.value_kind();

symbols_.insert_or_assign(
name, symbol(name, std::move(value), attributes, std::move(symbol_location), hlasm_ctx_.processing_stack()));
auto loc = hlasm_ctx_.processing_stack();
auto sym_loc = loc.frame().get_location();
sym_loc.pos.column = 0;
symbols_.insert_or_assign(name, symbol(name, std::move(value), attributes, std::move(sym_loc), std::move(loc)));

bool ok = true;

Expand Down Expand Up @@ -121,8 +123,7 @@ section* ordinary_assembly_context::get_section(id_index name)

const section* ordinary_assembly_context::current_section() const { return curr_section_; }

section* ordinary_assembly_context::set_section(
id_index name, section_kind kind, location symbol_location, const library_info& li)
section* ordinary_assembly_context::set_section(id_index name, section_kind kind, const library_info& li)
{
auto tmp = std::ranges::find_if(
sections_, [name, kind](const auto& sect) { return sect->name == name && sect->kind == kind; });
Expand All @@ -138,12 +139,15 @@ section* ordinary_assembly_context::set_section(
if (!name.empty())
{
assert(symbol_can_be_assigned(symbols_, name));
auto loc = hlasm_ctx_.processing_stack();
auto sym_loc = loc.frame().get_location();
sym_loc.pos.column = 0;
symbols_.insert_or_assign(name,
symbol(name,
s->current_location_counter().current_address(),
symbol_attributes::make_section_attrs(),
std::move(symbol_location),
hlasm_ctx_.processing_stack()));
std::move(sym_loc),
std::move(loc)));
m_symbol_dependencies->add_defined(name, nullptr, li);
}
}
Expand All @@ -152,7 +156,7 @@ section* ordinary_assembly_context::set_section(
}

section* ordinary_assembly_context::create_and_set_class(
id_index name, location symbol_location, const library_info& li, section* base, bool partitioned)
id_index name, const library_info& li, section* base, bool partitioned)
{
assert(std::ranges::find(sections_, name, &section::name) == sections_.end());
assert(symbol_can_be_assigned(symbols_, name));
Expand All @@ -164,12 +168,15 @@ section* ordinary_assembly_context::create_and_set_class(
.parent = base,
.partitioned = partitioned,
}));
auto loc = hlasm_ctx_.processing_stack();
auto sym_loc = loc.frame().get_location();
sym_loc.pos.column = 0;
symbols_.insert_or_assign(name,
symbol(name,
s->current_location_counter().current_address(),
symbol_attributes::make_section_attrs(),
std::move(symbol_location),
hlasm_ctx_.processing_stack()));
std::move(sym_loc),
std::move(loc)));
m_symbol_dependencies->add_defined(name, nullptr, li);

return s;
Expand All @@ -189,8 +196,7 @@ section* ordinary_assembly_context::set_section(section& s)
return &s;
}

void ordinary_assembly_context::create_external_section(
id_index name, section_kind kind, location symbol_location, processing_stack_t processing_stack)
void ordinary_assembly_context::create_external_section(id_index name, section_kind kind)
{
const auto attrs = [kind]() {
switch (kind)
Expand All @@ -206,15 +212,17 @@ void ordinary_assembly_context::create_external_section(

assert(symbol_can_be_assigned(symbols_, name));

auto loc = hlasm_ctx_.processing_stack();
auto sym_loc = loc.frame().get_location();
symbols_.insert_or_assign(name,
symbol(name,
create_section(name, kind)->current_location_counter().current_address(),
attrs,
std::move(symbol_location),
std::move(processing_stack)));
std::move(sym_loc),
std::move(loc)));
}

void ordinary_assembly_context::set_location_counter(id_index name, location symbol_location, const library_info& li)
void ordinary_assembly_context::set_location_counter(id_index name, const library_info& li)
{
ensure_current_section();

Expand All @@ -232,13 +240,16 @@ void ordinary_assembly_context::set_location_counter(id_index name, location sym
if (!defined)
{
auto& l = curr_section_->set_location_counter(name);
auto loc = hlasm_ctx_.processing_stack();
auto sym_loc = loc.frame().get_location();
sym_loc.pos.column = 0;
assert(symbol_can_be_assigned(symbols_, name));
symbols_.insert_or_assign(name,
symbol(name,
l.current_address(),
symbol_attributes::make_section_attrs(),
std::move(symbol_location),
hlasm_ctx_.processing_stack()));
std::move(sym_loc),
std::move(loc)));

m_symbol_dependencies->add_defined(name, nullptr, li);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,8 @@ class ordinary_assembly_context

// creates symbol
// returns false if loctr cycle has occured
[[nodiscard]] bool create_symbol(id_index name,
symbol_value value,
symbol_attributes attributes,
location symbol_location,
const library_info& li);
[[nodiscard]] bool create_symbol(
id_index name, symbol_value value, symbol_attributes attributes, const library_info& li);

void add_symbol_reference(symbol sym, const library_info& li);
const symbol* get_symbol_reference(context::id_index name) const;
Expand All @@ -115,17 +112,15 @@ class ordinary_assembly_context
const section* current_section() const;

// sets current section
section* set_section(id_index name, section_kind kind, location symbol_location, const library_info& li);
section* create_and_set_class(
id_index name, location symbol_location, const library_info& li, section* base, bool partitioned);
section* set_section(id_index name, section_kind kind, const library_info& li);
section* create_and_set_class(id_index name, const library_info& li, section* base, bool partitioned);
section* set_section(section& s);

// creates an external section
void create_external_section(
id_index name, section_kind kind, location symbol_location, processing_stack_t processing_stack);
void create_external_section(id_index name, section_kind kind);

// sets current location counter of current section
void set_location_counter(id_index name, location symbol_location, const library_info& li);
void set_location_counter(id_index name, const library_info& li);
void set_location_counter(location_counter& l);

// sets value of the current location counter
Expand Down
32 changes: 8 additions & 24 deletions parser_library/src/processing/instruction_sets/asm_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,8 @@ void asm_processor::process_sect(const context::section_kind kind, rebuilt_state
add_diagnostic(diagnostic_op::error_E031("symbol", stmt.label_ref().field_range));
}
else
{
auto sym_loc = hlasm_ctx.processing_stack_top().get_location();
sym_loc.pos.column = 0;
hlasm_ctx.ord_ctx.set_section(sect_name, kind, std::move(sym_loc), lib_info);
}
hlasm_ctx.ord_ctx.set_section(sect_name, kind, lib_info);

context::ordinary_assembly_dependency_solver dep_solver(hlasm_ctx.ord_ctx, lib_info);
hlasm_ctx.ord_ctx.symbol_dependencies().add_postponed_statement(
std::make_unique<postponed_statement_impl>(std::move(stmt), hlasm_ctx.processing_stack()),
Expand All @@ -123,15 +120,10 @@ void asm_processor::process_LOCTR(rebuilt_statement&& stmt)
add_diagnostic(diagnostic_op::error_E053(stmt.label_ref().field_range));

if (hlasm_ctx.ord_ctx.symbol_defined(loctr_name) && !hlasm_ctx.ord_ctx.counter_defined(loctr_name))
{
add_diagnostic(diagnostic_op::error_E031("symbol", stmt.label_ref().field_range));
}
else
{
auto sym_loc = hlasm_ctx.processing_stack_top().get_location();
sym_loc.pos.column = 0;
hlasm_ctx.ord_ctx.set_location_counter(loctr_name, std::move(sym_loc), lib_info);
}
hlasm_ctx.ord_ctx.set_location_counter(loctr_name, lib_info);

context::ordinary_assembly_dependency_solver dep_solver(hlasm_ctx.ord_ctx, lib_info);
hlasm_ctx.ord_ctx.symbol_dependencies().add_postponed_statement(
std::make_unique<postponed_statement_impl>(std::move(stmt), hlasm_ctx.processing_stack()),
Expand Down Expand Up @@ -498,8 +490,7 @@ void asm_processor::process_external(rebuilt_statement&& stmt, external_type t)
if (hlasm_ctx.ord_ctx.symbol_defined(name))
add_diagnostic(diagnostic_op::error_E031("external symbol", op_range));
else
hlasm_ctx.ord_ctx.create_external_section(
name, s_kind, hlasm_ctx.current_statement_location(), hlasm_ctx.processing_stack());
hlasm_ctx.ord_ctx.create_external_section(name, s_kind);
};
for (const auto& op : stmt.operands_ref().value)
{
Expand Down Expand Up @@ -1006,9 +997,7 @@ void asm_processor::process_START(rebuilt_statement&& stmt)
return;
}

auto sym_loc = hlasm_ctx.processing_stack_top().get_location();
sym_loc.pos.column = 0;
const auto* section = hlasm_ctx.ord_ctx.set_section(sect_name, EXECUTABLE, std::move(sym_loc), lib_info);
const auto* section = hlasm_ctx.ord_ctx.set_section(sect_name, EXECUTABLE, lib_info);

const auto& ops = stmt.operands_ref().value;
if (ops.size() != 1)
Expand Down Expand Up @@ -1541,20 +1530,15 @@ void asm_processor::handle_cattr_ops(context::id_index class_name,
}
else
{
auto sym_loc = hlasm_ctx.processing_stack_top().get_location();
sym_loc.pos.column = 0;
class_name_sect = hlasm_ctx.ord_ctx.create_and_set_class(
class_name, std::move(sym_loc), lib_info, nullptr, !part_name.empty());
class_name_sect = hlasm_ctx.ord_ctx.create_and_set_class(class_name, lib_info, nullptr, !part_name.empty());

// TODO: sectalign? part
}

if (part_name.empty())
return;

auto sym_loc = hlasm_ctx.processing_stack_top().get_location();
sym_loc.pos.column = 0;
hlasm_ctx.ord_ctx.create_and_set_class(part_name, std::move(sym_loc), lib_info, class_name_sect, false);
hlasm_ctx.ord_ctx.create_and_set_class(part_name, lib_info, class_name_sect, false);
}

void asm_processor::process_CATTR(rebuilt_statement&& stmt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ context::id_index low_language_processor::find_using_label(const rebuilt_stateme
bool low_language_processor::create_symbol(
range err_range, context::id_index symbol_name, context::symbol_value value, context::symbol_attributes attributes)
{
auto sym_loc = hlasm_ctx.processing_stack_top().get_location();
sym_loc.pos.column = 0;
bool ok = hlasm_ctx.ord_ctx.create_symbol(
symbol_name, std::move(value), std::move(attributes), std::move(sym_loc), lib_info);
bool ok = hlasm_ctx.ord_ctx.create_symbol(symbol_name, std::move(value), std::move(attributes), lib_info);

if (!ok)
add_diagnostic(diagnostic_op::error_E033(err_range));
Expand Down
2 changes: 1 addition & 1 deletion parser_library/src/processing/processing_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ void processing_manager::register_sequence_symbol(context::id_index target, rang
std::unique_ptr<context::opencode_sequence_symbol> processing_manager::create_opencode_sequence_symbol(
context::id_index name, range symbol_range)
{
auto loc = hlasm_ctx_.processing_stack_top(false).get_location();
auto loc = hlasm_ctx_.current_statement_location(false);
loc.pos = symbol_range.start;

auto&& [statement_position, snapshot] = hlasm_ctx_.get_begin_snapshot(lookahead_active());
Expand Down
Loading

0 comments on commit bad80a8

Please sign in to comment.