Improve max_insns_skipped logic
[official-gcc.git] / gcc / ada / sinput-p.adb
blobd643d6466ec65c76d79107539aa908c7a3d395f7
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S I N P U T . P --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2017, 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 ------------------------------------------------------------------------------
26 with Unchecked_Conversion;
27 with Unchecked_Deallocation;
29 with Prj.Err;
30 with Sinput.C;
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
51 begin
52 for X in 1 .. Source_File.Last loop
53 declare
54 S : Source_File_Record renames Source_File.Table (X);
55 begin
56 if S.Instance = No_Instance_Id then
57 Free_Source_Buffer (S.Source_Text);
58 else
59 Free_Dope (S.Source_Text'Address);
60 S.Source_Text := null;
61 end if;
63 Free (S.Lines_Table);
64 Free (S.Logical_Lines_Table);
65 end;
66 end loop;
68 Source_File.Free;
69 Sinput.Initialize;
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;
79 begin
80 X := Sinput.C.Load_File (Path);
82 if First then
83 Main_Source_File := X;
84 First := False;
85 end if;
87 return X;
88 end Load_Project_File;
90 -----------------
91 -- Reset_First --
92 -----------------
94 procedure Reset_First is
95 begin
96 First := True;
97 end Reset_First;
99 --------------------------------
100 -- Restore_Project_Scan_State --
101 --------------------------------
103 procedure Restore_Project_Scan_State
104 (Saved_State : Saved_Project_Scan_State)
106 begin
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)
119 begin
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
130 begin
131 -- Nothing to do if X is no source file, so simply return False
133 if X = No_Source_File then
134 return False;
135 end if;
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 ('$');
144 Check_For_BOM;
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)
154 loop
155 Prj.Err.Scanner.Scan;
156 end loop;
158 Prj.Err.Scanner.Reset_Special_Characters;
160 return Token = Tok_Separate;
161 end Source_File_Is_Subunit;
163 end Sinput.P;