Commits (5)
......@@ -25,7 +25,7 @@ AM_INIT_AUTOMAKE([1.11 -Wall -Wno-portability foreign no-dist-gzip dist-xz tar-p
AC_PROG_CC
AC_PROG_CXX
AX_CXX_COMPILE_STDCXX_14
AX_CXX_COMPILE_STDCXX_17
AC_CANONICAL_HOST
case ${host_os} in
......@@ -66,8 +66,6 @@ fi
# We need 1.36 because of unordered_{set,hash} used by Dynare++
AX_BOOST_BASE([1.36], [], [AC_MSG_ERROR([Can't find Boost >= 1.36])])
AX_BOOST_SYSTEM
AX_BOOST_FILESYSTEM
CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
......
......@@ -27,14 +27,15 @@ Copyright: 2008-2009 Thomas Porschberg <thomas@randspringer.de>
License: FSFAP
Files: m4/ax_cxx_compile_stdcxx.m4
m4/ax_cxx_compile_stdcxx_14.m4
m4/ax_cxx_compile_stdcxx_17.m4
Copyright: 2008 Benjamin Kosnik <bkoz@redhat.com>
2012 Zack Weinberg <zackw@panix.com>
2013 Roy Stogner <roystgnr@ices.utexas.edu>
2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
2015 Paul Norman <penorman@mac.com>
2015 Moritz Klammler <moritz@klammler.eu>
2016 Krzesimir Nowak <qdlacz@gmail.com>
2016, 2018 Krzesimir Nowak <qdlacz@gmail.com>
2019 Enji Cooper <yaneurabeya@gmail.com>
License: FSFAP
Files: m4/ax_latex_class.m4 m4/ax_tex_test.m4
......
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_boost_filesystem.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_BOOST_FILESYSTEM
#
# DESCRIPTION
#
# Test for Filesystem library from the Boost C++ libraries. The macro
# requires a preceding call to AX_BOOST_BASE. Further documentation is
# available at <http://randspringer.de/boost/index.html>.
#
# This macro calls:
#
# AC_SUBST(BOOST_FILESYSTEM_LIB)
#
# And sets:
#
# HAVE_BOOST_FILESYSTEM
#
# LICENSE
#
# Copyright (c) 2009 Thomas Porschberg <thomas@randspringer.de>
# Copyright (c) 2009 Michael Tindal
# Copyright (c) 2009 Roman Rybalko <libtorrent@romanr.info>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 27
AC_DEFUN([AX_BOOST_FILESYSTEM],
[
AC_ARG_WITH([boost-filesystem],
AS_HELP_STRING([--with-boost-filesystem@<:@=special-lib@:>@],
[use the Filesystem library from boost - it is possible to specify a certain library for the linker
e.g. --with-boost-filesystem=boost_filesystem-gcc-mt ]),
[
if test "$withval" = "no"; then
want_boost="no"
elif test "$withval" = "yes"; then
want_boost="yes"
ax_boost_user_filesystem_lib=""
else
want_boost="yes"
ax_boost_user_filesystem_lib="$withval"
fi
],
[want_boost="yes"]
)
if test "x$want_boost" = "xyes"; then
AC_REQUIRE([AC_PROG_CC])
CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
export CPPFLAGS
LDFLAGS_SAVED="$LDFLAGS"
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
export LDFLAGS
LIBS_SAVED=$LIBS
LIBS="$LIBS $BOOST_SYSTEM_LIB"
export LIBS
AC_CACHE_CHECK(whether the Boost::Filesystem library is available,
ax_cv_boost_filesystem,
[AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <boost/filesystem/path.hpp>]],
[[using namespace boost::filesystem;
path my_path( "foo/bar/data.txt" );
return 0;]])],
ax_cv_boost_filesystem=yes, ax_cv_boost_filesystem=no)
AC_LANG_POP([C++])
])
if test "x$ax_cv_boost_filesystem" = "xyes"; then
AC_DEFINE(HAVE_BOOST_FILESYSTEM,,[define if the Boost::Filesystem library is available])
BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
if test "x$ax_boost_user_filesystem_lib" = "x"; then
for libextension in `ls -r $BOOSTLIBDIR/libboost_filesystem* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'` ; do
ax_lib=${libextension}
AC_CHECK_LIB($ax_lib, exit,
[BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break],
[link_filesystem="no"])
done
if test "x$link_filesystem" != "xyes"; then
for libextension in `ls -r $BOOSTLIBDIR/boost_filesystem* 2>/dev/null | sed 's,.*/,,' | sed -e 's,\..*,,'` ; do
ax_lib=${libextension}
AC_CHECK_LIB($ax_lib, exit,
[BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break],
[link_filesystem="no"])
done
fi
else
for ax_lib in $ax_boost_user_filesystem_lib boost_filesystem-$ax_boost_user_filesystem_lib; do
AC_CHECK_LIB($ax_lib, exit,
[BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break],
[link_filesystem="no"])
done
fi
if test "x$ax_lib" = "x"; then
AC_MSG_ERROR(Could not find a version of the library!)
fi
if test "x$link_filesystem" != "xyes"; then
AC_MSG_ERROR(Could not link against $ax_lib !)
fi
fi
CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVED"
LIBS="$LIBS_SAVED"
fi
])
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_boost_system.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_BOOST_SYSTEM
#
# DESCRIPTION
#
# Test for System library from the Boost C++ libraries. The macro requires
# a preceding call to AX_BOOST_BASE. Further documentation is available at
# <http://randspringer.de/boost/index.html>.
#
# This macro calls:
#
# AC_SUBST(BOOST_SYSTEM_LIB)
#
# And sets:
#
# HAVE_BOOST_SYSTEM
#
# LICENSE
#
# Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
# Copyright (c) 2008 Michael Tindal
# Copyright (c) 2008 Daniel Casimiro <dan.casimiro@gmail.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 19
AC_DEFUN([AX_BOOST_SYSTEM],
[
AC_ARG_WITH([boost-system],
AS_HELP_STRING([--with-boost-system@<:@=special-lib@:>@],
[use the System library from boost - it is possible to specify a certain library for the linker
e.g. --with-boost-system=boost_system-gcc-mt ]),
[
if test "$withval" = "no"; then
want_boost="no"
elif test "$withval" = "yes"; then
want_boost="yes"
ax_boost_user_system_lib=""
else
want_boost="yes"
ax_boost_user_system_lib="$withval"
fi
],
[want_boost="yes"]
)
if test "x$want_boost" = "xyes"; then
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_BUILD])
CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
export CPPFLAGS
LDFLAGS_SAVED="$LDFLAGS"
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
export LDFLAGS
AC_CACHE_CHECK(whether the Boost::System library is available,
ax_cv_boost_system,
[AC_LANG_PUSH([C++])
CXXFLAGS_SAVE=$CXXFLAGS
CXXFLAGS=
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[@%:@include <boost/system/error_code.hpp>]],
[[boost::system::error_category *a = 0;]])],
ax_cv_boost_system=yes, ax_cv_boost_system=no)
CXXFLAGS=$CXXFLAGS_SAVE
AC_LANG_POP([C++])
])
if test "x$ax_cv_boost_system" = "xyes"; then
AC_SUBST(BOOST_CPPFLAGS)
AC_DEFINE(HAVE_BOOST_SYSTEM,,[define if the Boost::System library is available])
BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
LDFLAGS_SAVE=$LDFLAGS
if test "x$ax_boost_user_system_lib" = "x"; then
for libextension in `ls -r $BOOSTLIBDIR/libboost_system* 2>/dev/null | sed 's,.*/lib,,' | sed 's,\..*,,'` ; do
ax_lib=${libextension}
AC_CHECK_LIB($ax_lib, exit,
[BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break],
[link_system="no"])
done
if test "x$link_system" != "xyes"; then
for libextension in `ls -r $BOOSTLIBDIR/boost_system* 2>/dev/null | sed 's,.*/,,' | sed -e 's,\..*,,'` ; do
ax_lib=${libextension}
AC_CHECK_LIB($ax_lib, exit,
[BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break],
[link_system="no"])
done
fi
else
for ax_lib in $ax_boost_user_system_lib boost_system-$ax_boost_user_system_lib; do
AC_CHECK_LIB($ax_lib, exit,
[BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break],
[link_system="no"])
done
fi
if test "x$ax_lib" = "x"; then
AC_MSG_ERROR(Could not find a version of the library!)
fi
if test "x$link_system" = "xno"; then
AC_MSG_ERROR(Could not link against $ax_lib !)
fi
fi
CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVED"
fi
])
......@@ -33,19 +33,19 @@
# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
# Copyright (c) 2015 Paul Norman <penorman@mac.com>
# Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
# Copyright (c) 2016 Krzesimir Nowak <qdlacz@gmail.com>
# Copyright (c) 2016, 2018 Krzesimir Nowak <qdlacz@gmail.com>
# Copyright (c) 2019 Enji Cooper <yaneurabeya@gmail.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 7
#serial 11
dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
dnl (serial version number 13).
AX_REQUIRE_DEFINED([AC_MSG_WARN])
AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"],
[$1], [14], [ax_cxx_compile_alternatives="14 1y"],
......@@ -61,14 +61,6 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
[m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])])
AC_LANG_PUSH([C++])dnl
ac_success=no
AC_CACHE_CHECK(whether $CXX supports C++$1 features by default,
ax_cv_cxx_compile_cxx$1,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
[ax_cv_cxx_compile_cxx$1=yes],
[ax_cv_cxx_compile_cxx$1=no])])
if test x$ax_cv_cxx_compile_cxx$1 = xyes; then
ac_success=yes
fi
m4_if([$2], [noext], [], [dnl
if test x$ac_success = xno; then
......@@ -139,7 +131,6 @@ AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl
[define if the compiler supports basic C++$1 syntax])
fi
AC_SUBST(HAVE_CXX$1)
m4_if([$1], [17], [AC_MSG_WARN([C++17 is not yet standardized, so the checks may change in incompatible ways anytime])])
])
......@@ -199,11 +190,13 @@ namespace cxx11
struct Base
{
virtual ~Base() {}
virtual void f() {}
};
struct Derived : public Base
{
virtual ~Derived() override {}
virtual void f() override {}
};
......@@ -587,20 +580,12 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
#error "This is not a C++ compiler"
#elif __cplusplus <= 201402L
#elif __cplusplus < 201703L
#error "This is not a C++17 compiler"
#else
#if defined(__clang__)
#define REALLY_CLANG
#else
#if defined(__GNUC__)
#define REALLY_GCC
#endif
#endif
#include <initializer_list>
#include <utility>
#include <type_traits>
......@@ -608,16 +593,12 @@ m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[
namespace cxx17
{
#if !defined(REALLY_CLANG)
namespace test_constexpr_lambdas
{
// TODO: test it with clang++ from git
constexpr int foo = [](){return 42;}();
}
#endif // !defined(REALLY_CLANG)
namespace test::nested_namespace::definitions
{
......@@ -852,12 +833,9 @@ namespace cxx17
}
#if !defined(REALLY_CLANG)
namespace test_template_argument_deduction_for_class_templates
{
// TODO: test it with clang++ from git
template <typename T1, typename T2>
struct pair
{
......@@ -876,7 +854,6 @@ namespace cxx17
}
}
#endif // !defined(REALLY_CLANG)
namespace test_non_type_auto_template_parameters
{
......@@ -890,12 +867,9 @@ namespace cxx17
}
#if !defined(REALLY_CLANG)
namespace test_structured_bindings
{
// TODO: test it with clang++ from git
int arr[2] = { 1, 2 };
std::pair<int, int> pr = { 1, 2 };
......@@ -927,14 +901,10 @@ namespace cxx17
const auto [ x3, y3 ] = f3();
}
#endif // !defined(REALLY_CLANG)
#if !defined(REALLY_CLANG)
namespace test_exception_spec_type_system
{
// TODO: test it with clang++ from git
struct Good {};
struct Bad {};
......@@ -952,7 +922,6 @@ namespace cxx17
static_assert (std::is_same_v<Good, decltype(f(g1, g2))>);
}
#endif // !defined(REALLY_CLANG)
namespace test_inline_variables
{
......@@ -977,6 +946,6 @@ namespace cxx17
} // namespace cxx17
#endif // __cplusplus <= 201402L
#endif // __cplusplus < 201703L
]])
# =============================================================================
# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_14.html
# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_17.html
# =============================================================================
#
# SYNOPSIS
#
# AX_CXX_COMPILE_STDCXX_14([ext|noext], [mandatory|optional])
# AX_CXX_COMPILE_STDCXX_17([ext|noext], [mandatory|optional])
#
# DESCRIPTION
#
# Check for baseline language coverage in the compiler for the C++14
# Check for baseline language coverage in the compiler for the C++17
# standard; if necessary, add switches to CXX and CXXCPP to enable
# support.
#
# This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX
# macro with the version set to C++14. The two optional arguments are
# macro with the version set to C++17. The two optional arguments are
# forwarded literally as the second and third argument respectively.
# Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for
# more information. If you want to use this macro, you also need to
......@@ -22,13 +22,14 @@
# LICENSE
#
# Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
# Copyright (c) 2016 Krzesimir Nowak <qdlacz@gmail.com>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 5
#serial 2
AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX])
AC_DEFUN([AX_CXX_COMPILE_STDCXX_14], [AX_CXX_COMPILE_STDCXX([14], [$1], [$2])])
AC_DEFUN([AX_CXX_COMPILE_STDCXX_17], [AX_CXX_COMPILE_STDCXX([17], [$1], [$2])])
......@@ -645,6 +645,8 @@ StochSimulStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli
<< endl;
exit(EXIT_FAILURE);
}
symbol_list.removeDuplicates("stoch_simul", warnings);
}
void
......
......@@ -124,7 +124,7 @@ public:
class StochSimulStatement : public Statement
{
private:
const SymbolList symbol_list;
SymbolList symbol_list;
const OptionsList options_list;
public:
StochSimulStatement(SymbolList symbol_list_arg,
......
......@@ -22,10 +22,7 @@
#include <iostream>
#include <regex>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#include <boost/filesystem.hpp>
#pragma GCC diagnostic pop
#include <filesystem>
#include "DataTree.hh"
......@@ -765,6 +762,20 @@ DataTree::isUnaryOpUsed(UnaryOpcode opcode) const
return false;
}
bool
DataTree::isUnaryOpUsedOnType(SymbolType type, UnaryOpcode opcode) const
{
set<int> var;
for (const auto & it : unary_op_node_map)
if (get<1>(it.first) == opcode)
{
it.second->collectVariables(type, var);
if (!var.empty())
return true;
}
return false;
}
bool
DataTree::isBinaryOpUsed(BinaryOpcode opcode) const
{
......@@ -775,6 +786,20 @@ DataTree::isBinaryOpUsed(BinaryOpcode opcode) const
return false;
}
bool
DataTree::isBinaryOpUsedOnType(SymbolType type, BinaryOpcode opcode) const
{
set<int> var;
for (const auto & it : binary_op_node_map)
if (get<2>(it.first) == opcode)
{
it.second->collectVariables(type, var);
if (!var.empty())
return true;
}
return false;
}
bool
DataTree::isTrinaryOpUsed(TrinaryOpcode opcode) const
{
......@@ -862,6 +887,6 @@ DataTree::packageDir(const string &package)
{
regex pat{R"(\.)"};
string dirname = "+" + regex_replace(package, pat, "/+");
boost::filesystem::create_directories(dirname);
filesystem::create_directories(dirname);
return dirname;
}
/*
* Copyright © 2003-2018 Dynare Team
* Copyright © 2003-2019 Dynare Team
*
* This file is part of Dynare.
*
......@@ -261,8 +261,12 @@ public:
bool isSymbolUsed(int symb_id) const;
//! Checks if a given unary op is used somewhere in the data tree
bool isUnaryOpUsed(UnaryOpcode opcode) const;
//! Checks if a given unary op is used somewhere in the data tree on an endogenous variable
bool isUnaryOpUsedOnType(SymbolType type, UnaryOpcode opcode) const;
//! Checks if a given binary op is used somewhere in the data tree
bool isBinaryOpUsed(BinaryOpcode opcode) const;
//! Checks if a given binary op is used somewhere in the data tree on an endogenous variable
bool isBinaryOpUsedOnType(SymbolType type, BinaryOpcode opcode) const;
//! Checks if a given trinary op is used somewhere in the data tree
bool isTrinaryOpUsed(TrinaryOpcode opcode) const;
//! Checks if a given external function is used somewhere in the data tree
......
......@@ -965,7 +965,7 @@ DynamicModel::writeModelEquationsCode(const string &basename, const map_idx_t &m
unsigned int instruction_number = 0;
bool file_open = false;
boost::filesystem::create_directories(basename + "/model/bytecode");
filesystem::create_directories(basename + "/model/bytecode");
string main_name = basename + "/model/bytecode/dynamic.cod";
code_file.open(main_name, ios::out | ios::binary | ios::ate);
......@@ -1233,7 +1233,7 @@ DynamicModel::writeModelEquationsCode_Block(const string &basename, const map_id
vector<int> feedback_variables;
bool file_open = false;
string main_name;
boost::filesystem::create_directories(basename + "/model/bytecode");
filesystem::create_directories(basename + "/model/bytecode");
if (linear_decomposition)
main_name = basename + "/model/bytecode/non_linear.cod";
else
......@@ -1692,7 +1692,7 @@ DynamicModel::writeDynamicJuliaFile(const string &basename) const
void
DynamicModel::writeDynamicCFile(const string &basename, const int order) const
{
boost::filesystem::create_directories(basename + "/model/src");
filesystem::create_directories(basename + "/model/src");
string filename = basename + "/model/src/dynamic.c";
string filename_mex = basename + "/model/src/dynamic_mex.c";
ofstream mDynamicModelFile, mDynamicMexFile;
......@@ -2955,7 +2955,29 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de
outstruct = "oo_.";
}
output << modstruct << "orig_maximum_endo_lag = " << max_endo_lag_orig << ";" << endl
if (max_endo_lag_by_var.size() != symbol_table.orig_endo_nbr())
{
cerr << "ERROR: the number of endogenous variables found in the model block"
<< " is not equal to the number declared" << endl;
exit(EXIT_FAILURE);
}
if (max_exo_lag_by_var.size() != symbol_table.exo_nbr())
{
cerr << "ERROR: the number of exogenous variables found in the model block"
<< " is not equal to the number declared" << endl;
exit(EXIT_FAILURE);
}
output << modstruct << "max_endo_lag_by_var = [";
for (const auto & it : max_endo_lag_by_var)
output << it.second << " ";
output << "];" << endl
<< modstruct << "max_exo_lag_by_var = [";
for (const auto & it : max_exo_lag_by_var)
output << it.second << " ";
output << "];" << endl
<< modstruct << "orig_maximum_endo_lag = " << max_endo_lag_orig << ";" << endl
<< modstruct << "orig_maximum_endo_lead = " << max_endo_lead_orig << ";" << endl
<< modstruct << "orig_maximum_exo_lag = " << max_exo_lag_orig << ";" << endl
<< modstruct << "orig_maximum_exo_lead = " << max_exo_lead_orig << ";" << endl
......@@ -3356,7 +3378,7 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de
if (estimation_present)
{
ofstream KF_index_file;
boost::filesystem::create_directories(basename + "/model/bytecode");
filesystem::create_directories(basename + "/model/bytecode");
string main_name = basename + "/model/bytecode/kfi";
KF_index_file.open(main_name, ios::out | ios::binary | ios::ate);
int n_obs = symbol_table.observedVariablesNbr();
......@@ -5321,7 +5343,7 @@ DynamicModel::collectBlockVariables()
}
void
DynamicModel::writeDynamicFile(const string &basename, bool block, bool linear_decomposition, bool bytecode, bool use_dll, const string &mexext, const boost::filesystem::path &matlabroot, const boost::filesystem::path &dynareroot, int order, bool julia) const
DynamicModel::writeDynamicFile(const string &basename, bool block, bool linear_decomposition, bool bytecode, bool use_dll, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot, int order, bool julia) const
{
if (block && bytecode)
writeModelEquationsCode_Block(basename, map_idx, linear_decomposition);
......@@ -5546,21 +5568,35 @@ DynamicModel::setLeadsLagsOrig()
for (const auto & dynvar : dynvars)
{
int lag = dynvar.second;
SymbolType type = symbol_table.getType(dynvar.first);
max_lead_orig = max(lag, max_lead_orig);
max_lag_orig = max(-lag, max_lag_orig);
switch (type)
switch (symbol_table.getType(dynvar.first))
{
case SymbolType::endogenous:
max_endo_lead_orig = max(lag, max_endo_lead_orig);
max_endo_lag_orig = max(-lag, max_endo_lag_orig);
break;
{
max_endo_lead_orig = max(lag, max_endo_lead_orig);
max_endo_lag_orig = max(-lag, max_endo_lag_orig);
auto var = max_endo_lag_by_var.find(dynvar.first);
if (var != max_endo_lag_by_var.end())
max_endo_lag_by_var[dynvar.first] = max(0, lag);
else
max_endo_lag_by_var[dynvar.first] = max(var->second, lag);
break;
}
case SymbolType::exogenous:
max_exo_lead_orig = max(lag, max_exo_lead_orig);
max_exo_lag_orig = max(-lag, max_exo_lag_orig);
break;
{
max_exo_lead_orig = max(lag, max_exo_lead_orig);
max_exo_lag_orig = max(-lag, max_exo_lag_orig);
auto var = max_exo_lag_by_var.find(dynvar.first);
if (var != max_exo_lag_by_var.end())
max_exo_lag_by_var[dynvar.first] = max(0, lag);
else
max_exo_lag_by_var[dynvar.first] = max(var->second, lag);
break;
}
case SymbolType::exogenousDet:
max_exo_det_lead_orig = max(lag, max_exo_det_lead_orig);
max_exo_det_lag_orig = max(-lag, max_exo_det_lag_orig);
......@@ -6666,7 +6702,7 @@ DynamicModel::isChecksumMatching(const string &basename, bool block) const
result.process_bytes(private_buffer, strlen(private_buffer));
}
bool basename_dir_exists = !boost::filesystem::create_directory(basename);
bool basename_dir_exists = !filesystem::create_directory(basename);
// check whether basename directory exist. If not, create it.
// If it does, read old checksum if it exist
......
......@@ -23,10 +23,10 @@
using namespace std;
#include <fstream>
#include <filesystem>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#include <boost/filesystem.hpp>
#include <boost/crc.hpp>
#pragma GCC diagnostic pop
......@@ -84,6 +84,9 @@ private:
//! Maximum lag and lead over deterministic exogenous variables (positive values) of original model
int max_exo_det_lag_orig{0}, max_exo_det_lead_orig{0};
//! Max lags by symb_id
map<int, int> max_endo_lag_by_var, max_exo_lag_by_var;
//! Cross reference information
map<int, ExprNode::EquationInfo> xrefs;
map<pair<int, int>, set<int>> xref_param;
......@@ -362,7 +365,7 @@ public:
void Write_Inf_To_Bin_File_Block(const string &basename,
const int &num, int &u_count_int, bool &file_open, bool is_two_boundaries, const bool linear_decomposition) const;
//! Writes dynamic model file
void writeDynamicFile(const string &basename, bool block, bool linear_decomposition, bool bytecode, bool use_dll, const string &mexext, const boost::filesystem::path &matlabroot, const boost::filesystem::path &dynareroot, int order, bool julia) const;
void writeDynamicFile(const string &basename, bool block, bool linear_decomposition, bool bytecode, bool use_dll, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot, int order, bool julia) const;
//! Writes file containing parameters derivatives
void writeParamsDerivativesFile(const string &basename, bool julia) const;
......
......@@ -23,6 +23,7 @@
#include <vector>
#include <string>
#include <regex>
#include <filesystem>
#include <cstdlib>
......@@ -32,11 +33,6 @@
#include <unistd.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#include <boost/filesystem.hpp>
#pragma GCC diagnostic pop
#include "ParsingDriver.hh"
#include "ExtendedPreprocessorTypes.hh"
#include "ConfigFile.hh"
......@@ -52,8 +48,8 @@ void main2(stringstream &in, const string &basename, bool debug, bool clear_all,
bool minimal_workspace, bool compute_xrefs, FileOutputType output_mode,
LanguageOutputType lang, int params_derivs_order, bool transform_unary_ops,
JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple,
const string &mexext, const boost::filesystem::path &matlabroot,
const boost::filesystem::path &dynareroot, bool onlymodel);
const string &mexext, const filesystem::path &matlabroot,
const filesystem::path &dynareroot, bool onlymodel);
void main1(const string &filename, const string &basename, istream &modfile, bool debug, bool save_macro, string &save_macro_file,
bool no_line_macro, bool no_empty_line_macro, const vector<pair<string, string>> &defines, const vector<string> &path, stringstream &macro_output);
......@@ -167,8 +163,8 @@ main(int argc, char **argv)
bool jsonderivsimple = false;
LanguageOutputType language{LanguageOutputType::matlab};
string mexext;
boost::filesystem::path matlabroot;
boost::filesystem::path dynareroot{argv[0]};
filesystem::path matlabroot;
filesystem::path dynareroot{argv[0]};
dynareroot = dynareroot.parent_path();
dynareroot = dynareroot / ".." / "..";
bool onlymodel = false;
......@@ -382,7 +378,7 @@ main(int argc, char **argv)
cerr << "Incorrect syntax for matlabroot option" << endl;
usage();
}
matlabroot = boost::filesystem::path{s.substr(11)};
matlabroot = filesystem::path{s.substr(11)};
}
else if (s == "onlymodel")
onlymodel = true;
......
......@@ -18,11 +18,7 @@
*/
#include <iostream>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#include <boost/filesystem.hpp>
#pragma GCC diagnostic pop
#include <filesystem>
#include "ParsingDriver.hh"
#include "ModFile.hh"
......@@ -37,12 +33,12 @@ main2(stringstream &in, const string &basename, bool debug, bool clear_all, bool
bool minimal_workspace, bool compute_xrefs, FileOutputType output_mode,
LanguageOutputType language, int params_derivs_order, bool transform_unary_ops,
JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple,
const string &mexext, const boost::filesystem::path &matlabroot,
const boost::filesystem::path &dynareroot, bool onlymodel)
const string &mexext, const filesystem::path &matlabroot,
const filesystem::path &dynareroot, bool onlymodel)
{
ParsingDriver p(warnings, nostrict);
boost::filesystem::remove_all(basename + "/model/json");
filesystem::remove_all(basename + "/model/json");
// Do parsing and construct internal representation of mod file
unique_ptr<ModFile> mod_file = p.parse(in, debug);
......
......@@ -66,7 +66,7 @@ EXTRA_DIST = \
# The -I. is for <FlexLexer.h>
dynare_m_CPPFLAGS = $(BOOST_CPPFLAGS) -I.
dynare_m_LDFLAGS = $(AM_LDFLAGS) $(BOOST_LDFLAGS)
dynare_m_LDADD = macro/libmacro.a $(BOOST_FILESYSTEM_LIB) $(BOOST_SYSTEM_LIB)
dynare_m_LDADD = macro/libmacro.a -lstdc++fs
DynareFlex.cc: DynareFlex.ll
$(LEX) -o DynareFlex.cc DynareFlex.ll
......
......@@ -22,11 +22,9 @@
#include <fstream>
#include <typeinfo>
#include <cassert>
#include <random>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#include <boost/filesystem.hpp>
#pragma GCC diagnostic pop
#include <filesystem>
#include "ModFile.hh"
#include "ConfigFile.hh"
......@@ -307,17 +305,41 @@ ModFile::checkPass(bool nostrict, bool stochastic)
warnings << R"(WARNING: you are using a function (max, min, abs, sign) or an operator (<, >, <=, >=, ==, !=) which is unsuitable for a stochastic context; see the reference manual, section about "Expressions", for more details.)" << endl;
if (linear
&& (dynamic_model.isUnaryOpUsed(UnaryOpcode::sign)
|| dynamic_model.isUnaryOpUsed(UnaryOpcode::abs)
|| dynamic_model.isBinaryOpUsed(BinaryOpcode::max)
|| dynamic_model.isBinaryOpUsed(BinaryOpcode::min)
|| dynamic_model.isBinaryOpUsed(BinaryOpcode::greater)
|| dynamic_model.isBinaryOpUsed(BinaryOpcode::less)
|| dynamic_model.isBinaryOpUsed(BinaryOpcode::greaterEqual)
|| dynamic_model.isBinaryOpUsed(BinaryOpcode::lessEqual)
|| dynamic_model.isBinaryOpUsed(BinaryOpcode::equalEqual)
|| dynamic_model.isBinaryOpUsed(BinaryOpcode::different)))
warnings << "WARNING: you have declared your model 'linear' but you are using a function (max, min, abs, sign) or an operator (<, >, <=, >=, ==, !=) which potentially makes it non-linear." << endl;
&& (dynamic_model.isUnaryOpUsedOnType(SymbolType::endogenous, UnaryOpcode::sign)
|| dynamic_model.isUnaryOpUsedOnType(SymbolType::endogenous, UnaryOpcode::abs)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::endogenous, BinaryOpcode::max)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::endogenous, BinaryOpcode::min)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::endogenous, BinaryOpcode::greater)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::endogenous, BinaryOpcode::less)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::endogenous, BinaryOpcode::greaterEqual)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::endogenous, BinaryOpcode::lessEqual)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::endogenous, BinaryOpcode::equalEqual)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::endogenous, BinaryOpcode::different)))
{
cerr << "ERROR: you have declared your model 'linear' but you are using a function "
<< "(max, min, abs, sign) or an operator (<, >, <=, >=, ==, !=) on an "
<< "endogenous variable." << endl;
exit(EXIT_FAILURE);
}
if (linear
&& !mod_file_struct.perfect_foresight_solver_present
&& (dynamic_model.isUnaryOpUsedOnType(SymbolType::exogenous, UnaryOpcode::sign)
|| dynamic_model.isUnaryOpUsedOnType(SymbolType::exogenous, UnaryOpcode::abs)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::exogenous, BinaryOpcode::max)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::exogenous, BinaryOpcode::min)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::exogenous, BinaryOpcode::greater)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::exogenous, BinaryOpcode::less)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::exogenous, BinaryOpcode::greaterEqual)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::exogenous, BinaryOpcode::lessEqual)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::exogenous, BinaryOpcode::equalEqual)
|| dynamic_model.isBinaryOpUsedOnType(SymbolType::exogenous, BinaryOpcode::different)))
{
cerr << "ERROR: you have declared your model 'linear' but you are using a function "
<< "(max, min, abs, sign) or an operator (<, >, <=, >=, ==, !=) on an "
<< "exogenous variable in a non-perfect-foresight context." << endl;
exit(EXIT_FAILURE);
}
// Test if some estimated parameters are used within the values of shocks
// statements (see issue #469)
......@@ -819,8 +841,8 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
bool console, bool nograph, bool nointeractive, const ConfigFile &config_file,
bool check_model_changes, bool minimal_workspace, bool compute_xrefs,
const string &mexext,
const boost::filesystem::path &matlabroot,
const boost::filesystem::path &dynareroot, bool onlymodel) const
const filesystem::path &matlabroot,
const filesystem::path &dynareroot, bool onlymodel) const
{
bool hasModelChanged = !dynamic_model.isChecksumMatching(basename, block);
if (!check_model_changes)
......@@ -834,21 +856,21 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
preprocessor is not able to recreate it afterwards (presumably because
MATLAB maintains some sort of lock on it). The workaround is to rename
it before deleting it. */
if (boost::filesystem::exists("+" + basename))
if (filesystem::exists("+" + basename))
{
auto tmp = boost::filesystem::unique_path();
boost::filesystem::rename("+" + basename, tmp);
boost::filesystem::remove_all(tmp);
auto tmp = unique_path();
filesystem::rename("+" + basename, tmp);
filesystem::remove_all(tmp);
}
boost::filesystem::remove_all(basename + "/model/src");
boost::filesystem::remove_all(basename + "/model/bytecode");
filesystem::remove_all(basename + "/model/src");
filesystem::remove_all(basename + "/model/bytecode");
}
ofstream mOutputFile;
if (basename.size())
{
boost::filesystem::create_directory("+" + basename);
filesystem::create_directory("+" + basename);
string fname = "+" + basename + "/driver.m";
mOutputFile.open(fname, ios::out | ios::binary);
if (!mOutputFile.is_open())
......@@ -1193,7 +1215,7 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output)
jlOutputFile << endl
<< "options_ = dynare_options()" << endl
<< R"(options_.dynare_version = ")" << PACKAGE_VERSION << R"(")" << endl;
if (linear == 1)
if (linear)
jlOutputFile << "options_.linear = true" << endl;
// Write Model
......@@ -1414,7 +1436,7 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType
if (basename.size())
{
boost::filesystem::create_directories(basename + "/model/json");
filesystem::create_directories(basename + "/model/json");
string fname{basename + "/model/json/modfile.json"};
jsonOutputFile.open(fname, ios::out | ios::binary);
if (!jsonOutputFile.is_open())
......@@ -1521,7 +1543,7 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType
}
else
{
boost::filesystem::create_directories(basename + "/model/json");
filesystem::create_directories(basename + "/model/json");
writeJsonFileHelper(basename + "/model/json/static.json", static_output);
writeJsonFileHelper(basename + "/model/json/dynamic.json", dynamic_output);
......@@ -1547,3 +1569,24 @@ ModFile::writeJsonFileHelper(const string &fname, ostringstream &output) const
jsonOutput << output.str();
jsonOutput.close();
}
filesystem::path
ModFile::unique_path()
{
filesystem::path path;
string possible_characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
random_device rd;
mt19937 generator(rd());
uniform_int_distribution<int> distribution{0, static_cast<int>(possible_characters.size())-1};
do
{
constexpr int rand_length = 10;
string rand_str(rand_length, '\0');
for (auto &dis : rand_str)
dis = possible_characters[distribution(generator)];
path = filesystem::temp_directory_path() / rand_str;
}
while (filesystem::exists(path));
return path;
}
......@@ -131,6 +131,10 @@ private:
void writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonderivsimple) const;
void writeJsonFileHelper(const string &fname, ostringstream &output) const;
vector<expr_t> pac_growth;
/* Generate a random temporary path. Equivalent to
boost::filesystem::unique_path(). Both are insecure, but currently there
is no better portable solution. Maybe in a later C++ standard? */
static filesystem::path unique_path();
public:
//! Add a statement
void addStatement(unique_ptr<Statement> st);
......@@ -164,8 +168,8 @@ public:
void writeOutputFiles(const string &basename, bool clear_all, bool clear_global, bool no_log, bool no_warn,
bool console, bool nograph, bool nointeractive, const ConfigFile &config_file,
bool check_model_changes, bool minimal_workspace, bool compute_xrefs,
const string &mexext, const boost::filesystem::path &matlabroot,
const boost::filesystem::path &dynareroot, bool onlymodel) const;
const string &mexext, const filesystem::path &matlabroot,
const filesystem::path &dynareroot, bool onlymodel) const;
void writeExternalFiles(const string &basename, FileOutputType output, LanguageOutputType language) const;
void writeExternalFilesJulia(const string &basename, FileOutputType output) const;
......
......@@ -132,7 +132,7 @@ SteadyStateModel::checkPass(ModFileStructure &mod_file_struct, WarningConsolidat
void
SteadyStateModel::writeLatexSteadyStateFile(const string &basename) const
{
boost::filesystem::create_directories(basename + "/latex");
filesystem::create_directories(basename + "/latex");
ofstream output, content_output;
string filename = basename + "/latex/steady_state.tex";
......
......@@ -1845,7 +1845,7 @@ ModelTree::Write_Inf_To_Bin_File(const string &filename,
void
ModelTree::writeLatexModelFile(const string &mod_basename, const string &latex_basename, ExprNodeOutputType output_type, const bool write_equation_tags) const
{
boost::filesystem::create_directories(mod_basename + "/latex");
filesystem::create_directories(mod_basename + "/latex");
ofstream output, content_output;
string filename = mod_basename + "/latex/" + latex_basename + ".tex";
......@@ -2212,11 +2212,11 @@ ModelTree::matlab_arch(const string &mexext)
}
void
ModelTree::compileDll(const string &basename, const string &static_or_dynamic, const string &mexext, const boost::filesystem::path &matlabroot, const boost::filesystem::path &dynareroot)
ModelTree::compileDll(const string &basename, const string &static_or_dynamic, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot)
{
const string opt_flags = "-O3 -g0 --param ira-max-conflict-table-size=1 -fno-forward-propagate -fno-gcse -fno-dce -fno-dse -fno-tree-fre -fno-tree-pre -fno-tree-cselim -fno-tree-dse -fno-tree-dce -fno-tree-pta -fno-gcse-after-reload";
boost::filesystem::path compiler;
filesystem::path compiler;
ostringstream flags;
string libs;
......@@ -2254,7 +2254,7 @@ ModelTree::compileDll(const string &basename, const string &static_or_dynamic, c
// Windows
flags << " -static-libgcc -static-libstdc++ -shared";
// Put the MinGW environment shipped with Dynare in the path
boost::filesystem::path mingwpath = dynareroot / (string{"mingw"} + (mexext == "mexw32" ? "32" : "64")) / "bin";
filesystem::path mingwpath = dynareroot / (string{"mingw"} + (mexext == "mexw32" ? "32" : "64")) / "bin";
string newpath = "PATH=" + mingwpath.string() + ';' + string{getenv("PATH")};
if (putenv(const_cast<char *>(newpath.c_str())) != 0)
{
......@@ -2272,12 +2272,12 @@ ModelTree::compileDll(const string &basename, const string &static_or_dynamic, c
}
}
auto model_dir = boost::filesystem::path{basename} / "model" / "src";
boost::filesystem::path main_src{model_dir / (static_or_dynamic + ".c")},
auto model_dir = filesystem::path{basename} / "model" / "src";
filesystem::path main_src{model_dir / (static_or_dynamic + ".c")},
mex_src{model_dir / (static_or_dynamic + "_mex.c")};
boost::filesystem::path mex_dir{"+" + basename};
boost::filesystem::path binary{mex_dir / (static_or_dynamic + "." + mexext)};
filesystem::path mex_dir{"+" + basename};
filesystem::path binary{mex_dir / (static_or_dynamic + "." + mexext)};
ostringstream cmd;
......
......@@ -28,11 +28,7 @@ using namespace std;
#include <map>
#include <ostream>
#include <array>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#include <boost/filesystem.hpp>
#pragma GCC diagnostic pop
#include <filesystem>
#include "DataTree.hh"
#include "ExtendedPreprocessorTypes.hh"
......@@ -312,7 +308,7 @@ private:
//! Returns the name of the MATLAB architecture given the extension used for MEX files
static string matlab_arch(const string &mexext);
//! Compiles the MEX file
static void compileDll(const string &basename, const string &static_or_dynamic, const string &mexext, const boost::filesystem::path &matlabroot, const boost::filesystem::path &dynareroot);
static void compileDll(const string &basename, const string &static_or_dynamic, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot);
public:
ModelTree(SymbolTable &symbol_table_arg,
......
......@@ -556,7 +556,7 @@ StaticModel::writeModelEquationsCode(const string &basename, map_idx_t map_idx)
unsigned int instruction_number = 0;
bool file_open = false;
boost::filesystem::create_directories(basename + "/model/bytecode");
filesystem::create_directories(basename + "/model/bytecode");
string main_name = basename + "/model/bytecode/static.cod";
code_file.open(main_name, ios::out | ios::binary | ios::ate);
......@@ -733,7 +733,7 @@ StaticModel::writeModelEquationsCode_Block(const string &basename, map_idx_t map
deriv_node_temp_terms_t tef_terms;
bool file_open = false;
boost::filesystem::create_directories(basename + "/model/bytecode");
filesystem::create_directories(basename + "/model/bytecode");
string main_name = basename + "/model/bytecode/static.cod";
code_file.open(main_name, ios::out | ios::binary | ios::ate);
......@@ -1889,7 +1889,7 @@ void
StaticModel::writeStaticCFile(const string &basename) const
{
// Writing comments and function definition command
boost::filesystem::create_directories(basename + "/model/src");
filesystem::create_directories(basename + "/model/src");
string filename = basename + "/model/src/static.c";
string filename_mex = basename + "/model/src/static_mex.c";
......@@ -2027,7 +2027,7 @@ StaticModel::writeStaticJuliaFile(const string &basename) const
}
void
StaticModel::writeStaticFile(const string &basename, bool block, bool bytecode, bool use_dll, const string &mexext, const boost::filesystem::path &matlabroot, const boost::filesystem::path &dynareroot, bool julia) const
StaticModel::writeStaticFile(const string &basename, bool block, bool bytecode, bool use_dll, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot, bool julia) const
{
if (block && bytecode)
writeModelEquationsCode_Block(basename, map_idx, map_idx2);
......
......@@ -23,11 +23,7 @@
using namespace std;
#include <fstream>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#include <boost/filesystem.hpp>
#pragma GCC diagnostic pop
#include <filesystem>
#include "ModelTree.hh"
......@@ -200,7 +196,7 @@ public:
int &u_count_int, bool &file_open) const;
//! Writes static model file
void writeStaticFile(const string &basename, bool block, bool bytecode, bool use_dll, const string &mexext, const boost::filesystem::path &matlabroot, const boost::filesystem::path &dynareroot, bool julia) const;
void writeStaticFile(const string &basename, bool block, bool bytecode, bool use_dll, const string &mexext, const filesystem::path &matlabroot, const filesystem::path &dynareroot, bool julia) const;
//! Write JSON Output (used by PlannerObjectiveStatement)
void writeJsonOutput(ostream &output) const;
......
/*
* Copyright © 2003-2018 Dynare Team
* Copyright © 2003-2019 Dynare Team
*
* This file is part of Dynare.
*
......@@ -70,3 +70,16 @@ SymbolList::getSymbols() const
{
return symbols;
}
void
SymbolList::removeDuplicates(const string &dynare_command, WarningConsolidation &warnings)
{
vector<string> unique_symbols;
for (auto & it : symbols)
if (find(unique_symbols.begin(), unique_symbols.end(), it) == unique_symbols.end())
unique_symbols.push_back(it);
else
warnings << "WARNING: In " << dynare_command << ": " << it
<< " found more than once in symbol list. Removing all but first occurence." << endl;
symbols = unique_symbols;
}
/*
* Copyright © 2003-2017 Dynare Team
* Copyright © 2003-2019 Dynare Team
*
* This file is part of Dynare.
*
......@@ -24,6 +24,8 @@
#include <vector>
#include <ostream>
#include "WarningConsolidation.hh"
using namespace std;
//! Used to store a list of symbols
......@@ -36,6 +38,8 @@ private:
public:
//! Adds a symbol to the list
void addSymbol(const string &symbol);
//! Removed duplicate symbols
void removeDuplicates(const string &dynare_command, WarningConsolidation &warnings);
//! Output content in Matlab format
/*! Creates a string array for Matlab, stored in variable "varname" */
void writeOutput(const string &varname, ostream &output) const;
......