1------------------------------------------------------------------------------ 2-- Templates Parser -- 3-- -- 4-- Copyright (C) 1999-2013, AdaCore -- 5-- -- 6-- This library is free software; you can redistribute it and/or modify -- 7-- it under terms of the GNU General Public License as published by the -- 8-- Free Software Foundation; either version 3, or (at your option) any -- 9-- later version. This library is distributed in the hope that it will be -- 10-- useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- 11-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- 12-- -- 13-- As a special exception under Section 7 of GPL version 3, you are -- 14-- granted additional permissions described in the GCC Runtime Library -- 15-- Exception, version 3.1, as published by the Free Software Foundation. -- 16-- -- 17-- You should have received a copy of the GNU General Public License and -- 18-- a copy of the GCC Runtime Library Exception along with this program; -- 19-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- 20-- <http://www.gnu.org/licenses/>. -- 21-- -- 22-- As a special exception, if other files instantiate generics from this -- 23-- unit, or you link this unit with other files to produce an executable, -- 24-- this unit does not by itself cause the resulting executable to be -- 25-- covered by the GNU General Public License. This exception does not -- 26-- however invalidate any other reasons why the executable file might be -- 27-- covered by the GNU Public License. -- 28------------------------------------------------------------------------------ 29 30with Ada.Text_IO; 31 32separate (Templates_Parser) 33 34procedure Print_Tree (T : Tree; Level : Natural := 0) is 35 36 use type Expr.Tree; 37 38 procedure Print_Indent (L : Natural); 39 -- Output proper number of spaces for identation 40 41 procedure Print (Included : Included_File_Info); 42 -- Print info for included file 43 44 ----------- 45 -- Print -- 46 ----------- 47 48 procedure Print (Included : Included_File_Info) is 49 begin 50 if Included.File = Null_Static_Tree then 51 Data.Print_Tree (Included.Filename); 52 else 53 Text_IO.Put_Line (To_String (Included.File.Info.Filename)); 54 end if; 55 56 declare 57 use type Data.Tree; 58 begin 59 for K in Included.Params'Range loop 60 if Included.Params (K) /= null then 61 Print_Indent (Level + 2); 62 Text_IO.Put ("$" & Utils.Image (K) & " = "); 63 Data.Print_Tree (Included.Params (K)); 64 end if; 65 end loop; 66 end; 67 68 Print_Tree (Included.File.Info, Level + 1); 69 end Print; 70 71 ------------------ 72 -- Print_Indent -- 73 ------------------ 74 75 procedure Print_Indent (L : Natural) is 76 use Ada.Strings.Fixed; 77 begin 78 Text_IO.Put ((L * 2) * ' '); 79 end Print_Indent; 80 81begin 82 if T = null then 83 return; 84 end if; 85 86 Print_Indent (Level); 87 88 case T.Kind is 89 when Info => 90 Text_IO.Put_Line ("[INFO] " & To_String (T.Filename)); 91 declare 92 I : Tree := T.I_File; 93 Included : Included_File_Info; 94 begin 95 while I /= null loop 96 Text_IO.Put (" -> "); 97 98 if I.Kind = Include_Stmt then 99 Included := I.I_Included; 100 elsif I.Kind = Extends_Stmt then 101 Included := I.E_Included; 102 else 103 raise Program_Error; 104 end if; 105 106 if Included.File = Null_Static_Tree then 107 Data.Print_Tree (Included.Filename); 108 else 109 Text_IO.Put_Line (To_String (Included.File.Info.Filename)); 110 end if; 111 112 I := I.Next; 113 end loop; 114 end; 115 116 Print_Tree (T.Next, Level); 117 118 when C_Info => 119 Text_IO.Put_Line ("[C_INFO] " 120 & Natural'Image (T.Used) 121 & ' ' & Boolean'Image (T.Obsolete)); 122 123 Print_Tree (T.Next, Level); 124 125 when Text => 126 Text_IO.Put ("[TEXT] "); 127 Data.Print_Tree (T.Text); 128 Print_Tree (T.Next, Level); 129 130 when Set_Stmt => 131 Text_IO.Put ("[SET] "); 132 Definitions.Print_Tree (T.Def); 133 Text_IO.New_Line; 134 Print_Tree (T.Next, Level); 135 136 when If_Stmt => 137 Text_IO.Put ("[IF] "); 138 Expr.Print_Tree (T.Cond); 139 Text_IO.New_Line; 140 Print_Tree (T.N_True, Level + 1); 141 if T.N_False /= null then 142 Print_Indent (Level); 143 Text_IO.Put_Line ("[ELSE]"); 144 Print_Tree (T.N_False, Level + 1); 145 end if; 146 Print_Indent (Level); 147 Text_IO.Put_Line ("[END_IF]"); 148 Print_Tree (T.Next, Level); 149 150 when Table_Stmt => 151 Text_IO.Put ("[TABLE]"); 152 153 if T.Terminate_Sections then 154 Text_IO.Put (" TERMINATE_SECTIONS"); 155 end if; 156 157 if T.Reverse_Index then 158 Text_IO.Put (" REVERSE"); 159 end if; 160 161 if T.Terse then 162 Text_IO.Put (" TERSE"); 163 end if; 164 165 Text_IO.New_Line; 166 Print_Tree (T.Blocks, Level + 1); 167 Print_Indent (Level); 168 Text_IO.Put_Line ("[END_TABLE]"); 169 Print_Tree (T.Next, Level); 170 171 when Extends_Stmt => 172 Text_IO.Put_Line ("[EXTENDS]"); 173 Print_Tree (T.Next, Level + 1); 174 Print_Tree (T.N_Extends, Level); 175 176 when Block_Stmt => 177 Text_IO.Put_Line ("[BLOCK]"); 178 Print_Tree (T.Next, Level + 1); 179 Print_Tree (T.N_Block, Level); 180 181 when Section_Block => 182 Text_IO.Put_Line ("[BLOCK]"); 183 184 if T.Common /= null then 185 Print_Indent (Level + 1); 186 Text_IO.Put_Line ("[COMMON]"); 187 Print_Tree (T.Common, Level + 2); 188 end if; 189 190 if T.Sections /= null then 191 Print_Tree (T.Sections, Level + 1); 192 end if; 193 194 Print_Indent (Level); 195 Text_IO.Put_Line ("[END_BLOCK]"); 196 Print_Tree (T.Next, Level); 197 198 when Section_Stmt => 199 Text_IO.Put_Line ("[SECTION]"); 200 Print_Tree (T.Next, Level + 1); 201 Print_Tree (T.N_Section, Level); 202 203 when Include_Stmt => 204 Text_IO.Put ("[INCLUDE] "); 205 Print (T.I_Included); 206 Print_Tree (T.Next, Level); 207 208 when Inline_Stmt => 209 Text_IO.Put_Line ("[INLINE] (" & To_String (T.Sep) & ')'); 210 Print_Tree (T.I_Block, Level + 1); 211 Text_IO.Put_Line ("[END_INLINE]"); 212 Print_Tree (T.Next, Level); 213 end case; 214 215end Print_Tree; 216