1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2020-2023, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Ada
.Streams
.Stream_IO
; use Ada
.Streams
.Stream_IO
;
28 package body Gen_IL
is
30 procedure Put
(F
: File_Type
; S
: String);
31 -- The output primitive
37 function Image
(X
: Root_Int
) return String is
38 Result
: constant String := X
'Img;
40 if Result
(1) = ' ' then
41 return Result
(2 .. Result
'Last);
51 procedure Capitalize
(S
: in out String) is
52 Cap
: Boolean := True;
56 Old
: constant Character := X
;
64 Cap
:= not (Is_Letter
(Old
) or else Is_Digit
(Old
));
73 function Capitalize
(S
: String) return String is
75 return Result
: String (S
'Range) := S
do
84 procedure Create_File
(Buffer
: in out Sink
; Name
: String) is
86 Create
(Buffer
.File
, Out_File
, Name
);
88 Buffer
.New_Line
:= True;
95 procedure Increase_Indent
(Buffer
: in out Sink
; Amount
: Natural) is
97 Buffer
.Indent
:= Buffer
.Indent
+ Amount
;
100 ---------------------
101 -- Decrease_Indent --
102 ---------------------
104 procedure Decrease_Indent
(Buffer
: in out Sink
; Amount
: Natural) is
106 Buffer
.Indent
:= Buffer
.Indent
- Amount
;
113 procedure Put
(F
: File_Type
; S
: String) is
115 String'Write (Stream
(F
), S
);
118 procedure Put
(Buffer
: in out Sink
; Item
: String) is
120 -- If the first character is LF, indent after it only
122 if Item
(Item
'First) = ASCII
.LF
then
123 Put
(Buffer
.File
, LF
);
124 Buffer
.New_Line
:= True;
126 if Item
'Length > 1 then
127 Put
(Buffer
, Item
(Item
'First + 1 .. Item
'Last));
133 -- If this is a new line, indent
135 if Buffer
.New_Line
and then Buffer
.Indent
> 0 then
137 S
: constant String (1 .. Buffer
.Indent
) := (others => ' ');
139 Put
(Buffer
.File
, S
);
143 Put
(Buffer
.File
, Item
);
145 Buffer
.New_Line
:= Item
(Item
'Last) = ASCII
.LF
;