1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT COMPILER COMPONENTS                         --
4--                                                                          --
5--                             S I N P U T . L                              --
6--                                                                          --
7--                                 S p e c                                  --
8--                                                                          --
9--          Copyright (C) 1992-2019, Free Software Foundation, Inc.         --
10--                                                                          --
11-- GNAT is free software;  you can  redistribute it  and/or modify it under --
12-- terms of the  GNU General Public License as published  by the Free Soft- --
13-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17-- for  more details.  You should have  received  a copy of the GNU General --
18-- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
19-- http://www.gnu.org/licenses for a complete copy of the license.          --
20--                                                                          --
21-- GNAT was originally developed  by the GNAT team at  New York University. --
22-- Extensive contributions were provided by Ada Core Technologies Inc.      --
23--                                                                          --
24------------------------------------------------------------------------------
25
26--  This child package contains the routines used to actually load a source
27--  file and create entries in the source file table. It also contains the
28--  routines to create virtual entries for instantiations. This is separated
29--  off into a child package to avoid a dependence of Sinput on Osint which
30--  would cause trouble in the tree read/write routines.
31
32package Sinput.L is
33
34   ------------------------------------------
35   -- Subprograms for Loading Source Files --
36   ------------------------------------------
37
38   function Load_Source_File (N : File_Name_Type) return Source_File_Index;
39   --  Given a source file name, returns the index of the corresponding entry
40   --  in the source file table. If the file is not currently loaded, then
41   --  this is the call that causes the source file to be read and an entry
42   --  made in the table. A new entry in the table has the file name and time
43   --  stamp entries set and the Casing entries set to Unknown. Version is set
44   --  to all blanks, and the lines table is initialized but only the first
45   --  entry is set (and Last_Line is set to 1). If the given source file
46   --  cannot be opened, then the value returned is No_Source_File.
47
48   function Load_Config_File (N : File_Name_Type) return Source_File_Index;
49   --  Similar to Load_Source_File, except that the file name is always
50   --  interpreted in the context of the current working directory.
51   --  The file is never preprocessed.
52
53   function Load_Definition_File
54     (N : File_Name_Type) return Source_File_Index;
55   --  Loads preprocessing definition file. Similar to Load_Source_File
56   --  except that this file is not itself preprocessed.
57
58   function Load_Preprocessing_Data_File
59     (N : File_Name_Type) return Source_File_Index;
60   --  Loads preprocessing data file. Similar to Load_Source_File except
61   --  that this file is not itself preprocessed.
62
63   procedure Complete_Source_File_Entry;
64   --  Called on completing the parsing of a source file. This call completes
65   --  the source file table entry for the current source file.
66
67   function Source_File_Is_Body (X : Source_File_Index) return Boolean;
68   --  Returns true if the designated source file contains a subprogram body
69   --  or a package body. This is a limited scan just to determine the answer
70   --  to this question.
71
72   function Source_File_Is_No_Body (X : Source_File_Index) return Boolean;
73   --  Returns true if the designated source file contains pragma No_Body;
74   --  and no other tokens. If the source file contains anything other than
75   --  this sequence of three tokens, then False is returned.
76
77   -------------------------------------------------
78   -- Subprograms for Dealing With Instantiations --
79   -------------------------------------------------
80
81   type Sloc_Adjustment is private;
82   --  Type returned by Create_Instantiation_Source for use in subsequent calls
83   --  to Adjust_Instantiation_Sloc.
84
85   procedure Adjust_Instantiation_Sloc
86     (N      : Node_Id;
87      Factor : Sloc_Adjustment);
88   --  The instantiation tree is created by copying the tree of the generic
89   --  template (including the original Sloc values), and then applying
90   --  Adjust_Instantiation_Sloc to each copied node to adjust the Sloc to
91   --  reference the source entry for the instantiation.
92
93   procedure Create_Instantiation_Source
94     (Inst_Node        : Entity_Id;
95      Template_Id      : Entity_Id;
96      Factor           : out Sloc_Adjustment;
97      Inlined_Body     : Boolean := False;
98      Inherited_Pragma : Boolean := False);
99   --  This procedure creates the source table entry for an instantiation.
100   --  Inst_Node is the instantiation node, and Template_Id is the defining
101   --  identifier of the generic declaration or body unit as appropriate.
102   --  Factor is set to an adjustment factor to be used in subsequent calls to
103   --  Adjust_Instantiation_Sloc. Template_Id can also be a subunit body that
104   --  replaces a stub in a generic unit.
105   --
106   --  The instantiation mechanism is also used for inlined function and
107   --  procedure calls. The parameter Inlined_Body is set to True in such
108   --  cases. This is used for generating error messages that distinguish these
109   --  two cases, otherwise the two cases are handled identically. Similarly,
110   --  the instantiation mechanism is also used for inherited class-wide pre-
111   --  and postconditions. Parameter Inherited_Pragma is set to True in such
112   --  cases.
113
114private
115
116   type Sloc_Adjustment is record
117      Adjust : Source_Ptr;
118      --  Adjustment factor. To be added to source location values in the
119      --  source table entry for the template to get corresponding sloc
120      --  values for the instantiation image of the template. This is not
121      --  really a Source_Ptr value, but rather an offset, but it is more
122      --  convenient to represent it as a Source_Ptr value and this is a
123      --  private type anyway.
124
125      Lo, Hi : Source_Ptr;
126      --  Lo and hi values to which adjustment factor can legitimately
127      --  be applied, used to ensure that no incorrect adjustments are
128      --  made. Really it is a bug if anyone ever tries to adjust outside
129      --  this range, but since we are only doing this anyway for getting
130      --  better error messages, it is not critical.
131
132   end record;
133
134end Sinput.L;
135