-
Notifications
You must be signed in to change notification settings - Fork 274
Add checks for symbol well-formedness. #3193
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "source_location.h" | ||
#include "std_expr.h" | ||
#include "suffix.h" | ||
|
||
/// Dump the state of a symbol object to a given output stream. | ||
/// \param out: The stream to output object state to. | ||
|
@@ -121,3 +122,25 @@ symbol_exprt symbolt::symbol_expr() const | |
{ | ||
return symbol_exprt(name, type); | ||
} | ||
|
||
/// Check that the instance object is well formed. | ||
/// \return: true if well-formed; false otherwise. | ||
bool symbolt::is_well_formed() const | ||
{ | ||
// Well-formedness criterion number 1 is for a symbol | ||
// to have a non-empty mode (see #1880) | ||
if(mode.empty()) | ||
{ | ||
return false; | ||
} | ||
|
||
// Well-formedness criterion number 2 is for a symbol | ||
// to have it's base name as a suffix to it's more | ||
// general name. | ||
if(!has_suffix(id2string(name), id2string(base_name))) | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/// Author: Diffblue Ltd. | ||
|
||
/// \file Tests for symbol_tablet | ||
|
||
#include <testing-utils/catch.hpp> | ||
#include <util/exception_utils.h> | ||
#include <util/symbol.h> | ||
|
||
SCENARIO( | ||
"Constructed symbol validity checks", | ||
"[core][utils][symbol__validity_checks]") | ||
{ | ||
GIVEN("A valid symbol") | ||
{ | ||
symbolt symbol; | ||
irep_idt symbol_name = "Test_TestBase"; | ||
symbol.name = symbol_name; | ||
symbol.base_name = "TestBase"; | ||
symbol.module = "TestModule"; | ||
symbol.mode = "C"; | ||
|
||
THEN("Symbol should be well formed") | ||
{ | ||
REQUIRE(symbol.is_well_formed()); | ||
} | ||
} | ||
|
||
GIVEN("An improperly initialised symbol") | ||
{ | ||
symbolt symbol; | ||
|
||
WHEN("The symbol doesn't have a valid mode") | ||
{ | ||
symbol.mode = ""; | ||
|
||
THEN("Symbol well-formedness check should fail") | ||
{ | ||
REQUIRE_FALSE(symbol.is_well_formed()); | ||
} | ||
} | ||
|
||
WHEN("The symbol doesn't have base name as a suffix to name") | ||
{ | ||
symbol.name = "TEST"; | ||
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. That will fail due to a non-empty mode, which isn't what you intend to test. 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. Yes, you were right. I fixed this now. |
||
symbol.base_name = "TestBase"; | ||
symbol.mode = "C"; | ||
|
||
THEN("Symbol well-formedness check should fail") | ||
{ | ||
REQUIRE_FALSE(symbol.is_well_formed()); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,10 +35,11 @@ SCENARIO( | |
symbol_tablet symbol_table; | ||
|
||
symbolt symbol; | ||
irep_idt symbol_name = "Test"; | ||
irep_idt symbol_name = "Test_TestBase"; | ||
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. Given this test doesn't check 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. This is because this was a test for something related added by @chrisr-diffblue but went in first, so my change had now broken this test, so I had to edit this test to conform to what the validity checks expected, and make it pass again. |
||
symbol.name = symbol_name; | ||
symbol.base_name = "TestBase"; | ||
symbol.module = "TestModule"; | ||
symbol.mode = "C"; | ||
|
||
symbol_table.insert(symbol); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.