160 Commits

Author SHA1 Message Date
Julian Brost
0ebcd2662d No longer allow overriding the frozen attribute of containers
The Array, Dictionary, and Namespace types provide a Freeze() method that makes
them read-only. So far, there was the possibility to call some methods with
`overrideFrozen=true` which would then bypass the corresponding check and allow
modification of the data structures nonetheless.

With 24b57f0d3a222835178e88489eabd595755ed883, this possibility was already
removed from the Namespace type. However, for interface compatibility, it kept
the parameter and just ignores it, throwing an exception on any modification on
a frozen instance.

The only place using `overrideFrozen` was processing of the `-D`/`--define`
command line flag that allows setting additional variables in the DSL. At the
time it is evaluated, there are no user-created data structures yet that could
be frozen, so the only frozen objects that could be encountered are Namespaces
(Icinga doesn't freeze other types by itself) and for these, `overrideFrozen`
already has no effect.

Hence, there is no harm in removing `overrideFrozen` altogether. This
simplifies the code and also means that frozen objects are now indeed read-only
without exceptions, allowing further optimizations regarding locking in the
future.
2025-07-08 14:16:20 +02:00
Alexander A. Klimov
9376a311ea Fix file endings
git ls-files -z \
	|grep -zEe '^lib/' \
	|grep -zEe '\.[ch]pp$' \
	|xargs -0 perl -p0i -e 's/\n*(?!(?:.|\n))/\n/'
2023-05-17 18:05:13 +02:00
Julian Brost
1c066fc02e Simplify NamespaceValue class hierarchy to one struct without member functions
This commit removes EmbeddedNamespaceValue and ConstEmbeddedNamespaceValue and
reduces NamespaceValue down to a simple struct without inheritance or member
functions. The code from these clases is inlined into the Namespace class. The
class hierarchy determining whether a value is const is moved to an attribute
of NamespaceValue.

This is done in preparation for changes to the locking in the Namespace class.
Currently, it relies on a recursive mutex. In the future, a shared mutex
(read/write lock) should be used instead, which cannot allow recursive locking
(without failing or risk deadlocking on lock upgrades). With this change, all
operations requiring a lock for one operation are within one function, no
recursive locking is not needed any more.
2023-01-19 17:55:11 +01:00
Julian Brost
fbb68dbcd0 Namespace: replace behavior classes with a bool
In essence, namespace behaviors acted as hooks for update operations on
namespaces. Two behaviors were implemented:

- `NamespaceBehavior`: allows the update operation unless it acts on a value
  that itself was explicitly marked as constant.
- `ConstNamespaceBehavior`: initially allows insert operations but marks the
  individual values as const. Additionally provides a `Freeze()` member
  function. After this was called, updates are rejected unless a special
  `overrideFrozen` flag is set explicitly.

This marvel of object-oriented programming can be replaced with a simple bool.
This commit basically replaces `Namespace::m_Behavior` with
`Namespace::m_ConstValues` and inlines the behavior functions where they were
called. While doing so, the code was slightly simplified by assuming that
`m_ConstValues` is true if `m_Frozen` is true. This is similar to what the API
allowed in the old code as you could only freeze a `ConstNamespaceBehavior`.
However, this PR moves the `Freeze()` member function and the related
`m_Freeze` member variable to the `Namespace` class. So now the API allows any
namespace to be frozen. The new code also makes sense with the previously
mentioned simplification: a `Namespace` with `m_ConstValues = false` can be
modified without restrictions until `Freeze()` is called. When this is done, it
becomes read-only.

The changes outside of `namespace.*` just adapt the code to the slightly
changed API.
2022-12-09 09:25:46 +01:00
Yonas Habteab
31785b48fd Expression: Decrease frame.Depth only when calling IncreaseStackDepth() succeeds
This ensures that `frame.Depth` is only decreased when preceding `frame.IncreaseStackDepth()` callee was successful.
This way, `frame.Depth` will have the same depth prior to and after evaluating a frame.
2022-09-07 09:41:16 +02:00
Alexander A. Klimov
768044a754 Replace std::shared_ptr<NamespaceValue> with NamespaceValue::Ptr
refs #7361
2019-10-21 17:10:51 +02:00
Alexander A. Klimov
aa4cad7482 Replace std::shared_ptr<Expression> with Expression::Ptr
refs #7361
2019-10-21 17:10:51 +02:00
Alexander A. Klimov
b4e3736e31 WarnOnImplicitlySetGlobalVar(): warn only on sins inside actual DSL code 2019-09-23 15:09:57 +02:00
Alexander A. Klimov
429080ee1c DSL: warn on x=y if x is a global variable 2019-08-27 13:30:02 +02:00
Michael Friedrich
d14a88235d Replace Copyright header with a short version, part I
CLion -> replace in path
2019-02-25 14:48:22 +01:00
Michael Friedrich
dab53448bc icinga.com: Update *.{h,c}pp 2018-10-18 09:27:04 +02:00
Gunnar Beutner
e678fa1aa5 Refactor Application::*Const() 2018-08-13 15:27:05 +02:00
Gunnar Beutner
8fda8d72ac Implement support for the namespace and using keywords 2018-08-13 13:44:31 +02:00
Gunnar Beutner
1a8692d972 Implement support for namespaces 2018-08-13 13:44:31 +02:00
Gunnar Beutner
9d513d8f05 Implement support for modifying frozen attributes 2018-08-13 13:44:31 +02:00
Gunnar Beutner
8bfd419702 Implement references 2018-08-07 07:44:48 +02:00
Gunnar Beutner
c2fb9fe226 Use initializer lists for arrays and dictionaries 2018-01-16 12:27:44 +01:00
Gunnar Beutner
e3ad0be769 Apply clang-tidy fix 'modernize-use-auto' 2018-01-04 12:24:57 +01:00
Gunnar Beutner
621eed3f13 Apply clang-tidy fix 'modernize-pass-by-value' 2018-01-04 12:24:57 +01:00
Gunnar Beutner
ac155d1dda Apply clang-tidy fix 'modernize-redundant-void-arg' 2018-01-04 12:24:57 +01:00
Gunnar Beutner
2f953d6204 Implement shim for libmysqlclient and libpq 2018-01-02 23:29:48 +01:00
Gunnar Beutner
90496b5456 Build libraries as static libraries 2018-01-02 23:29:48 +01:00
Michael Insel
158ae2188e Change copyright header for 2018 2018-01-02 12:08:55 +01:00
Jean Flach
2636e6a77a Whitespace fix
What does this change?
* Remove use of spaces for formatting
These could be found by using `grep -r -l -P '^\t+ +[^*]'
* Removal of training whitespaces
* A few lines longer than 120 chars
2017-12-20 14:53:52 +01:00
Gunnar Beutner
ab8386cf5c Use std::unique_ptr for Expression objects 2017-12-15 10:44:54 +01:00
Gunnar Beutner
1ad83886ac Replace a few more NULLs with nullptr 2017-12-14 15:37:20 +01:00
Gunnar Beutner
96e214221d Remove unused variables 2017-12-14 08:50:09 +01:00
Gunnar Beutner
db6a1fcdb7 Avoid unnecessary allocations in the FunctionCallExpression class 2017-11-29 14:11:09 +01:00
Gunnar Beutner
f9feb41877 Implement support for handling exceptions in user scripts 2017-06-13 14:03:41 +02:00
Gunnar Beutner
d05b7c4178 Allow expressions for the type in object/template declarations 2017-05-11 14:21:30 +02:00
Michael Friedrich
b7caf0820d Ensure that *.icinga.com is used everywhere
fixes #13897
fixes #13277
2017-01-10 17:19:12 +01:00
Gunnar Beutner
7879c09789 Avoid unnecessary dictionary lookups
refs #12555
2016-09-01 07:41:41 +02:00
Gunnar Beutner
06cb3cf875 Another build fix for Windows
refs #9182
2016-08-31 13:43:50 +02:00
Gunnar Beutner
68dceaab06 Replace boost::exception_ptr with std::exception_ptr
refs #9182
2016-08-30 20:46:23 +02:00
Gunnar Beutner
489269e2fa Fix incorrect debug hints for nested dictionary expressions
fixes #12571
2016-08-29 08:46:29 +02:00
Gunnar Beutner
78cd56e277 Implement support for default templates
fixes #12575
2016-08-28 10:27:43 +02:00
Gunnar Beutner
eafe4c578d Avoid unnecessary copies for the DebugHint class
refs #12509
2016-08-27 18:43:14 +02:00
Gunnar Beutner
7194b36d3e Avoid unnecessary string copies for LiteralExpression objects
refs #12509
2016-08-26 18:11:56 +02:00
Gunnar Beutner
288413f046 Replace BOOST_FOREACH with range-based for loops
fixes #12538
2016-08-25 06:46:17 +02:00
Gunnar Beutner
419500e55e Fix 'use' keyword for templates
fixes #12409
2016-08-12 13:32:13 +02:00
Gunnar Beutner
2a40a71ffa Change scoping mechanism for the __using keyword
refs #12408
2016-08-12 13:14:10 +02:00
Gunnar Beutner
3980cf04a0 Fix exception with __using
refs #12408
2016-08-12 12:05:02 +02:00
Gunnar Beutner
c5a170a972 Implement support for namespaces
fixes #12408
2016-08-12 11:32:16 +02:00
Gunnar Beutner
54bbaf9f7d Implement support for marking functions as deprecated
fixes #12393
2016-08-10 15:48:05 +02:00
Gunnar Beutner
3008d5ef31 Improve performance for field accesses
fixes #11612
2016-04-18 17:05:22 +02:00
Gunnar Beutner
eb0892273e Implement the DateTime class
fixes #9839
2016-03-29 13:27:20 +02:00
Gunnar Beutner
6ba0c5fe01 Implement recursion limit for AST expressions which don't use a separate stack frame
fixes #11106
2016-03-23 09:03:49 +01:00
Gunnar Beutner
599929b0f6 Update copyright headers for 2016 2016-01-12 08:29:59 +01:00
Gunnar Beutner
2d2e7ecdb2 Improve location information for exceptions
fixes #10568
2015-11-10 17:05:40 +01:00
Gunnar Beutner
7621870278 Implement a debugger for Icinga scripts
fixes #10547
2015-11-05 14:29:45 +01:00