Commit Graph

201 Commits (93b9ed69577246cb13eef1890d52708f2aea4a9d)

Author SHA1 Message Date
Sébastien Villemot d36eb82b7c
Macro processor: removed unused “basename” variable 2023-01-05 15:49:36 +01:00
Sébastien Villemot f349e22f4c
Macro processor: fix error message when @#include is used with nonexistent file 2022-12-14 15:22:20 +01:00
Sébastien Villemot 50a2737e41
Macro processor: fix tracking of line numbers after @#define, @#include and @#includepath directives
Closes: #108
2022-12-14 15:22:07 +01:00
Sébastien Villemot 3d9ac26aa6
Remove all instances of the “map.find(key)->second” pattern
This is unsafe since the find() method can return a past-the-end iterator,
which should be tested for.

Replace most instances by calls to the std::map::at() method (which throws if
the key is unknown), and which is incidentally more readable.
2022-09-27 12:56:16 +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 435e56369c
Compatibility fixes with GCC 12 2022-07-16 12:46:16 +02:00
Sébastien Villemot c3fc5b1dd7
Enable -Wunused-parameter
As a consequence, add many [[maybe_unused]] attributes for legitimate
cases (mainly in virtual functions).
2022-06-24 17:11:48 +02:00
Sébastien Villemot b390390a98
Remove unnecessary inline specifiers
A function defined entirely inside a class/struct/union definition is
implicitly an inline function.
2022-06-24 15:09:08 +02:00
Sébastien Villemot 41b1e89756
Macro-processor: when a variable is defined without a value, set it to “true”
Previously it was set to 1.

Also do the same change for variable defined on the command-line, for
consistency.

Closes: #43
2022-06-16 16:50:38 +02:00
Sébastien Villemot 46b2c73565
C++17 modernization: more uses of std::optional 2022-06-08 12:34:25 +02:00
Sébastien Villemot c94dfb848c
C++20 modernization: use initialization within range-based for loop
In particular, use this feature in many loops which feature a special treatment
for the first iteration, using a boolean variable (replacing iterator
manipulation). By the way, also use std::exchange() to simultaneously test the
value of this variable and update it.
2022-06-07 14:35:59 +02:00
Sébastien Villemot 0b5c88109f
Various simplifications 2022-06-07 14:34:30 +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 b42ee40b55
C++20 modernization: use contains() method on containers 2022-05-04 17:37:57 +02:00
Sébastien Villemot 894f5cda46
Macro-processor: more robust handling of empty files
The support for empty files at the macro-processor level, as implemented in
1291320053, was relying on
basic_streambuf::in_avail(), which does not seem to behave consistently across
platforms, and which may not be the right tool for the job.

Rather use the Bison grammar to support empty files.

Closes: #93
2022-04-19 16:40:18 +02:00
Sébastien Villemot 8064bdc7d0
Use Unicode copyright symbol (in UTF-8 encoding)
This file was apparently a left-over from a previous conversion.

[skip ci]
2022-04-13 13:24:33 +02:00
Sébastien Villemot ff0e094d6f
Macroprocessor: MinGW bug for filesystem::path→string implicit conversion is still present in Debian 11 2022-01-25 12:57:12 +01:00
Sébastien Villemot 3d894b3a47
Macroprocessor: under Windows, trim trailing slashes and backslashes in the value of “@#includepath”
This is a  workaround for a GCC/MinGW bug present in version 10.2
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88881), that affects
gcc-mingw-w64 in Debian “Bullseye” 11. It is fixed in GCC 10.3, and thus should
be fixed in Debian “Bookworm” 12.

Ref. Madysson/estimation-codes#11
2022-01-25 12:57:09 +01:00
Sébastien Villemot 1de3476546
Macroprocessor: fix line counter inside @{} constructs
There were two bugs:
– with the LF convention, newlines were counted twice
– with the CR+LF convention, they were counted four times (because the CR was
  included in yyleng, alongside the LF)

The fix consists in implementing a location_increment() method similar to the
one used for the Dynare parser. This is the most robust solution.

By the way, mark the method DynareFlex::location_increment() method static.
2021-11-19 14:55:14 +01:00
Sébastien Villemot 487c372900
Macroprocessor: fix newlines in output when under Windows and input uses CR+LF convention
If the input .mod file uses CR+LF convention, and if the user is under Windows,
then the output of the macroprocessor (as given by the “savemacro” option) had
incorrect end of lines: those would be CR+CR+LF.

The reason is that some TextNode(s) internally created by the macroprocessor
would themselves contain CR+LF sequences, which would then be transformed into
CR+CR+LF in the output (because MinGW transforms LF into CR+LF in output
streams).

The fix consists in changing the nature of the EOL token: the parsed text is no
longer attached to it, so that the Bison file now systematically turns it into
a LF inside TextNode(s).

