This change introduces a new switch "-a" (all source text preserved) for gnatprep and the integrated preprocessor, causing all source text to be preserved (i.e. the "if", all "elsif" and the "else" branch of a #if construct all show up in the output). This is useful to perform simple style checks on all branches.
The following command must produce the shown output: $ gnatprep -a -c all_source_.adb.in all_source_text.adb $ cat all_source_text.adb procedure All_Source_Text is beGin Some_Code; --! #if Some_Condition then Do_Something; --! #else Do_Something_else; --! #end if; Some_More_Code; end All_Source_Text; Input: procedure All_Source_Text is beGin Some_Code; #if Some_Condition then Do_Something; #else Do_Something_else; #end if; Some_More_Code; end All_Source_Text; Tested on x86_64-pc-linux-gnu, committed on trunk 2012-10-04 Thomas Quinot <qui...@adacore.com> * prep.adb, prepcomp.adb, gprep.adb, opt.ads: New preprocessor switch -a (all source text preserved).
Index: prep.adb =================================================================== --- prep.adb (revision 192066) +++ prep.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 2002-2010, Free Software Foundation, Inc. -- +-- Copyright (C) 2002-2012, 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- -- @@ -292,8 +292,8 @@ Result.Value := End_String; end if; - -- Now, check the syntax of the symbol (we don't allow accented and - -- wide characters) + -- Now, check the syntax of the symbol (we don't allow accented or + -- wide characters). if Name_Buffer (1) not in 'a' .. 'z' and then Name_Buffer (1) not in 'A' .. 'Z' @@ -356,7 +356,7 @@ begin -- Always return False when not inside an #if statement - if Pp_States.Last = Ground then + if Opt.No_Deletion or else Pp_States.Last = Ground then return False; else return Pp_States.Table (Pp_States.Last).Deleting; Index: prepcomp.adb =================================================================== --- prepcomp.adb (revision 192066) +++ prepcomp.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 2003-2010, Free Software Foundation, Inc. -- +-- Copyright (C) 2003-2012, 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- -- @@ -60,6 +60,7 @@ Undef_False : Boolean := False; Always_Blank : Boolean := False; Comments : Boolean := False; + No_Deletion : Boolean := False; List_Symbols : Boolean := False; Processed : Boolean := False; end record; @@ -73,6 +74,7 @@ Undef_False => False, Always_Blank => False, Comments => False, + No_Deletion => False, List_Symbols => False, Processed => False); @@ -330,6 +332,16 @@ -- significant. case Sinput.Source (Token_Ptr) is + when 'a' => + + -- All source text preserved (also implies -u) + + if Name_Len = 1 then + Current_Data.No_Deletion := True; + Current_Data.Undef_False := True; + OK := True; + end if; + when 'u' => -- Undefined symbol are False @@ -581,15 +593,15 @@ -- Set the preprocessing flags according to the preprocessing data - if Current_Data.Comments and then not Current_Data.Always_Blank then + if Current_Data.Comments and not Current_Data.Always_Blank then Comment_Deleted_Lines := True; Blank_Deleted_Lines := False; - else Comment_Deleted_Lines := False; Blank_Deleted_Lines := True; end if; + No_Deletion := Current_Data.No_Deletion; Undefined_Symbols_Are_False := Current_Data.Undef_False; List_Preprocessing_Symbols := Current_Data.List_Symbols; Index: gprep.adb =================================================================== --- gprep.adb (revision 192066) +++ gprep.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 2002-2011, Free Software Foundation, Inc. -- +-- Copyright (C) 2002-2012, 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- -- @@ -720,7 +720,7 @@ loop begin - Switch := GNAT.Command_Line.Getopt ("D: b c C r s T u v"); + Switch := GNAT.Command_Line.Getopt ("D: a b c C r s T u v"); case Switch is @@ -731,6 +731,10 @@ Process_Command_Line_Symbol_Definition (S => GNAT.Command_Line.Parameter); + when 'a' => + Opt.No_Deletion := True; + Opt.Undefined_Symbols_Are_False := True; + when 'b' => Opt.Blank_Deleted_Lines := True; Index: opt.ads =================================================================== --- opt.ads (revision 192066) +++ opt.ads (working copy) @@ -968,6 +968,12 @@ -- in this variable (e.g. 2 = select second unit in file). A value of -- zero indicates that we are in normal (one unit per file) mode. + No_Deletion : Boolean := False; + -- GNATPREP + -- Set by preprocessor switch -a. Do not eliminate any source text. Implies + -- Undefined_Symbols_Are_False. Useful to perform a syntax check on all + -- branches of #if constructs. + No_Main_Subprogram : Boolean := False; -- GNATMAKE, GNATBIND -- Set to True if compilation/binding of a program without main