Skip to content

Error handling cleanup in src/util (files starting with a-g) #2762

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

Merged
merged 2 commits into from
Sep 25, 2018
Merged
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
3 changes: 1 addition & 2 deletions src/ansi-c/ansi_c_entry_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ bool ansi_c_entry_point(
return false; // give up
}

if(static_lifetime_init(symbol_table, symbol.location, message_handler))
return true;
static_lifetime_init(symbol_table, symbol.location, message_handler);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This procedure still has a non-void return type, should that change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, changed it to void. The remaining check in static_lifetime_init is a precondition now.


return generate_ansi_c_start_function(symbol, symbol_table, message_handler);
}
Expand Down
27 changes: 9 additions & 18 deletions src/linking/static_lifetime_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@ Author: Daniel Kroening, [email protected]

#include <goto-programs/goto_functions.h>

bool static_lifetime_init(
void static_lifetime_init(
symbol_tablet &symbol_table,
const source_locationt &source_location,
message_handlert &message_handler)
{
namespacet ns(symbol_table);
PRECONDITION(symbol_table.has_symbol(INITIALIZE_FUNCTION));

const auto maybe_symbol=symbol_table.get_writeable(INITIALIZE_FUNCTION);
if(!maybe_symbol)
return false;
symbolt &init_symbol=*maybe_symbol;
const namespacet ns(symbol_table);

symbolt &init_symbol = symbol_table.get_writeable_ref(INITIALIZE_FUNCTION);

init_symbol.value=code_blockt();
init_symbol.value.add_source_location()=source_location;
Expand Down Expand Up @@ -117,16 +116,10 @@ bool static_lifetime_init(

if(symbol.value.is_nil())
{
try
{
namespacet ns(symbol_table);
rhs=zero_initializer(symbol.type, symbol.location, ns, message_handler);
assert(rhs.is_not_nil());
}
catch(...)
Copy link
Member

Choose a reason for hiding this comment

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

Thanks.

{
return true;
}
const namespacet ns(symbol_table);
rhs = zero_initializer(symbol.type, symbol.location, ns, message_handler);
INVARIANT(
rhs.is_not_nil(), "result of zero-initialization must be non-nil");
}
else
rhs=symbol.value;
Expand Down Expand Up @@ -156,6 +149,4 @@ bool static_lifetime_init(
dest.move_to_operands(function_call);
}
}

return false;
}
2 changes: 1 addition & 1 deletion src/linking/static_lifetime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class message_handlert;
class source_locationt;
class symbol_tablet;

bool static_lifetime_init(
void static_lifetime_init(
symbol_tablet &symbol_table,
const source_locationt &source_location,
message_handlert &message_handler);
Expand Down
15 changes: 7 additions & 8 deletions src/util/array_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@ Author: Daniel Kroening, [email protected]
#include "array_name.h"

#include "expr.h"
#include "invariant.h"
#include "namespace.h"
#include "symbol.h"
#include "ssa_expr.h"
#include "symbol.h"

std::string array_name(
const namespacet &ns,
const exprt &expr)
{
if(expr.id()==ID_index)
{
if(expr.operands().size()!=2)
throw "index takes two operands";

return array_name(ns, expr.op0())+"[]";
return array_name(ns, to_index_expr(expr).array()) + "[]";
}
else if(is_ssa_expr(expr))
{
Expand All @@ -44,9 +42,10 @@ std::string array_name(
}
else if(expr.id()==ID_member)
{
assert(expr.operands().size()==1);
return array_name(ns, expr.op0())+"."+
expr.get_string(ID_component_name);
const member_exprt &member_expr = to_member_expr(expr);

return array_name(ns, member_expr.compound()) + "." +
id2string(member_expr.get_component_name());
}

return "array";
Expand Down
13 changes: 6 additions & 7 deletions src/util/bv_arithmetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Author: Daniel Kroening, [email protected]

#include "bv_arithmetic.h"

#include <cassert>
#include <ostream>

#include "string2int.h"
Expand Down Expand Up @@ -90,7 +89,7 @@ exprt bv_arithmetict::to_expr() const

bv_arithmetict &bv_arithmetict::operator/=(const bv_arithmetict &other)
{
assert(other.spec==spec);
PRECONDITION(other.spec == spec);

if(other.value==0)
value=0;
Expand All @@ -102,7 +101,7 @@ bv_arithmetict &bv_arithmetict::operator/=(const bv_arithmetict &other)

bv_arithmetict &bv_arithmetict::operator*=(const bv_arithmetict &other)
{
assert(other.spec==spec);
PRECONDITION(other.spec == spec);

value*=other.value;
adjust();
Expand All @@ -112,7 +111,7 @@ bv_arithmetict &bv_arithmetict::operator*=(const bv_arithmetict &other)

bv_arithmetict &bv_arithmetict::operator+=(const bv_arithmetict &other)
{
assert(other.spec==spec);
PRECONDITION(other.spec == spec);

value+=other.value;
adjust();
Expand All @@ -122,7 +121,7 @@ bv_arithmetict &bv_arithmetict::operator+=(const bv_arithmetict &other)

bv_arithmetict &bv_arithmetict::operator -= (const bv_arithmetict &other)
{
assert(other.spec==spec);
PRECONDITION(other.spec == spec);

value-=other.value;
adjust();
Expand All @@ -132,7 +131,7 @@ bv_arithmetict &bv_arithmetict::operator -= (const bv_arithmetict &other)

bv_arithmetict &bv_arithmetict::operator%=(const bv_arithmetict &other)
{
assert(other.spec==spec);
PRECONDITION(other.spec == spec);

value%=other.value;
adjust();
Expand Down Expand Up @@ -183,7 +182,7 @@ void bv_arithmetict::change_spec(const bv_spect &dest_spec)

void bv_arithmetict::from_expr(const exprt &expr)
{
assert(expr.is_constant());
PRECONDITION(expr.is_constant());
spec=bv_spect(expr.type());
value=binary2integer(expr.get_string(ID_value), spec.is_signed);
}
3 changes: 0 additions & 3 deletions src/util/byte_operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ Author: Daniel Kroening, [email protected]

#include "byte_operators.h"

#include <cassert>

#include "invariant.h"
#include "config.h"

irep_idt byte_extract_id()
Expand Down
49 changes: 37 additions & 12 deletions src/util/byte_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
* \date Sun Jul 31 21:54:44 BST 2011
*/

#include "invariant.h"
#include "std_expr.h"

/*! \brief TO_BE_DOCUMENTED
Expand Down Expand Up @@ -51,13 +52,13 @@ class byte_extract_exprt:public binary_exprt

inline const byte_extract_exprt &to_byte_extract_expr(const exprt &expr)
{
assert(expr.operands().size()==2);
PRECONDITION(expr.operands().size() == 2);
return static_cast<const byte_extract_exprt &>(expr);
}

inline byte_extract_exprt &to_byte_extract_expr(exprt &expr)
{
assert(expr.operands().size()==2);
PRECONDITION(expr.operands().size() == 2);
return static_cast<byte_extract_exprt &>(expr);
}

Expand All @@ -78,14 +79,20 @@ class byte_extract_little_endian_exprt:public byte_extract_exprt
inline const byte_extract_little_endian_exprt
&to_byte_extract_little_endian_expr(const exprt &expr)
{
assert(expr.id()==ID_byte_extract_little_endian && expr.operands().size()==2);
PRECONDITION(expr.id() == ID_byte_extract_little_endian);
DATA_INVARIANT(
expr.operands().size() == 2, "byte extract expressions have two operands");

return static_cast<const byte_extract_little_endian_exprt &>(expr);
}

inline byte_extract_little_endian_exprt
&to_byte_extract_little_endian_expr(exprt &expr)
{
assert(expr.id()==ID_byte_extract_little_endian && expr.operands().size()==2);
PRECONDITION(expr.id() == ID_byte_extract_little_endian);
DATA_INVARIANT(
expr.operands().size() == 2, "byte extract expressions have two operands");

return static_cast<byte_extract_little_endian_exprt &>(expr);
}

Expand All @@ -109,14 +116,20 @@ class byte_extract_big_endian_exprt:public byte_extract_exprt
inline const byte_extract_big_endian_exprt
&to_byte_extract_big_endian_expr(const exprt &expr)
{
assert(expr.id()==ID_byte_extract_big_endian && expr.operands().size()==2);
PRECONDITION(expr.id() == ID_byte_extract_big_endian);
DATA_INVARIANT(
expr.operands().size() == 2, "byte extract expressions have two operands");

return static_cast<const byte_extract_big_endian_exprt &>(expr);
}

inline byte_extract_big_endian_exprt
&to_byte_extract_big_endian_expr(exprt &expr)
{
assert(expr.id()==ID_byte_extract_big_endian && expr.operands().size()==2);
PRECONDITION(expr.id() == ID_byte_extract_big_endian);
DATA_INVARIANT(
expr.operands().size() == 2, "byte extract expressions have two operands");

return static_cast<byte_extract_big_endian_exprt &>(expr);
}

Expand Down Expand Up @@ -154,13 +167,13 @@ class byte_update_exprt : public ternary_exprt

inline const byte_update_exprt &to_byte_update_expr(const exprt &expr)
{
assert(expr.operands().size()==3);
PRECONDITION(expr.operands().size() == 3);
return static_cast<const byte_update_exprt &>(expr);
}

inline byte_update_exprt &to_byte_update_expr(exprt &expr)
{
assert(expr.operands().size()==3);
PRECONDITION(expr.operands().size() == 3);
return static_cast<byte_update_exprt &>(expr);
}

Expand All @@ -184,14 +197,20 @@ class byte_update_little_endian_exprt:public byte_update_exprt
inline const byte_update_little_endian_exprt
&to_byte_update_little_endian_expr(const exprt &expr)
{
assert(expr.id()==ID_byte_update_little_endian && expr.operands().size()==3);
PRECONDITION(expr.id() == ID_byte_update_little_endian);
DATA_INVARIANT(
expr.operands().size() == 3, "byte update expressions have three operands");

return static_cast<const byte_update_little_endian_exprt &>(expr);
}

inline byte_update_little_endian_exprt
&to_byte_update_little_endian_expr(exprt &expr)
{
assert(expr.id()==ID_byte_update_little_endian && expr.operands().size()==3);
PRECONDITION(expr.id() == ID_byte_update_little_endian);
DATA_INVARIANT(
expr.operands().size() == 3, "byte update expressions have three operands");

return static_cast<byte_update_little_endian_exprt &>(expr);
}

Expand All @@ -215,14 +234,20 @@ class byte_update_big_endian_exprt:public byte_update_exprt
inline const byte_update_big_endian_exprt
&to_byte_update_big_endian_expr(const exprt &expr)
{
assert(expr.id()==ID_byte_update_big_endian && expr.operands().size()==3);
PRECONDITION(expr.id() == ID_byte_update_big_endian);
DATA_INVARIANT(
expr.operands().size() == 3, "byte update expressions have three operands");

return static_cast<const byte_update_big_endian_exprt &>(expr);
}

inline byte_update_big_endian_exprt
&to_byte_update_big_endian_expr(exprt &expr)
{
assert(expr.id()==ID_byte_update_big_endian && expr.operands().size()==3);
PRECONDITION(expr.id() == ID_byte_update_big_endian);
DATA_INVARIANT(
expr.operands().size() == 3, "byte update expressions have three operands");

return static_cast<byte_update_big_endian_exprt &>(expr);
}

Expand Down
Loading