Skip to content

Commit eb74c6c

Browse files
committed
Address majority of second round review comments
1 parent 869d4e1 commit eb74c6c

File tree

5 files changed

+34
-50
lines changed

5 files changed

+34
-50
lines changed

cpp_api/api.cpp

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,10 @@
1616

1717
extern configt config;
1818

19-
// Default initialise the api_dependencies object
20-
cbmc_api::api_dependenciest::api_dependenciest()
21-
: // We don't print anything to the console as part of the API
22-
message_handler(new null_message_handlert()),
23-
// We create a default options object which we are going to
24-
// customise later.
25-
options(new optionst())
26-
{
27-
}
28-
29-
cbmc_api::api_dependenciest::api_dependenciest(const optionst options)
30-
: // We don't print anything to the console as part of the API
31-
message_handler(new null_message_handlert()),
32-
options(util_make_unique<optionst>(options))
33-
{
34-
}
35-
36-
cbmc_api::api_dependenciest::~api_dependenciest() = default;
37-
38-
cbmc_api::cbmc_api() : dependencies(new api_dependenciest())
19+
cprover_api::cprover_api()
20+
: message_handler(
21+
util_make_unique<null_message_handlert>(null_message_handlert{})),
22+
options(util_make_unique<optionst>(optionst{}))
3923
{
4024
// Needed to initialise the language options correctly
4125
cmdlinet cmdline;
@@ -45,8 +29,10 @@ cbmc_api::cbmc_api() : dependencies(new api_dependenciest())
4529
register_language(new_ansi_c_language);
4630
}
4731

48-
cbmc_api::cbmc_api(const api_optionst &options)
49-
: dependencies(new api_dependenciest(options.to_engine_options()))
32+
cprover_api::cprover_api(const api_optionst &options)
33+
: message_handler(
34+
util_make_unique<null_message_handlert>(null_message_handlert{})),
35+
options(options.to_engine_options())
5036
{
5137
// Needed to initialise the language options correctly
5238
cmdlinet cmdline;
@@ -56,10 +42,10 @@ cbmc_api::cbmc_api(const api_optionst &options)
5642
register_language(new_ansi_c_language);
5743
}
5844

59-
cbmc_api::~cbmc_api() = default;
45+
cprover_api::~cprover_api() = default;
6046

61-
void cbmc_api::load_model_from_files(const std::vector<std::string> &files)
47+
void cprover_api::load_model_from_files(const std::vector<std::string> &files)
6248
{
63-
model = util_make_unique<goto_modelt>(initialize_goto_model(
64-
files, *dependencies->message_handler, *dependencies->options));
49+
model = util_make_unique<goto_modelt>(
50+
initialize_goto_model(files, *message_handler, *options));
6551
}

cpp_api/api.h

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef CPROVER_API_API_H
2+
#define CPROVER_API_API_H
3+
14
#include <memory>
25
#include <vector>
36

@@ -10,12 +13,12 @@ class optionst;
1013

1114
// An object in the pattern of Session Facade - owning all of the memory
1215
// the API is using and being responsible for the management of that.
13-
struct cbmc_api
16+
struct cprover_api
1417
{
1518
// Initialising constructor
16-
explicit cbmc_api();
17-
cbmc_api(const api_optionst &options);
18-
~cbmc_api();
19+
cprover_api();
20+
explicit cprover_api(const api_optionst &options);
21+
~cprover_api(); // default constructed in the .cpp file
1922

2023
/// Load a goto_model from a given vector of filenames.
2124
/// \param files: A vector<string> containing the filenames to be loaded
@@ -24,17 +27,9 @@ struct cbmc_api
2427
void load_model_from_files(const std::vector<std::string> &files);
2528

2629
private:
27-
// A struct containing the API dependencies (some of them, at least)
28-
struct api_dependenciest
29-
{
30-
explicit api_dependenciest();
31-
api_dependenciest(const optionst options);
32-
~api_dependenciest();
33-
34-
std::unique_ptr<message_handlert> message_handler;
35-
std::unique_ptr<optionst> options;
36-
};
37-
3830
std::unique_ptr<goto_modelt> model;
39-
std::unique_ptr<api_dependenciest> dependencies;
31+
std::unique_ptr<message_handlert> message_handler;
32+
std::unique_ptr<optionst> options;
4033
};
34+
35+
#endif

cpp_api/call_bmc.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ int main(int argc, char *argv[])
1919
auto api_options = api_optionst::create().simplify(false);
2020

2121
// Initialise API dependencies and global configuration in one step.
22-
cbmc_api api(api_options);
22+
cprover_api api(api_options);
2323

2424
// Demonstrate the loading of a goto-model from the command line arguments
2525
api.load_model_from_files(arguments);
@@ -30,5 +30,3 @@ int main(int argc, char *argv[])
3030
std::cout << e.what() << std::endl;
3131
}
3232
}
33-
34-

cpp_api/options.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "options.h"
22

3+
#include <util/make_unique.h>
34
#include <util/options.h>
45

56
api_optionst api_optionst::create()
@@ -13,9 +14,9 @@ api_optionst &api_optionst::simplify(bool on)
1314
return *this;
1415
}
1516

16-
optionst api_optionst::to_engine_options() const
17+
std::unique_ptr<optionst> api_optionst::to_engine_options() const
1718
{
1819
optionst engine_options;
1920
engine_options.set_option("simplify", simplify_enabled);
20-
return engine_options;
21+
return util_make_unique<optionst>(engine_options);
2122
}

cpp_api/options.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#pragma once
1+
#ifndef CPROVER_API_OPTIONS_H
2+
#define CPROVER_API_OPTIONS_H
3+
4+
#include <memory>
25

36
class optionst;
47

@@ -11,10 +14,11 @@ class api_optionst
1114
api_optionst() = default;
1215

1316
public:
14-
~api_optionst() = default;
1517
static api_optionst create();
1618

1719
api_optionst &simplify(bool on);
1820

19-
optionst to_engine_options() const;
21+
std::unique_ptr<optionst> to_engine_options() const;
2022
};
23+
24+
#endif

0 commit comments

Comments
 (0)