Commit Graph

220 Commits (master)

Author SHA1 Message Date
Sébastien Villemot b31de3d9a6
Pre-allocate std::vector instances filled from loops
Automatically detected by clang-tidy using
performance-inefficient-vector-operation check.
2023-12-13 16:19:51 +01:00
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 d635aac04a
Turn some loop variables into const references when possible
Automatically detected by clang-tidy using performance-for-range-copy check.
2023-12-13 14:21:09 +01:00
Sébastien Villemot 3d94f1956c
Remove some unneeded object copies
Automatically detected by clang-tidy using performance-unnecessary-value-param
check.
2023-12-13 10:28:54 +01:00
Sébastien Villemot e4b23fecb0
Update comments in relation to implicit conversion from std::filesystem::path to std::string
There is actually no bug in MinGW. The different behaviour under Windows is
expected, because the implicit conversion there is only to std::wstring.
2023-12-08 18:39:27 +01:00
Sébastien Villemot 4790fa00d8
Remove workaround for bug in MinGW compiler
It would mishandle trailing slashes or backslashes in std::filesystem::path, see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88881

The bug is now fixed in the version of MinGW in Debian “bookworm” 12.

Ref. Madysson/estimation-codes#11
2023-12-08 18:36:25 +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 5e89921ea1
Use emplace() and emplace_back() at several places
Automatically detected using clang-tidy with modernize-use-emplace check.
2023-12-01 14:30:03 +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 b6adff7de7
Manually reformat Flex and Bison files to be closer to clang-format style 2023-11-30 16:21:34 +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 3804222667
Ignore -Wold-style-cast in Flex-generated files 2023-09-22 14:29:22 +02:00
Sébastien Villemot 5104759bd5
Drop autoconf/automake build system 2023-09-20 15:26:32 +02:00
Sébastien Villemot 1947e6de58
Use different filenames for Bison-generated location files 2023-06-07 11:57:12 +02:00
Sébastien Villemot 3cc531315b
C++20 modernization: use new standard mathematical constants 2023-05-25 19:06:48 +02:00
Sébastien Villemot 1b7b70ec93
Build system: enable the dangling else warning (-Wdangling-else)
Adapt the code accordingly.
2023-04-11 14:22:32 +02:00
Sébastien Villemot a219c68543
Macroprocessor: drop useless Expression::clone() method 2023-03-16 11:36:41 +01:00
Sébastien Villemot 96e7a764b2
Macroprocessor: make method Expression::eval() const 2023-03-16 11:32:50 +01:00
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