Skip to content

Commit d6d4627

Browse files
Following coding guidelines in string preprocessing
I run the cpplint script on the string solver file, and improved the coding style according to its suggestions. I also added more explenations in string_constraint_generator. ALl the errors signaled by cpplint have been dealt with except a few that conserns indentation in the comments and one concerning an array of non-constant size.
1 parent 582547d commit d6d4627

11 files changed

+2574
-1905
lines changed

src/goto-programs/string_refine_preprocess.cpp

Lines changed: 502 additions & 263 deletions
Large diffs are not rendered by default.

src/goto-programs/string_refine_preprocess.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Date: September 2016
99
1010
\*******************************************************************/
1111

12-
#ifndef CPROVER_STRING_REFINE_PREPROCESS_H
13-
#define CPROVER_STRING_REFINE_PREPROCESS_H
12+
#ifndef CPROVER_GOTO_PROGRAMS_STRING_REFINE_PREPROCESS_H
13+
#define CPROVER_GOTO_PROGRAMS_STRING_REFINE_PREPROCESS_H
1414

1515
#include <goto-programs/goto_model.h>
1616
#include <util/ui_message.h>
@@ -31,16 +31,16 @@ class string_refine_preprocesst:public messaget
3131
std::map<irep_idt, irep_idt> side_effect_char_array_functions;
3232

3333
public:
34-
string_refine_preprocesst(symbol_tablet &, goto_functionst &, message_handlert &);
34+
string_refine_preprocesst
35+
(symbol_tablet &, goto_functionst &, message_handlert &);
3536

3637
private:
37-
3838
// add a temporary symbol to the symbol table
3939
symbol_exprt new_tmp_symbol(const std::string &name, const typet &type);
4040

4141
void declare_function(irep_idt function_name, const typet &type);
4242

43-
exprt replace_string_literals(const exprt & );
43+
exprt replace_string_literals(const exprt &);
4444

4545
// replace "lhs=s.some_function(x,...)" by "lhs=function_name(s,x,...)"
4646
void make_string_function
@@ -74,15 +74,15 @@ class string_refine_preprocesst:public messaget
7474
void make_char_array_function_call
7575
(goto_programt::instructionst::iterator & i_it, irep_idt function_name);
7676

77-
// replace "r = s.some_function(i,arr,...)" by "s=function_name(s,i,arr.length,arr.data)"
77+
// replace `r = s.some_function(i,arr,...)` by
78+
// `s=function_name(s,i,arr.length,arr.data)`
7879
// and add a correspondance from r to s in the string_builders map
7980
void make_char_array_side_effect
8081
(goto_programt::instructionst::iterator & i_it, irep_idt function_name);
8182

8283
bool has_java_string_type(const exprt &expr);
8384

8485
void replace_string_calls(goto_functionst::function_mapt::iterator f_it);
85-
8686
};
8787

88-
#endif
88+
#endif

src/solvers/refinement/refined_string_type.cpp

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,83 @@ Author: Romain Brenguier, [email protected]
1010
#include <solvers/refinement/refined_string_type.h>
1111
#include <ansi-c/string_constant.h>
1212

