* [Ada] New function GNAT.Source_Info.Compilation_ISO_Date
@ 2016-04-18 10:36 Arnaud Charlet
0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2016-04-18 10:36 UTC (permalink / raw)
To: gcc-patches; +Cc: Bob Duff
[-- Attachment #1: Type: text/plain, Size: 1385 bytes --]
This patch adds a new function Compilation_ISO_Date to package
GNAT.Source_Info. It is identical to Compilation_Date, except
that the date is returned in standard ISO form -- "yyyy-mm-dd".
This form has the advantage that string comparisons like "<"
can be used to determine the order of dates.
The following source file should compile with errors
(assuming the current date is in the 21'st century):
gnatmake -q -f very_obsolete.ads
very_obsolete.ads:4:30: Delete this package from library
gnatmake: "very_obsolete.ads" compilation error
with GNAT.Source_Info;
package Very_Obsolete is
pragma Obsolescent
(Very_Obsolete,"This package will be compleatly removed 1999-01-01");
pragma Compile_Time_Error
(GNAT.Source_Info.Compilation_ISO_Date > "1999-01-01",
"Delete this package from library");
end Very_Obsolete;
Tested on x86_64-pc-linux-gnu, committed on trunk
2016-04-18 Bob Duff <duff@adacore.com>
* g-souinf.ads (Compilation_ISO_Date): New function to return
the current date in ISO form.
* exp_intr.adb (Expand_Source_Info, Add_Source_Info): Expand
a call to Compilation_ISO_Date into a string literal containing
the current date in ISO form.
* exp_intr.ads (Add_Source_Info): Improve documentation.
* sem_intr.adb (Check_Intrinsic_Subprogram): Recognize
Compilation_ISO_Date.
* snames.ads-tmpl (Name_Compilation_ISO_Date): New Name_Id.
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 6800 bytes --]
Index: sem_intr.adb
===================================================================
--- sem_intr.adb (revision 235093)
+++ sem_intr.adb (working copy)
@@ -359,6 +359,7 @@
Name_Line,
Name_Source_Location,
Name_Enclosing_Entity,
+ Name_Compilation_ISO_Date,
Name_Compilation_Date,
Name_Compilation_Time)
then
Index: g-souinf.ads
===================================================================
--- g-souinf.ads (revision 235093)
+++ g-souinf.ads (working copy)
@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
--- Copyright (C) 2000-2014, Free Software Foundation, Inc. --
+-- Copyright (C) 2000-2015, 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- --
@@ -79,6 +79,10 @@
-- package itself. This is useful in identifying and logging information
-- from within generic templates.
+ function Compilation_ISO_Date return String with
+ Import, Convention => Intrinsic;
+ -- Returns date of compilation as a static string "yyyy-mm-dd".
+
function Compilation_Date return String with
Import, Convention => Intrinsic;
-- Returns date of compilation as a static string "mmm dd yyyy". This is
Index: exp_intr.adb
===================================================================
--- exp_intr.adb (revision 235093)
+++ exp_intr.adb (working copy)
@@ -107,14 +107,10 @@
-- System.Address_To_Access_Conversions.
procedure Expand_Source_Info (N : Node_Id; Nam : Name_Id);
- -- Rewrite the node by the appropriate string or positive constant.
- -- Nam can be one of the following:
- -- Name_File - expand string name of source file
- -- Name_Line - expand integer line number
- -- Name_Source_Location - expand string of form file:line
- -- Name_Enclosing_Entity - expand string name of enclosing entity
- -- Name_Compilation_Date - expand string with compilation date
- -- Name_Compilation_Time - expand string with compilation time
+ -- Rewrite the node as the appropriate string literal or positive
+ -- constant. Nam is the name of one of the intrinsics declared in
+ -- GNAT.Source_Info; see g-souinf.ads for documentation of these
+ -- intrinsics.
procedure Write_Entity_Name (E : Entity_Id);
-- Recursive procedure to construct string for qualified name of enclosing
@@ -165,6 +161,10 @@
Write_Entity_Name (Ent);
+ when Name_Compilation_ISO_Date =>
+ Name_Buffer (1 .. 10) := Opt.Compilation_Time (1 .. 10);
+ Name_Len := 10;
+
when Name_Compilation_Date =>
declare
subtype S13 is String (1 .. 3);
@@ -696,6 +696,7 @@
Name_Line,
Name_Source_Location,
Name_Enclosing_Entity,
+ Name_Compilation_ISO_Date,
Name_Compilation_Date,
Name_Compilation_Time)
then
@@ -851,6 +852,8 @@
------------------------
procedure Expand_Source_Info (N : Node_Id; Nam : Name_Id) is
+ -- ???There is duplicated code here (see Add_Source_Info)
+
Loc : constant Source_Ptr := Sloc (N);
Ent : Entity_Id;
@@ -891,6 +894,10 @@
Write_Entity_Name (Ent);
+ when Name_Compilation_ISO_Date =>
+ Name_Buffer (1 .. 10) := Opt.Compilation_Time (1 .. 10);
+ Name_Len := 10;
+
when Name_Compilation_Date =>
declare
subtype S13 is String (1 .. 3);
Index: exp_intr.ads
===================================================================
--- exp_intr.ads (revision 235093)
+++ exp_intr.ads (working copy)
@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
--- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2015, 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- --
@@ -31,15 +31,11 @@
package Exp_Intr is
procedure Add_Source_Info (Loc : Source_Ptr; Nam : Name_Id);
- -- Append a string to Name_Buffer depending on Nam
- -- Name_File - append name of source file
- -- Name_Line - append line number
- -- Name_Source_Location - append source location (file:line)
- -- Name_Enclosing_Entity - append name of enclosing entity
- -- Name_Compilation_Date - append compilation date
- -- Name_Compilation_Time - append compilation time
- -- The caller must set Name_Buffer and Name_Len before the call. Loc is
- -- passed to provide location information where it is needed.
+ -- Append a string to Name_Buffer depending on Nam, which is the name of
+ -- one of the intrinsics declared in GNAT.Source_Info; see g-souinf.ads for
+ -- documentation of these intrinsics. The caller must set Name_Buffer and
+ -- Name_Len before the call. Loc is passed to provide location information
+ -- where it is needed.
procedure Expand_Intrinsic_Call (N : Node_Id; E : Entity_Id);
-- N is either a function call node, a procedure call statement node, or
Index: snames.ads-tmpl
===================================================================
--- snames.ads-tmpl (revision 235093)
+++ snames.ads-tmpl (working copy)
@@ -1204,6 +1204,7 @@
-- convention name. So is To_Address, which is a GNAT attribute.
First_Intrinsic_Name : constant Name_Id := N + $;
+ Name_Compilation_ISO_Date : constant Name_Id := N + $;
Name_Compilation_Date : constant Name_Id := N + $;
Name_Compilation_Time : constant Name_Id := N + $;
Name_Divide : constant Name_Id := N + $;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2016-04-18 10:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-18 10:36 [Ada] New function GNAT.Source_Info.Compilation_ISO_Date Arnaud Charlet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).