1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Unchecked_Conversion
;
27 with Unchecked_Deallocation
;
32 package body Sinput
.P
is
34 First
: Boolean := True;
35 -- Flag used when Load_Project_File is called the first time,
36 -- to set Main_Source_File.
37 -- The flag is reset to False at the first call to Load_Project_File.
38 -- Calling Reset_First sets it back to True.
40 procedure Free
is new Unchecked_Deallocation
41 (Lines_Table_Type
, Lines_Table_Ptr
);
43 procedure Free
is new Unchecked_Deallocation
44 (Logical_Lines_Table_Type
, Logical_Lines_Table_Ptr
);
46 -----------------------------
47 -- Clear_Source_File_Table --
48 -----------------------------
50 procedure Clear_Source_File_Table
is
52 for X
in 1 .. Source_File
.Last
loop
54 S
: Source_File_Record
renames Source_File
.Table
(X
);
56 if S
.Instance
= No_Instance_Id
then
57 Free_Source_Buffer
(S
.Source_Text
);
59 Free_Dope
(S
.Source_Text
'Address);
60 S
.Source_Text
:= null;
64 Free
(S
.Logical_Lines_Table
);
70 end Clear_Source_File_Table
;
72 -----------------------
73 -- Load_Project_File --
74 -----------------------
76 function Load_Project_File
(Path
: String) return Source_File_Index
is
77 X
: Source_File_Index
;
80 X
:= Sinput
.C
.Load_File
(Path
);
83 Main_Source_File
:= X
;
88 end Load_Project_File
;
94 procedure Reset_First
is
99 --------------------------------
100 -- Restore_Project_Scan_State --
101 --------------------------------
103 procedure Restore_Project_Scan_State
104 (Saved_State
: Saved_Project_Scan_State
)
107 Restore_Scan_State
(Saved_State
.Scan_State
);
108 Source
:= Saved_State
.Source
;
109 Current_Source_File
:= Saved_State
.Current_Source_File
;
110 end Restore_Project_Scan_State
;
112 -----------------------------
113 -- Save_Project_Scan_State --
114 -----------------------------
116 procedure Save_Project_Scan_State
117 (Saved_State
: out Saved_Project_Scan_State
)
120 Save_Scan_State
(Saved_State
.Scan_State
);
121 Saved_State
.Source
:= Source
;
122 Saved_State
.Current_Source_File
:= Current_Source_File
;
123 end Save_Project_Scan_State
;
125 ----------------------------
126 -- Source_File_Is_Subunit --
127 ----------------------------
129 function Source_File_Is_Subunit
(X
: Source_File_Index
) return Boolean is
131 -- Nothing to do if X is no source file, so simply return False
133 if X
= No_Source_File
then
137 Prj
.Err
.Scanner
.Initialize_Scanner
(X
);
139 -- No error for special characters that are used for preprocessing
141 Prj
.Err
.Scanner
.Set_Special_Character
('#');
142 Prj
.Err
.Scanner
.Set_Special_Character
('$');
146 -- We scan past junk to the first interesting compilation unit token, to
147 -- see if it is SEPARATE. We ignore WITH keywords during this and also
148 -- PRIVATE. The reason for ignoring PRIVATE is that it handles some
149 -- error situations, and also to handle PRIVATE WITH in Ada 2005 mode.
151 while Token
= Tok_With
152 or else Token
= Tok_Private
153 or else (Token
not in Token_Class_Cunit
and then Token
/= Tok_EOF
)
155 Prj
.Err
.Scanner
.Scan
;
158 Prj
.Err
.Scanner
.Reset_Special_Characters
;
160 return Token
= Tok_Separate
;
161 end Source_File_Is_Subunit
;