Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleanup various style issues.

This patch cleans up some style issues: no need to check that a value
is defined before freeing or deleting it, use C++ style casts, make
sure to NULL terminate strncpy(), empty() is faster than size() for
size == 0 or size >= 0 checks, re-scope some variables, etc.
  • Loading branch information...
commit 8cbff6def0a7d2eb5f30c5953fc3d71b7cbd7cf7 1 parent 6f9e364
@steveicarus authored
View
3  driver/main.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000-2009 Stephen Williams (steve@icarus.com)
+ * Copyright (c) 2000-2010 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@@ -781,6 +781,7 @@ int main(int argc, char **argv)
/* Convert to a short name to remove any embedded spaces. */
GetShortPathName(tmp, basepath, sizeof basepath);
strncpy(ivl_root, basepath, MAXSIZE);
+ ivl_root[MAXSIZE-1] = 0;
s = strrchr(ivl_root, sep);
if (s) *s = 0;
s = strrchr(ivl_root, sep);
View
9 elaborate.cc
@@ -1111,7 +1111,7 @@ void PGModule::elaborate_mod_(Design*des, Module*rmod, NetScope*scope) const
// unconnected_drive directive and for a
// unconnected input warning when asked for.
vector<PEIdent*> mport = rmod->get_port(idx);
- if (mport.size() == 0) continue;
+ if (mport.empty()) continue;
perm_string pname = peek_tail_name(mport[0]->path());
@@ -1214,8 +1214,7 @@ void PGModule::elaborate_mod_(Design*des, Module*rmod, NetScope*scope) const
// that connects to the port.
NetNet*sig;
- if ((prts.size() == 0)
- || (prts[0]->port_type() == NetNet::PINPUT)) {
+ if (prts.empty() || (prts[0]->port_type() == NetNet::PINPUT)) {
/* Input to module. elaborate the expression to
the desired width. If this in an instance
@@ -1271,14 +1270,14 @@ void PGModule::elaborate_mod_(Design*des, Module*rmod, NetScope*scope) const
// width cast. Since a real is only one bit the whole
// thing needs to go to each instance when arrayed.
if ((sig->data_type() == IVL_VT_REAL ) &&
- prts.size() && (prts[0]->data_type() != IVL_VT_REAL )) {
+ !prts.empty() && (prts[0]->data_type() != IVL_VT_REAL )) {
sig = cast_to_int(des, scope, sig,
prts_vector_width/instance.size());
}
// If we have a bit/vector signal driving a real port
// then we convert the value to a real.
if ((sig->data_type() != IVL_VT_REAL ) &&
- prts.size() && (prts[0]->data_type() == IVL_VT_REAL )) {
+ !prts.empty() && (prts[0]->data_type() == IVL_VT_REAL )) {
sig = cast_to_real(des, scope, sig);
}
View
8 net_assign.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000-2008 Stephen Williams (steve@icarus.com)
+ * Copyright (c) 2000-2010 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@@ -52,7 +52,7 @@ NetAssign_::~NetAssign_()
}
assert( more == 0 );
- if (word_) delete word_;
+ delete word_;
}
void NetAssign_::set_word(NetExpr*r)
@@ -120,7 +120,7 @@ NetAssignBase::NetAssignBase(NetAssign_*lv, NetExpr*rv)
NetAssignBase::~NetAssignBase()
{
- if (rval_) delete rval_;
+ delete rval_;
while (lval_) {
NetAssign_*tmp = lval_;
lval_ = tmp->more;
@@ -141,7 +141,7 @@ const NetExpr* NetAssignBase::rval() const
void NetAssignBase::set_rval(NetExpr*r)
{
- if (rval_) delete rval_;
+ delete rval_;
rval_ = r;
}
View
5 net_link.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000-2008 Stephen Williams (steve@icarus.com)
+ * Copyright (c) 2000-2010 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@@ -267,8 +267,7 @@ Nexus::Nexus(Link&that)
Nexus::~Nexus()
{
assert(list_ == 0);
- if (name_)
- delete[]name_;
+ delete[] name_;
}
bool Nexus::assign_lval() const
View
4 net_proc.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000-2002 Stephen Williams (steve@icarus.com)
+ * Copyright (c) 2000-2010 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@@ -140,7 +140,7 @@ NetPDelay::NetPDelay(NetExpr*d, NetProc*st)
NetPDelay::~NetPDelay()
{
- if (expr_) delete expr_;
+ delete expr_;
}
uint64_t NetPDelay::delay() const
View
1  net_scope.cc
@@ -136,6 +136,7 @@ bool NetScope::auto_name(const char*prefix, char pad, const char* suffix)
int pad_pos = strlen(prefix);
int max_pos = sizeof(tmp) - strlen(suffix) - 1;
strncpy(tmp, prefix, sizeof(tmp));
+ tmp[31] = 0;
// Try a variety of potential new names. Make sure the new
// name is not in the parent scope. Keep looking until we are
View
6 netlist.cc
@@ -174,7 +174,7 @@ NetPins::NetPins(unsigned npins)
NetPins::~NetPins()
{
- if (pins_) delete[]pins_;
+ delete[] pins_;
}
Link& NetPins::pin(unsigned idx)
@@ -1821,8 +1821,8 @@ NetCondit::NetCondit(NetExpr*ex, NetProc*i, NetProc*e)
NetCondit::~NetCondit()
{
delete expr_;
- if (if_) delete if_;
- if (else_) delete else_;
+ delete if_;
+ delete else_;
}
const NetExpr* NetCondit::expr() const
View
14 pform.cc
@@ -1123,7 +1123,7 @@ void pform_make_udp(perm_string name, list<perm_string>*parms,
const char*file, unsigned lineno)
{
unsigned local_errors = 0;
- assert(parms->size() > 0);
+ assert(!parms->empty());
/* Put the declarations into a map, so that I can check them
off with the parameters in the list. If the port is already
@@ -1437,8 +1437,7 @@ void pform_set_net_range(list<perm_string>*names,
}
delete names;
- if (range)
- delete range;
+ delete range;
}
/*
@@ -1937,8 +1936,7 @@ void pform_makewire(const vlltype&li,
}
delete names;
- if (range)
- delete range;
+ delete range;
}
/*
@@ -2090,8 +2088,7 @@ svector<PWire*>*pform_make_task_ports(NetNet::PortType pt,
res = tmp;
}
- if (range)
- delete range;
+ delete range;
delete names;
return res;
}
@@ -2362,8 +2359,7 @@ void pform_set_port_type(const struct vlltype&li,
}
delete names;
- if (range)
- delete range;
+ delete range;
}
static void pform_set_reg_integer(perm_string name)
View
4 tgt-vhdl/vhdl_helper.hh
@@ -1,7 +1,7 @@
/*
* Helper functions for VHDL syntax elements.
*
- * Copyright (C) 2008 Nick Gasson (nick@nickg.me.uk)
+ * Copyright (C) 2008-2010 Nick Gasson (nick@nickg.me.uk)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -32,7 +32,7 @@ void emit_children(std::ostream &of,
bool trailing_newline = true)
{
// Don't indent if there are no children
- if (children.size() == 0)
+ if (children.empty())
newline(of, level);
else {
typename std::list<T*>::const_iterator it;
View
5 tgt-vhdl/vhdl_type.cc
@@ -1,7 +1,7 @@
/*
* VHDL variable and signal types.
*
- * Copyright (C) 2008 Nick Gasson (nick@nickg.me.uk)
+ * Copyright (C) 2008-2010 Nick Gasson (nick@nickg.me.uk)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -159,8 +159,7 @@ vhdl_type::vhdl_type(const vhdl_type &other)
vhdl_type::~vhdl_type()
{
- if (base_ != NULL)
- delete base_;
+ delete base_;
}
vhdl_type *vhdl_type::std_logic_vector(int msb, int lsb)
View
5 tgt-vvp/vvp_process.c
@@ -691,7 +691,6 @@ static int show_stmt_assign_nb_real(ivl_statement_t net)
ivl_expr_t rval = ivl_stmt_rval(net);
ivl_expr_t del = ivl_stmt_delay_expr(net);
/* variables for the selection of word from an array. */
- ivl_expr_t word_ix;
unsigned long use_word = 0;
/* thread address for a word value. */
int word;
@@ -715,7 +714,7 @@ static int show_stmt_assign_nb_real(ivl_statement_t net)
word = draw_eval_real(rval);
if (ivl_signal_dimensions(sig) > 0) {
- word_ix = ivl_lval_idx(lval);
+ ivl_expr_t word_ix = ivl_lval_idx(lval);
assert(word_ix);
assign_to_array_r_word(sig, word_ix, word, delay, del, nevents);
clr_word(word);
@@ -1127,7 +1126,7 @@ static int show_stmt_case_r(ivl_statement_t net, ivl_scope_t sscope)
/* The out of the case. */
fprintf(vvp_out, "T_%d.%d ;\n", thread_count, local_base+count);
- return 0;
+ return rc;
}
static void force_real_to_lval(ivl_statement_t net, int res)
View
4 vpi/sys_finish.c
@@ -24,7 +24,7 @@
static PLI_INT32 sys_finish_calltf(PLI_BYTE8 *name)
{
- vpiHandle callh, argv, arg;
+ vpiHandle callh, argv;
s_vpi_value val;
long diag_msg = 1;
@@ -32,7 +32,7 @@ static PLI_INT32 sys_finish_calltf(PLI_BYTE8 *name)
callh = vpi_handle(vpiSysTfCall, 0);
argv = vpi_iterate(vpiArgument, callh);
if (argv) {
- arg = vpi_scan(argv);
+ vpiHandle arg = vpi_scan(argv);
vpi_free_object(argv);
val.format = vpiIntVal;
vpi_get_value(arg, &val);
View
3  vpi/vcd_priv.c
@@ -32,11 +32,10 @@
int is_escaped_id(const char *name)
{
- int lp;
-
assert(name);
/* The first digit must be alpha or '_' to be a normal id. */
if (isalpha((int)name[0]) || name[0] == '_') {
+ int lp;
for (lp=1; name[lp] != '\0'; lp++) {
/* If this digit is not alpha-numeric or '_' we have
* an escaped identifier. */
View
10 vvp/array.cc
@@ -1675,17 +1675,15 @@ void memory_delete(vpiHandle item)
struct __vpiArray*arr = ARRAY_HANDLE(item);
if (arr->vals_words) delete [] (arr->vals_words-1);
- if (arr->vals4) {
+// if (arr->vals4) {}
// Delete the individual words?
// constant_delete(handle)?
- delete arr->vals4;
- }
+ delete arr->vals4;
- if (arr->valsr) {
+// if (arr->valsr) {}
// Delete the individual words?
// constant_delete(handle)?
- delete arr->valsr;
- }
+ delete arr->valsr;
if (arr->nets) {
for (unsigned idx = 0; idx < arr->array_count; idx += 1) {
View
5 vvp/compile.cc
@@ -1629,7 +1629,7 @@ void compile_code(char*label, char*mnem, comp_operands_t opa)
}
}
- if (opa) free(opa);
+ free(opa);
free(mnem);
}
@@ -1749,8 +1749,7 @@ void compile_thread(char*start_sym, char*flag)
schedule_vthread(thr, 0, push_flag);
free(start_sym);
- if (flag != 0)
- free(flag);
+ free(flag);
}
void compile_param_logic(char*label, char*name, char*value, bool signed_flag,
View
24 vvp/udp.cc
@@ -47,10 +47,12 @@ void udp_defns_delete()
{
for (unsigned idx = 0; idx < udp_defns_count; idx += 1) {
if (udp_defns[idx]->is_sequential()) {
- vvp_udp_seq_s *obj = (vvp_udp_seq_s *) udp_defns[idx];
+ vvp_udp_seq_s *obj = static_cast<vvp_udp_seq_s *>
+ (udp_defns[idx]);
delete obj;
} else {
- vvp_udp_comb_s *obj = (vvp_udp_comb_s *) udp_defns[idx];
+ vvp_udp_comb_s *obj = static_cast<vvp_udp_comb_s *>
+ (udp_defns[idx]);
delete obj;
}
}
@@ -128,8 +130,8 @@ vvp_udp_comb_s::vvp_udp_comb_s(char*label, char*name, unsigned ports)
vvp_udp_comb_s::~vvp_udp_comb_s()
{
- if (levels0_) delete[] levels0_;
- if (levels1_) delete[] levels1_;
+ delete[] levels0_;
+ delete[] levels1_;
}
/*
@@ -320,13 +322,13 @@ vvp_udp_seq_s::vvp_udp_seq_s(char*label, char*name,
vvp_udp_seq_s::~vvp_udp_seq_s()
{
- if (levels0_) delete[]levels0_;
- if (levels1_) delete[]levels1_;
- if (levelsx_) delete[]levelsx_;
- if (levelsL_) delete[]levelsL_;
- if (edges0_) delete[]edges0_;
- if (edges1_) delete[]edges1_;
- if (edgesL_) delete[]edgesL_;
+ delete[] levels0_;
+ delete[] levels1_;
+ delete[] levelsx_;
+ delete[] levelsL_;
+ delete[] edges0_;
+ delete[] edges1_;
+ delete[] edgesL_;
}
void edge_based_on_char(struct udp_edges_table&cur, char chr, unsigned pos)
View
4 vvp/vpi_callback.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2001-2009 Stephen Williams (steve@icarus.com)
+ * Copyright (c) 2001-2010 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@@ -107,7 +107,7 @@ void delete_vpi_callback(struct __vpiCallback* ref)
assert(ref);
assert(ref->base.vpi_type);
assert(ref->base.vpi_type->type_code == vpiCallback);
- if (ref->cb_sync != 0) delete ref->cb_sync;
+ delete ref->cb_sync;
delete ref;
}
View
9 vvp/vpi_priv.cc
@@ -1123,9 +1123,6 @@ static vpiHandle find_scope(const char *name, vpiHandle handle, int depth)
vpiHandle vpi_handle_by_name(const char *name, vpiHandle scope)
{
vpiHandle hand;
- const char *nm, *cp;
- int len;
-
if (vpi_trace) {
fprintf(vpi_trace, "vpi_handle_by_name(%s, %p) -->\n",
@@ -1155,9 +1152,9 @@ vpiHandle vpi_handle_by_name(const char *name, vpiHandle scope)
if (hand) {
/* remove hierarchical portion of name */
- nm = vpi_get_str(vpiFullName, hand);
- len = strlen(nm);
- cp = name + len;
+ const char *nm = vpi_get_str(vpiFullName, hand);
+ int len = strlen(nm);
+ const char *cp = name + len;
if (!strncmp(name, nm, len) && *cp == '.') name = cp + 1;
/* Ok, time to burn some cycles */
View
8 vvp/vvp_net.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004-2009 Stephen Williams (steve@icarus.com)
+ * Copyright (c) 2004-2010 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@@ -2195,7 +2195,7 @@ vvp_vector2_t& vvp_vector2_t::operator -= (const vvp_vector2_t&that)
vvp_vector2_t::~vvp_vector2_t()
{
- if (vec_) delete[]vec_;
+ delete[] vec_;
}
void vvp_vector2_t::trim()
@@ -2886,8 +2886,8 @@ vvp_wide_fun_core::vvp_wide_fun_core(vvp_net_t*net, unsigned nports)
vvp_wide_fun_core::~vvp_wide_fun_core()
{
- if (port_values_) delete[]port_values_;
- if (port_rvalues_) delete[]port_rvalues_;
+ delete[] port_values_;
+ delete[] port_rvalues_;
}
void vvp_wide_fun_core::propagate_vec4(const vvp_vector4_t&bit,
View
14 vvp/words.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2009 Stephen Williams (steve@icarus.com)
+ * Copyright (c) 2003-2010 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@@ -66,7 +66,7 @@ static void __compile_var_real(char*label, char*name,
array_attach_word(array, array_addr, obj);
}
free(label);
- if (name) delete[] name;
+ delete[] name;
}
void compile_var_real(char*label, char*name, int msb, int lsb)
@@ -131,7 +131,7 @@ static void __compile_var(char*label, char*name,
if (obj) array_attach_word(array, array_addr, obj);
}
free(label);
- if (name) delete[] name;
+ delete[] name;
}
void compile_variable(char*label, char*name,
@@ -283,7 +283,7 @@ static void __compile_net2(vvp_net_t*node, vvp_array_t array,
vpip_attach_to_scope(scope,obj);
free(my_label);
- if (name) delete[] name;
+ delete[] name;
}
static void __compile_net(char*label,
@@ -295,7 +295,7 @@ static void __compile_net(char*label,
vvp_array_t array = array_label? array_find(array_label) : 0;
assert(array_label ? array!=0 : true);
- if (array_label) free(array_label);
+ free(array_label);
assert(argc == 1);
vvp_net_t*node = vvp_net_lookup(argv[0].text);
@@ -410,7 +410,7 @@ static void __compile_real_net2(vvp_net_t*node, vvp_array_t array,
vpip_attach_to_scope(scope, obj);
free(my_label);
- if (name) delete[]name;
+ delete[] name;
}
static void __compile_real(char*label, char*name,
@@ -421,7 +421,7 @@ static void __compile_real(char*label, char*name,
vvp_array_t array = array_label ? array_find(array_label) : 0;
assert(array_label ? array!=0 : true);
- if (array_label) free(array_label);
+ free(array_label);
assert(argc == 1);
vvp_net_t*node = vvp_net_lookup(argv[0].text);
Please sign in to comment.
Something went wrong with that request. Please try again.