Interesting. But how is that any different to searching for special comments like gnatdoc does? With comments having the benefit of not creating warnings?
1 Like
The only disadvantage, that I can think of, for using pragma instead of a comment is the warning. (But I think most compilers have a command line switch to disable this warning. GNAT uses -gnatwG to “Suppress warnings on unrecognized pragmas.”)
However, there are several advantages, in my opinion, to using a pragma:
pragmadoes not look like a comment. Readers of the program will immediately know that it has significance beyond informing the reader.- Existing Ada source parsers may pick it up as part of the code. (Such as libadalang.) Building tools using such parsers could be simplified because a custom parser would not be needed. (I expect parsers will pickup all
pragmaor none of them, as it would not know whichpragmaare vaild for you compiler.) - If a compiler wanted to add support for the
pragma, it would be easy to implement, in contrast to adding support for magic comments. - Finally, in my opinion, using a
pragmafeels more inline with the Ada philosophy.
There is a nice way to do this with GNAT, the pragma Annotate:
pragma Annotate (Unit_Test, Test_Function);
-- Maybe it should be an function instead, idk.
procedure Test_Function is begin ... end;
This pragma is used by AdaCore tools, but according to the documentation, and my experience, you don’t get any warning.
This pragma is intended for use by external tools, including ASIS. The use of pragma Annotate does not affect the compilation process in any way.
And you can even get the entity name checked if you use the Entity parameter:
pragma Annotate (Unit_Test, Entity => Test_Funttion);
-- Maybe it should be an function instead, idk.
procedure Test_Function is begin ... end;
test.adb:14:42: error: "Test_Funttion" is undefined
test.adb:14:42: error: possible misspelling of "Test_Function"
3 Likes