4
votes

A question out of curiosity here, Is it possible to find the name of the method you are in ? Something like this where Magic should output "foo.bar.foobar" without resorting to a string literal.

with ada.text_io;
package body foo.bar is 

   function foobar return boolean is 
   begin
     ada.text_io.put_line ("I am in :" & Magic);
     return true;
   end foobar;

end foo.bar;

I would assume this is information is located somewhere as similar is output for stack traces, exceptions and profiling tools etc, but i cannot find it documented anywhere!

1

1 Answers

5
votes

As I'm sure you already know, Ada (unfortunately) doesn't support reflection.

However... if you're using GNAT and are okay with compiler-specific utilities, you can get this kind of information from the package GNAT.Source_Info.