diff mbox

[Ada] Argument of pragma Depends has wrong source location

Message ID 20150302110741.GA11796@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet March 2, 2015, 11:07 a.m. UTC
This patch ensures that the normalization mechanism which services aspects
or pragmas Abstract_State, Contract_State, Depends, Global, Initializes,
Refined_Depends, Refined_Global and Refined_State properly sets the
source location of the first item. No change in behavior. No reproducer
possible as this requires ASIS.

Tested on x86_64-pc-linux-gnu, committed on trunk

2015-03-02  Hristian Kirtchev  <kirtchev@adacore.com>

	* sem_prag.adb (Ensure_Aggregate_Form):
	Ensure that the name denoted by the Chars of a pragma argument
	association has the proper Sloc when converted into an aggregate.
diff mbox

Patch

Index: sem_prag.adb
===================================================================
--- sem_prag.adb	(revision 221103)
+++ sem_prag.adb	(working copy)
@@ -5222,21 +5222,32 @@ 
       ---------------------------
 
       procedure Ensure_Aggregate_Form (Arg : Node_Id) is
-         Expr  : constant Node_Id    := Expression (Arg);
-         Loc   : constant Source_Ptr := Sloc (Expr);
-         Comps : List_Id := No_List;
-         Exprs : List_Id := No_List;
-         Nam   : Name_Id;
+         CFSD    : constant Boolean    := Get_Comes_From_Source_Default;
+         Expr    : constant Node_Id    := Expression (Arg);
+         Loc     : constant Source_Ptr := Sloc (Expr);
+         Comps   : List_Id := No_List;
+         Exprs   : List_Id := No_List;
+         Nam     : Name_Id := No_Name;
+         Nam_Loc : Source_Ptr;
 
-         CFSD : constant Boolean := Get_Comes_From_Source_Default;
-         --  Used to restore Comes_From_Source_Default
+      begin
+         --  The pragma argument is in positional form:
 
-      begin
-         if Nkind (Arg) = N_Aspect_Specification then
-            Nam := No_Name;
-         else
-            pragma Assert (Nkind (Arg) = N_Pragma_Argument_Association);
-            Nam := Chars (Arg);
+         --    pragma Depends (Nam => ...)
+         --                    ^
+         --                    Chars field
+
+         --  Note that the Sloc of the Chars field is the Sloc of the pragma
+         --  argument association.
+
+         if Nkind (Arg) = N_Pragma_Argument_Association then
+            Nam     := Chars (Arg);
+            Nam_Loc := Sloc (Arg);
+
+            --  Remove the pragma argument name as this will be captured in the
+            --  aggregate.
+
+            Set_Chars (Arg, No_Name);
          end if;
 
          --  The argument is already in aggregate form, but the presence of a
@@ -5279,17 +5290,10 @@ 
          else
             Comps := New_List (
               Make_Component_Association (Loc,
-                Choices    => New_List (Make_Identifier (Loc, Chars (Arg))),
+                Choices    => New_List (Make_Identifier (Nam_Loc, Nam)),
                 Expression => Relocate_Node (Expr)));
          end if;
 
-         --  Remove the pragma argument name as this information has been
-         --  captured in the aggregate.
-
-         if Nkind (Arg) = N_Pragma_Argument_Association then
-            Set_Chars (Arg, No_Name);
-         end if;
-
          Set_Expression (Arg,
            Make_Aggregate (Loc,
              Component_Associations => Comps,