Rename files, classes and variables in relation to the configuration file

In particular, makes clearer the distinction between configuration and
configuration file. The former includes information that is not in the
latter (command-line options.)
master
Sébastien Villemot 2023-12-11 17:16:49 +01:00
parent 7dd125e43a
commit 4389e5320d
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
6 changed files with 53 additions and 53 deletions

View File

@ -22,7 +22,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "ConfigFile.hh" #include "Configuration.hh"
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic ignored "-Wold-style-cast"
@ -98,9 +98,9 @@ Cluster::Cluster(member_nodes_t member_nodes_arg) : member_nodes {move(member_no
} }
} }
ConfigFile::ConfigFile(bool parallel_arg, bool parallel_test_arg, Configuration::Configuration(bool parallel_arg, bool parallel_test_arg,
bool parallel_follower_open_mode_arg, bool parallel_use_psexec_arg, bool parallel_follower_open_mode_arg, bool parallel_use_psexec_arg,
string cluster_name_arg) : string cluster_name_arg) :
parallel {parallel_arg}, parallel {parallel_arg},
parallel_test {parallel_test_arg}, parallel_test {parallel_test_arg},
parallel_follower_open_mode {parallel_follower_open_mode_arg}, parallel_follower_open_mode {parallel_follower_open_mode_arg},
@ -110,12 +110,12 @@ ConfigFile::ConfigFile(bool parallel_arg, bool parallel_test_arg,
} }
void void
ConfigFile::getConfigFileInfo(const filesystem::path& config_file) Configuration::getConfigFileInfo(const filesystem::path& conffile_option)
{ {
using namespace boost; using namespace boost;
ifstream configFile; ifstream configFile;
if (config_file.empty()) if (conffile_option.empty())
{ {
filesystem::path defaultConfigFile; filesystem::path defaultConfigFile;
// Test OS and try to open default file // Test OS and try to open default file
@ -162,10 +162,10 @@ ConfigFile::getConfigFileInfo(const filesystem::path& config_file)
} }
else else
{ {
configFile.open(config_file, fstream::in); configFile.open(conffile_option, fstream::in);
if (!configFile.is_open()) if (!configFile.is_open())
{ {
cerr << "ERROR: Couldn't open file " << config_file.string() << endl; cerr << "ERROR: Couldn't open file " << conffile_option.string() << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -469,7 +469,7 @@ ConfigFile::getConfigFileInfo(const filesystem::path& config_file)
} }
void void
ConfigFile::addHooksConfFileElement(string global_init_file) Configuration::addHooksConfFileElement(string global_init_file)
{ {
if (global_init_file.empty()) if (global_init_file.empty())
{ {
@ -482,7 +482,7 @@ ConfigFile::addHooksConfFileElement(string global_init_file)
} }
void void
ConfigFile::addPathsConfFileElement(vector<string> includepath) Configuration::addPathsConfFileElement(vector<string> includepath)
{ {
if (includepath.empty()) if (includepath.empty())
{ {
@ -494,15 +494,15 @@ ConfigFile::addPathsConfFileElement(vector<string> includepath)
} }
void void
ConfigFile::addParallelConfFileElement(bool inNode, bool inCluster, Configuration::addParallelConfFileElement(bool inNode, bool inCluster,
const member_nodes_t& member_nodes, const string& name, const member_nodes_t& member_nodes, const string& name,
const string& computerName, const string& port, const string& computerName, const string& port,
int minCpuNbr, int maxCpuNbr, const string& userName, int minCpuNbr, int maxCpuNbr, const string& userName,
const string& password, const string& remoteDrive, const string& password, const string& remoteDrive,
const string& remoteDirectory, const string& programPath, const string& remoteDirectory, const string& programPath,
const string& programConfig, const string& matlabOctavePath, const string& programConfig,
bool singleCompThread, int numberOfThreadsPerJob, const string& matlabOctavePath, bool singleCompThread,
const string& operatingSystem) int numberOfThreadsPerJob, const string& operatingSystem)
{ {
//! ADD NODE //! ADD NODE
if (inNode) if (inNode)
@ -546,7 +546,7 @@ ConfigFile::addParallelConfFileElement(bool inNode, bool inCluster,
} }
void void
ConfigFile::checkPass([[maybe_unused]] WarningConsolidation& warnings) const Configuration::checkPass([[maybe_unused]] WarningConsolidation& warnings) const
{ {
for (bool global_init_file_declared {false}; const auto& hook : hooks) for (bool global_init_file_declared {false}; const auto& hook : hooks)
for (const auto& mapit : hook.get_hooks()) for (const auto& mapit : hook.get_hooks())
@ -684,7 +684,7 @@ ConfigFile::checkPass([[maybe_unused]] WarningConsolidation& warnings) const
} }
void void
ConfigFile::transformPass() Configuration::transformPass()
{ {
if (!parallel && !parallel_test) if (!parallel && !parallel_test)
return; return;
@ -711,7 +711,7 @@ ConfigFile::transformPass()
} }
vector<filesystem::path> vector<filesystem::path>
ConfigFile::getIncludePaths() const Configuration::getIncludePaths() const
{ {
vector<filesystem::path> include_paths; vector<filesystem::path> include_paths;
for (auto path : paths) for (auto path : paths)
@ -722,7 +722,7 @@ ConfigFile::getIncludePaths() const
} }
void void
ConfigFile::writeHooks(ostream& output) const Configuration::writeHooks(ostream& output) const
{ {
for (auto hook : hooks) for (auto hook : hooks)
for (const auto& mapit : hook.get_hooks()) for (const auto& mapit : hook.get_hooks())
@ -730,7 +730,7 @@ ConfigFile::writeHooks(ostream& output) const
} }
void void
ConfigFile::writeCluster(ostream& output) const Configuration::writeCluster(ostream& output) const
{ {
if (!parallel && !parallel_test) if (!parallel && !parallel_test)
return; return;
@ -804,7 +804,7 @@ ConfigFile::writeCluster(ostream& output) const
} }
void void
ConfigFile::writeEndParallel(ostream& output) const Configuration::writeEndParallel(ostream& output) const
{ {
if ((!parallel && !parallel_test) || !parallel_follower_open_mode) if ((!parallel && !parallel_test) || !parallel_follower_open_mode)
return; return;

View File

@ -17,8 +17,8 @@
* along with Dynare. If not, see <https://www.gnu.org/licenses/>. * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef CONFIG_FILE_HH #ifndef CONFIGURATION_HH
#define CONFIG_FILE_HH #define CONFIGURATION_HH
#include <filesystem> #include <filesystem>
#include <map> #include <map>
@ -64,7 +64,7 @@ public:
class FollowerNode class FollowerNode
{ {
friend class ConfigFile; friend class Configuration;
public: public:
FollowerNode(string computerName_arg, string port_arg, int minCpuNbr_arg, int maxCpuNbr_arg, FollowerNode(string computerName_arg, string port_arg, int minCpuNbr_arg, int maxCpuNbr_arg,
@ -86,7 +86,7 @@ protected:
class Cluster class Cluster
{ {
friend class ConfigFile; friend class Configuration;
public: public:
explicit Cluster(member_nodes_t member_nodes_arg); explicit Cluster(member_nodes_t member_nodes_arg);
@ -95,12 +95,13 @@ protected:
member_nodes_t member_nodes; member_nodes_t member_nodes;
}; };
//! The abstract representation of a "config" file /* The abstract representation of the configuration.
class ConfigFile Merges information from the command-line and from the configuration file. */
class Configuration
{ {
public: public:
ConfigFile(bool parallel_arg, bool parallel_test_arg, bool parallel_follower_open_mode_arg, Configuration(bool parallel_arg, bool parallel_test_arg, bool parallel_follower_open_mode_arg,
bool parallel_use_psexec_arg, string cluster_name); bool parallel_use_psexec_arg, string cluster_name);
private: private:
const bool parallel, parallel_test, parallel_follower_open_mode, parallel_use_psexec; const bool parallel, parallel_test, parallel_follower_open_mode, parallel_use_psexec;
@ -130,7 +131,7 @@ private:
public: public:
//! Parse config file //! Parse config file
void getConfigFileInfo(const filesystem::path& parallel_config_file); void getConfigFileInfo(const filesystem::path& conffile_option);
//! Check Pass //! Check Pass
void checkPass(WarningConsolidation& warnings) const; void checkPass(WarningConsolidation& warnings) const;
//! Check Pass //! Check Pass

View File

@ -31,7 +31,7 @@
#include <unistd.h> #include <unistd.h>
#include "ConfigFile.hh" #include "Configuration.hh"
#include "ExtendedPreprocessorTypes.hh" #include "ExtendedPreprocessorTypes.hh"
#include "ModFile.hh" #include "ModFile.hh"
#include "ParsingDriver.hh" #include "ParsingDriver.hh"
@ -53,7 +53,7 @@ usage()
cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] " cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] "
"[savemacro[=macro_file]] [onlymacro] [linemacro] [notmpterms] [nolog] [warn_uninit]" "[savemacro[=macro_file]] [onlymacro] [linemacro] [notmpterms] [nolog] [warn_uninit]"
<< " [console] [nograph] [nointeractive] [parallel[=cluster_name]] " << " [console] [nograph] [nointeractive] [parallel[=cluster_name]] "
"[conffile=parallel_config_path_and_filename] [parallel_follower_open_mode] " "[conffile=path_to_config_file] [parallel_follower_open_mode] "
"[parallel_test] [parallel_use_psexec=true|false]" "[parallel_test] [parallel_use_psexec=true|false]"
<< " [-D<variable>[=<value>]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] " << " [-D<variable>[=<value>]] [-I/path] [nostrict] [stochastic] [fast] [minimal_workspace] "
"[compute_xrefs] [output=second|third] [language=matlab|julia]" "[compute_xrefs] [output=second|third] [language=matlab|julia]"
@ -142,7 +142,7 @@ main(int argc, char** argv)
bool console = false; bool console = false;
bool nograph = false; bool nograph = false;
bool nointeractive = false; bool nointeractive = false;
filesystem::path parallel_config_file; filesystem::path conffile;
bool parallel = false; bool parallel = false;
string cluster_name; string cluster_name;
bool parallel_follower_open_mode bool parallel_follower_open_mode
@ -234,7 +234,7 @@ main(int argc, char** argv)
cerr << "Incorrect syntax for conffile option" << endl; cerr << "Incorrect syntax for conffile option" << endl;
usage(); usage();
} }
parallel_config_file = s.substr(9); conffile = s.substr(9);
} }
else if (s == "parallel_follower_open_mode" else if (s == "parallel_follower_open_mode"
|| s == "parallel_slave_open_mode") // Kept for backward compatibility, see #86 || s == "parallel_slave_open_mode") // Kept for backward compatibility, see #86
@ -461,15 +461,15 @@ main(int argc, char** argv)
WarningConsolidation warnings(no_warn); WarningConsolidation warnings(no_warn);
// Process config file // Process config file
ConfigFile config_file(parallel, parallel_test, parallel_follower_open_mode, parallel_use_psexec, Configuration config {parallel, parallel_test, parallel_follower_open_mode, parallel_use_psexec,
cluster_name); cluster_name};
config_file.getConfigFileInfo(parallel_config_file); config.getConfigFileInfo(conffile);
config_file.checkPass(warnings); config.checkPass(warnings);
config_file.transformPass(); config.transformPass();
// If Include option was passed to the [paths] block of the config file, add // If Include option was passed to the [paths] block of the config file, add
// it to paths before macroprocessing // it to paths before macroprocessing
for (const auto& it : config_file.getIncludePaths()) for (const auto& it : config.getIncludePaths())
paths.emplace_back(it); paths.emplace_back(it);
/* /*
@ -540,7 +540,7 @@ main(int argc, char** argv)
mod_file->writeJuliaOutput(basename); mod_file->writeJuliaOutput(basename);
else else
mod_file->writeMOutput(basename, clear_all, clear_global, no_warn, console, nograph, mod_file->writeMOutput(basename, clear_all, clear_global, no_warn, console, nograph,
nointeractive, config_file, check_model_changes, minimal_workspace, nointeractive, config, check_model_changes, minimal_workspace,
compute_xrefs, mexext, matlabroot, onlymodel, gui, notime); compute_xrefs, mexext, matlabroot, onlymodel, gui, notime);
/* Ensures that workers are not destroyed before they finish compiling. /* Ensures that workers are not destroyed before they finish compiling.

View File

@ -27,7 +27,6 @@
#include <filesystem> #include <filesystem>
#include "ComputingTasks.hh" #include "ComputingTasks.hh"
#include "ConfigFile.hh"
#include "ModFile.hh" #include "ModFile.hh"
#include "Shocks.hh" #include "Shocks.hh"
@ -843,7 +842,7 @@ ModFile::remove_directory_with_matlab_lock(const filesystem::path& dir)
void void
ModFile::writeMOutput(const string& basename, bool clear_all, bool clear_global, bool no_warn, ModFile::writeMOutput(const string& basename, bool clear_all, bool clear_global, bool no_warn,
bool console, bool nograph, bool nointeractive, const ConfigFile& config_file, bool console, bool nograph, bool nointeractive, const Configuration& config,
bool check_model_changes, bool minimal_workspace, bool compute_xrefs, bool check_model_changes, bool minimal_workspace, bool compute_xrefs,
const string& mexext, const filesystem::path& matlabroot, bool onlymodel, const string& mexext, const filesystem::path& matlabroot, bool onlymodel,
bool gui, bool notime) const bool gui, bool notime) const
@ -916,7 +915,7 @@ ModFile::writeMOutput(const string& basename, bool clear_all, bool clear_global,
<< "% Some global variables initialization" << endl << "% Some global variables initialization" << endl
<< "%" << endl; << "%" << endl;
if (!onlymodel) if (!onlymodel)
config_file.writeHooks(mOutputFile); config.writeHooks(mOutputFile);
mOutputFile << "global_initialization;" << endl; mOutputFile << "global_initialization;" << endl;
if (minimal_workspace) if (minimal_workspace)
@ -1002,7 +1001,7 @@ ModFile::writeMOutput(const string& basename, bool clear_all, bool clear_global,
} }
if (!onlymodel) if (!onlymodel)
config_file.writeCluster(mOutputFile); config.writeCluster(mOutputFile);
if (bytecode) if (bytecode)
mOutputFile << "if exist('bytecode') ~= 3" << endl mOutputFile << "if exist('bytecode') ~= 3" << endl
@ -1131,7 +1130,7 @@ ModFile::writeMOutput(const string& basename, bool clear_all, bool clear_global,
<< "_results.mat'], 'options_mom_', '-append');" << endl << "_results.mat'], 'options_mom_', '-append');" << endl
<< "end" << endl; << "end" << endl;
config_file.writeEndParallel(mOutputFile); config.writeEndParallel(mOutputFile);
if (!no_warn) if (!no_warn)
{ {

View File

@ -26,7 +26,7 @@
#include <ostream> #include <ostream>
#include <sstream> #include <sstream>
#include "ConfigFile.hh" #include "Configuration.hh"
#include "DynamicModel.hh" #include "DynamicModel.hh"
#include "ExtendedPreprocessorTypes.hh" #include "ExtendedPreprocessorTypes.hh"
#include "ExternalFunctionsTable.hh" #include "ExternalFunctionsTable.hh"
@ -176,7 +176,7 @@ public:
\param compute_xrefs if true, equation cross references will be computed \param compute_xrefs if true, equation cross references will be computed
*/ */
void writeMOutput(const string& basename, bool clear_all, bool clear_global, bool no_warn, void writeMOutput(const string& basename, bool clear_all, bool clear_global, bool no_warn,
bool console, bool nograph, bool nointeractive, const ConfigFile& config_file, bool console, bool nograph, bool nointeractive, const Configuration& config,
bool check_model_changes, bool minimal_workspace, bool compute_xrefs, bool check_model_changes, bool minimal_workspace, bool compute_xrefs,
const string& mexext, const filesystem::path& matlabroot, bool onlymodel, const string& mexext, const filesystem::path& matlabroot, bool onlymodel,
bool gui, bool notime) const; bool gui, bool notime) const;

View File

@ -42,7 +42,7 @@ preprocessor_src = [ 'ComputingTasks.cc',
'ParsingDriver.cc', 'ParsingDriver.cc',
'DataTree.cc', 'DataTree.cc',
'ModFile.cc', 'ModFile.cc',
'ConfigFile.cc', 'Configuration.cc',
'Statement.cc', 'Statement.cc',
'ExprNode.cc', 'ExprNode.cc',
'VariableDependencyGraph.cc', 'VariableDependencyGraph.cc',