Skip to content

Commit 540a60f

Browse files
committed
Refactor api_session_implementationt to reduce forward declarations
This avoids exposing forward declarations of internal type in the API by introducing a singular api_session_implementationt type instead. This should also result in reduced build times during development as changing the members of the implementation struct can be done without altering the header file.
1 parent cdc0b5c commit 540a60f

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/libcprover-cpp/api.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,23 @@
1919

2020
extern configt config;
2121

22+
struct api_session_implementationt
23+
{
24+
std::unique_ptr<goto_modelt> model;
25+
std::unique_ptr<message_handlert> message_handler;
26+
std::unique_ptr<optionst> options;
27+
};
28+
2229
api_sessiont::api_sessiont() : api_sessiont{api_optionst::create()}
2330
{
2431
}
2532

2633
api_sessiont::api_sessiont(const api_optionst &options)
27-
: message_handler(
28-
util_make_unique<null_message_handlert>(null_message_handlert{})),
29-
options(options.to_engine_options())
34+
: implementation{util_make_unique<api_session_implementationt>()}
3035
{
36+
implementation->message_handler =
37+
util_make_unique<null_message_handlert>(null_message_handlert{});
38+
implementation->options = options.to_engine_options();
3139
// Needed to initialise the language options correctly
3240
cmdlinet cmdline;
3341
// config is global in config.cpp
@@ -40,6 +48,6 @@ api_sessiont::~api_sessiont() = default;
4048

4149
void api_sessiont::load_model_from_files(const std::vector<std::string> &files)
4250
{
43-
model = util_make_unique<goto_modelt>(
44-
initialize_goto_model(files, *message_handler, *options));
51+
implementation->model = util_make_unique<goto_modelt>(initialize_goto_model(
52+
files, *implementation->message_handler, *implementation->options));
4553
}

src/libcprover-cpp/api.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
#include <vector>
99

1010
// Forward declaration of API dependencies
11-
class goto_modelt;
12-
class message_handlert;
11+
struct api_session_implementationt;
1312

1413
// There has been a design decision to allow users to include all of
1514
// the API headers by just including `api.h`, so we want to have an
@@ -34,9 +33,7 @@ struct api_sessiont
3433
void load_model_from_files(const std::vector<std::string> &files);
3534

3635
private:
37-
std::unique_ptr<goto_modelt> model;
38-
std::unique_ptr<message_handlert> message_handler;
39-
std::unique_ptr<optionst> options;
36+
std::unique_ptr<api_session_implementationt> implementation;
4037
};
4138

4239
#endif

0 commit comments

Comments
 (0)