trendy_test_0.0.3_a0e14736/src/trendy_locations.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
with Interfaces.C.Strings;

-- Source code reporting using GCC built-ins to avoid dependencies on GNAT
-- libraries.
package Trendy_Locations is
    subtype Char_Ptr is Interfaces.C.Strings.chars_ptr;
    function File_Line return Natural;
    function File_Name return Char_Ptr;
    function Subprogram_Name return Char_Ptr;
    function Image (Str : Char_Ptr) return String renames Interfaces.C.Strings.Value;
    pragma Import (Intrinsic, File_Line, "__builtin_LINE");
    pragma Import (Intrinsic, File_Name, "__builtin_FILE");
    pragma Import (Intrinsic, Subprogram_Name, "__builtin_FUNCTION");

    -- Prevent from having to lug around files and lines separately by
    -- simply making them part of the same group.
    type Source_Location is record
        File : Char_Ptr;
        Line : Natural;
    end record;

    -- Call with no parameters to make a file/line location at the current
    -- in the file.
    function Make_Source_Location (File : Char_Ptr := File_Name;
                                    Line : Natural := File_Line) return Source_Location;

    function Image (Loc : Source_Location) return String;
end Trendy_Locations;