summaryrefslogtreecommitdiffstats
path: root/gcc/ada/prj-pars.adb
blob: b76a77f1066f39053725a6ff1ff321c5651ac665 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
------------------------------------------------------------------------------
--                                                                          --
--                         GNAT COMPILER COMPONENTS                         --
--                                                                          --
--                             P R J . P A R S                              --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
--          Copyright (C) 2001-2011, Free Software Foundation, Inc.         --
--                                                                          --
-- GNAT is free software;  you can  redistribute it  and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
-- for  more details.  You should have  received  a copy of the GNU General --
-- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license.          --
--                                                                          --
-- GNAT was originally developed  by the GNAT team at  New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc.      --
--                                                                          --
------------------------------------------------------------------------------

with Ada.Exceptions; use Ada.Exceptions;
with GNAT.Directory_Operations; use GNAT.Directory_Operations;

with Output;   use Output;
with Prj.Conf; use Prj.Conf;
with Prj.Err;  use Prj.Err;
with Prj.Part;
with Prj.Tree; use Prj.Tree;
with Sinput.P;

package body Prj.Pars is

   -----------
   -- Parse --
   -----------

   procedure Parse
     (In_Tree           : Project_Tree_Ref;
      Project           : out Project_Id;
      Project_File_Name : String;
      Packages_To_Check : String_List_Access;
      Reset_Tree        : Boolean := True;
      In_Node_Tree      : Prj.Tree.Project_Node_Tree_Ref := null;
      Env               : in out Prj.Tree.Environment)
   is
      Project_Node            : Project_Node_Id := Empty_Node;
      The_Project             : Project_Id      := No_Project;
      Success                 : Boolean         := True;
      Current_Dir             : constant String := Get_Current_Dir;
      Project_Node_Tree       : Prj.Tree.Project_Node_Tree_Ref := In_Node_Tree;
      Automatically_Generated : Boolean;
      Config_File_Path        : String_Access;

   begin
      if Project_Node_Tree = null then
         Project_Node_Tree := new Project_Node_Tree_Data;
         Prj.Tree.Initialize (Project_Node_Tree);
      end if;

      --  Parse the main project file into a tree

      Sinput.P.Reset_First;
      Prj.Part.Parse
        (In_Tree                => Project_Node_Tree,
         Project                => Project_Node,
         Project_File_Name      => Project_File_Name,
         Errout_Handling        => Prj.Part.Finalize_If_Error,
         Packages_To_Check      => Packages_To_Check,
         Current_Directory      => Current_Dir,
         Env                    => Env,
         Is_Config_File         => False);

      --  If there were no error, process the tree

      if Project_Node /= Empty_Node then
         begin
            --  No config file should be read from the disk for gnatmake.
            --  However, we will simulate one that only contains the
            --  default GNAT naming scheme.

            Process_Project_And_Apply_Config
              (Main_Project               => The_Project,
               User_Project_Node          => Project_Node,
               Config_File_Name           => "",
               Autoconf_Specified         => False,
               Project_Tree               => In_Tree,
               Project_Node_Tree          => Project_Node_Tree,
               Packages_To_Check          => null,
               Allow_Automatic_Generation => False,
               Automatically_Generated    => Automatically_Generated,
               Config_File_Path           => Config_File_Path,
               Env                        => Env,
               Normalized_Hostname        => "",
               On_Load_Config             =>
                 Add_Default_GNAT_Naming_Scheme'Access,
               Reset_Tree                 => Reset_Tree);

            Success := The_Project /= No_Project;

         exception
            when Invalid_Config =>
               Success := False;
         end;

         Prj.Err.Finalize;

         if not Success then
            The_Project := No_Project;
         end if;
      end if;

      Project := The_Project;

      --  ??? Should free the project_node_tree, no longer useful

   exception
      when X : others =>

         --  Internal error

         Write_Line (Exception_Information (X));
         Write_Str  ("Exception ");
         Write_Str  (Exception_Name (X));
         Write_Line (" raised, while processing project file");
         Project := No_Project;
   end Parse;

   -------------------
   -- Set_Verbosity --
   -------------------

   procedure Set_Verbosity (To : Verbosity) is
   begin
      Current_Verbosity := To;
   end Set_Verbosity;

end Prj.Pars;
OpenPOWER on IntegriCloud