Skip to content

Commit 3d94a62

Browse files
authored
Merge pull request #4591 from diffblue/config_main_optional
config.main is now optionalt<string> [blocks: #4041]
2 parents b8539ce + bef4da3 commit 3d94a62

12 files changed

+38
-32
lines changed

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ bool java_bytecode_languaget::parse(
249249
java_cp_include_files);
250250
if(config.java.main_class.empty())
251251
{
252-
const std::string &entry_method = config.main;
253252
// If we have an entry method, we can derive a main class.
254-
if(!entry_method.empty())
253+
if(config.main.has_value())
255254
{
255+
const std::string &entry_method = config.main.value();
256256
const auto last_dot_position = entry_method.find_last_of('.');
257257
main_class = entry_method.substr(0, last_dot_position);
258258
}

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,14 +533,14 @@ main_function_resultt get_main_symbol(
533533
messaget message(message_handler);
534534

535535
// find main symbol
536-
if(config.main!="")
536+
if(config.main.has_value())
537537
{
538538
// Add java:: prefix
539-
std::string main_identifier="java::"+config.main;
539+
std::string main_identifier = "java::" + config.main.value();
540540

541541
std::string error_message;
542-
irep_idt main_symbol_id=
543-
resolve_friendly_method_name(config.main, symbol_table, error_message);
542+
irep_idt main_symbol_id = resolve_friendly_method_name(
543+
config.main.value(), symbol_table, error_message);
544544

545545
if(main_symbol_id==irep_idt())
546546
{

jbmc/unit/pointer-analysis/custom_value_set_analysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ SCENARIO("test_value_set_analysis",
171171
GIVEN("Normal and custom value-set analysis of CustomVSATest::test")
172172
{
173173
config.set_arch("none");
174-
config.main = "";
174+
config.main = {};
175175

176176
// This classpath is the default, but the config object
177177
// is global and previous unit tests may have altered it

src/ansi-c/ansi_c_entry_point.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,13 @@ bool ansi_c_entry_point(
122122

123123
irep_idt main_symbol;
124124

125-
// find main symbol
126-
if(config.main!="")
125+
// find main symbol, if any is given
126+
if(config.main.has_value())
127127
{
128128
std::list<irep_idt> matches;
129129

130-
forall_symbol_base_map(it, symbol_table.symbol_base_map, config.main)
130+
forall_symbol_base_map(
131+
it, symbol_table.symbol_base_map, config.main.value())
131132
{
132133
// look it up
133134
symbol_tablet::symbolst::const_iterator s_it=
@@ -143,15 +144,15 @@ bool ansi_c_entry_point(
143144
if(matches.empty())
144145
{
145146
messaget message(message_handler);
146-
message.error() << "main symbol `" << config.main
147-
<< "' not found" << messaget::eom;
147+
message.error() << "main symbol `" << config.main.value() << "' not found"
148+
<< messaget::eom;
148149
return true; // give up
149150
}
150151

151152
if(matches.size()>=2)
152153
{
153154
messaget message(message_handler);
154-
message.error() << "main symbol `" << config.main
155+
message.error() << "main symbol `" << config.main.value()
155156
<< "' is ambiguous" << messaget::eom;
156157
return true;
157158
}

src/goto-instrument/dump_c.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,14 @@ void dump_ct::operator()(std::ostream &os)
202202
goto_functionst::function_mapt::const_iterator func_entry=
203203
goto_functions.function_map.find(symbol.name);
204204

205-
if(!harness &&
206-
func_entry!=goto_functions.function_map.end() &&
207-
func_entry->second.body_available() &&
208-
(symbol.name==ID_main ||
209-
(!config.main.empty() && symbol.name==config.main)))
205+
if(
206+
!harness && func_entry != goto_functions.function_map.end() &&
207+
func_entry->second.body_available() &&
208+
(symbol.name == ID_main ||
209+
(config.main.has_value() && symbol.name == config.main.value())))
210+
{
210211
skip_function_main=true;
212+
}
211213
}
212214
}
213215

src/goto-instrument/model_argc_argv.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ bool model_argc_argv(
5353
return true;
5454
}
5555

56-
const symbolt &main_symbol=
57-
ns.lookup(config.main.empty()?ID_main:config.main);
56+
const symbolt &main_symbol =
57+
ns.lookup(config.main.has_value() ? config.main.value() : ID_main);
5858

5959
if(main_symbol.mode!=ID_C)
6060
{

src/jsil/jsil_entry_point.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ bool jsil_entry_point(
5555

5656
irep_idt main_symbol;
5757

58-
// find main symbol
59-
if(config.main!="")
58+
// find main symbol, if any is given
59+
if(config.main.has_value())
6060
{
6161
std::list<irep_idt> matches;
6262

63-
forall_symbol_base_map(it, symbol_table.symbol_base_map, config.main)
63+
forall_symbol_base_map(
64+
it, symbol_table.symbol_base_map, config.main.value())
6465
{
6566
// look it up
6667
symbol_tablet::symbolst::const_iterator s_it=
@@ -76,15 +77,15 @@ bool jsil_entry_point(
7677
if(matches.empty())
7778
{
7879
messaget message(message_handler);
79-
message.error() << "main symbol `" << config.main
80-
<< "' not found" << messaget::eom;
80+
message.error() << "main symbol `" << config.main.value() << "' not found"
81+
<< messaget::eom;
8182
return true; // give up
8283
}
8384

8485
if(matches.size()>=2)
8586
{
8687
messaget message(message_handler);
87-
message.error() << "main symbol `" << config.main
88+
message.error() << "main symbol `" << config.main.value()
8889
<< "' is ambiguous" << messaget::eom;
8990
return true;
9091
}

src/linking/remove_internal_symbols.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ void remove_internal_symbols(
138138
else if(is_function)
139139
{
140140
// body? not local (i.e., "static")?
141-
if(has_body &&
142-
(!is_file_local || (config.main==symbol.name.c_str())))
141+
if(
142+
has_body && (!is_file_local || (config.main.has_value() &&
143+
symbol.name == config.main.value())))
143144
{
144145
get_symbols(ns, symbol, exported);
145146
}

src/util/config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
1414

1515
#include "ieee_float.h"
1616
#include "irep.h"
17+
#include "optional.h"
1718

1819
class cmdlinet;
1920
class symbol_tablet;
@@ -169,7 +170,7 @@ class configt
169170
} bv_encoding;
170171

171172
// this is the function to start executing
172-
std::string main;
173+
optionalt<std::string> main;
173174

174175
void set_arch(const irep_idt &);
175176

unit/compound_block_locations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ void compound_block_locationst::check_compound_block_locations(
277277
register_language(new_ansi_c_language);
278278
cmdlinet cmdline;
279279
cmdline.args.push_back(tmp());
280-
config.main = "main";
280+
config.main = std::string("main");
281281
config.set(cmdline);
282282

283283
optionst opts;

unit/json_symbol_table.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ TEST_CASE("json symbol table read/write consistency")
9797
register_language(new_ansi_c_language);
9898

9999
cmdlinet cmdline;
100-
config.main = "main";
100+
config.main = std::string("main");
101101
config.set(cmdline);
102102

103103
goto_modelt goto_model;

unit/path_strategies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void _check_with_strategy(
381381
register_language(new_ansi_c_language);
382382
cmdlinet cmdline;
383383
cmdline.args.push_back(tmp());
384-
config.main = "main";
384+
config.main = std::string("main");
385385
config.set(cmdline);
386386

387387
optionst options;

0 commit comments

Comments
 (0)