In GNATprove, we need to distinguish code form inlined subprograms and code from generic instances, based on their source locations, to have better messages. This new query does precisely this.
Tested on x86_64-pc-linux-gnu, committed on trunk 2014-07-30 Yannick Moy <m...@adacore.com> * sinput.ads, sinput.adb (Comes_From_Inlined_Body): New function that returns True for source pointer for an inlined body.
Index: sinput.adb =================================================================== --- sinput.adb (revision 213201) +++ sinput.adb (working copy) @@ -302,6 +302,17 @@ end case; end Check_For_BOM; + ----------------------------- + -- Comes_From_Inlined_Body -- + ----------------------------- + + function Comes_From_Inlined_Body (S : Source_Ptr) return Boolean is + SIE : Source_File_Record renames + Source_File.Table (Get_Source_File_Index (S)); + begin + return SIE.Inlined_Body; + end Comes_From_Inlined_Body; + ----------------------- -- Get_Column_Number -- ----------------------- Index: sinput.ads =================================================================== --- sinput.ads (revision 213201) +++ sinput.ads (working copy) @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 1992-2013, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2014, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -638,6 +638,13 @@ -- value of the instantiation if this location is within an instance. -- If S is not within an instance, then this returns No_Location. + function Comes_From_Inlined_Body (S : Source_Ptr) return Boolean; + pragma Inline (Comes_From_Inlined_Body); + -- Given a source pointer S, returns whether it comes from an inlined body. + -- This allows distinguishing these source pointers from those that come + -- from instantiation of generics, since Instantiation_Location returns a + -- valid location in both cases. + function Top_Level_Location (S : Source_Ptr) return Source_Ptr; -- Given a source pointer S, returns the argument unchanged if it is -- not in an instantiation. If S is in an instantiation, then it returns