13-
refined_string_typet::refined_string_typet(unsignedbv_typet char_type) : struct_typet() {
13+
refined_string_typet::refined_string_typet(unsignedbv_typet char_type)
14+
:struct_typet()
15+
{
1416
components().resize(2);
1517
components()[0].set_name("length");
1618
components()[0].set_pretty_name("length");
1719
components()[0].type()=refined_string_typet::index_type();
1820

19-
array_typet char_array(char_type,infinity_exprt(refined_string_typet::index_type()));
21+
infinity_exprt infinite_index(refined_string_typet::index_type());
22+
array_typet char_array(char_type, infinite_index);
2023
components()[1].set_name("content");
2124
components()[1].set_pretty_name("content");
2225
components()[1].type()=char_array;
2326
}
2427

2528
bool refined_string_typet::is_c_string_type(const typet &type)
2629
{
27-
if (type.id() == ID_struct) {
28-
irep_idt tag = to_struct_type(type).get_tag();
29-
return (tag == irep_idt("__CPROVER_string"));
30-
} else return false;
30+
if(type.id()==ID_struct)
31+
{
32+
irep_idt tag=to_struct_type(type).get_tag();
33+
return (tag==irep_idt("__CPROVER_string"));
34+
}
35+
return false;
3136
}
3237

3338
bool refined_string_typet::is_java_string_type(const typet &type)
3439
{
35-
if(type.id() == ID_pointer) {
36-
pointer_typet pt = to_pointer_type(type);
37-
typet subtype = pt.subtype();
40+
if(type.id()==ID_pointer)
41+
{
42+
pointer_typet pt=to_pointer_type(type);
43+
typet subtype=pt.subtype();
3844
return is_java_deref_string_type(subtype);
39-
} else return false;
45+
}
46+
return false;
4047
}
4148

4249
bool refined_string_typet::is_java_deref_string_type(const typet &type)
4350
{
44-
if(type.id() == ID_symbol)
51+
if(type.id()==ID_symbol)
4552
{
46-
irep_idt tag = to_symbol_type(type).get_identifier();
47-
return (tag == irep_idt("java::java.lang.String"));
53+
irep_idt tag=to_symbol_type(type).get_identifier();
54+
return (tag==irep_idt("java::java.lang.String"));
4855
}
49-
else if(type.id() == ID_struct)
56+
else if(type.id()==ID_struct)
5057
{
51-
irep_idt tag = to_struct_type(type).get_tag();
52-
return (tag == irep_idt("java.lang.String"));
58+
irep_idt tag=to_struct_type(type).get_tag();
59+
return (tag==irep_idt("java.lang.String"));
5360
}
54-
else return false;
61+
return false;
5562
}
5663

5764
bool refined_string_typet::is_java_string_builder_type(const typet &type)
5865
{
59-
if(type.id() == ID_pointer) {
60-
pointer_typet pt = to_pointer_type(type);
61-
typet subtype = pt.subtype();
62-
if(subtype.id() == ID_struct) {
63-
irep_idt tag = to_struct_type(subtype).get_tag();
64-
return (tag == irep_idt("java.lang.StringBuilder"));
66+
if(type.id()==ID_pointer)
67+
{
68+
pointer_typet pt=to_pointer_type(type);
69+
typet subtype=pt.subtype();
70+
if(subtype.id()==ID_struct)
71+
{
72+
irep_idt tag=to_struct_type(subtype).get_tag();
73+
return (tag==irep_idt("java.lang.StringBuilder"));
6574
}
66-
else return false;
67-
} else return false;
75+
}
76+
return false;
6877
}
6978

7079
bool refined_string_typet::is_java_char_sequence_type(const typet &type)
7180
{
72-
if(type.id() == ID_pointer) {
73-
pointer_typet pt = to_pointer_type(type);
74-
typet subtype = pt.subtype();
75-
if(subtype.id() == ID_struct) {
76-
irep_idt tag = to_struct_type(subtype).get_tag();
77-
return (tag == irep_idt("java.lang.CharSequence"));
81+
if(type.id()==ID_pointer)
82+
{
83+
pointer_typet pt=to_pointer_type(type);
84+
typet subtype=pt.subtype();
85+
if(subtype.id()==ID_struct)
86+
{
87+
irep_idt tag=to_struct_type(subtype).get_tag();
88+
return (tag==irep_idt("java.lang.CharSequence"));
7889
}
79-
else return false;
80-
} else return false;
90+
}
91+
return false;
8192
}

src/solvers/refinement/refined_string_type.h

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Author: Romain Brenguier, [email protected]
77
88
\*******************************************************************/
99

10-
#ifndef CPROVER_SOLVER_REFINED_STRING_TYPE_H
11-
#define CPROVER_SOLVER_REFINED_STRING_TYPE_H
10+
#ifndef CPROVER_SOLVERS_REFINEMENT_REFINED_STRING_TYPE_H
11+
#define CPROVER_SOLVERS_REFINEMENT_REFINED_STRING_TYPE_H
1212

1313
#include <util/std_types.h>
1414
#include <util/std_expr.h>
@@ -19,22 +19,30 @@ Author: Romain Brenguier, [email protected]
1919
#define STRING_SOLVER_JAVA_CHAR_WIDTH 16
2020

2121
// Internal type used for string refinement
22-
class refined_string_typet : public struct_typet {
22+
class refined_string_typet: public struct_typet
23+
{
2324
public:
24-
refined_string_typet(unsignedbv_typet char_type);
25+
explicit refined_string_typet(unsignedbv_typet char_type);
2526

2627
// Type for the content (list of characters) of a string
2728
inline array_typet get_content_type()
2829
{ return to_array_type((to_struct_type(*this)).components()[1].type());}
2930

3031
// Types used in this refinement
31-
static inline unsignedbv_typet char_type() { return unsignedbv_typet(STRING_SOLVER_C_CHAR_WIDTH);}
32+
static inline unsignedbv_typet char_type()
33+
{ return unsignedbv_typet(STRING_SOLVER_C_CHAR_WIDTH); }
3234

33-
static inline unsignedbv_typet java_char_type() { return unsignedbv_typet(STRING_SOLVER_JAVA_CHAR_WIDTH);}
35+
static inline unsignedbv_typet java_char_type()
36+
{ return unsignedbv_typet(STRING_SOLVER_JAVA_CHAR_WIDTH);}
3437

35-
static inline signedbv_typet index_type() { return signedbv_typet(STRING_SOLVER_INDEX_WIDTH);}
38+
static inline signedbv_typet index_type()
39+
{ return signedbv_typet(STRING_SOLVER_INDEX_WIDTH);}
3640

37-
static inline exprt index_zero() { return constant_exprt(integer2binary(0, STRING_SOLVER_INDEX_WIDTH), index_type());}
41+
static inline exprt index_zero()
42+
{
43+
return constant_exprt(integer2binary(0, STRING_SOLVER_INDEX_WIDTH),
44+
index_type());
45+
}
3846

3947
// For C the unrefined string type is __CPROVER_string, for java it is a
4048
// pointer to a strict with tag java.lang.String
@@ -49,24 +57,27 @@ class refined_string_typet : public struct_typet {
4957

5058
static bool is_java_char_sequence_type(const typet & type);
5159

52-
static inline unsignedbv_typet get_char_type(const exprt & expr) {
53-
if(is_c_string_type(expr.type())) return char_type();
54-
else return java_char_type();
60+
static inline unsignedbv_typet get_char_type(const exprt & expr)
61+
{
62+
if(is_c_string_type(expr.type()))
63+
return char_type();
64+
else
65+
return java_char_type();
5566
}
5667

5768
static inline bool is_unrefined_string_type(const typet & type)
58-
{ return (is_c_string_type(type)
59-
|| is_java_string_type(type)
60-
|| is_java_string_builder_type(type)
61-
|| is_java_char_sequence_type(type)
62-
); }
69+
{
70+
return (is_c_string_type(type)
71+
|| is_java_string_type(type)
72+
|| is_java_string_builder_type(type)
73+
|| is_java_char_sequence_type(type));
74+
}
6375

6476
static inline bool is_unrefined_string(const exprt & expr)
65-
{ return (is_unrefined_string_type(expr.type())); }
77+
{ return (is_unrefined_string_type(expr.type())); }
6678

6779
static inline constant_exprt index_of_int(int i)
68-
{ return from_integer(i,index_type()); }
69-
80+
{ return from_integer(i, index_type()); }
7081
};
7182

7283

0 commit comments

Comments
 (0)