Skip to content

Commit a88feea

Browse files
committed
Refactor global state init into its own function
1 parent e6ac21b commit a88feea

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

cpp_api/api.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
1+
#include <ansi-c/ansi_c_language.h>
2+
13
#include <goto-programs/goto_model.h>
24
#include <goto-programs/initialize_goto_model.h>
35

6+
#include <langapi/mode.h>
7+
8+
#include <util/cmdline.h>
49
#include <util/message.h>
510
#include <util/options.h>
611

712
#include "api.h"
813

914
api_depst api_deps;
15+
extern configt config;
1016

11-
// Initialise API dependencies
1217
void initialize_api() {
13-
// Initialise a null-message handler (we don't print anything yet)
18+
// Initialise a null-message handler (we don't print anything in the API)
1419
api_deps.msg_handler = new null_message_handlert();
1520
// Initialise default options
1621
api_deps.opts = new optionst();
22+
// Needed to initialise the language options correctly
23+
cmdlinet cmdline;
24+
// config is global in config.cpp
25+
config.set(cmdline);
26+
// Initialise C language mode
27+
register_language(new_ansi_c_language);
1728
}
1829

1930
goto_modelt load_model_from_files(
2031
const std::vector<std::string> &files,
2132
const optionst &options)
2233
{
34+
// This could be nested inside a try/catch, but for now let's leave it alone.
2335
return initialize_goto_model(files, *api_deps.msg_handler, options);
2436
}

cpp_api/api.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44

55
#include <util/message.h>
66
#include <util/options.h>
7+
#include <util/config.h>
78

9+
// A struct containing the API dependencies (some of them, at least)
810
struct api_depst {
911
message_handlert *msg_handler;
1012
optionst *opts;
1113
};
1214

15+
/// Initialise API dependencies
1316
void initialize_api();
1417

18+
/// Load a goto_model from a given vector of filenames.
19+
/// \param files: A vector<string> containing the filenames to be loaded
20+
/// \param options: An options object, to be passed on to analysis or transformation
21+
/// passes.
1522
goto_modelt load_model_from_files(
1623
const std::vector<std::string> &files,
1724
const optionst &options);

0 commit comments

Comments
 (0)