Is it possible to write your own gnatcheck rules, and if so, can someone point me to a good reference? I am searching for a particular "style" that is being used, and would love if I could simply write a rule that says if you see said style, it will throw up a warning, or an error, this way we can flag when this isn't following a particular standard.
3 Answers
In addition to trashgod's reference, I think Section 7.1 of this PDF might be of some help:
http://extranet.eu.adacore.com/articles/HighIntegrityAda.pdf

- 4,095
- 1
- 17
- 31
-
Ah, [GNATcheck](http://www.adacore.com/2011/01/14/gnatcheck-reference-manual/) is part of GNAT Pro. – trashgod Jun 22 '11 at 01:47
-
Also part of GNAT GPL 2011. I found the RM in the distribution at share/doc/gnat/pdf/gnatcheck_rm.pdf. The strong impression is that you can only change which rules are checked, so if -gnaty doesn't support your check you will be out of luck. Would AdaControl help? (http://www.adalog.fr/adacontrol2.htm) – Simon Wright Jun 24 '11 at 11:30
-
And GNAT GPL 2010 and 2009, at least. – JasonFruit Jul 09 '11 at 11:51
-
@JasonFruit - I just read your article "My Two Languages," and must say it's pretty good. – Shark8 Jul 11 '11 at 23:43
-
@Shark8 --- Thanks! It's nice to know that someone's reading now and then! – JasonFruit Jul 12 '11 at 19:50
A bit of background may be helpful here. While the style checks hold out a lot of promise for enforcing user style guidelines, that isn't exactly what they are for.
The main purpose of those checks is to enforce Ada Core's (The folks who maintain the compiler) style on the sources of the Ada compiler itself. You may notice that the checks get automatically turned on if you try compiling one of the compiler's own source files.
It doesn't really serve AdaCore's purposes at all if the styles enforced by the checks themselves are user-configurable, so they added no feature like that.
Your first option if you want to use it yourself is to just stick to AdaCore's coding style. I haven't found it horrible in the past, so you may just look at doing that.
Still, making some kind of configurability would be a really cool feature for somebody to add. If you go this route, you probably would have to make it configurable (with the current behavior as the default), rather than just changing the checks. The reason is that you'd have to modify the compiler sources to accomplish this, and as I mentioned above, the compiler turns the checks on when compiling itself. You really don't want to have to reformat a ton of working Gnat compiler source files.
I'd really like to see someone do this at some point, as it would make the checks much more useful to those of us who work for someone besides AdaCore.

- 44,016
- 10
- 73
- 134
-
IMO, it's a poor choice to have the compiler enforce style-checks (style is, after all, a matter of preference); a better option would be to have the compiler able to read in some valid code and re-format it in whatever [user-specified] style was appropriate. – Shark8 Jul 01 '11 at 18:35
-
@Shark8 - I can see where you are coming from. The problem is that if one does want some kind of style enforcement (or at least warnings), then for all but the most trivial cases it requires a certain amount of source code parsing. A compiler is obviously well situated to do this, where a separate program without access to the compiler's codebase would have a lot of work ahead of it. – T.E.D. Jul 05 '11 at 16:27
-
Well, if you're using the compiler itself to re-format the source into some "standard style" then the 'separate program' argument is predicated on an invalid assumption. – Shark8 Jul 07 '11 at 23:21
-
@T.E.D. - Is there a reference to AdaCore's house style somewhere public? – JasonFruit Jul 13 '11 at 18:04
For reference, the existing GNAT style checking is described in the GNAT User's Guide under §3.2.5 Style Checking
. As the rules are enforced by the compiler, additional rules would require corresponding modifications.

- 203,806
- 29
- 246
- 1,045