Commit Graph

65 Commits (master)

Author SHA1 Message Date
Sébastien Villemot 22675728aa
No longer call std::move on trivially-copyable types
Automatically detected by clang-tidy with performance-move-const-arg check.

Do not make the modification for Tokenizer::location type, since we have no
guarantee that the type will remain trivially-copyable in the future.
2023-12-13 15:37:07 +01:00
Sébastien Villemot bffd68e0bf
Add a clang-tidy configuration file
Also add some annotations to remove some false positives.

There remain some boost-related false positives, it’s unclear how to suppress
them.
2023-12-04 16:37:00 +01:00
Sébastien Villemot b2e9ec205e
No longer use reserved identifiers for include guards
Automatically detected using clang-tidy with bugprone-reserved-identifier
check.

By the way, homogeneize the define identifiers in relation to camel case
convention.
2023-12-01 15:39:01 +01:00
Sébastien Villemot 7e6abc97c4
Add [[nodiscard]] attribute to various functions
Automatically detected using clang-tidy with modernize-use-nodiscard check.
2023-12-01 14:14:44 +01:00
Sébastien Villemot d463607e90
Reformat C++ source code using clang-format 15 2023-11-30 15:58:32 +01:00
Sébastien Villemot e1e1a753d0
Do not use C++20 aggregate initialization with parentheses
Initialization with initalizer list is nicer. And, more importantly,
initialization with parentheses is not supported by Clang < 16.
2023-07-07 14:32:16 +02:00
Sébastien Villemot faa1291055
use_dll: turn getPowerDeriv() and sign() into inline functions
This allows the compiler to better optimize by inlining those call when worth
it.
2023-04-11 15:58:49 +02:00
Sébastien Villemot b1e4884237
🐛 sign(0) was returning 1 instead of 0 with use_dll
The C99 copysign() function was used in the generated C output, but that
function does not correctly handle zero. Replace it by a custom sign()
function.
2023-04-07 16:38:23 +02:00
Sébastien Villemot 7c6402cc34
DataTree: optimize the filling of node maps
Use map::{try,}emplace() instead of operator[], which should in theory be
slightly faster.
2023-03-23 16:10:40 +01:00
Sébastien Villemot 762243c705
Julia: drop get_power_deriv function from module
The function is now provided separately by Dynare.jl.
2022-11-02 15:49:56 +01:00
Sébastien Villemot 0278c8577c
Provisions for new sparse representation of dynamic/static files
The new representation is only supported for MATLAB/Octave, C and Julia output
for the time being. Bytecode and JSON are unsupported.

This commit adds new fields in M_.

This is a preliminary step for dynare#1859.
2022-11-02 15:49:56 +01:00
Sébastien Villemot 93054cf692
Various filesystem refactorings
– DataTree::packageDir() now takes a std::string_view, returns a
  std::filesystem::path, and no longer creates that directory
– DataTree::writeToFileIfModified() now takes a std::filesystem::path as
  argument
– Do not call DataTree::writeToFileIfModified() for generating MATLAB/Octave
  files, since it does not work (the directory inside which the file is written
  has been deleted by the preprocessor just before)
– Consistently use DataTree::packageDir() everywhere (for compatibility with
  planner_objective)
2022-10-11 16:28:17 +02:00
Sébastien Villemot 198ff70bce
Simplify strsplit() using std::string_view
By the way:
– improve the semantics by having a consistent treatment of empty substring
  components (previously, only the last one was ignored)
– move it to DataTree to make it more accessible from elsewhere (even though
  ideally it should be in a “utilities” namespace).
2022-10-11 16:23:11 +02:00
Sébastien Villemot f0629555a5
Remove useless constructors (aggregate initialization is enough for those)
By the way, turn those classes into structs since all their members are public.
2022-07-20 14:48:28 +02:00
Sébastien Villemot 157c67e04b
New helpers to simplify common operations with derivation IDs 2022-07-12 16:30:45 +02:00
Sébastien Villemot f38c8278ae
Refactor methods for writing static and dynamic files
– factorize common code between the static and the dynamic version
– reorganise language-specific code into dedicated functions
– use a function template in the main helper to do some computations
  at compile-time (using constexpr features)
2022-07-11 22:29:28 +02:00
Sébastien Villemot 2795207802
No longer delete move constructor/assignment operator
We follow the advice given by Josuttis in his book about move semantics.

Deleting those member fuctions can be a bug if we want to allow copy semantics,
because overload resolution will no longer fallback to the copy
constructor/assignment operator when given an rvalue.

In particular, this explain why it was not possible to delete the move
assignment operator of the StaticModel class.
2022-05-18 16:33:48 +02:00
Sébastien Villemot 8c07fb5e43
Compatibility fix for GCC 12
Ref. dynare#1852
2022-05-02 17:03:42 +02:00
Sébastien Villemot 0db05a886a
Move “using namespace std” statement after inclusion of standard headers
Otherwise clang emits this warning:
 using directive refers to implicitly-defined namespace 'std'
2022-01-06 14:54:57 +01:00
Sébastien Villemot ea6fb40db7
PAC: new “pac_target_info” block and “pac_target_nonstationary” operator
Ref. Madysson/estimation-codes#5
2021-12-16 15:40:47 +01:00
Sébastien Villemot d15b2110a0
Add erfc() primitive
Closes: #85
2021-12-07 15:19:40 +01:00
Sébastien Villemot 5498ce98ee
Use NumConstNode* type for DataTree constants (previously they were just expr_t) 2021-07-21 17:53:54 +02:00
Sébastien Villemot ed31d1cb5e
Remove unused functions 2021-07-21 16:33:23 +02:00
Sébastien Villemot c9c36c037a
New preprocessor option “nocommutativity”
This option tells the preprocessor not to use the commutativity of addition and
multiplication when looking for common subexpressions.

