diff options
author | Tonu Naks <naks@adacore.com> | 2024-07-09 12:02:57 +0000 |
---|---|---|
committer | Marc Poulhiès <dkm@gcc.gnu.org> | 2024-08-02 09:08:06 +0200 |
commit | 8239a5f75dffe5e3a95b3400da9a12c11fd0d100 (patch) | |
tree | 29cd11c81614eb911a56df43336fdf1df2af6cb1 /gcc/ada/doc/gnat_rm | |
parent | ee7945e367c2e9a1127aac0c11c078638601258d (diff) | |
download | gcc-8239a5f75dffe5e3a95b3400da9a12c11fd0d100.zip gcc-8239a5f75dffe5e3a95b3400da9a12c11fd0d100.tar.gz gcc-8239a5f75dffe5e3a95b3400da9a12c11fd0d100.tar.bz2 |
ada: Update doc of Style_Checks pragma
gcc/ada/
* doc/gnat_rm/implementation_defined_pragmas.rst: Add examples.
* gnat_rm.texi: Regenerate.
* gnat_ugn.texi: Regenerate.
Diffstat (limited to 'gcc/ada/doc/gnat_rm')
-rw-r--r-- | gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst | 79 |
1 files changed, 74 insertions, 5 deletions
diff --git a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst index 926c5f4..7ff94c4 100644 --- a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst +++ b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst @@ -6328,21 +6328,91 @@ activated. These are additive, so they apply in addition to any previously set style check options. The codes for the options are the same as those used in the *-gnaty* switch to *gcc* or *gnatmake*. For example the following two methods can be used to enable -layout checking: +layout checking and to change the maximum nesting level value: * - :: + .. code-block:: ada + -- switch on layout checks pragma Style_Checks ("l"); - + -- set the number of maximum allowed nesting levels to 15 + pragma Style_Checks ("L15"); * :: - gcc -c -gnatyl ... + gcc -c -gnatyl -gnatyL15 ... + + +The string literal values can be cumulatively switched on and off by prefixing +the value with ``+`` or ``-``, where: + +* ``+`` is equivalent to no prefix. It applies the check referenced by the + literal value; +* ``-`` switches the referenced check off. + + +.. code-block:: ada + :linenos: + :emphasize-lines: 15 + + -- allow misaligned block by disabling layout check + pragma Style_Checks ("-l"); + declare + msg : constant String := "Hello"; + begin + Put_Line (msg); + end; + + -- enable the layout check again + pragma Style_Checks ("l"); + declare + msg : constant String := "Hello"; + begin + Put_Line (msg); + end; + +The code above contains two layout errors, however, only +the last line is picked up by the compiler. + +Similarly, the switches containing a numeric value can be applied in sequence. +In the example below, the permitted nesting level is reduced in in the middle +block and the compiler raises a warning on the highlighted line. +.. code-block:: ada + :linenos: + :emphasize-lines: 15 + + -- Permit 3 levels of nesting + pragma Style_Checks ("L3"); + + procedure Main is + begin + if True then + if True then + null; + end if; + end if; + -- Reduce permitted nesting levels to 2. + -- Note that "+L2" and "L2" are equivalent. + pragma Style_Checks ("+L2"); + if True then + if True then + null; + end if; + end if; + -- Disable checking permitted nesting levels. + -- Note that the number after "-L" is insignificant, + -- "-L", "-L3" and "-Lx" are all equivalent. + pragma Style_Checks ("-L3"); + if True then + if True then + null; + end if; + end if; + end Main; The form ``ALL_CHECKS`` activates all standard checks (its use is equivalent to the use of the :switch:`gnaty` switch with no options. @@ -6356,7 +6426,6 @@ The forms with ``Off`` and ``On`` can be used to temporarily disable style checks as shown in the following example: - .. code-block:: ada pragma Style_Checks ("k"); -- requires keywords in lower case |