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

WIP: clang-tidy fixes around const std::string references. #1764

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 9 additions & 9 deletions ODIN_II/SRC/Hashtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,33 @@
#include "vtr_memory.h"

void Hashtable::destroy_free_items() {
for (auto kv : my_map)
for (const auto& kv : my_map)
vtr::free(kv.second);
}

void Hashtable::add(std::string key, void* item) {
this->my_map.emplace(key, item);
void Hashtable::add(const std::string& key, void* item) {
this->my_map.insert({key, item});
}

void* Hashtable::remove(std::string key) {
void* Hashtable::remove(const std::string& key) {
void* value = NULL;
auto v = this->my_map.find(key);
if (v != this->my_map.end()) {
value = v->second;
this->my_map.erase(v);
value = this->my_map[key];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a good strategy, the original v = v->second is what we want.
Because otherwise what we do here is to look up the value again which we already did before.

this->my_map.erase(key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, this also doesn't look like the right strategy. Here again we force the map to look up the value from the key.
But we already have the iterator. So here as well, the original code is better.

}
return value;
}

void* Hashtable::get(std::string key) {
void* Hashtable::get(const std::string& key) {
void* value = NULL;
auto v = this->my_map.find(key);
if (v != this->my_map.end())
value = v->second;
value = this->my_map[key];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, this should be the original v->second


return value;
}

bool Hashtable::is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to make this is_empty() call a const method. As well Hashtable::get(). But I guess this is out of the scope for this change.

return my_map.empty();
return (my_map.size() == 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This as well should be the original code my_map.empty(), not call to size().

}
3 changes: 2 additions & 1 deletion ODIN_II/SRC/ast_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <stdarg.h>
#include <math.h>
#include <algorithm>
#include <utility>
#include "odin_globals.h"
#include "odin_types.h"

Expand Down Expand Up @@ -520,7 +521,7 @@ void change_to_number_node(ast_node_t* node, VNumber number) {

node->type = NUMBERS;
node->types.identifier = temp_ident;
node->types.vnumber = new VNumber(number);
node->types.vnumber = new VNumber(std::move(number));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably keep changes that involve std::move in a separate change to keep it by const std::string &.

(I'd only use std::move if really needed. It more uglifies code otherwise)

}

/*---------------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions ODIN_II/SRC/hierarchy_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
STRING_CACHE* copy_param_table_sc(STRING_CACHE* to_copy);

ast_node_t* resolve_hierarchical_name_reference_by_path_search(sc_hierarchy* local_ref, std::string identifier);
ast_node_t* resolve_hierarchical_name_reference_by_upward_search(sc_hierarchy* local_ref, std::string identifier);
ast_node_t* resolve_hierarchical_name_reference_by_upward_search(sc_hierarchy* local_ref, const std::string& identifier);

sc_hierarchy* init_sc_hierarchy() {
sc_hierarchy* hierarchy = (sc_hierarchy*)vtr::calloc(1, sizeof(sc_hierarchy));
Expand Down Expand Up @@ -275,7 +275,7 @@ ast_node_t* resolve_hierarchical_name_reference_by_path_search(sc_hierarchy* loc
/*---------------------------------------------------------------------------
* (function: resolve_hierarchical_name_reference_by_upward_search)
*-------------------------------------------------------------------------*/
ast_node_t* resolve_hierarchical_name_reference_by_upward_search(sc_hierarchy* local_ref, std::string identifier) {
ast_node_t* resolve_hierarchical_name_reference_by_upward_search(sc_hierarchy* local_ref, const std::string& identifier) {
if (!identifier.empty()) {
ast_node_t* var_declare = NULL;

Expand Down
2 changes: 1 addition & 1 deletion ODIN_II/SRC/implicit_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void free_implicit_memory_index_and_finalize_memories() {
implicit_memory_inputs.clear();

if (!implicit_memories.empty()) {
for (auto mem_it : implicit_memories) {
for (const auto& mem_it : implicit_memories) {
finalize_implicit_memory(mem_it.second);
vtr::free(mem_it.second->name);
vtr::free(mem_it.second);
Expand Down
6 changes: 3 additions & 3 deletions ODIN_II/SRC/include/Hashtable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class Hashtable {

public:
// Adds an item to the hashtable.
void add(std::string key, void* item);
void add(const std::string& key, void* item);
// Removes an item from the hashtable. If the item is not present, a null pointer is returned.
void* remove(std::string key);
void* remove(const std::string& key);
// Gets an item from the hashtable without removing it. If the item is not present, a null pointer is returned.
void* get(std::string key);
void* get(const std::string& key);
// Check to see if the hashtable is empty.
bool is_empty();
// calls free on each item.
Expand Down
4 changes: 2 additions & 2 deletions ODIN_II/SRC/include/netlist_visualizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <string>
#include "odin_types.h"

void graphVizOutputNetlist(std::string path, const char* name, uintptr_t marker_value, netlist_t* input_netlist);
void graphVizOutputCombinationalNet(std::string path, const char* name, uintptr_t marker_value, nnode_t* current_node);
void graphVizOutputNetlist(const std::string& path, const char* name, uintptr_t marker_value, netlist_t* input_netlist);
void graphVizOutputCombinationalNet(const std::string& path, const char* name, uintptr_t marker_value, nnode_t* current_node);

#endif
2 changes: 1 addition & 1 deletion ODIN_II/SRC/include/node_creation_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ char* op_node_name(operation_list op, char* instance_prefix_name);
char* hard_node_name(nnode_t* node, char* instance_name_prefix, char* hb_name, char* hb_inst);
nnode_t* make_mult_block(nnode_t* node, short mark);

edge_type_e edge_type_blif_enum(std::string edge_kind_str, loc_t loc);
edge_type_e edge_type_blif_enum(const std::string& edge_kind_str, loc_t loc);
const char* edge_type_blif_str(nnode_t* node);

#endif
8 changes: 4 additions & 4 deletions ODIN_II/SRC/include/odin_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

long shift_left_value_with_overflow_check(long input_value, long shift_by, loc_t loc);

std::string get_file_extension(std::string input_file);
void create_directory(std::string path);
void assert_supported_file_extension(std::string input_file, loc_t loc);
std::string get_file_extension(const std::string& input_file);
void create_directory(const std::string& path);
void assert_supported_file_extension(const std::string& input_file, loc_t loc);
FILE* open_file(const char* file_name, const char* open_type);

const char* name_based_on_op(operation_list op);
Expand Down Expand Up @@ -66,7 +66,7 @@ double wall_time();
int print_progress_bar(double completion, int position, int length, double time);

void trim_string(char* string, const char* chars);
bool only_one_is_true(std::vector<bool> tested);
bool only_one_is_true(const std::vector<bool>& tested);
int odin_sprintf(char* s, const char* format, ...);
char* str_collate(char* str1, char* str2);

Expand Down
2 changes: 1 addition & 1 deletion ODIN_II/SRC/include/parse_making_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ast_node_t* newDefparam(ids id, ast_node_t* val, loc_t loc);
void next_parsed_verilog_file(ast_node_t* file_items_list);

/* VISUALIZATION */
void graphVizOutputAst(std::string path, ast_node_t* top);
void graphVizOutputAst(const std::string& path, ast_node_t* top);
void graphVizOutputAst_traverse_node(FILE* fp, ast_node_t* node, ast_node_t* from, int from_num);
void graphVizOutputAst_Var_Declare(FILE* fp, ast_node_t* node, int from_num);

Expand Down
2 changes: 1 addition & 1 deletion ODIN_II/SRC/multipliers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void instantiate_hard_multiplier(nnode_t* node, short mark, netlist_t* /*netlist

declare_hard_multiplier(node);

std::string node_name = "";
std::string node_name;
if (node->name) {
node_name = node->name;
vtr::free(node->name);
Expand Down
4 changes: 2 additions & 2 deletions ODIN_II/SRC/netlist_visualizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void backward_traversal_net_graph_display(FILE* out, uintptr_t marker_value, nno
/*---------------------------------------------------------------------------------------------
* (function: graphVizOutputNetlist)
*-------------------------------------------------------------------------------------------*/
void graphVizOutputNetlist(std::string path, const char* name, uintptr_t marker_value, netlist_t* netlist) {
void graphVizOutputNetlist(const std::string& path, const char* name, uintptr_t marker_value, netlist_t* netlist) {
char path_and_file[4096];
FILE* fp;

Expand Down Expand Up @@ -163,7 +163,7 @@ void depth_first_traverse_visualize(nnode_t* node, FILE* fp, uintptr_t traverse_
/*---------------------------------------------------------------------------------------------
* (function: graphVizOutputCobinationalNet)
*-------------------------------------------------------------------------------------------*/
void graphVizOutputCombinationalNet(std::string path, const char* name, uintptr_t marker_value, nnode_t* current_node) {
void graphVizOutputCombinationalNet(const std::string& path, const char* name, uintptr_t marker_value, nnode_t* current_node) {
char path_and_file[4096];
FILE* fp;

Expand Down
2 changes: 1 addition & 1 deletion ODIN_II/SRC/node_creation_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ const char* edge_type_blif_str(nnode_t* node) {
}
}

edge_type_e edge_type_blif_enum(std::string edge_kind_str, loc_t loc) {
edge_type_e edge_type_blif_enum(const std::string& edge_kind_str) {
if (edge_kind_str == "fe")
return FALLING_EDGE_SENSITIVITY;
else if (edge_kind_str == "re")
Expand Down
2 changes: 1 addition & 1 deletion ODIN_II/SRC/odin_ii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ int terminate_odin_ii(netlist_t* odin_netlist) {
}

struct ParseInitRegState {
int from_str(std::string str) {
int from_str(const std::string& str) {
if (str == "0")
return 0;
else if (str == "1")
Expand Down
21 changes: 15 additions & 6 deletions ODIN_II/SRC/odin_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ long shift_left_value_with_overflow_check(long input_value, long shift_by, loc_t
return input_value << shift_by;
}

std::string get_file_extension(std::string input_file) {
std::string get_file_extension(const std::string& input_file) {
auto dot_location = input_file.find_last_of('.');
if (dot_location != std::string::npos) {
return input_file.substr(dot_location);
Expand All @@ -65,7 +65,7 @@ std::string get_file_extension(std::string input_file) {
}
}

void create_directory(std::string path) {
void create_directory(const std::string& path) {
// CREATE OUTPUT DIRECTORY
int error_code = 0;
#ifdef WIN32
Expand All @@ -79,15 +79,15 @@ void create_directory(std::string path) {
}
}

void assert_supported_file_extension(std::string input_file, loc_t loc) {
void assert_supported_file_extension(const std::string& input_file, loc_t loc) {
bool supported = false;
std::string extension = get_file_extension(input_file);
for (int i = 0; i < file_extension_supported_END && !supported; i++) {
supported = (extension == std::string(file_extension_supported_STR[i]));
}

if (!supported) {
std::string supported_extension_list = "";
std::string supported_extension_list;
for (int i = 0; i < file_extension_supported_END; i++) {
supported_extension_list += " ";
supported_extension_list += file_extension_supported_STR[i];
Expand Down Expand Up @@ -830,7 +830,16 @@ std::string find_substring(char* src, const char* sKey, int flag) {
* Prints the time in appropriate units.
*/
void print_time(double time) {
printf("%.1fms", time * 1000);
if (time > 24 * 3600)
printf("%.1fd", time / (24 * 3600.0));
else if (time > 3600)
printf("%.1fh", time / 3600.0);
else if (time > 60)
printf("%.1fm", time / 60.0);
else if (time > 1)
printf("%.1fs", time);
else
printf("%.1fms", time * 1000);
}

/*
Expand Down Expand Up @@ -963,7 +972,7 @@ bool output_vector_headers_equal(char* buffer1, char* buffer2) {
/**
* verifies only one condition evaluates to true
*/
bool only_one_is_true(std::vector<bool> tested) {
bool only_one_is_true(const std::vector<bool>& tested) {
bool previous_value = false;
for (bool next_value : tested) {
if (!previous_value && next_value)
Expand Down
2 changes: 1 addition & 1 deletion ODIN_II/SRC/output_blif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ FILE* create_blif(const char* file_name) {

/* open the file for output */
if (global_args.high_level_block.provenance() == argparse::Provenance::SPECIFIED) {
std::string out_file = "";
std::string out_file;
out_file = out_file + file_name + "_" + global_args.high_level_block.value() + ".blif";
out = fopen(out_file.c_str(), "w+");
} else {
Expand Down
2 changes: 1 addition & 1 deletion ODIN_II/SRC/parse_making_ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@ int unique_label_count;
/*---------------------------------------------------------------------------
* (function: graphVizOutputAst)
*-------------------------------------------------------------------------*/
void graphVizOutputAst(std::string path, ast_node_t* top) {
void graphVizOutputAst(const std::string& path, ast_node_t* top) {
char path_and_file[4096];
FILE* fp;
static int file_num = 0;
Expand Down
2 changes: 1 addition & 1 deletion ODIN_II/SRC/read_blif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void create_latch_node_and_driver(FILE* file, Hashtable* output_nets_hash) {
names[4] = names[2];
names[2] = vtr::strdup("re");
} else {
std::string line = "";
std::string line;
for (int i = 0; i < input_token_count; i++) {
line += names[i];
line += " ";
Expand Down
4 changes: 2 additions & 2 deletions ODIN_II/SRC/simulate_blif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,7 @@ static void instantiate_memory(nnode_t* node, long data_width, long addr_width)
}
}

static int parse_mif_radix(std::string radix) {
static int parse_mif_radix(const std::string& radix) {
return (radix == "HEX") ? 16 : (radix == "DEC") ? 10 : (radix == "OCT") ? 8 : (radix == "BIN") ? 2 : 0;
}

Expand Down Expand Up @@ -2312,7 +2312,7 @@ static test_vector* parse_test_vector(char* buffer) {
*
* If you want better randomness, call srand at some point.
*/
static bool contains_a_substr_of_name(std::vector<std::string> held, const char* name_in) {
static bool contains_a_substr_of_name(const std::vector<std::string>& held, const char* name_in) {
if (!name_in)
return false;

Expand Down
2 changes: 1 addition & 1 deletion abc/src/base/abci/abcTiming.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct Abc_ManTime_t_

#define TOLERANCE 0.001

static inline int Abc_FloatEqual( float x, float y ) { return fabs(x-y) < TOLERANCE; }
static inline int Abc_FloatEqual( float x, float y ) { return fabsf(x-y) < TOLERANCE; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The abc/ directory is probably also something that is just imported and we shouldn't touch too much.


// static functions
static Abc_ManTime_t * Abc_ManTimeStart( Abc_Ntk_t * pNtk );
Expand Down
6 changes: 3 additions & 3 deletions abc/src/map/scl/sclSize.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void Abc_SclTimeNode( SC_Man * p, Abc_Obj_t * pObj, int fDept )
if ( fDept )
{
SC_Pair * pDepOut = Abc_SclObjDept( p, pObj );
float EstDelta = p->EstLinear * log( Value );
float EstDelta = p->EstLinear * logf( Value );
DeptRise = pDepOut->rise;
DeptFall = pDepOut->fall;
pDepOut->rise += EstDelta;
Expand Down Expand Up @@ -374,7 +374,7 @@ void Abc_SclTimeNode( SC_Man * p, Abc_Obj_t * pObj, int fDept )
else
{
SC_Pair * pArrOut = Abc_SclObjTime( p, pObj );
float EstDelta = p->EstLinear * log( Value );
float EstDelta = p->EstLinear * logf( Value );
pArrOut->rise += EstDelta;
pArrOut->fall += EstDelta;
}
Expand Down Expand Up @@ -864,7 +864,7 @@ void Abc_SclPrintBuffersOne( SC_Man * p, Abc_Obj_t * pObj, int nOffset )
printf( "L =%5.0f ff ", Abc_SclCountNonBufferLoad(p, pObj) );
printf( "Lx =%5.0f ff ", 100.0*Abc_SclCountNonBufferLoad(p, pObj)/p->EstLoadAve );
printf( "Dx =%5.0f ps ", Abc_SclCountNonBufferDelay(p, pObj)/Abc_SclCountNonBufferFanouts(pObj) - Abc_SclObjTimeOne(p, pObj, 1) );
printf( "Cx =%5.0f ps", (Abc_SclCountNonBufferDelay(p, pObj)/Abc_SclCountNonBufferFanouts(pObj) - Abc_SclObjTimeOne(p, pObj, 1))/log(Abc_SclCountNonBufferLoad(p, pObj)/p->EstLoadAve) );
printf( "Cx =%5.0f ps", (Abc_SclCountNonBufferDelay(p, pObj)/Abc_SclCountNonBufferFanouts(pObj) - Abc_SclObjTimeOne(p, pObj, 1))/logf(Abc_SclCountNonBufferLoad(p, pObj)/p->EstLoadAve) );
}
printf( "\n" );
}
Expand Down
2 changes: 1 addition & 1 deletion dev/odin2_helper/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ default: $(EXE)
run: Md5Core.vv

$(EXE): $(EXE).c++
g++ -Wall -Wextra -Werror -pedantic -std=c++11 $< -o $@ -ggdb -D_GLIBCXX_DEBUG
g++ -Wall -Wextra -Werror -pedantic -std=c++14 $< -o $@ -ggdb -D_GLIBCXX_DEBUG

test: Md5Core.v
less $<
Expand Down
12 changes: 7 additions & 5 deletions libs/EXTERNAL/capnproto/c++/src/capnp/compat/json.c++
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <kj/encoding.h>
#include <kj/map.h>

#include <utility>

namespace capnp {

struct JsonCodec::Impl {
Expand Down Expand Up @@ -189,7 +191,7 @@ void JsonCodec::setHasMode(HasMode mode) { impl->hasMode = mode; }
kj::String JsonCodec::encode(DynamicValue::Reader value, Type type) const {
MallocMessageBuilder message;
auto json = message.getRoot<JsonValue>();
encode(value, type, json);
encode(std::move(value), type, json);
return encodeRaw(json);
}

Expand All @@ -213,7 +215,7 @@ kj::String JsonCodec::encodeRaw(JsonValue::Reader value) const {
return impl->encodeRaw(value, 0, multiline, false).flatten();
}

void JsonCodec::encode(DynamicValue::Reader input, Type type, JsonValue::Builder output) const {
void JsonCodec::encode(const DynamicValue::Reader& input, Type type, JsonValue::Builder output) const {
// TODO(someday): For interfaces, check for handlers on superclasses, per documentation...
// TODO(someday): For branded types, should we check for handlers on the generic?
// TODO(someday): Allow registering handlers for "all structs", "all lists", etc?
Expand Down Expand Up @@ -362,7 +364,7 @@ void JsonCodec::encode(DynamicValue::Reader input, Type type, JsonValue::Builder
}
}

void JsonCodec::encodeField(StructSchema::Field field, DynamicValue::Reader input,
void JsonCodec::encodeField(StructSchema::Field field, const DynamicValue::Reader& input,
JsonValue::Builder output) const {
KJ_IF_MAYBE(handler, impl->fieldHandlers.find(field)) {
(*handler)->encodeBase(*this, input, output);
Expand Down Expand Up @@ -1210,10 +1212,10 @@ private:
kj::OneOf<StructSchema::Field, Type> type, DynamicValue::Reader value)
: ownName(prefix.size() > 0 ? kj::str(prefix, name) : nullptr),
name(prefix.size() > 0 ? ownName : name),
type(type), value(value) {}
type(type), value(std::move(value)) {}
};

void gatherForEncode(const JsonCodec& codec, DynamicValue::Reader input,
void gatherForEncode(const JsonCodec& codec, const DynamicValue::Reader& input,
kj::StringPtr prefix, kj::StringPtr morePrefix,
kj::Vector<FlattenedField>& flattenedFields) const {
kj::String ownPrefix;
Expand Down
Loading