As a consequence, when using this option, equations in various outputs (LaTeX,
JSON…) will appear as the user entered them.

There is however a potential performance cost to using this option, yet to be
determined.

Ref. dynare#1788
2021-07-13 14:35:10 +02:00
Sébastien Villemot 74ef3457b4
Use secure URL for link to GNU licenses 2021-06-09 17:21:00 +02:00
MichelJuillard 9773bafc5b Julia: write definition of get_power_deriv inside generated static/dynamic files 2021-04-26 10:52:18 +00:00
Sébastien Villemot 4cfc7a563b
Julia: do not overwrite Static/Dynamic files if contents has not changed
Ref. DynareJulia/Dynare.jl#1
2021-04-22 18:03:47 +02:00
Sébastien Villemot ad5e196d30
Block decomposition now compatible with 'use_dll' option 2020-06-23 15:13:04 +02:00
Sébastien Villemot 7b11898689
use_dll: merge the two generated C source files into a single one
Also, do various other cosmetic/simplification changes.
2020-05-29 16:12:01 +02:00
Sébastien Villemot e88c05e3b8
Change prototype of DataTree::AddEqual()
This permits some simplifications.
2020-04-02 19:19:57 +02:00
Sébastien Villemot e2d5a83592
Global reindentation 2019-12-20 16:59:30 +01:00
Sébastien Villemot 031c0cff5f
Various code simplifications and modernizations 2019-12-16 19:42:59 +01:00
Houtan Bastani 0c1373bc5e
stop processing when certain functions are used in a linear context on endogenous/exogenous variables. closes dynare#1537 2019-09-10 12:37:28 +02:00
Houtan Bastani ae0a91256a
add cubic root to dynare language 2019-07-15 12:18:26 -04:00
Sébastien Villemot b73d554ad2
Use Unicode copyright symbol (in UTF-8 encoding) 2019-04-16 11:35:31 +02:00
Sébastien Villemot 1793078ba2
Minor stylistic improvements 2019-03-18 18:49:55 +01:00
Sébastien Villemot 4a974bb428
The preprocessor now compiles the MEX when use_dll is specified
New options "mexext" and "matlabroot" are introduced, so that the preprocessor
knows where to find MATLAB and which architecture to compile for.

Only recent gcc is now supported. A set of optimization flags is used so that
compilation goes reasonably fast on large models.

Consequently, options "msvc", "mingw" and "cygwin" have been removed.
2018-10-26 18:09:13 +02:00
Sébastien Villemot 1089a223c4 Clean up default constructors/destructors 2018-10-11 17:08:44 +02:00
Sébastien Villemot 24f1276b42 Make all DataTree::*_map private
Introducing a new DataTree::getVariable() const method was necessary in the process.
2018-10-10 13:03:52 +02:00
Sébastien Villemot f2cf86b734 Add copy constructors / assignment operators for the DataTree class hierarchy
In particular, it is necessary to turn back DataTree::AddVariable() into a
non-virtual method, because it is called from DataTree's constructor. Enforcing
the absence of leads/lags is now done using a new boolean DataTree::is_static.

Take advantage of the new copy constructor for handling
PlannerObjectiveStatement more elegantly.

Unfortunately it is not possible to implement *move* constructor / assigment
operators, because the reference ExprNode::datatree is not mutable.
2018-10-10 12:53:55 +02:00
Sébastien Villemot 6d26dc2349 Remove implicitly-defined copy/move constructors/assignments in several classes 2018-10-04 18:08:17 +02:00
Sébastien Villemot 7bb5382428 Always use brace-initializer in constructors
The syntax makes clearer the distinction between a function call and an
initialization. Also, it prevents bugs due to implicit type conversions.
2018-10-04 17:19:18 +02:00
Sébastien Villemot a4aefb4c65 Mark all constructors taking a single argument as "explicit"
For a rationale, see http://www.sjbrown.co.uk/2004/05/01/always-use-explicit/
2018-10-04 17:19:18 +02:00
Houtan Bastani 85dbb649b7 move trend_component_table and var_model_table to DynamicModel as they are only used there 2018-09-14 17:04:06 +02:00
Sébastien Villemot c6d4cb88c3 ExprNode and its subclasses are no longer friends of DataTree
This ensures a better isolation between the container and the containees.
2018-09-05 18:28:32 +02:00
Sébastien Villemot 004d909621 Use smart pointers for storage of ExprNode in DataTree class
- BTW, store them in a std::vector rather than std::list

- incidentally, fix issue in VariableNode::removeTrendLeadLag where expression
  sharing was possibly violated when creating a new VariableNode
2018-09-05 18:28:32 +02:00
Houtan Bastani 539fddc9f6 introduce var model table 2018-08-22 12:15:02 +02:00
Houtan Bastani afe0e475b1 trend_component_model statement 2018-08-17 16:52:48 +02:00
Sébastien Villemot f3c2a1bf87 New var_expectation_model statement and re-design of var_expectation operator
Given a previously declared var_model, the var_expectation_model statement is
used to declare a way of forming expectations with this VAR (possibly using a
finite or infinite discounted sum). The var_expectation operator now takes a
single argument, the name of the var_expectation_model.

For the moment, this only works when the var_model is using equations
explicitly declared in the model block.
2018-08-02 08:39:09 +02:00
Sébastien Villemot 4ad0e500d4 C++11: convert {Unary,Binary,Trinary}Opcode to class enums 2018-07-18 16:18:26 +02:00