Skip to content

Commit

Permalink
Merge pull request #26 from agatti/std_foreach
Browse files Browse the repository at this point in the history
Removed usages of BOOST_FOREACH.
  • Loading branch information
DorianBDev committed Feb 14, 2024
2 parents 1e8c768 + 50a6ae7 commit 42fb0aa
Show file tree
Hide file tree
Showing 34 changed files with 87 additions and 98 deletions.
22 changes: 14 additions & 8 deletions src/Core/Generator/CodeTemplateGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
*/

#include "Core/Generator/CodeTemplateGenerator.h"
#include <boost/foreach.hpp>
#include <algorithm>
#include <string>

using namespace degate;
using namespace boost;

CodeTemplateGenerator::CodeTemplateGenerator(std::string const& entity_name,
std::string const& description,
Expand Down Expand Up @@ -112,7 +110,7 @@ std::string CodeTemplateGenerator::get_first_port_name_not_in(std::vector<std::s
{
typedef std::vector<std::string>::const_iterator iter;

BOOST_FOREACH(std::string const& p_name, ports)
for (const auto& p_name : ports)
{
iter i = std::find(blacklist.begin(), blacklist.end(), p_name);
if (i == blacklist.end()) return p_name;
Expand All @@ -133,8 +131,11 @@ std::vector<std::string> CodeTemplateGenerator::get_inports() const
{
std::vector<std::string> ports;

BOOST_FOREACH(port_direction_type::value_type const& p, port_direction)
if (p.second == true) ports.push_back(p.first);
for(const auto& p : port_direction)
{
if (p.second == true)
ports.push_back(p.first);
}

std::sort(ports.begin(), ports.end());
return ports;
Expand All @@ -144,8 +145,11 @@ std::vector<std::string> CodeTemplateGenerator::get_outports() const
{
std::vector<std::string> ports;

BOOST_FOREACH(port_direction_type::value_type const& p, port_direction)
if (p.second == false) ports.push_back(p.first);
for (const auto& p : port_direction)
{
if (p.second == false)
ports.push_back(p.first);
}

std::sort(ports.begin(), ports.end());
return ports;
Expand All @@ -155,8 +159,10 @@ std::vector<std::string> CodeTemplateGenerator::get_ports() const
{
std::vector<std::string> ports;

BOOST_FOREACH(port_direction_type::value_type const& p, port_direction)
for (const auto& p : port_direction)
{
ports.push_back(p.first);
}

std::sort(ports.begin(), ports.end());
return ports;
Expand Down
4 changes: 1 addition & 3 deletions src/Core/Generator/CodeTemplateGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include <vector>
#include <string>

#include <boost/foreach.hpp>

namespace degate
{
/**
Expand Down Expand Up @@ -101,7 +99,7 @@ namespace degate
Container generate_identifier(Container const& c, std::string const& prefix = "") const
{
Container new_c;
BOOST_FOREACH(typename Container::value_type const& s, c)
for (const auto& s : c)
{
new_c.push_back(generate_identifier(s, prefix));
}
Expand Down
5 changes: 2 additions & 3 deletions src/Core/Generator/VHDLCodeTemplateGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include "Core/Generator/VHDLCodeTemplateGenerator.h"
#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/join.hpp>
#include <list>

Expand Down Expand Up @@ -210,7 +209,7 @@ std::string VHDLCodeTemplateGenerator::generate_identifier(std::string const& na
std::string identifier = prefix;

bool first_char = true;
BOOST_FOREACH(char c, name)
for (auto c : name)
{
if (c == '/' || c == '!') identifier.append("not");
else if (first_char && !isalpha(c))
Expand All @@ -233,7 +232,7 @@ std::string VHDLCodeTemplateGenerator::generate_instance(std::string const& inst
{
std::list<std::string> port_map_str;

BOOST_FOREACH(port_map_type::value_type p, port_map)
for (auto p : port_map)
{
boost::format m(" %1% => %2%");
m % generate_identifier(p.first) % generate_identifier(p.second);
Expand Down
1 change: 0 additions & 1 deletion src/Core/Generator/VHDLCodeTemplateGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <cctype>

#include "Core/Generator/CodeTemplateGenerator.h"
#include <boost/foreach.hpp>

namespace degate
{
Expand Down
9 changes: 6 additions & 3 deletions src/Core/Generator/VHDLTBCodeTemplateGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include "Core/Generator/VHDLTBCodeTemplateGenerator.h"
#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/join.hpp>
#include <iostream>

Expand All @@ -46,8 +45,12 @@ std::string VHDLTBCodeTemplateGenerator::generate() const
tb_entity_name += entity_name;

port_map_type port_map;
BOOST_FOREACH(std::string const& port_name, get_inports()) port_map[port_name] = port_name;
BOOST_FOREACH(std::string const& port_name, get_outports()) port_map[port_name] = port_name;
for (const auto& port_name : get_inports()) {
port_map[port_name] = port_name;
}
for (const auto& port_name : get_outports()) {
port_map[port_name] = port_name;
}


std::string clock_process_impl;
Expand Down
1 change: 0 additions & 1 deletion src/Core/Generator/VHDLTBCodeTemplateGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <cctype>

#include "Core/Generator/VHDLCodeTemplateGenerator.h"
#include <boost/foreach.hpp>

namespace degate
{
Expand Down
9 changes: 4 additions & 5 deletions src/Core/Generator/VerilogCodeTemplateGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "Core/Utils/DegateExceptions.h"

#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/join.hpp>

using namespace boost;
Expand Down Expand Up @@ -97,7 +96,7 @@ std::string VerilogCodeTemplateGenerator::generate_port_definition() const
std::string ret;

ret += " // input ports\n";
BOOST_FOREACH(std::string const& port_name,
for (const auto& port_name :
generate_identifier<std::vector<std::string> >(get_inports()))
{
boost::format f(" input %1%;\n");
Expand All @@ -107,7 +106,7 @@ std::string VerilogCodeTemplateGenerator::generate_port_definition() const


ret += "\n // output ports\n";
BOOST_FOREACH(std::string const& port_name,
for (const auto& port_name :
generate_identifier<std::vector<std::string> >(get_outports()))
{
boost::format f(" output %1%;\n");
Expand Down Expand Up @@ -327,7 +326,7 @@ std::string VerilogCodeTemplateGenerator::generate_impl(std::string const& logic
logic_class == "oai")
{
std::string ret;
BOOST_FOREACH(std::string const& oport,
for (const auto& oport :
generate_identifier<std::vector<std::string> >(get_outports()))
{
boost::format f(" assign %1% = ...;\n");
Expand Down Expand Up @@ -402,7 +401,7 @@ std::string VerilogCodeTemplateGenerator::generate_identifier(std::string const&
std::string identifier = prefix;

bool first_char = prefix == "" ? true : false;
BOOST_FOREACH(char c, name)
for (auto c : name)
{
if (c == '/' || c == '!' || c == '~') identifier.append("not");
else if (first_char && !isalpha(c))
Expand Down
1 change: 0 additions & 1 deletion src/Core/Generator/VerilogCodeTemplateGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <cctype>

#include "Core/Generator/CodeTemplateGenerator.h"
#include <boost/foreach.hpp>

namespace degate
{
Expand Down
3 changes: 1 addition & 2 deletions src/Core/Generator/VerilogModuleGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include "Core/Generator/VerilogModuleGenerator.h"
#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/join.hpp>

using namespace boost;
Expand Down Expand Up @@ -167,7 +166,7 @@ std::string VerilogModuleGenerator::generate_impl(std::string const& logic_class


// genereate wire definitions
BOOST_FOREACH(net_names_table::value_type const& v, nets)
for (const auto& v : nets)
{
if (!mod->exists_module_port_name(v.second))
wire_definitions += " wire " + v.second + ";\n";
Expand Down
22 changes: 12 additions & 10 deletions src/Core/Generator/VerilogTBCodeTemplateGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include "Core/Generator/VerilogTBCodeTemplateGenerator.h"
#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/join.hpp>
#include <list>
#include <boost/lexical_cast.hpp>
Expand All @@ -44,10 +43,14 @@ VerilogTBCodeTemplateGenerator::~VerilogTBCodeTemplateGenerator()
std::string VerilogTBCodeTemplateGenerator::generate() const
{
port_map_type port_map;
BOOST_FOREACH(std::string const& port_name, get_inports())
for (const auto& port_name : get_inports())
{
port_map[port_name] = port_name;
BOOST_FOREACH(std::string const& port_name, get_outports())
}
for (const auto& port_name : get_outports())
{
port_map[port_name] = port_name;
}

return
generate_header() +
Expand Down Expand Up @@ -77,17 +80,15 @@ std::string VerilogTBCodeTemplateGenerator::generate_module(std::string const& d
boost::algorithm::join(generate_identifier<std::vector<std::string>>(get_outports()), ", ");

std::list<std::string> port_wiring;
BOOST_FOREACH(std::string const & pname,
generate_identifier(get_ports()))
for (const auto& pname : generate_identifier(get_ports()))
{
boost::format f(".%1%(%2%)");
f % pname % pname;
port_wiring.push_back(f.str());
}

std::string inport_init;
BOOST_FOREACH(std::string const & pname,
generate_identifier(get_inports()))
for (const auto& pname : generate_identifier(get_inports()))
{
boost::format f(" %1% <= 1'b0;\n");
f % pname;
Expand Down Expand Up @@ -193,8 +194,10 @@ std::string VerilogTBCodeTemplateGenerator::generate_all_assignments
while (increment(assignment))
{
std::string assignment2;
BOOST_FOREACH(int i, assignment)
for (auto i : assignment)
{
assignment2.push_back(boost::lexical_cast<char>(i));
}
std::reverse(assignment2.begin(), assignment2.end());

// generate assignemt string
Expand All @@ -203,8 +206,7 @@ std::string VerilogTBCodeTemplateGenerator::generate_all_assignments
f % assignment_dst % prefix % assignment2;

testcode += f.str();
BOOST_FOREACH(std::string const& oport,
generate_identifier<std::vector<std::string> >(out_port_idents))
for (const auto& oport : generate_identifier<std::vector<std::string> >(out_port_idents))
{
boost::format f2(" assert(%1% === 1'bX); // please edit\n\n");
f2 % oport;
Expand Down
1 change: 0 additions & 1 deletion src/Core/Generator/VerilogTBCodeTemplateGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <cctype>

#include "Core/Generator/VerilogCodeTemplateGenerator.h"
#include <boost/foreach.hpp>

namespace degate
{
Expand Down
3 changes: 1 addition & 2 deletions src/Core/Image/ImageHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "Core/Image/ImageReader.h"

#include <set>
#include <boost/foreach.hpp>

namespace degate
{
Expand Down Expand Up @@ -159,7 +158,7 @@ namespace degate
unsigned int w = img->get_width(), h = img->get_height();
std::vector<double> i_tmp(4 * static_cast<std::size_t>(w) * static_cast<std::size_t>(h));

BOOST_FOREACH(const std::shared_ptr<ImageType> i, images)
for (const auto& i : images)
{
// verify that all images have the same dimensions
if (w != i->get_width() || h != i->get_height())
Expand Down
4 changes: 1 addition & 3 deletions src/Core/LogicModel/ConnectedLogicModelObject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include "Net.h"
#include "ConnectedLogicModelObject.h"

#include <boost/foreach.hpp>

using namespace degate;

ConnectedLogicModelObject::ConnectedLogicModelObject()
Expand Down Expand Up @@ -80,7 +78,7 @@ bool ConnectedLogicModelObject::is_connected() const
{
if (net == nullptr) return false;
if (net->size() >= 2) return true;
BOOST_FOREACH(object_id_t oid, *net)
for (auto oid : *net)
{
if (oid != get_object_id()) return true;
}
Expand Down
6 changes: 2 additions & 4 deletions src/Core/LogicModel/Gate/AutoNameGates.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include "Core/LogicModel/LogicModelHelper.h"
#include "Core/LogicModel/Layer.h"

#include <boost/foreach.hpp>

using namespace degate;

bool compare_min_x(const Gate_shptr lhs, const Gate_shptr rhs)
Expand Down Expand Up @@ -58,7 +56,7 @@ void AutoNameGates::rename_gates(std::vector<unsigned int> const& histogram, std
unsigned int col_num = 1;
unsigned int row_num = 1;

BOOST_FOREACH(int i, scan_lines)
for (auto i : scan_lines)
{
// naming = along-rows => histogram along y-axis, following scanlines along x-axis

Expand All @@ -85,7 +83,7 @@ void AutoNameGates::rename_gates(std::vector<unsigned int> const& histogram, std
gate_list.sort(compare_min_y);

// rename gates
BOOST_FOREACH(Gate_shptr gate, gate_list)
for (auto gate : gate_list)
{
boost::format f("%1%.%2%");
f % row_num % col_num;
Expand Down
Loading

0 comments on commit 42fb0aa

Please sign in to comment.