Closes: #80
2021-11-19 14:55:12 +01:00
Sébastien Villemot 74ef3457b4
Use secure URL for link to GNU licenses 2021-06-09 17:21:00 +02:00
Sébastien Villemot 2781e3e6f6
A few modernizations using clang-tidy 2021-02-10 16:48:46 +01:00
Sébastien Villemot 1e5de7d71e
Fix typo
Introduced in 4c14dc3fbf.
2021-01-22 14:20:52 +01:00
Sébastien Villemot 4c14dc3fbf
Macro processor: gracefully fail when argument to @#ifdef/@#ifndef is not a variable name
Ref. dynare#1771
2021-01-22 12:20:13 +01:00
Sébastien Villemot ec779235ea
Macro-processor: move environment out of node classes
This completes the separation of parse trees from their evaluation.

Closes: #32
2020-12-07 17:29:05 +01:00
Sébastien Villemot 5d564eed07
Fix the interpretation of @#elseif clauses within an @#ifdef or @#ifndef 2020-11-02 12:47:33 +01:00
Sébastien Villemot df8d8ef116
Fix logic for @#ifndef
Ref. dynare#1747
2020-11-02 12:27:27 +01:00
Houtan Bastani 28b98c7c0e
Rework the function that handles the macro-expansion of the .mod file 2020-02-20 15:30:46 +01:00
Houtan Bastani abedb47573
macro processor: allow for the definition of a variable without a value
- by default, set the value of the variable to `1`, as is done on the command line with the `-D` flag

issue #43
2020-02-19 21:40:40 +01:00
Houtan Bastani 1dbbd87d3d
Remove options `noemptylinemacro` and `nolinemacro`; add option `linemacro`
This only concerns the situation when `savemacro` is also passed.

When `linemacro` is passed, the macro expanded .mod file is the same as before

When `linemacro` is not passed, the macro expanded .mod file is equivalent to what it was before when both `noemptylinemacro` and `nolinemacro` were passed.

closes #44
closes #45
2020-02-05 15:19:01 +01:00
Houtan Bastani 12296b620f
macro processor: fix bug in file reported when error encountered after a file has been included
closes #42
2020-02-04 11:12:41 +01:00
Houtan Bastani 6284e991fc
macro processor: remove unnecessary type specifiers 2020-02-04 11:12:41 +01:00
Houtan Bastani 148aa9d924
macro processor: simplify handling of `@#define` 2020-01-29 14:52:01 +01:00
Houtan Bastani c6a52fd778
macro processor: c++ modernization 2020-01-21 15:43:25 +01:00
Houtan Bastani fa2f6c9206
macro processor: use `map.count()` instead of `map.find()` 2020-01-21 15:41:25 +01:00
Houtan Bastani 3c546ddb20
macro processor: declare function const 2020-01-21 15:41:08 +01:00
Houtan Bastani e9049aa81f
use prefix notation `R"()"` for quote in quotes 2020-01-16 16:24:21 +01:00
Houtan Bastani 6d1c2ca82b
macro processor: allow colon-separated arrays as command-line defines
colon-separated command line arguments such as
```
dynare <<.mod file>> -DA=1:5 -DAA=1:2:5
```
are now translated as:
```
@#define C = [2, 3, 4, 5, 6]
@#define CC = [2, 5]
```
2020-01-16 16:24:21 +01:00
Houtan Bastani f00d7c4b4c
macro processor: fix bug where command line arguments that began with an integer were being treated as integers even if they weren't (e.g. dates) 2020-01-16 13:09:42 +01:00
Houtan Bastani f2271eb806
Partial reversion of global indentation of macro processor header files introduced in e2d5a83592
The global indentation introduced in e2d5a83592 made the macro processor header files difficult to read. Revert spacing changes that made simple, inline, one-line functions take up 5 lines making headers tougher to read. Similary change for constructors, not to place each brace on an individual line.
2019-12-23 19:39:34 +01:00
Sébastien Villemot e2d5a83592
Global reindentation 2019-12-20 16:59:30 +01:00
Houtan Bastani 653b2477db
Update for bison 3.5 2019-12-18 15:43:48 +01:00
Sébastien Villemot 031c0cff5f
Various code simplifications and modernizations 2019-12-16 19:42:59 +01:00
Houtan Bastani 8dc70602c8
macro processor: move evaluation of all arguments for unary, binary, and trinary ops into their switch cases 2019-12-10 16:33:32 +01:00
Houtan Bastani 952e899f3a
fix bug in macro processor ensuring short-circuit functionality of `||` and `&&` statements
closes dynare#1676
2019-12-10 16:30:11 +01:00
Houtan Bastani a61565bd01
macro processor: fix bug in cast of string to bool
The incorrect `equal` template was being used.
2019-11-26 11:11:34 +01:00
Houtan Bastani 4540bed06c
macro processor: missed if statement with initializer for C++17 2019-11-26 10:40:51 +01:00
Houtan Bastani 4e3bf09495
macro processor: fix typo that caused logical or not to work when one of the arguments is Real == 1 and other arguments are false 2019-11-26 10:39:16 +01:00
Houtan Bastani 8034513578
macro processor: fix bug: allow empty strings
previously, `@#define str=""` caused an error
2019-11-26 10:32:43 +01:00
Houtan Bastani c6beb6c5c6
macro processor: ignore `@#line` directive 2019-11-22 14:14:05 +01:00