Skip to content

Commit d6eae52

Browse files
authored
Merge pull request #4041 from tautschnig/empty-string
Cleanup use of empty strings
2 parents 104a704 + 13b3e4f commit d6eae52

File tree

103 files changed

+261
-285
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+261
-285
lines changed

jbmc/src/janalyzer/janalyzer_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ int janalyzer_parse_optionst::perform_analysis(const optionst &options)
405405

406406
if(cmdline.isset("show-taint"))
407407
{
408-
taint_analysis(goto_model, taint_file, ui_message_handler, true, "");
408+
taint_analysis(goto_model, taint_file, ui_message_handler, true);
409409
return CPROVER_EXIT_SUCCESS;
410410
}
411411
else

jbmc/src/java_bytecode/expr2java.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ std::string expr2javat::convert_rec(
246246
qualifierst &new_qualifiers = *clone;
247247
new_qualifiers.read(src);
248248

249-
const std::string d=
250-
declarator==""?declarator:(" "+declarator);
249+
const std::string d = declarator.empty() ? declarator : (" " + declarator);
251250

252251
const std::string q=
253252
new_qualifiers.as_string();
@@ -278,7 +277,7 @@ std::string expr2javat::convert_rec(
278277
// so we make one up, loosely inspired by the syntax
279278
// of lambda expressions.
280279

281-
std::string dest="";
280+
std::string dest;
282281

283282
dest+='(';
284283
const java_method_typet::parameterst &parameters = method_type.parameters();

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ main_function_resultt get_main_symbol(
542542
irep_idt main_symbol_id = resolve_friendly_method_name(
543543
config.main.value(), symbol_table, error_message);
544544

545-
if(main_symbol_id==irep_idt())
545+
if(main_symbol_id.empty())
546546
{
547547
message.error()
548548
<< "main symbol resolution failed: " << error_message << messaget::eom;

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class recursion_set_entryt
290290
/// Removes erase_entry (if set) from the controlled set.
291291
~recursion_set_entryt()
292292
{
293-
if(erase_entry!=irep_idt())
293+
if(!erase_entry.empty())
294294
recursion_set.erase(erase_entry);
295295
}
296296

@@ -303,10 +303,8 @@ class recursion_set_entryt
303303
/// \return true if added to the set (and therefore owned by this object)
304304
bool insert_entry(const irep_idt &entry)
305305
{
306-
INVARIANT(
307-
erase_entry==irep_idt(),
308-
"insert_entry should only be called once");
309-
INVARIANT(entry!=irep_idt(), "entry should be a struct tag");
306+
INVARIANT(erase_entry.empty(), "insert_entry should only be called once");
307+
INVARIANT(!entry.empty(), "entry should be a struct tag");
310308
bool ret=recursion_set.insert(entry).second;
311309
if(ret)
312310
{

jbmc/src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static irep_idt get_tag(const typet &type)
4141
else if(type.id() == ID_struct)
4242
return irep_idt("java::" + id2string(to_struct_type(type).get_tag()));
4343
else
44-
return "";
44+
return irep_idt();
4545
}
4646

4747
/// \param type: a type

jbmc/unit/java-testing-utils/require_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ require_type::require_struct_tag(const typet &type, const irep_idt &identifier)
470470
{
471471
REQUIRE(type.id() == ID_struct_tag);
472472
const struct_tag_typet &result = to_struct_tag_type(type);
473-
if(identifier != "")
473+
if(!identifier.empty())
474474
{
475475
REQUIRE(result.get_identifier() == identifier);
476476
}

jbmc/unit/java_bytecode/java_types/java_type_from_string.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SCENARIO("java_type_from_string", "[core][java_types]")
1515

1616
GIVEN("Ljava/lang/Integer;")
1717
{
18-
const auto integer_type = java_type_from_string("Ljava/lang/Integer;", "");
18+
const auto integer_type = java_type_from_string("Ljava/lang/Integer;");
1919
REQUIRE(integer_type.has_value());
2020
}
2121

@@ -35,7 +35,7 @@ SCENARIO("java_type_from_string", "[core][java_types]")
3535
GIVEN("Ljava/util/List<Ljava/lang/Integer>;")
3636
{
3737
const auto integer_list_type =
38-
java_type_from_string("Ljava/util/List<Ljava/lang/Integer;>;", "");
38+
java_type_from_string("Ljava/util/List<Ljava/lang/Integer;>;");
3939
REQUIRE(integer_list_type.has_value());
4040
}
4141

src/analyses/ai.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class ai_baset
157157
const goto_functionst::goto_functiont &goto_function,
158158
std::ostream &out) const
159159
{
160-
output(ns, "", goto_function.body, out);
160+
output(ns, irep_idt(), goto_function.body, out);
161161
}
162162

163163
/// Output the abstract states for the whole program as JSON
@@ -178,15 +178,15 @@ class ai_baset
178178
const namespacet &ns,
179179
const goto_programt &goto_program) const
180180
{
181-
return output_json(ns, "", goto_program);
181+
return output_json(ns, irep_idt(), goto_program);
182182
}
183183

184184
/// Output the abstract states for a single function as JSON
185185
jsont output_json(
186186
const namespacet &ns,
187187
const goto_functionst::goto_functiont &goto_function) const
188188
{
189-
return output_json(ns, "", goto_function.body);
189+
return output_json(ns, irep_idt(), goto_function.body);
190190
}
191191

192192
/// Output the abstract states for the whole program as XML
@@ -207,15 +207,15 @@ class ai_baset
207207
const namespacet &ns,
208208
const goto_programt &goto_program) const
209209
{
210-
return output_xml(ns, "", goto_program);
210+
return output_xml(ns, irep_idt(), goto_program);
211211
}
212212

213213
/// Output the abstract states for a single function as XML
214214
xmlt output_xml(
215215
const namespacet &ns,
216216
const goto_functionst::goto_functiont &goto_function) const
217217
{
218-
return output_xml(ns, "", goto_function.body);
218+
return output_xml(ns, irep_idt(), goto_function.body);
219219
}
220220

221221
protected:

src/analyses/goto_rw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ void guarded_range_domaint::output(
671671
out << itr->first << ":" << itr->second.first;
672672
// we don't know what mode (language) we are in, so we rely on the default
673673
// language to be reasonable for from_expr
674-
out << " if " << from_expr(ns, "", itr->second.second);
674+
out << " if " << from_expr(ns, irep_idt(), itr->second.second);
675675
}
676676
out << "]";
677677
}

src/analyses/invariant_set.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ bool inv_object_storet::get(const exprt &expr, unsigned &n)
6363
unsigned inv_object_storet::add(const exprt &expr)
6464
{
6565
std::string s=build_string(expr);
66-
67-
assert(s!="");
66+
CHECK_RETURN(!s.empty());
6867

6968
mapt::number_type n=map.number(s);
7069

@@ -137,7 +136,7 @@ std::string inv_object_storet::build_string(const exprt &expr) const
137136
// we don't know what mode (language) we are in, so we rely on the default
138137
// language to be reasonable for from_expr
139138
if(is_constant_address(expr))
140-
return from_expr(ns, "", expr);
139+
return from_expr(ns, irep_idt(), expr);
141140

142141
if(expr.id()==ID_member)
143142
{
@@ -391,8 +390,8 @@ void invariant_sett::strengthen_rec(const exprt &expr)
391390
throw "non-Boolean argument to strengthen()";
392391

393392
#if 0
394-
std::cout << "S: " << from_expr(*ns, "", expr) << '\n';
395-
#endif
393+
std::cout << "S: " << from_expr(*ns, irep_idt(), expr) << '\n';
394+
#endif
396395

397396
if(is_false)
398397
{
@@ -594,8 +593,8 @@ tvt invariant_sett::implies_rec(const exprt &expr) const
594593
throw "implies: non-Boolean expression";
595594

596595
#if 0
597-
std::cout << "I: " << from_expr(*ns, "", expr) << '\n';
598-
#endif
596+
std::cout << "I: " << from_expr(*ns, irep_idt(), expr) << '\n';
597+
#endif
599598

600599
if(is_false) // can't get any stronger
601600
return tvt(true);

src/analyses/local_bitvector_analysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ void local_bitvector_analysist::output(
347347
}
348348

349349
out << "\n";
350-
goto_function.body.output_instruction(ns, "", out, *i_it);
350+
goto_function.body.output_instruction(ns, irep_idt(), out, *i_it);
351351
out << "\n";
352352

353353
l++;

src/analyses/local_may_alias.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ void local_may_aliast::output(
458458
if(loc_info.aliases.find(j)==i)
459459
{
460460
assert(j<objects.size());
461-
irep_idt identifier = "";
461+
irep_idt identifier;
462462
if(objects[j].id() == ID_symbol)
463463
identifier = to_symbol_expr(objects[j]).get_identifier();
464464
out << ' ' << from_expr(ns, identifier, objects[j]);
@@ -470,7 +470,7 @@ void local_may_aliast::output(
470470
}
471471

472472
out << "\n";
473-
goto_function.body.output_instruction(ns, "", out, *i_it);
473+
goto_function.body.output_instruction(ns, irep_idt(), out, *i_it);
474474
out << "\n";
475475

476476
l++;

src/analyses/local_safe_pointers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void local_safe_pointerst::output(
207207
}
208208

209209
out << '\n';
210-
goto_program.output_instruction(ns, "", out, *i_it);
210+
goto_program.output_instruction(ns, irep_idt(), out, *i_it);
211211
out << '\n';
212212
}
213213
}
@@ -258,7 +258,7 @@ void local_safe_pointerst::output_safe_dereferences(
258258
}
259259

260260
out << '\n';
261-
goto_program.output_instruction(ns, "", out, *i_it);
261+
goto_program.output_instruction(ns, irep_idt(), out, *i_it);
262262
out << '\n';
263263
}
264264
}

src/analyses/static_analysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class static_analysis_baset
155155
const goto_programt &goto_program,
156156
std::ostream &out) const
157157
{
158-
output(goto_program, "", out);
158+
output(goto_program, irep_idt(), out);
159159
}
160160

161161
virtual bool has_location(locationt l) const=0;

src/ansi-c/ansi_c_language.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ bool ansi_c_languaget::preprocess(
4343
std::ostream &outstream)
4444
{
4545
// stdin?
46-
if(path=="")
46+
if(path.empty())
4747
return c_preprocess(instream, outstream, get_message_handler());
4848

4949
return c_preprocess(path, outstream, get_message_handler());

src/ansi-c/ansi_c_parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void ansi_c_parsert::add_declarator(
106106
}
107107

108108
// global?
109-
if(current_scope().prefix=="")
109+
if(current_scope().prefix.empty())
110110
ansi_c_declaration.set_is_global(true);
111111

112112
// abstract?

src/ansi-c/c_preprocess.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ static void error_parse_line(
200200
if(state==2)
201201
{
202202
saved_error_location.set_file(file);
203-
saved_error_location.set_function("");
203+
saved_error_location.set_function(irep_idt());
204204
saved_error_location.set_line(line_no);
205-
saved_error_location.set_column("");
205+
saved_error_location.set_column(irep_idt());
206206
}
207207
}
208208

0 commit comments

Comments
 (0)