Skip to content

Commit 4c341b7

Browse files
committed
Implement toString() methods of box types using CProverString methods
1 parent 30b09d1 commit 4c341b7

File tree

8 files changed

+38
-19
lines changed

8 files changed

+38
-19
lines changed

src/main/java/java/lang/Boolean.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ public static Boolean valueOf(String s) {
176176
* @param b the boolean to be converted
177177
* @return the string representation of the specified {@code boolean}
178178
* @since 1.4
179+
*
180+
* @diffblue.fullSupport
179181
*/
180182
public static String toString(boolean b) {
181183
return b ? "true" : "false";

src/main/java/java/lang/Byte.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package java.lang;
2727

2828
import org.cprover.CProver;
29+
import org.cprover.CProverString;
2930

3031
/**
3132
*
@@ -71,9 +72,11 @@ public final class Byte extends Number implements Comparable<Byte> {
7172
* @param b the {@code byte} to be converted
7273
* @return the string representation of the specified {@code byte}
7374
* @see java.lang.Integer#toString(int)
75+
*
76+
* @diffblue.fullSupport
7477
*/
7578
public static String toString(byte b) {
76-
return Integer.toString((int)b, 10);
79+
return CProverString.toString((int)b);
7780
}
7881

7982
/**

src/main/java/java/lang/Character.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.Locale;
3232

3333
import org.cprover.CProver;
34+
import org.cprover.CProverString;
3435

3536
/**
3637
* The {@code Character} class wraps a value of the primitive
@@ -4651,9 +4652,12 @@ public String toString() {
46514652
* @param c the {@code char} to be converted
46524653
* @return the string representation of the specified {@code char}
46534654
* @since 1.4
4655+
*
4656+
* @diffblue.fullSupport
46544657
*/
46554658
public static String toString(char c) {
4656-
return String.valueOf(c);
4659+
char data[] = {c};
4660+
return CProverString.ofCharArray(data, 0, 1);
46574661
}
46584662

46594663
/**

src/main/java/java/lang/Double.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,14 @@ public final class Double extends Number implements Comparable<Double> {
208208
*
209209
* @param d the {@code double} to be converted.
210210
* @return a string representation of the argument.
211-
* @diffblue.noSupport
211+
*
212+
* @diffblue.limitedSupport
213+
* The precision in the produced string may not match that of the
214+
* actual program.
212215
*/
213216
public static String toString(double d) {
214217
// return FloatingDecimal.toJavaFormatString(d);
215-
return String.valueOf(d);
218+
return CProverString.toString(d);
216219
}
217220

218221
/**

src/main/java/java/lang/Float.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import sun.misc.FloatConsts;
3232
import sun.misc.DoubleConsts;
3333
import org.cprover.CProver;
34+
import org.cprover.CProverString;
3435

3536
/**
3637
* The {@code Float} class wraps a value of primitive type
@@ -204,14 +205,13 @@ public final class Float extends Number implements Comparable<Float> {
204205
*
205206
* @param f the float to be converted.
206207
* @return a string representation of the argument.
207-
* @diffblue.noSupport
208+
*
209+
* @diffblue.limitedSupport
210+
* The precision in the produced string may not match that of the
211+
* actual program.
208212
*/
209213
public static String toString(float f) {
210-
// DIFFBLUE MODEL LIBRARY
211-
// removed for compatibility with Java 9 and newer
212-
// return FloatingDecimal.toJavaFormatString(f);
213-
CProver.notModelled();
214-
return CProver.nondetWithNullForNotModelled();
214+
return CProverString.toString(f);
215215
}
216216

217217
/**

src/main/java/java/lang/Integer.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,11 @@ public final class Integer extends Number implements Comparable<Integer> {
119119
* @return a string representation of the argument in the specified radix.
120120
* @see java.lang.Character#MAX_RADIX
121121
* @see java.lang.Character#MIN_RADIX
122+
*
123+
* @diffblue.fullSupport
122124
*/
123-
// DIFFBLUE MODEL LIBRARY: Handled internally by CBMC
124125
public static String toString(int i, int radix) {
125-
return CProver.nondetWithoutNullForNotModelled();
126+
return CProverString.toString(i, radix);
126127
}
127128

128129
/**
@@ -287,11 +288,11 @@ public static String toBinaryString(int i) {
287288
*
288289
* @param i an integer to be converted.
289290
* @return a string representation of the argument in base&nbsp;10.
291+
*
292+
* @diffblue.fullSupport
290293
*/
291-
// DIFFBLUE MODEL LIBRARY: Handled internally by CBMC
292294
public static String toString(int i) {
293-
// this function is handled by cbmc internally
294-
return CProver.nondetWithoutNullForNotModelled();
295+
return CProverString.toString(i);
295296
}
296297

297298
/**

src/main/java/java/lang/Long.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ public final class Long extends Number implements Comparable<Long> {
123123
* @return a string representation of the argument in the specified radix.
124124
* @see java.lang.Character#MAX_RADIX
125125
* @see java.lang.Character#MIN_RADIX
126+
*
127+
* @diffblue.fullSupport
126128
*/
127129
public static String toString(long i, int radix) {
128-
return CProver.nondetWithoutNullForNotModelled();
130+
return CProverString.toString(i, radix);
129131
}
130132

131133
/**
@@ -349,10 +351,11 @@ static String toUnsignedString0(long val, int shift) {
349351
*
350352
* @param i a {@code long} to be converted.
351353
* @return a string representation of the argument in base&nbsp;10.
354+
*
355+
* @diffblue.fullSupport
352356
*/
353357
public static String toString(long i) {
354-
// this function is handled by cbmc internally
355-
return CProver.nondetWithoutNullForNotModelled();
358+
return CProverString.toString(i);
356359
}
357360

358361
/**

src/main/java/java/lang/Short.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package java.lang;
2727

2828
import org.cprover.CProver;
29+
import org.cprover.CProverString;
2930

3031
/**
3132
* The {@code Short} class wraps a value of primitive type {@code
@@ -69,9 +70,11 @@ public final class Short extends Number implements Comparable<Short> {
6970
* @param s the {@code short} to be converted
7071
* @return the string representation of the specified {@code short}
7172
* @see java.lang.Integer#toString(int)
73+
*
74+
* @diffblue.fullSupport
7275
*/
7376
public static String toString(short s) {
74-
return Integer.toString((int)s, 10);
77+
return CProverString.toString((int)s);
7578
}
7679

7780
/**

0 commit comments

Comments
 (0)