summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@diac24.net>2019-08-13 16:02:51 +0200
committerDavid Lamparter <equinox@diac24.net>2019-09-03 17:18:35 +0200
commit81047bc5b7f8c28037084adda318fdd68c1a5776 (patch)
treebb59211f6c73ff8a468914b3fb7f8381667fd20c
parent*: frr_elevate_privs -> frr_with_privs (diff)
downloadfrr-81047bc5b7f8c28037084adda318fdd68c1a5776.tar.xz
frr-81047bc5b7f8c28037084adda318fdd68c1a5776.zip
doc: add frr_{each,with} to coding style
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
-rw-r--r--doc/developer/workflow.rst22
1 files changed, 22 insertions, 0 deletions
diff --git a/doc/developer/workflow.rst b/doc/developer/workflow.rst
index 07c43ac2d..3c6887fba 100644
--- a/doc/developer/workflow.rst
+++ b/doc/developer/workflow.rst
@@ -767,6 +767,28 @@ ways that can be unexpected for the original implementor. As such debugs
ability to turn on/off debugs from the CLI and it is expected that the
developer will use this convention to allow control of their debugs.
+Custom syntax-like block macros
+-------------------------------
+
+FRR uses some macros that behave like the ``for`` or ``if`` C keywords. These
+macros follow these patterns:
+
+- loop-style macros are named ``frr_each_*`` (and ``frr_each``)
+- single run macros are named ``frr_with_*``
+- to avoid confusion, ``frr_with_*`` macros must always use a ``{ ... }``
+ block even if the block only contains one statement. The ``frr_each``
+ constructs are assumed to be well-known enough to use normal ``for`` rules.
+- ``break``, ``return`` and ``goto`` all work correctly. For loop-style
+ macros, ``continue`` works correctly too.
+
+Both the ``each`` and ``with`` keywords are inspired by other (more
+higher-level) programming languages that provide these constructs.
+
+There are also some older iteration macros, e.g. ``ALL_LIST_ELEMENTS`` and
+``FOREACH_AFI_SAFI``. These macros in some cases do **not** fulfill the above
+pattern (e.g. ``break`` does not work in ``FOREACH_AFI_SAFI`` because it
+expands to 2 nested loops.)
+
Static Analysis and Sanitizers
------------------------------
Clang/LLVM and GCC come with a variety of tools that can be used to help find