comp.lang.ada
 help / color / mirror / Atom feed
* GNATCheck and pragma Annotate
@ 2011-07-29 17:11 Vinzent Hoefler
  0 siblings, 0 replies; only message in thread
From: Vinzent Hoefler @ 2011-07-29 17:11 UTC (permalink / raw)


Hi,

I was recently trying to implement some coding standard rules based on gnatcheck
and ran into a problem with the "Annotate pragma".

Following simple example shall show the problem:

-- 8< --
procedure Test_Subtypes is

    pragma Suppress (All_Checks);

    subtype A is Integer range  1 ..  5;

begin
    null;
end Test_Subtypes;
-- 8< --

Now I don't want dependence on predefined numeric types and initially disallow any
use of pragmas:

$ gnatcheck test_subtypes.adb -rules +RPredefined_Numeric_Types
   +RForbidden_Pragmas:ALL

test_subtypes.adb:3:4: use of pragma Suppress
test_subtypes.adb:5:17: explicit reference to predefined numeric subtype

So far, so good. Now, let's say, I want to silence down the rule check on this
particular type declaration. So, there's the Annotate pragma:

-- 8< --
    pragma Suppress (All_Checks);

    pragma Annotate (gnatcheck, Exempt_On, "Predefined_Numeric_Types", "We need it here.");
    subtype A is Integer range  1 ..  5;
    pragma Annotate (gnatcheck, Exempt_Off, "Predefined_Numeric_Types");
-- 8< --

$ gnatcheck src/test_subtypes.adb -rules +RPredefined_Numeric_Types
   +RForbidden_Pragmas:ALL

test_subtypes.adb:3:4: use of pragma Suppress
test_subtypes.adb:5:4: use of pragma Annotate
test_subtypes.adb:7:4: use of pragma Annotate

Ok, this somehow works. Now - of course - I do not want to swap one coding
standard violation (predefined numeric types) with two different ones
(forbidden pragma), so I want allow the "Annotate" pragma:

$ gnatcheck src/test_subtypes.adb -rules +RPredefined_Numeric_Types
   +RForbidden_Pragmas:ALL -RForbidden_Pragmas:Annotate

test_subtypes.adb:3:4: use of pragma Suppress
test_subtypes.adb:5:4: use of pragma Annotate
test_subtypes.adb:7:4: use of pragma Annotate

What...? Although I stated that "Annotate" is allowed, the rule is
still violated?

Interestingly, for "pragma Suppress" the above works, if I say
"-RForbidden_Pragmas:Annotate,Suppress" the "Suppress" pragma does not
get flagged anymore, but the two "Annotate" pragmas still do get flagged.

So I suppose I read the gnatcheck manual correctly and it's not just some
stupid syntactic error on my side.

Is that intended behaviour of gnatcheck or am I doing something fundamentally
wrong? For now, I will probably reverse the logic for pragma usage by explicitely
listing all that are disallowed (my intent was to disallow all and turn off
the check explicitely for those allowed), but especially for implementation defined
pragmas this is not really a good solution, because I can not know them in
advance.

And of course, for each justified coding standard violation I now get two
different ones into the report, and somehow I doubt, I could convince the
Important People(tm) that this is better than not justifying the rule violation
at all.


Vinzent.

-- 
f u cn rd ths, u cn gt a gd jb n cmptr prgrmmng.



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-07-29 17:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-29 17:11 GNATCheck and pragma Annotate Vinzent Hoefler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox