OSDN Git Service

2007-10-15 Hristian Kirtchev <kirtchev@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / fname-sf.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             F N A M E . S F                              --
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 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 Casing;   use Casing;
27 with Fname;    use Fname;
28 with Fname.UF; use Fname.UF;
29 with SFN_Scan; use SFN_Scan;
30 with Osint;    use Osint;
31 with Types;    use Types;
32
33 with Unchecked_Conversion;
34
35 package body Fname.SF is
36
37    subtype Big_String is String (Positive);
38    type Big_String_Ptr is access all Big_String;
39
40    function To_Big_String_Ptr is new Unchecked_Conversion
41      (Source_Buffer_Ptr, Big_String_Ptr);
42
43    ----------------------
44    -- Local Procedures --
45    ----------------------
46
47    procedure Set_File_Name
48      (Typ   : Character;
49       U     : String;
50       F     : String;
51       Index : Natural);
52    --  This is a transfer function that is called from Scan_SFN_Pragmas,
53    --  and reformats its parameters appropriately for the version of
54    --  Set_File_Name found in Fname.SF.
55
56    procedure Set_File_Name_Pattern
57      (Pat : String;
58       Typ : Character;
59       Dot : String;
60       Cas : Character);
61    --  This is a transfer function that is called from Scan_SFN_Pragmas,
62    --  and reformats its parameters appropriately for the version of
63    --  Set_File_Name_Pattern found in Fname.SF.
64
65    -----------------------------------
66    -- Read_Source_File_Name_Pragmas --
67    -----------------------------------
68
69    procedure Read_Source_File_Name_Pragmas is
70       Src : Source_Buffer_Ptr;
71       Hi  : Source_Ptr;
72       BS  : Big_String_Ptr;
73       SP  : String_Ptr;
74
75    begin
76       Name_Buffer (1 .. 8) := "gnat.adc";
77       Name_Len := 8;
78       Read_Source_File (Name_Enter, 0, Hi, Src);
79
80       if Src /= null then
81          BS := To_Big_String_Ptr (Src);
82          SP := BS (1 .. Natural (Hi))'Unrestricted_Access;
83          Scan_SFN_Pragmas
84            (SP.all,
85             Set_File_Name'Access,
86             Set_File_Name_Pattern'Access);
87       end if;
88    end Read_Source_File_Name_Pragmas;
89
90    -------------------
91    -- Set_File_Name --
92    -------------------
93
94    procedure Set_File_Name
95      (Typ   : Character;
96       U     : String;
97       F     : String;
98       Index : Natural)
99    is
100       Unm : Unit_Name_Type;
101       Fnm : File_Name_Type;
102    begin
103       Name_Buffer (1 .. U'Length) := U;
104       Name_Len := U'Length;
105       Set_Casing (All_Lower_Case);
106       Name_Buffer (Name_Len + 1) := '%';
107       Name_Buffer (Name_Len + 2) := Typ;
108       Name_Len := Name_Len + 2;
109       Unm := Name_Find;
110       Name_Buffer (1 .. F'Length) := F;
111       Name_Len := F'Length;
112       Fnm := Name_Find;
113       Fname.UF.Set_File_Name (Unm, Fnm, Nat (Index));
114    end Set_File_Name;
115
116    ---------------------------
117    -- Set_File_Name_Pattern --
118    ---------------------------
119
120    procedure Set_File_Name_Pattern
121      (Pat : String;
122       Typ : Character;
123       Dot : String;
124       Cas : Character)
125    is
126       Ctyp : Casing_Type;
127       Patp : constant String_Ptr := new String'(Pat);
128       Dotp : constant String_Ptr := new String'(Dot);
129
130    begin
131       if Cas = 'l' then
132          Ctyp := All_Lower_Case;
133       elsif Cas = 'u' then
134          Ctyp := All_Upper_Case;
135       else -- Cas = 'm'
136          Ctyp := Mixed_Case;
137       end if;
138
139       Fname.UF.Set_File_Name_Pattern (Patp, Typ, Dotp, Ctyp);
140    end Set_File_Name_Pattern;
141
142 end Fname.SF;