-
Notifications
You must be signed in to change notification settings - Fork 277
Conversion functions from primitive types to strings #5048
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
Conversion functions from primitive types to strings #5048
Conversation
In the initialization of the conversion table, CProverString operations are grouped together for better readability.
@@ -1548,6 +1548,21 @@ void java_string_library_preprocesst::initialize_conversion_table() | |||
cprover_equivalent_to_java_string_returning_function | |||
["java::org.cprover.CProverString.substring:(Ljava/Lang/" | |||
"StringBuffer;II)Ljava/lang/String;"] = ID_cprover_string_substring_func; | |||
cprover_equivalent_to_java_string_returning_function | |||
["java::org.cprover.CProverString.toString:(Z)Ljava/lang/String;"] = | |||
ID_cprover_string_of_bool_func; |
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.
⛏️ actually this could be implemented directly as a model, there is not complicated logic involved, so I don't know if this is needed 🍭
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.
Yes, I think in that case we can remove both ID_cprover_string_of_bool_func
as well as CProverString.toString(char)
and use b ? "true" : "false"
directly.
ID_cprover_string_of_bool_func; | ||
cprover_equivalent_to_java_string_returning_function | ||
["java::org.cprover.CProverString.toString:(C)Ljava/lang/String;"] = | ||
ID_cprover_string_of_char_func; |
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.
🍭
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.
We could use
char arr[] = {c};
return new String(arr);
which calls ofCharArray()
which creates a StringBuilder
and uses append()
to insert the char and then returns StringBuilder.toString()
. Any idea if this might have performance implications?
ID_cprover_string_of_long_func; | ||
cprover_equivalent_to_java_string_returning_function | ||
["java::org.cprover.CProverString.toString:(F)Ljava/lang/String;"] = | ||
ID_cprover_string_of_float_func; |
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.
why is there no string_of_double entry?
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.
Double to string is handled by a model via CProverString.toString(CProver.doubleToFloat(d))
as double to string conversion is not implemented AFAIK.
/*case 5: | ||
c = Character.MAX_VALUE; | ||
r = "\uFFFF"; | ||
break;*/ |
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.
why is this commented out? ☕
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 case does not work. I have to investigate why.
case 8: | ||
f = Float.NaN; | ||
r = "NaN"; | ||
break;*/ |
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.
☕
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.
Does not work yet.
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.
A passing thought
break; | ||
case 5: | ||
f = Float.MIN_VALUE; | ||
r = "1.4E-45"; |
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.
Where did this number come from?
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.
That's the result of String.valueOf(f)
(same as Float.toString(f)
) 🍞
break; | ||
/*case 4: | ||
f = Float.MAX_VALUE; | ||
r = "3.4028235E38"; |
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 is kind of a weird way of formatting this.
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.
🍞
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.
No further comments except what @romainbrenguier already raised
874f2ff
to
3cf74b0
Compare
…able New CProverString.toString() operations are added which are now handled internally by cbmc. These operations can be used to model other Java methods such as Integer.toString().
These models can be compiled and run and have the same semantics as implemented by the string solver. They can thus be used to check that the string solver gives the correct result by comparing the result of a concrete run with the result obtained by cbmc.
3cf74b0
to
ba12215
Compare
After converting '\uFFFF' to string the result differs from "\uFFFF" for a check with `equals()`.
Ok, I'll merge this once CI passes. The behavior of the string operations does not change, but a new test has revealed some issues in the float to string conversion. I've marked the test as |
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.
✔️
Passed Diffblue compatibility checks (cbmc commit: ba12215).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/124413147
Uh oh!
There was an error while loading. Please reload this page.