-
Notifications
You must be signed in to change notification settings - Fork 273
add parameter for depth of recursive objects #567
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 |
---|---|---|
|
@@ -42,6 +42,8 @@ class java_object_factoryt:public messaget | |
std::set<irep_idt> recursion_set; | ||
bool assume_non_null; | ||
size_t max_nondet_array_length; | ||
size_t recursion_depth; | ||
size_t max_recursion_depth; | ||
symbol_tablet &symbol_table; | ||
message_handlert &message_handler; | ||
namespacet ns; | ||
|
@@ -51,11 +53,14 @@ class java_object_factoryt:public messaget | |
code_blockt &_init_code, | ||
bool _assume_non_null, | ||
size_t _max_nondet_array_length, | ||
size_t _max_recursion_depth, | ||
symbol_tablet &_symbol_table, | ||
message_handlert &_message_handler): | ||
init_code(_init_code), | ||
assume_non_null(_assume_non_null), | ||
max_nondet_array_length(_max_nondet_array_length), | ||
recursion_depth(0), | ||
max_recursion_depth(_max_recursion_depth), | ||
symbol_table(_symbol_table), | ||
message_handler(_message_handler), | ||
ns(_symbol_table) | ||
|
@@ -189,20 +194,23 @@ void java_object_factoryt::gen_nondet_init( | |
{ | ||
const struct_typet &struct_type=to_struct_type(subtype); | ||
const irep_idt struct_tag=struct_type.get_tag(); | ||
// set to null if found in recursion set and not a sub-type | ||
if(recursion_set.find(struct_tag)!=recursion_set.end() && | ||
struct_tag==class_identifier) | ||
// set to null if found in recursion set and recursion depth allows it | ||
if(recursion_set.find(struct_tag)!=recursion_set.end()) | ||
{ | ||
// make null | ||
null_pointer_exprt null_pointer_expr(pointer_type); | ||
code_assignt code(expr, null_pointer_expr); | ||
code.add_source_location()=loc; | ||
init_code.copy_to_operands(code); | ||
|
||
return; | ||
if(recursion_depth<max_recursion_depth) | ||
recursion_depth++; | ||
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. Isn't this going to count the total number of recursive steps, across multiple "branches" of the data structures? For instance, for mutual recursion, the number of objects of a type X would actually just be max_recursion_depth/2. 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. @mgudemann, what is the intended semantics of the parameter? I agree with @tautschnig that the current solution is rather unintuitive from the user's perspective. 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. There is a problem with The idea of this parameter was to create a solution between using exclusively the recursion set and not using it at all, i.e., having a bounded initialization of hierarchical objects. 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. Shouldn't the solution be passing the 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. you are perfectly right with this |
||
else | ||
{ | ||
recursion_depth=0; | ||
// make null | ||
null_pointer_exprt null_pointer_expr(pointer_type); | ||
code_assignt code(expr, null_pointer_expr); | ||
code.add_source_location()=loc; | ||
init_code.copy_to_operands(code); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
code_labelt set_null_label; | ||
code_labelt init_done_label; | ||
|
||
|
@@ -483,12 +491,14 @@ void gen_nondet_init( | |
bool create_dyn_objs, | ||
bool assume_non_null, | ||
message_handlert &message_handler, | ||
size_t max_nondet_array_length) | ||
size_t max_nondet_array_length, | ||
size_t max_recursion_depth) | ||
{ | ||
java_object_factoryt state( | ||
init_code, | ||
assume_non_null, | ||
max_nondet_array_length, | ||
max_recursion_depth, | ||
symbol_table, | ||
message_handler); | ||
state.gen_nondet_init( | ||
|
@@ -567,6 +577,7 @@ exprt object_factory( | |
bool allow_null, | ||
symbol_tablet &symbol_table, | ||
size_t max_nondet_array_length, | ||
size_t max_recursion_depth, | ||
const source_locationt &loc, | ||
message_handlert &message_handler) | ||
{ | ||
|
@@ -588,7 +599,8 @@ exprt object_factory( | |
false, | ||
!allow_null, | ||
message_handler, | ||
max_nondet_array_length); | ||
max_nondet_array_length, | ||
max_recursion_depth); | ||
|
||
return object; | ||
} | ||
|
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.
While I do accept that the initialisation code currently exists for Java only: I don't think this command-line option should remain as specific. Furthermore the option name suggests that functional recursion is limited, whereas this is all about object initialisation. How about: "recursive-object-bound"?