Skip to content

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

Merged
merged 5 commits into from
Aug 23, 2019

Conversation

danpoe
Copy link
Contributor

@danpoe danpoe commented Aug 22, 2019

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/s My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

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;
Copy link
Contributor

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 🍭

Copy link
Contributor Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

🍭

Copy link
Contributor Author

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;
Copy link
Contributor

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?

Copy link
Contributor Author

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;*/
Copy link
Contributor

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? ☕

Copy link
Contributor Author

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;*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does not work yet.

Copy link
Collaborator

@martin-cs martin-cs left a 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";
Copy link
Collaborator

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?

Copy link
Contributor Author

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";
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🍞

Copy link
Contributor

@smowton smowton left a 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

@danpoe danpoe force-pushed the refactor/primitive-types-to-string branch 3 times, most recently from 874f2ff to 3cf74b0 Compare August 23, 2019 16:42
danpoe added 2 commits August 23, 2019 17:42
…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.
@danpoe danpoe force-pushed the refactor/primitive-types-to-string branch from 3cf74b0 to ba12215 Compare August 23, 2019 16:57
danpoe added 2 commits August 23, 2019 17:57
After converting '\uFFFF' to string the result differs from "\uFFFF" for a check
with `equals()`.
@danpoe
Copy link
Contributor Author

danpoe commented Aug 23, 2019

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 KNOWNBUG for now.

@danpoe danpoe merged commit cbec723 into diffblue:develop Aug 23, 2019
Copy link
Contributor

@allredj allredj left a 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

@danpoe danpoe deleted the refactor/primitive-types-to-string branch June 2, 2020 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants