libgpr2_24.0.0_eda3c693/src/lib/gpr2-source.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
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
--
--  Copyright (C) 2019-2023, AdaCore
--
--  SPDX-License-Identifier: Apache-2.0 WITH LLVM-Exception
--

--  This package defines a source Object. This source object is shared with all
--  loaded project tree.

with Ada.Calendar;

with GPR2.Unit;
with GPR2.Unit.List;
with GPR2.Path_Name;
with GPR2.Source_Info;

package GPR2.Source is

   --  use type GPR2.Unit.Library_Unit_Type;

   type Object is new Source_Info.Object with private;

   Undefined : constant Object;
   --  This constant is equal to any object declared without an explicit
   --  initializer.

   overriding function Is_Defined (Self : Object) return Boolean;
   --  Returns true if Self is defined

   function "<" (Left, Right : Object) return Boolean;

   overriding function "=" (Left, Right : Object) return Boolean;
   --  A source object is equal if it is the same unit for unit based language,
   --  and if it is the same filename otherwise.

   function Path_Name (Self : Object) return Path_Name.Object
     with Pre => Self.Is_Defined;
   --  Returns the path-name for the given source

   function Timestamp (Self : Object; ALI : Boolean) return Ada.Calendar.Time
     with Pre => Self.Is_Defined;
   --  Returns last modification time for this source
   --  If Ali is True then timestamp returned as it is rounded in ALI files.

   function Create
     (Filename  : GPR2.Path_Name.Object;
      Language  : Language_Id;
      Kind      : GPR2.Unit.Library_Unit_Type;
      Timestamp : Ada.Calendar.Time) return Object'Class
     with Pre  => Filename.Is_Defined and then Language /= Ada_Language,
          Post => Create'Result.Is_Defined;
   --  Constructor for a non-Ada source object

   function Create_Ada
     (Filename      : GPR2.Path_Name.Object;
      Units         : GPR2.Unit.List.Object;
      Timestamp     : Ada.Calendar.Time) return Object'Class
     with Pre  => Filename.Is_Defined and then not Units.Is_Empty,
          Post => Create_Ada'Result.Is_Defined;
   --  Constructor for a multi-unit Ada source object.
   --  Information in Units parameter came from filenames and
   --  project information only. It can be different from function
   --  Units call results because Separate Ada units can be
   --  determined only on parsing source files.

   function Create_Ada
     (Filename      : GPR2.Path_Name.Object;
      Unit          : GPR2.Unit.Object;
      Is_RTS_Source : Boolean;
      Timestamp     : Ada.Calendar.Time) return Object'Class
     with Pre  => Filename.Is_Defined and then Unit.Is_Defined,
     Post => Create_Ada'Result.Is_Defined;
   --  Constructor for a single-unit Ada source object

private

   function To_ALI_Timestamp (Stamp : Calendar.Time) return Calendar.Time;
   --  Round Timestamp to the precision used in ALI file. On windows use first
   --  greater time with an even number of second.

   type Object is new Source_Info.Object with record
      Path_Name : GPR2.Path_Name.Object;
      Timestamp : Calendar.Time := No_Time;
      Ada_Key   : Unbounded_String;
   end record;

   Undefined : constant Object :=
                 Object'(Source_Info.Undefined
                         with others => <>);

   overriding function Is_Defined (Self : Object) return Boolean is
     (Self /= Undefined);

   function Timestamp (Self : Object; ALI : Boolean) return Ada.Calendar.Time
   is (if ALI then To_ALI_Timestamp (Self.Timestamp) else Self.Timestamp);

   function Path_Name (Self : Object) return GPR2.Path_Name.Object is
     (Self.Path_Name);

end GPR2.Source;