12
12
// / types, in particular int, long, float, double, char, bool
13
13
14
14
#include < solvers/refinement/string_constraint_generator.h>
15
- #include < solvers/floatbv/float_bv.h>
16
15
17
- // / add axioms corresponding to the String.valueOf(I) java function
18
- // / \par parameters : function application with one integer argument
16
+ // / Add axioms corresponding to the String.valueOf(I) java function.
17
+ // / \param expr : function application with one integer argument
19
18
// / \return a new string expression
20
19
string_exprt string_constraint_generatort::add_axioms_from_int (
21
20
const function_application_exprt &expr)
@@ -24,8 +23,8 @@ string_exprt string_constraint_generatort::add_axioms_from_int(
24
23
return add_axioms_from_int (args (expr, 1 )[0 ], MAX_INTEGER_LENGTH, ref_type);
25
24
}
26
25
27
- // / add axioms corresponding to the String.valueOf(J) java function
28
- // / \par parameters : function application with one long argument
26
+ // / Add axioms corresponding to the String.valueOf(J) java function.
27
+ // / \param expr : function application with one long argument
29
28
// / \return a new string expression
30
29
string_exprt string_constraint_generatort::add_axioms_from_long (
31
30
const function_application_exprt &expr)
@@ -34,125 +33,8 @@ string_exprt string_constraint_generatort::add_axioms_from_long(
34
33
return add_axioms_from_int (args (expr, 1 )[0 ], MAX_LONG_LENGTH, ref_type);
35
34
}
36
35
37
- // / add axioms corresponding to the String.valueOf(F) java function
38
- // / \par parameters: function application with one float argument
39
- // / \return a new string expression
40
- string_exprt string_constraint_generatort::add_axioms_from_float (
41
- const function_application_exprt &f)
42
- {
43
- const refined_string_typet &ref_type=to_refined_string_type (f.type ());
44
- return add_axioms_from_float (args (f, 1 )[0 ], ref_type, false );
45
- }
46
-
47
- // / add axioms corresponding to the String.valueOf(D) java function
48
- // / \par parameters: function application with one double argument
49
- // / \return a new string expression
50
- string_exprt string_constraint_generatort::add_axioms_from_double (
51
- const function_application_exprt &f)
52
- {
53
- const refined_string_typet &ref_type=to_refined_string_type (f.type ());
54
- return add_axioms_from_float (args (f, 1 )[0 ], ref_type, true );
55
- }
56
-
57
- // / add axioms corresponding to the String.valueOf(F) java function Warning: we
58
- // / currently only have partial specification
59
- // / \par parameters: float expression and Boolean signaling that the argument
60
- // / has
61
- // / double precision
62
- // / \return a new string expression
63
- string_exprt string_constraint_generatort::add_axioms_from_float (
64
- const exprt &f, const refined_string_typet &ref_type, bool double_precision)
65
- {
66
- string_exprt res=fresh_string (ref_type);
67
- const typet &index_type=ref_type.get_index_type ();
68
- const typet &char_type=ref_type.get_char_type ();
69
- const exprt &index24=from_integer (24 , index_type);
70
- axioms.push_back (res.axiom_for_is_shorter_than (index24));
71
-
72
- string_exprt magnitude=fresh_string (ref_type);
73
- string_exprt sign_string=fresh_string (ref_type);
74
- string_exprt nan_string=add_axioms_for_constant (" NaN" , ref_type);
75
-
76
- // We add the axioms:
77
- // a1 : If the argument is NaN, the result length is that of "NaN".
78
- // a2 : If the argument is NaN, the result content is the string "NaN".
79
- // a3 : f<0 => |sign_string|=1
80
- // a4 : f>=0 => |sign_string|=0
81
- // a5 : f<0 => sign_string[0]='-'
82
- // a6 : f infinite => |magnitude|=|"Infinity"|
83
- // a7 : forall i<|"Infinity"|, f infinite => magnitude[i]="Infinity"[i]
84
- // a8 : f=0 => |magnitude|=|"0.0"|
85
- // a9 : forall i<|"0.0"|, f=0 => f[i]="0.0"[i]
86
-
87
- ieee_float_spect fspec=
88
- double_precision?ieee_float_spect::double_precision ()
89
- :ieee_float_spect::single_precision ();
90
-
91
- exprt isnan=float_bvt ().isnan (f, fspec);
92
- implies_exprt a1 (isnan, magnitude.axiom_for_has_same_length_as (nan_string));
93
- axioms.push_back (a1);
94
-
95
- symbol_exprt qvar=fresh_univ_index (" QA_equal_nan" , index_type);
96
- string_constraintt a2 (
97
- qvar,
98
- nan_string.length (),
99
- isnan,
100
- equal_exprt (magnitude[qvar], nan_string[qvar]));
101
- axioms.push_back (a2);
102
-
103
- // If the argument is not NaN, the result is a string that represents
104
- // the sign and magnitude (absolute value) of the argument.
105
- // If the sign is negative, the first character of the result is '-';
106
- // if the sign is positive, no sign character appears in the result.
107
-
108
- bitvector_typet bv_type=to_bitvector_type (f.type ());
109
- unsigned width=bv_type.get_width ();
110
- exprt isneg=extractbit_exprt (f, width-1 );
111
-
112
- implies_exprt a3 (isneg, sign_string.axiom_for_has_length (1 ));
113
- axioms.push_back (a3);
114
-
115
- implies_exprt a4 (not_exprt (isneg), sign_string.axiom_for_has_length (0 ));
116
- axioms.push_back (a4);
117
-
118
- implies_exprt a5 (
119
- isneg, equal_exprt (sign_string[0 ], constant_char (' -' , char_type)));
120
- axioms.push_back (a5);
121
-
122
- // If m is infinity, it is represented by the characters "Infinity";
123
- // thus, positive infinity produces the result "Infinity" and negative
124
- // infinity produces the result "-Infinity".
125
-
126
- string_exprt infinity_string=add_axioms_for_constant (" Infinity" , ref_type);
127
- exprt isinf=float_bvt ().isinf (f, fspec);
128
- implies_exprt a6 (
129
- isinf, magnitude.axiom_for_has_same_length_as (infinity_string));
130
- axioms.push_back (a6);
131
-
132
- symbol_exprt qvar_inf=fresh_univ_index (" QA_equal_infinity" , index_type);
133
- equal_exprt meq (magnitude[qvar_inf], infinity_string[qvar_inf]);
134
- string_constraintt a7 (qvar_inf, infinity_string.length (), isinf, meq);
135
- axioms.push_back (a7);
136
-
137
- // If m is zero, it is represented by the characters "0.0"; thus, negative
138
- // zero produces the result "-0.0" and positive zero produces "0.0".
139
-
140
- string_exprt zero_string=add_axioms_for_constant (" 0.0" , ref_type);
141
- exprt iszero=float_bvt ().is_zero (f, fspec);
142
- implies_exprt a8 (iszero, magnitude.axiom_for_has_same_length_as (zero_string));
143
- axioms.push_back (a8);
144
-
145
- symbol_exprt qvar_zero=fresh_univ_index (" QA_equal_zero" , index_type);
146
- equal_exprt eq_zero (magnitude[qvar_zero], zero_string[qvar_zero]);
147
- string_constraintt a9 (qvar_zero, zero_string.length (), iszero, eq_zero);
148
- axioms.push_back (a9);
149
-
150
- return add_axioms_for_concat (sign_string, magnitude);
151
- }
152
-
153
-
154
- // / add axioms corresponding to the String.valueOf(Z) java function
155
- // / \par parameters: function application with on Boolean argument
36
+ // / Add axioms corresponding to the String.valueOf(Z) java function.
37
+ // / \param f: function application with a Boolean argument
156
38
// / \return a new string expression
157
39
string_exprt string_constraint_generatort::add_axioms_from_bool (
158
40
const function_application_exprt &f)
@@ -161,10 +43,10 @@ string_exprt string_constraint_generatort::add_axioms_from_bool(
161
43
return add_axioms_from_bool (args (f, 1 )[0 ], ref_type);
162
44
}
163
45
164
-
165
- // / add axioms stating that the returned string equals "true " when the Boolean
166
- // / expression is true and "false" when it is false
167
- // / \par parameters: Boolean expression
46
+ // / Add axioms stating that the returned string equals "true" when the Boolean
47
+ // / expression is true and "false " when it is false.
48
+ // / \param b: Boolean expression
49
+ // / \param ref_type: type of refined string expressions
168
50
// / \return a new string expression
169
51
string_exprt string_constraint_generatort::add_axioms_from_bool (
170
52
const exprt &b, const refined_string_typet &ref_type)
@@ -329,8 +211,8 @@ string_exprt string_constraint_generatort::add_axioms_from_int(
329
211
return res;
330
212
}
331
213
332
- // / returns the value represented by the character
333
- // / \par parameters : a character expression in the following set:
214
+ // / Returns the integer value represented by the character.
215
+ // / \param chr : a character expression in the following set:
334
216
// / 0123456789abcdef
335
217
// / \return an integer expression
336
218
exprt string_constraint_generatort::int_of_hex_char (const exprt &chr) const
@@ -344,9 +226,10 @@ exprt string_constraint_generatort::int_of_hex_char(const exprt &chr) const
344
226
minus_exprt (chr, zero_char));
345
227
}
346
228
347
- // / add axioms stating that the returned string corresponds to the integer
348
- // / argument written in hexadecimal
349
- // / \par parameters: one integer argument
229
+ // / Add axioms stating that the returned string corresponds to the integer
230
+ // / argument written in hexadecimal.
231
+ // / \param i: an integer argument
232
+ // / \param ref_type: type of refined string expressions
350
233
// / \return a new string expression
351
234
string_exprt string_constraint_generatort::add_axioms_from_int_hex (
352
235
const exprt &i, const refined_string_typet &ref_type)
@@ -402,7 +285,7 @@ string_exprt string_constraint_generatort::add_axioms_from_int_hex(
402
285
}
403
286
404
287
// / add axioms corresponding to the Integer.toHexString(I) java function
405
- // / \par parameters : function application with integer argument
288
+ // / \param f : function application with an integer argument
406
289
// / \return a new string expression
407
290
string_exprt string_constraint_generatort::add_axioms_from_int_hex (
408
291
const function_application_exprt &f)
@@ -411,8 +294,8 @@ string_exprt string_constraint_generatort::add_axioms_from_int_hex(
411
294
return add_axioms_from_int_hex (args (f, 1 )[0 ], ref_type);
412
295
}
413
296
414
- // / add axioms corresponding to the String.valueOf(C) java function
415
- // / \par parameters : function application one char argument
297
+ // / Add axioms corresponding to the String.valueOf(C) java function.
298
+ // / \param f : function application one char argument
416
299
// / \return a new string expression
417
300
string_exprt string_constraint_generatort::add_axioms_from_char (
418
301
const function_application_exprt &f)
@@ -421,9 +304,10 @@ string_exprt string_constraint_generatort::add_axioms_from_char(
421
304
return add_axioms_from_char (args (f, 1 )[0 ], ref_type);
422
305
}
423
306
424
- // / add axioms stating that the returned string has length 1 and the character
425
- // / it contains correspond to the input expression
426
- // / \par parameters: one expression of type char
307
+ // / Add axioms stating that the returned string has length 1 and the character
308
+ // / it contains correspond to the input expression.
309
+ // / \param c: one expression of type char
310
+ // / \param ref_type: type of refined string expressions
427
311
// / \return a new string expression
428
312
string_exprt string_constraint_generatort::add_axioms_from_char (
429
313
const exprt &c, const refined_string_typet &ref_type)
@@ -434,9 +318,9 @@ string_exprt string_constraint_generatort::add_axioms_from_char(
434
318
return res;
435
319
}
436
320
437
- // / add axioms corresponding to the String.valueOf([C) and String.valueOf([CII)
438
- // / functions
439
- // / \par parameters : function application with one or three arguments
321
+ // / Add axioms corresponding to the String.valueOf([C) and String.valueOf([CII)
322
+ // / functions.
323
+ // / \param f : function application with one or three arguments
440
324
// / \return a new string expression
441
325
string_exprt string_constraint_generatort::add_axioms_for_value_of (
442
326
const function_application_exprt &f)
@@ -471,9 +355,9 @@ string_exprt string_constraint_generatort::add_axioms_for_value_of(
471
355
}
472
356
}
473
357
474
- // / add axioms making the return value true if the given string is a correct
475
- // / number
476
- // / \par parameters : function application with one string expression
358
+ // / Add axioms making the return value true if the given string is a correct
359
+ // / number.
360
+ // / \param f : function application with one string expression
477
361
// / \return an boolean expression
478
362
exprt string_constraint_generatort::add_axioms_for_correct_number_format (
479
363
const string_exprt &str, std::size_t max_size)
@@ -527,7 +411,7 @@ exprt string_constraint_generatort::add_axioms_for_correct_number_format(
527
411
}
528
412
529
413
// / add axioms corresponding to the Integer.parseInt java function
530
- // / \par parameters : function application with one string expression
414
+ // / \param f : function application with one string expression
531
415
// / \return an integer expression
532
416
exprt string_constraint_generatort::add_axioms_for_parse_int (
533
417
const function_application_exprt &f)
0 commit comments