OSDN Git Service

2009-05-06 Sergey Rybin <rybin@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sinput-l.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             S I N P U T . L                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2009, 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 with Alloc;
27 with Atree;    use Atree;
28 with Debug;    use Debug;
29 with Einfo;    use Einfo;
30 with Errout;   use Errout;
31 with Fname;    use Fname;
32 with Hostparm;
33 with Opt;      use Opt;
34 with Osint;    use Osint;
35 with Output;   use Output;
36 with Prep;     use Prep;
37 with Prepcomp; use Prepcomp;
38 with Scans;    use Scans;
39 with Scn;      use Scn;
40 with Sinfo;    use Sinfo;
41 with Snames;   use Snames;
42 with System;   use System;
43
44 with System.OS_Lib; use System.OS_Lib;
45
46 with Unchecked_Conversion;
47
48 package body Sinput.L is
49
50    Prep_Buffer : Text_Buffer_Ptr := null;
51    --  A buffer to temporarily stored the result of preprocessing a source.
52    --  It is only allocated if there is at least one source to preprocess.
53
54    Prep_Buffer_Last : Text_Ptr := 0;
55    --  Index of the last significant character in Prep_Buffer
56
57    Initial_Size_Of_Prep_Buffer : constant := 10_000;
58    --  Size of Prep_Buffer when it is first allocated
59
60    --  When a file is to be preprocessed and the options to list symbols
61    --  has been selected (switch -s), Prep.List_Symbols is called with a
62    --  "foreword", a single line indicating what source the symbols apply to.
63    --  The following two constant String are the start and the end of this
64    --  foreword.
65
66    Foreword_Start : constant String :=
67                       "Preprocessing Symbols for source """;
68
69    Foreword_End : constant String := """";
70
71    -----------------
72    -- Subprograms --
73    -----------------
74
75    procedure Put_Char_In_Prep_Buffer (C : Character);
76    --  Add one character in Prep_Buffer, extending Prep_Buffer if need be.
77    --  Used to initialize the preprocessor.
78
79    procedure New_EOL_In_Prep_Buffer;
80    --  Add an LF to Prep_Buffer (used to initialize the preprocessor)
81
82    function Load_File
83      (N : File_Name_Type;
84       T : Osint.File_Type) return Source_File_Index;
85    --  Load a source file, a configuration pragmas file or a definition file
86    --  Coding also allows preprocessing file, but not a library file ???
87
88    -------------------------------
89    -- Adjust_Instantiation_Sloc --
90    -------------------------------
91
92    procedure Adjust_Instantiation_Sloc (N : Node_Id; A : Sloc_Adjustment) is
93       Loc : constant Source_Ptr := Sloc (N);
94
95    begin
96       --  We only do the adjustment if the value is between the appropriate low
97       --  and high values. It is not clear that this should ever not be the
98       --  case, but in practice there seem to be some nodes that get copied
99       --  twice, and this is a defence against that happening.
100
101       if A.Lo <= Loc and then Loc <= A.Hi then
102          Set_Sloc (N, Loc + A.Adjust);
103       end if;
104    end Adjust_Instantiation_Sloc;
105
106    --------------------------------
107    -- Complete_Source_File_Entry --
108    --------------------------------
109
110    procedure Complete_Source_File_Entry is
111       CSF : constant Source_File_Index := Current_Source_File;
112
113    begin
114       Trim_Lines_Table (CSF);
115       Source_File.Table (CSF).Source_Checksum := Checksum;
116    end Complete_Source_File_Entry;
117
118    ---------------------------------
119    -- Create_Instantiation_Source --
120    ---------------------------------
121
122    procedure Create_Instantiation_Source
123      (Inst_Node    : Entity_Id;
124       Template_Id  : Entity_Id;
125       Inlined_Body : Boolean;
126       A            : out Sloc_Adjustment)
127    is
128       Dnod : constant Node_Id := Declaration_Node (Template_Id);
129       Xold : Source_File_Index;
130       Xnew : Source_File_Index;
131
132    begin
133       Xold := Get_Source_File_Index (Sloc (Template_Id));
134       A.Lo := Source_File.Table (Xold).Source_First;
135       A.Hi := Source_File.Table (Xold).Source_Last;
136
137       Source_File.Append (Source_File.Table (Xold));
138       Xnew := Source_File.Last;
139
140       Source_File.Table (Xnew).Inlined_Body  := Inlined_Body;
141       Source_File.Table (Xnew).Instantiation := Sloc (Inst_Node);
142       Source_File.Table (Xnew).Template      := Xold;
143
144       --  Now we need to compute the new values of Source_First, Source_Last
145       --  and adjust the source file pointer to have the correct virtual
146       --  origin for the new range of values.
147
148       Source_File.Table (Xnew).Source_First :=
149         Source_File.Table (Xnew - 1).Source_Last + 1;
150       A.Adjust := Source_File.Table (Xnew).Source_First - A.Lo;
151       Source_File.Table (Xnew).Source_Last := A.Hi + A.Adjust;
152
153       Set_Source_File_Index_Table (Xnew);
154
155       Source_File.Table (Xnew).Sloc_Adjust :=
156         Source_File.Table (Xold).Sloc_Adjust - A.Adjust;
157
158       if Debug_Flag_L then
159          Write_Eol;
160          Write_Str ("*** Create instantiation source for ");
161
162          if Nkind (Dnod) in N_Proper_Body
163            and then Was_Originally_Stub (Dnod)
164          then
165             Write_Str ("subunit ");
166
167          elsif Ekind (Template_Id) = E_Generic_Package then
168             if Nkind (Dnod) = N_Package_Body then
169                Write_Str ("body of package ");
170             else
171                Write_Str ("spec of package ");
172             end if;
173
174          elsif Ekind (Template_Id) = E_Function then
175             Write_Str ("body of function ");
176
177          elsif Ekind (Template_Id) = E_Procedure then
178             Write_Str ("body of procedure ");
179
180          elsif Ekind (Template_Id) = E_Generic_Function then
181             Write_Str ("spec of function ");
182
183          elsif Ekind (Template_Id) = E_Generic_Procedure then
184             Write_Str ("spec of procedure ");
185
186          elsif Ekind (Template_Id) = E_Package_Body then
187             Write_Str ("body of package ");
188
189          else pragma Assert (Ekind (Template_Id) = E_Subprogram_Body);
190
191             if Nkind (Dnod) = N_Procedure_Specification then
192                Write_Str ("body of procedure ");
193             else
194                Write_Str ("body of function ");
195             end if;
196          end if;
197
198          Write_Name (Chars (Template_Id));
199          Write_Eol;
200
201          Write_Str ("  new source index = ");
202          Write_Int (Int (Xnew));
203          Write_Eol;
204
205          Write_Str ("  copying from file name = ");
206          Write_Name (File_Name (Xold));
207          Write_Eol;
208
209          Write_Str ("  old source index = ");
210          Write_Int (Int (Xold));
211          Write_Eol;
212
213          Write_Str ("  old lo = ");
214          Write_Int (Int (A.Lo));
215          Write_Eol;
216
217          Write_Str ("  old hi = ");
218          Write_Int (Int (A.Hi));
219          Write_Eol;
220
221          Write_Str ("  new lo = ");
222          Write_Int (Int (Source_File.Table (Xnew).Source_First));
223          Write_Eol;
224
225          Write_Str ("  new hi = ");
226          Write_Int (Int (Source_File.Table (Xnew).Source_Last));
227          Write_Eol;
228
229          Write_Str ("  adjustment factor = ");
230          Write_Int (Int (A.Adjust));
231          Write_Eol;
232
233          Write_Str ("  instantiation location: ");
234          Write_Location (Sloc (Inst_Node));
235          Write_Eol;
236       end if;
237
238       --  For a given character in the source, a higher subscript will be used
239       --  to access the instantiation, which means that the virtual origin must
240       --  have a corresponding lower value. We compute this new origin by
241       --  taking the address of the appropriate adjusted element in the old
242       --  array. Since this adjusted element will be at a negative subscript,
243       --  we must suppress checks.
244
245       declare
246          pragma Suppress (All_Checks);
247
248          pragma Warnings (Off);
249          --  This unchecked conversion is aliasing safe, since it is never used
250          --  to create improperly aliased pointer values.
251
252          function To_Source_Buffer_Ptr is new
253            Unchecked_Conversion (Address, Source_Buffer_Ptr);
254
255          pragma Warnings (On);
256
257       begin
258          Source_File.Table (Xnew).Source_Text :=
259            To_Source_Buffer_Ptr
260              (Source_File.Table (Xold).Source_Text (-A.Adjust)'Address);
261       end;
262    end Create_Instantiation_Source;
263
264    ----------------------
265    -- Load_Config_File --
266    ----------------------
267
268    function Load_Config_File
269      (N : File_Name_Type) return Source_File_Index
270    is
271    begin
272       return Load_File (N, Osint.Config);
273    end Load_Config_File;
274
275    --------------------------
276    -- Load_Definition_File --
277    --------------------------
278
279    function Load_Definition_File
280      (N : File_Name_Type) return Source_File_Index
281    is
282    begin
283       return Load_File (N, Osint.Definition);
284    end Load_Definition_File;
285
286    ---------------
287    -- Load_File --
288    ---------------
289
290    function Load_File
291      (N : File_Name_Type;
292       T : Osint.File_Type) return Source_File_Index
293    is
294       Src : Source_Buffer_Ptr;
295       X   : Source_File_Index;
296       Lo  : Source_Ptr;
297       Hi  : Source_Ptr;
298
299       Preprocessing_Needed : Boolean := False;
300
301    begin
302       --  If already there, don't need to reload file. An exception occurs
303       --  in multiple unit per file mode. It would be nice in this case to
304       --  share the same source file for each unit, but this leads to many
305       --  difficulties with assumptions (e.g. in the body of lib), that a
306       --  unit can be found by locating its source file index. Since we do
307       --  not expect much use of this mode, it's no big deal to waste a bit
308       --  of space and time by reading and storing the source multiple times.
309
310       if Multiple_Unit_Index = 0 then
311          for J in 1 .. Source_File.Last loop
312             if Source_File.Table (J).File_Name = N then
313                return J;
314             end if;
315          end loop;
316       end if;
317
318       --  Here we must build a new entry in the file table
319
320       --  But first, we must check if a source needs to be preprocessed,
321       --  because we may have to load and parse a definition file, and we want
322       --  to do that before we load the source, so that the buffer of the
323       --  source will be the last created, and we will be able to replace it
324       --  and modify Hi without stepping on another buffer.
325
326       if T = Osint.Source and then not Is_Internal_File_Name (N) then
327          Prepare_To_Preprocess
328            (Source => N, Preprocessing_Needed => Preprocessing_Needed);
329       end if;
330
331       Source_File.Increment_Last;
332       X := Source_File.Last;
333
334       if X = Source_File.First then
335          Lo := First_Source_Ptr;
336       else
337          Lo := Source_File.Table (X - 1).Source_Last + 1;
338       end if;
339
340       Osint.Read_Source_File (N, Lo, Hi, Src, T);
341
342       if Src = null then
343          Source_File.Decrement_Last;
344          return No_Source_File;
345
346       else
347          if Debug_Flag_L then
348             Write_Eol;
349             Write_Str ("*** Build source file table entry, Index = ");
350             Write_Int (Int (X));
351             Write_Str (", file name = ");
352             Write_Name (N);
353             Write_Eol;
354             Write_Str ("  lo = ");
355             Write_Int (Int (Lo));
356             Write_Eol;
357             Write_Str ("  hi = ");
358             Write_Int (Int (Hi));
359             Write_Eol;
360
361             Write_Str ("  first 10 chars -->");
362
363             declare
364                procedure Wchar (C : Character);
365                --  Writes character or ? for control character
366
367                procedure Wchar (C : Character) is
368                begin
369                   if C < ' ' or C in ASCII.DEL .. Character'Val (16#9F#) then
370                      Write_Char ('?');
371                   else
372                      Write_Char (C);
373                   end if;
374                end Wchar;
375
376             begin
377                for J in Lo .. Lo + 9 loop
378                   Wchar (Src (J));
379                end loop;
380
381                Write_Str ("<--");
382                Write_Eol;
383
384                Write_Str ("  last 10 chars  -->");
385
386                for J in Hi - 10 .. Hi - 1 loop
387                   Wchar (Src (J));
388                end loop;
389
390                Write_Str ("<--");
391                Write_Eol;
392
393                if Src (Hi) /= EOF then
394                   Write_Str ("  error: no EOF at end");
395                   Write_Eol;
396                end if;
397             end;
398          end if;
399
400          declare
401             S         : Source_File_Record renames Source_File.Table (X);
402             File_Type : Type_Of_File;
403
404          begin
405             case T is
406                when Osint.Source =>
407                   File_Type := Sinput.Src;
408
409                when Osint.Library =>
410                   raise Program_Error;
411
412                when Osint.Config =>
413                   File_Type := Sinput.Config;
414
415                when Osint.Definition =>
416                   File_Type := Def;
417
418                when Osint.Preprocessing_Data =>
419                   File_Type := Preproc;
420             end case;
421
422             S := (Debug_Source_Name   => N,
423                   File_Name           => N,
424                   File_Type           => File_Type,
425                   First_Mapped_Line   => No_Line_Number,
426                   Full_Debug_Name     => Osint.Full_Source_Name,
427                   Full_File_Name      => Osint.Full_Source_Name,
428                   Full_Ref_Name       => Osint.Full_Source_Name,
429                   Identifier_Casing   => Unknown,
430                   Inlined_Body        => False,
431                   Instantiation       => No_Location,
432                   Keyword_Casing      => Unknown,
433                   Last_Source_Line    => 1,
434                   License             => Unknown,
435                   Lines_Table         => null,
436                   Lines_Table_Max     => 1,
437                   Logical_Lines_Table => null,
438                   Num_SRef_Pragmas    => 0,
439                   Reference_Name      => N,
440                   Sloc_Adjust         => 0,
441                   Source_Checksum     => 0,
442                   Source_First        => Lo,
443                   Source_Last         => Hi,
444                   Source_Text         => Src,
445                   Template            => No_Source_File,
446                   Unit                => No_Unit,
447                   Time_Stamp          => Osint.Current_Source_File_Stamp);
448
449             Alloc_Line_Tables (S, Opt.Table_Factor * Alloc.Lines_Initial);
450             S.Lines_Table (1) := Lo;
451          end;
452
453          --  Preprocess the source if it needs to be preprocessed
454
455          if Preprocessing_Needed then
456
457             --  Temporarily set the Source_File_Index_Table entries for the
458             --  source, to avoid crash when reporting an error.
459
460             Set_Source_File_Index_Table (X);
461
462             if Opt.List_Preprocessing_Symbols then
463                Get_Name_String (N);
464
465                declare
466                   Foreword : String (1 .. Foreword_Start'Length +
467                                           Name_Len + Foreword_End'Length);
468
469                begin
470                   Foreword (1 .. Foreword_Start'Length) := Foreword_Start;
471                   Foreword (Foreword_Start'Length + 1 ..
472                               Foreword_Start'Length + Name_Len) :=
473                     Name_Buffer (1 .. Name_Len);
474                   Foreword (Foreword'Last - Foreword_End'Length + 1 ..
475                               Foreword'Last) := Foreword_End;
476                   Prep.List_Symbols (Foreword);
477                end;
478             end if;
479
480             declare
481                T : constant Nat := Total_Errors_Detected;
482                --  Used to check if there were errors during preprocessing
483
484                Save_Style_Check : Boolean;
485                --  Saved state of the Style_Check flag (which needs to be
486                --  temporarily set to False during preprocessing, see below).
487
488                Modified : Boolean;
489
490             begin
491                --  If this is the first time we preprocess a source, allocate
492                --  the preprocessing buffer.
493
494                if Prep_Buffer = null then
495                   Prep_Buffer :=
496                     new Text_Buffer (1 .. Initial_Size_Of_Prep_Buffer);
497                end if;
498
499                --  Make sure the preprocessing buffer is empty
500
501                Prep_Buffer_Last := 0;
502
503                --  Initialize the preprocessor hooks
504
505                Prep.Setup_Hooks
506                  (Error_Msg         => Errout.Error_Msg'Access,
507                   Scan              => Scn.Scanner.Scan'Access,
508                   Set_Ignore_Errors => Errout.Set_Ignore_Errors'Access,
509                   Put_Char          => Put_Char_In_Prep_Buffer'Access,
510                   New_EOL           => New_EOL_In_Prep_Buffer'Access);
511
512                --  Initialize scanner and set its behavior for preprocessing,
513                --  then preprocess. Also disable style checks, since some of
514                --  them are done in the scanner (specifically, those dealing
515                --  with line length and line termination), and cannot be done
516                --  during preprocessing (because the source file index table
517                --  has not been set yet).
518
519                Scn.Scanner.Initialize_Scanner (X);
520
521                Scn.Scanner.Set_Special_Character ('#');
522                Scn.Scanner.Set_Special_Character ('$');
523                Scn.Scanner.Set_End_Of_Line_As_Token (True);
524                Save_Style_Check := Opt.Style_Check;
525                Opt.Style_Check := False;
526
527                --  Make sure that there will be no check of pragma Restrictions
528                --  for obsolescent features while preprocessing the source.
529
530                Scn.Set_Obsolescent_Check (False);
531                Preprocess (Modified);
532                Scn.Set_Obsolescent_Check (True);
533
534                --  Reset the scanner to its standard behavior, and restore the
535                --  Style_Checks flag.
536
537                Scn.Scanner.Reset_Special_Characters;
538                Scn.Scanner.Set_End_Of_Line_As_Token (False);
539                Opt.Style_Check := Save_Style_Check;
540
541                --  If there were errors during preprocessing, record an error
542                --  at the start of the file, and do not change the source
543                --  buffer.
544
545                if T /= Total_Errors_Detected then
546                   Errout.Error_Msg
547                     ("file could not be successfully preprocessed", Lo);
548                   return No_Source_File;
549
550                else
551                   --  Output the result of the preprocessing, if requested and
552                   --  the source has been modified by the preprocessing.
553
554                   if Generate_Processed_File and then Modified then
555                      declare
556                         FD     : File_Descriptor;
557                         NB     : Integer;
558                         Status : Boolean;
559
560                      begin
561                         Get_Name_String (N);
562
563                         if Hostparm.OpenVMS then
564                            Add_Str_To_Name_Buffer ("_prep");
565                         else
566                            Add_Str_To_Name_Buffer (".prep");
567                         end if;
568
569                         Delete_File (Name_Buffer (1 .. Name_Len), Status);
570
571                         FD :=
572                           Create_New_File (Name_Buffer (1 .. Name_Len), Text);
573
574                         Status := FD /= Invalid_FD;
575
576                         if Status then
577                            NB :=
578                              Write
579                                (FD,
580                                 Prep_Buffer (1)'Address,
581                                 Integer (Prep_Buffer_Last));
582                            Status := NB = Integer (Prep_Buffer_Last);
583                         end if;
584
585                         if Status then
586                            Close (FD, Status);
587                         end if;
588
589                         if not Status then
590                            Errout.Error_Msg
591                              ("could not write processed file """ &
592                               Name_Buffer (1 .. Name_Len) & '"',
593                               Lo);
594                            return No_Source_File;
595                         end if;
596                      end;
597                   end if;
598
599                   --  Set the new value of Hi
600
601                   Hi := Lo + Source_Ptr (Prep_Buffer_Last);
602
603                   --  Create the new source buffer
604
605                   declare
606                      subtype Actual_Source_Buffer is Source_Buffer (Lo .. Hi);
607                      --  Physical buffer allocated
608
609                      type Actual_Source_Ptr is access Actual_Source_Buffer;
610                      --  Pointer type for the physical buffer allocated
611
612                      Actual_Ptr : constant Actual_Source_Ptr :=
613                                     new Actual_Source_Buffer;
614                      --  Actual physical buffer
615
616                   begin
617                      Actual_Ptr (Lo .. Hi - 1) :=
618                        Prep_Buffer (1 .. Prep_Buffer_Last);
619                      Actual_Ptr (Hi) := EOF;
620
621                      --  Now we need to work out the proper virtual origin
622                      --  pointer to return. This is Actual_Ptr (0)'Address, but
623                      --  we have to be careful to suppress checks to compute
624                      --  this address.
625
626                      declare
627                         pragma Suppress (All_Checks);
628
629                         pragma Warnings (Off);
630                         --  This unchecked conversion is aliasing safe, since
631                         --  it is never used to create improperly aliased
632                         --  pointer values.
633
634                         function To_Source_Buffer_Ptr is new
635                           Unchecked_Conversion (Address, Source_Buffer_Ptr);
636
637                         pragma Warnings (On);
638
639                      begin
640                         Src := To_Source_Buffer_Ptr (Actual_Ptr (0)'Address);
641
642                         --  Record in the table the new source buffer and the
643                         --  new value of Hi.
644
645                         Source_File.Table (X).Source_Text := Src;
646                         Source_File.Table (X).Source_Last := Hi;
647
648                         --  Reset Last_Line to 1, because the lines do not
649                         --  have necessarily the same starts and lengths.
650
651                         Source_File.Table (X).Last_Source_Line := 1;
652                      end;
653                   end;
654                end if;
655             end;
656          end if;
657
658          Set_Source_File_Index_Table (X);
659          return X;
660       end if;
661    end Load_File;
662
663    ----------------------------------
664    -- Load_Preprocessing_Data_File --
665    ----------------------------------
666
667    function Load_Preprocessing_Data_File
668      (N : File_Name_Type) return Source_File_Index
669    is
670    begin
671       return Load_File (N, Osint.Preprocessing_Data);
672    end Load_Preprocessing_Data_File;
673
674    ----------------------
675    -- Load_Source_File --
676    ----------------------
677
678    function Load_Source_File
679      (N : File_Name_Type) return Source_File_Index
680    is
681    begin
682       return Load_File (N, Osint.Source);
683    end Load_Source_File;
684
685    ----------------------------
686    -- New_EOL_In_Prep_Buffer --
687    ----------------------------
688
689    procedure New_EOL_In_Prep_Buffer is
690    begin
691       Put_Char_In_Prep_Buffer (ASCII.LF);
692    end New_EOL_In_Prep_Buffer;
693
694    -----------------------------
695    -- Put_Char_In_Prep_Buffer --
696    -----------------------------
697
698    procedure Put_Char_In_Prep_Buffer (C : Character) is
699    begin
700       --  If preprocessing buffer is not large enough, double it
701
702       if Prep_Buffer_Last = Prep_Buffer'Last then
703          declare
704             New_Prep_Buffer : constant Text_Buffer_Ptr :=
705               new Text_Buffer (1 .. 2 * Prep_Buffer_Last);
706
707          begin
708             New_Prep_Buffer (Prep_Buffer'Range) := Prep_Buffer.all;
709             Free (Prep_Buffer);
710             Prep_Buffer := New_Prep_Buffer;
711          end;
712       end if;
713
714       Prep_Buffer_Last := Prep_Buffer_Last + 1;
715       Prep_Buffer (Prep_Buffer_Last) := C;
716    end Put_Char_In_Prep_Buffer;
717
718    -----------------------------------
719    -- Source_File_Is_Pragma_No_Body --
720    -----------------------------------
721
722    function Source_File_Is_No_Body (X : Source_File_Index) return Boolean is
723    begin
724       Initialize_Scanner (No_Unit, X);
725
726       if Token /= Tok_Pragma then
727          return False;
728       end if;
729
730       Scan; -- past pragma
731
732       if Token /= Tok_Identifier
733         or else Chars (Token_Node) /= Name_No_Body
734       then
735          return False;
736       end if;
737
738       Scan; -- past No_Body
739
740       if Token /= Tok_Semicolon then
741          return False;
742       end if;
743
744       Scan; -- past semicolon
745
746       return Token = Tok_EOF;
747    end Source_File_Is_No_Body;
748
749    ----------------------------
750    -- Source_File_Is_Subunit --
751    ----------------------------
752
753    function Source_File_Is_Subunit (X : Source_File_Index) return Boolean is
754    begin
755       Initialize_Scanner (No_Unit, X);
756
757       --  We scan past junk to the first interesting compilation unit token, to
758       --  see if it is SEPARATE. We ignore WITH keywords during this and also
759       --  PRIVATE. The reason for ignoring PRIVATE is that it handles some
760       --  error situations, and also to handle PRIVATE WITH in Ada 2005 mode.
761
762       while Token = Tok_With
763         or else Token = Tok_Private
764         or else (Token not in Token_Class_Cunit and then Token /= Tok_EOF)
765       loop
766          Scan;
767       end loop;
768
769       return Token = Tok_Separate;
770    end Source_File_Is_Subunit;
771
772 end Sinput.L;