-
Notifications
You must be signed in to change notification settings - Fork 273
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
tautschnig
merged 2 commits into
diffblue:develop
from
danpoe:refactor/error-handling-util
Sep 25, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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(...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -156,6 +149,4 @@ bool static_lifetime_init( | |
dest.move_to_operands(function_call); | ||
} | ||
} | ||
|
||
return false; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
{ | ||
|
@@ -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"; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "bv_arithmetic.h" | ||
|
||
#include <cassert> | ||
#include <ostream> | ||
|
||
#include "string2int.h" | ||
|
@@ -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; | ||
|
@@ -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(); | ||
|
@@ -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(); | ||
|
@@ -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(); | ||
|
@@ -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(); | ||
|
@@ -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); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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() | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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); | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.