OSDN Git Service

2007-08-31 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sinput-p.adb
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-2007, 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 2,  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 COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 with Prj.Err;
28 with Sinput.C;
29
30 package body Sinput.P is
31
32    First : Boolean := True;
33    --  Flag used when Load_Project_File is called the first time,
34    --  to set Main_Source_File.
35    --  The flag is reset to False at the first call to Load_Project_File.
36    --  Calling Reset_First sets it back to True.
37
38    -----------------------
39    -- Load_Project_File --
40    -----------------------
41
42    function Load_Project_File (Path : String) return Source_File_Index is
43       X    : Source_File_Index;
44
45    begin
46       X := Sinput.C.Load_File (Path);
47
48       if First then
49          Main_Source_File := X;
50          First := False;
51       end if;
52
53       return X;
54    end Load_Project_File;
55
56    -----------------
57    -- Reset_First --
58    -----------------
59
60    procedure Reset_First is
61    begin
62       First := True;
63    end Reset_First;
64
65    --------------------------------
66    -- Restore_Project_Scan_State --
67    --------------------------------
68
69    procedure Restore_Project_Scan_State
70      (Saved_State : Saved_Project_Scan_State)
71    is
72    begin
73       Restore_Scan_State (Saved_State.Scan_State);
74       Source              := Saved_State.Source;
75       Current_Source_File := Saved_State.Current_Source_File;
76    end Restore_Project_Scan_State;
77
78    -----------------------------
79    -- Save_Project_Scan_State --
80    -----------------------------
81
82    procedure Save_Project_Scan_State
83      (Saved_State : out Saved_Project_Scan_State)
84    is
85    begin
86       Save_Scan_State (Saved_State.Scan_State);
87       Saved_State.Source              := Source;
88       Saved_State.Current_Source_File := Current_Source_File;
89    end Save_Project_Scan_State;
90
91    ----------------------------
92    -- Source_File_Is_Subunit --
93    ----------------------------
94
95    function Source_File_Is_Subunit (X : Source_File_Index) return Boolean is
96    begin
97       Prj.Err.Scanner.Initialize_Scanner (X);
98
99       --  We scan past junk to the first interesting compilation unit
100       --  token, to see if it is SEPARATE. We ignore WITH keywords during
101       --  this and also PRIVATE. The reason for ignoring PRIVATE is that
102       --  it handles some error situations, and also to handle PRIVATE WITH
103       --  in Ada 2005 mode.
104
105       while Token = Tok_With
106         or else Token = Tok_Private
107         or else (Token not in Token_Class_Cunit and then Token /= Tok_EOF)
108       loop
109          Prj.Err.Scanner.Scan;
110       end loop;
111
112       return Token = Tok_Separate;
113    end Source_File_Is_Subunit;
114
115 end Sinput.P;