-- Write Sptr as a JSON location, an object containing a file attribute,
-- a line number and a column number.
- procedure Write_JSON_Span (Span : Source_Span);
- -- Write Span as a JSON span, an object containing a "caret" attribute
- -- whose value is the JSON location of Span.Ptr. If Span.First and
- -- Span.Last are different from Span.Ptr, they will be printed as JSON
+ procedure Write_JSON_Span (Error : Error_Msg_Object);
+ -- Write Error as a JSON span, an object containing a "caret" attribute
+ -- whose value is the JSON location of Error.Sptr.Ptr. If Sptr.First and
+ -- Sptr.Last are different from Sptr.Ptr, they will be printed as JSON
-- locations under the names "start" and "finish".
+ -- When Include_Subprogram_In_Messages is true (-gnatdJ) an additional,
+ -- non-standard, attribute named "subprogram" will be added, allowing
+ -- precisely identifying the subprogram surrounding the span.
-----------------------
-- Is_Continuation --
-- Write_JSON_Span --
---------------------
- procedure Write_JSON_Span (Span : Source_Span) is
+ procedure Write_JSON_Span (Error : Error_Msg_Object) is
+ Span : constant Source_Span := Error.Sptr;
begin
Write_Str ("{""caret"":");
Write_JSON_Location (Span.Ptr);
Write_JSON_Location (Span.Last);
end if;
+ if Include_Subprogram_In_Messages then
+ Write_Str
+ (",""subprogram"":""" & Subprogram_Name_Ptr (Error.Node) & """");
+ end if;
+
Write_Str ("}");
end Write_JSON_Span;
-- Print message location
Write_Str (",""locations"":[");
- Write_JSON_Span (Errors.Table (E).Sptr);
+ Write_JSON_Span (Errors.Table (E));
if Errors.Table (E).Optr /= Errors.Table (E).Sptr.Ptr then
Write_Str (",{""caret"":");