From: Robert Dewar Date: Tue, 15 Nov 2005 13:59:30 +0000 (+0100) Subject: gprep.adb: Implement -C switch to scan comments X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=383b2b42cbdd3868ebccf2fdf107ba4e2741bf55;p=gcc.git gprep.adb: Implement -C switch to scan comments 2005-11-14 Robert Dewar Vincent Celier * gprep.adb: Implement -C switch to scan comments * scng.adb: Scan comment symbol separately if Replace_In_Comments set * scans.ads: Comment updates (including new use of Tok_Comment in preprocessing) * opt.ads: Add documentation for flags that are used by gprmake, currently and in the next version of gprmake. (Verbosity_Level): New variable Add Replace_In_Comments switch * vms_data.ads: Add VMS equivalent for new gnatmake switches -vl, -vm and -vm. Add /REPLACE_IN_COMMENTS for gnatprep -C switch From-SVN: r106983 --- diff --git a/gcc/ada/gprep.adb b/gcc/ada/gprep.adb index 83cd12101f7..ebe5184204f 100644 --- a/gcc/ada/gprep.adb +++ b/gcc/ada/gprep.adb @@ -73,7 +73,7 @@ package body GPrep is File_Name_Buffer_Initial_Size : constant := 50; File_Name_Buffer : String_Access := new String (1 .. File_Name_Buffer_Initial_Size); - -- A buffer to build output file names from input file names. + -- A buffer to build output file names from input file names ----------------- -- Subprograms -- @@ -102,7 +102,7 @@ package body GPrep is -- True if C is in 'a' .. 'z' or in 'A' .. 'Z' procedure Double_File_Name_Buffer; - -- Double the size of the file name buffer. + -- Double the size of the file name buffer procedure Preprocess_Infile_Name; -- When the specified output is a directory, preprocess the infile name @@ -116,12 +116,12 @@ package body GPrep is -- Process a -D switch on the command line procedure Put_Char_To_Outfile (C : Character); - -- Output one character to the output file. - -- Used to initialize the preprocessor. + -- Output one character to the output file. Used to initialize the + -- preprocessor. procedure New_EOL_To_Outfile; - -- Output a new line to the output file. - -- Used to initialize the preprocessor. + -- Output a new line to the output file. Used to initialize the + -- preprocessor. procedure Scan_Command_Line; -- Scan the switches and the file names @@ -137,7 +137,7 @@ package body GPrep is begin if not Copyright_Displayed then Write_Line ("GNAT Preprocessor " & Gnatvsn.Gnat_Version_String); - Write_Line ("Copyright 1996-2004 Free Software Foundation, Inc."); + Write_Line ("Copyright 1996-2005, Free Software Foundation, Inc."); Copyright_Displayed := True; end if; end Display_Copyright; @@ -198,21 +198,23 @@ package body GPrep is -- Test we had all the arguments needed if Infile_Name = No_Name then + -- No input file specified, just output the usage and exit Usage; return; elsif Outfile_Name = No_Name then + -- No output file specified, just output the usage and exit Usage; return; end if; - -- If a pragma Source_File_Name, we need to keep line numbers. - -- So, if the deleted lines are not put as comment, we must output them - -- as blank lines. + -- If a pragma Source_File_Name, we need to keep line numbers. So, if + -- the deleted lines are not put as comment, we must output them as + -- blank lines. if Source_Ref_Pragma and (not Opt.Comment_Deleted_Lines) then Opt.Blank_Deleted_Lines := True; @@ -245,8 +247,7 @@ package body GPrep is end; end if; - -- If there are errors in the definition file, output these errors - -- and exit. + -- If there are errors in the definition file, output them and exit if Total_Errors_Detected > 0 then Errutil.Finalize (Source_Type => "definition"); @@ -281,7 +282,6 @@ package body GPrep is -- rooted at the input directory. Process_Files; - end Gnatprep; --------------------- @@ -327,7 +327,7 @@ package body GPrep is procedure Preprocess_Infile_Name is Len : Natural; - First : Positive := 1; + First : Positive; Last : Natural; Symbol : Name_Id; Data : Symbol_Data; @@ -346,6 +346,7 @@ package body GPrep is -- Look for possible symbols in the file name + First := 1; while First < Len loop -- A symbol starts with a dollar sign followed by a letter @@ -387,7 +388,7 @@ package body GPrep is declare Sym_Len : constant Positive := Last - First + 1; - Offset : constant Integer := Name_Len - Sym_Len; + Offset : constant Integer := Name_Len - Sym_Len; New_Len : constant Natural := Len + Offset; begin @@ -465,7 +466,7 @@ package body GPrep is -- Outfile_Name. procedure Recursive_Process (In_Dir : String; Out_Dir : String); - -- Process recursively files in In_Dir. Results go to Out_Dir. + -- Process recursively files in In_Dir. Results go to Out_Dir ---------------------- -- Process_One_File -- @@ -475,7 +476,7 @@ package body GPrep is Infile : Source_File_Index; begin - -- Create the output file; fails if this does not work. + -- Create the output file (fails if this does not work) begin Create (Text_Outfile, Out_File, Get_Name_String (Outfile_Name)); @@ -521,8 +522,7 @@ package body GPrep is Errutil.Finalize (Source_Type => "input"); end if; - -- If we had some errors, delete the output file, and report - -- the errors. + -- If we had some errors, delete the output file, and report them if Err_Vars.Total_Errors_Detected > 0 then if Outfile /= Standard_Output then @@ -533,7 +533,7 @@ package body GPrep is OS_Exit (0); - -- otherwise, close the output file, and we are done. + -- Otherwise, close the output file, and we are done elsif Outfile /= Standard_Output then Close (Text_Outfile); @@ -564,6 +564,8 @@ package body GPrep is Output_Directory := Out_Dir_Name; end Set_Directory_Names; + -- Start of processing for Recursive_Process + begin -- Open the current input directory @@ -645,8 +647,11 @@ package body GPrep is end loop; end Recursive_Process; + -- Start of processing for Process_Files + begin if Output_Directory = No_Name then + -- If the output is not a directory, fail if the input is -- an existing directory, to avoid possible problems. @@ -660,6 +665,7 @@ package body GPrep is Process_One_File; elsif Input_Directory = No_Name then + -- Get the output file name from the input file name, and process -- the single input file. @@ -697,7 +703,8 @@ package body GPrep is loop begin - Switch := GNAT.Command_Line.Getopt ("D: b c r s u v"); + Switch := GNAT.Command_Line.Getopt ("D: b c C r s u v"); + case Switch is when ASCII.NUL => @@ -713,6 +720,9 @@ package body GPrep is when 'c' => Opt.Comment_Deleted_Lines := True; + when 'C' => + Opt.Replace_In_Comments := True; + when 'r' => Source_Ref_Pragma := True; @@ -780,6 +790,7 @@ package body GPrep is Write_Line ("gnatprep switches:"); Write_Line (" -b Replace preprocessor lines by blank lines"); Write_Line (" -c Keep preprocessor lines as comments"); + Write_Line (" -C Do symbol replacements within comments"); Write_Line (" -D Associate symbol with value"); Write_Line (" -r Generate Source_Reference pragma"); Write_Line (" -s Print a sorted list of symbol names and values"); diff --git a/gcc/ada/opt.ads b/gcc/ada/opt.ads index d0b1d431bfa..69cd038e124 100644 --- a/gcc/ada/opt.ads +++ b/gcc/ada/opt.ads @@ -34,7 +34,7 @@ -- This package contains global flags set by the initialization routine from -- the command line and referenced throughout the compiler, the binder, or -- other GNAT tools. The comments indicate which options are used by which --- programs (GNAT, GNATBIND, GNATMAKE, etc). +-- programs (GNAT, GNATBIND, GNATLINK, GNATMAKE, GPRMAKE, etc). with Gnatvsn; use Gnatvsn; with Hostparm; use Hostparm; @@ -61,8 +61,12 @@ package Opt is -- Set True if binder file to be generated in Ada rather than C type Ada_Version_Type is (Ada_83, Ada_95, Ada_05); + pragma Warnings (Off, Ada_Version_Type); -- Versions of Ada for Ada_Version below. Note that these are ordered, -- so that tests like Ada_Version >= Ada_95 are legitimate and useful. + -- The Warnings_Off pragma stops warnings for Ada_Version >= Ada_05, + -- which we want to allow, so that things work OK when Ada_15 is added! + -- This warning is now removed, so this pragma can be removed some time??? Ada_Version_Default : Ada_Version_Type := Ada_95; -- GNAT @@ -148,7 +152,7 @@ package Opt is -- it ON. It is set ON when Tree_Output is set ON, it can also be set ON -- from the code of GNSA-based tool (a client may need to set ON the -- Back_Annotate_Rep_Info flag in this case. At the moment this does not - -- make very much sense, because GNSA can not do back annotation). + -- make very much sense, because GNSA cannot do back annotation). Back_Annotate_Rep_Info : Boolean := False; -- GNAT @@ -173,7 +177,7 @@ package Opt is -- building a library. May be set to True by Gnatbind.Scan_Bind_Arg. Bind_Only : Boolean := False; - -- GNATMAKE + -- GNATMAKE, GPRMAKE -- Set to True to skip compile and link steps -- (except when Compile_Only and/or Link_Only are True). @@ -218,7 +222,7 @@ package Opt is -- directly modified by gnatmake, to affect the shared binder routines. Check_Switches : Boolean := False; - -- GNATMAKE + -- GNATMAKE, GPRMAKE -- Set to True to check compiler options during the make process Check_Unreferenced : Boolean := False; @@ -242,9 +246,9 @@ package Opt is -- in the output file. Compile_Only : Boolean := False; - -- GNATMAKE, GNATCLEAN - -- GNATMAKE: set to True to skip bind and link steps (except when - -- Bind_Only is True). + -- GNATMAKE, GNATCLEAN, GPRMAKE + -- GNATMAKE, GPRMAKE: set to True to skip bind and link steps (except when + -- Bind_Only is True). -- GNATCLEAN: set to True to only the files produced by the compiler are to -- be deleted, but not the library files or executable files. @@ -268,9 +272,9 @@ package Opt is -- Set to True to activate warnings on constant conditions Create_Mapping_File : Boolean := False; - -- GNATMAKE - -- Set to True (-C switch) to indicate that gnatmake will invoke - -- the compiler with a mapping file (-gnatem compiler switch). + -- GNATMAKE, GPRMAKE + -- Set to True (-C switch) to indicate that the compiler will be invoked + -- with a mapping file (-gnatem compiler switch). Debug_Pragmas_Enabled : Boolean := False; -- GNAT @@ -309,7 +313,7 @@ package Opt is -- potentially blocking operations are detected from protected actions. Display_Compilation_Progress : Boolean := False; - -- GNATMAKE + -- GNATMAKE, GPRMAKE -- Set True (-d switch) to display information on progress while compiling -- files. Internal flag to be used in conjunction with an IDE (e.g GPS). @@ -451,11 +455,11 @@ package Opt is -- (-F switch set). Force_Compilations : Boolean := False; - -- GNATMAKE + -- GNATMAKE, GPRMAKE -- Set to force recompilations even when the objects are up-to-date. Full_Path_Name_For_Brief_Errors : Boolean := False; - -- GNAT, GNATMAKE, GNATCLEAN + -- GNAT, GNATMAKE, GNATCLEAN, GPRMAKE -- When True, in Brief_Output mode, each error message line -- will start with the full path name of the source. -- When False, only the file name without directory information @@ -566,8 +570,8 @@ package Opt is -- if not. Keep_Going : Boolean := False; - -- GNATMAKE - -- When True signals gnatmake to ignore compilation errors and keep + -- GNATMAKE, GPRMAKE + -- When True signals to ignore compilation errors and keep -- processing sources until there is no more work. Keep_Temporary_Files : Boolean := False; @@ -576,7 +580,7 @@ package Opt is -- deleted. Set by switch -dn or qualifier /KEEP_TEMPORARY_FILES. Link_Only : Boolean := False; - -- GNATMAKE + -- GNATMAKE, GPRMAKE -- Set to True to skip compile and bind steps -- (except when Bind_Only is set to True). @@ -693,7 +697,7 @@ package Opt is -- Column_Number'Last during scanning of configuration pragma files. Maximum_Processes : Positive := 1; - -- GNATMAKE + -- GNATMAKE, GPRMAKE -- Maximum number of processes that should be spawned to carry out -- compilations. @@ -762,11 +766,11 @@ package Opt is -- This constant reflects the optimization level (0,1,2 for -O0,-O1,-O2) Output_File_Name_Present : Boolean := False; - -- GNATBIND, GNAT, GNATMAKE + -- GNATBIND, GNAT, GNATMAKE, GPRMAKE -- Set to True when the output C file name is given with option -o -- for GNATBIND, when the object file name is given with option -- -gnatO for GNAT or when the executable is given with option -o - -- for GNATMAKE. + -- for GNATMAKE or GPRMAKE. Output_Linker_Option_List : Boolean := False; -- GNATBIND @@ -829,10 +833,14 @@ package Opt is -- used if the policy is set in package System. Quiet_Output : Boolean := False; - -- GNATMAKE, GNATCLEAN, GPR2MAKE + -- GNATMAKE, GNATCLEAN, GPRMAKE -- Set to True if the tool should not have any output if there are no -- errors or warnings. + Replace_In_Comments : Boolean := False; + -- GNATPREP + -- Set to True if -C switch used + RTS_Lib_Path_Name : String_Ptr := null; RTS_Src_Path_Name : String_Ptr := null; -- GNAT @@ -1017,17 +1025,33 @@ package Opt is -- This flag determines if validity checking is on or off. The initial -- state is on, and the required default validity checks are active. The -- actual set of checks that is performed if Validity_Checks_On is set is - -- defined by the switches in package Sem_Val. The Validity_Checks_On flag + -- defined by the switches in package Validsw. The Validity_Checks_On flag -- is controlled by pragma Validity_Checks (On | Off), and also some -- generated compiler code (typically code that has to do with validity -- check generation) is compiled with this flag set to False. This flag is -- set to False by the -gnatp switch. Verbose_Mode : Boolean := False; - -- GNAT, GNATBIND, GNATMAKE, GNATLINK, GNATLS, GNATNAME, GNATCLEAN + -- GNAT, GNATBIND, GNATMAKE, GNATLINK, GNATLS, GNATNAME, GNATCLEAN, + -- GPRMAKE -- Set to True to get verbose mode (full error message text and location -- information sent to standard output, also header, copyright and summary) + type Verbosity_Level_Type is (None, Low, Medium, High); + Verbosity_Level : Verbosity_Level_Type := High; + -- GNATMAKE, GPRMAKE + -- Modified by gnatmake or gprmake switches -v, -vl, -vm, -vh. Indicates + -- the level of verbosity of informational messages: + -- + -- In Low Verbosity, the reasons why a source is recompiled, the name + -- of the executable and the reason it must be rebuilt is output. + -- + -- In Medium Verbosity, additional lines are output for each ALI file + -- that is checked. + -- + -- In High Verbosity, additional lines are output when the ALI file + -- is part of an Ada library, is read-only or is part of the runtime. + Warn_On_Ada_2005_Compatibility : Boolean := True; -- GNAT -- Set to True to active all warnings on Ada 2005 compatibility issues, diff --git a/gcc/ada/scans.ads b/gcc/ada/scans.ads index 955637acb76..7e2a58078a1 100644 --- a/gcc/ada/scans.ads +++ b/gcc/ada/scans.ads @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 1992-2005 Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2005, 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- -- @@ -190,22 +190,27 @@ package Scans is Tok_Dot_Dot, -- .. Sterm, Chtok - -- The following three entries are used only when scanning project - -- files. - Tok_Project, Tok_Extends, Tok_External, - Tok_Comment, + -- These three entries represent keywords for the project file language + -- and can be returned only in the case of scanning project files. - -- The following entry is used by the preprocessor and when scanning - -- project files. + Tok_Comment, + -- This entry is used when scanning project files (where it represents + -- an entire comment), and in preprocessing with the -C switch set + -- (where it represents just the "--" of a comment). For the project + -- file case, the text of the comment is stored in Tok_End_Of_Line, - - -- The following entry is used by the preprocessor + -- Represents an end of line. Not used during normal compilation scans + -- where end of line is ignored. Active for preprocessor scanning and + -- also when scanning project files (where it is neede because of ???) Tok_Special, + -- Used only in preprocessor scanning (to represent one of the + -- characters '#', '$', '?', '@', '`', '\', '^', '~', or '_'. The + -- character value itself is stored in Scans.Special_Character. No_Token); -- No_Token is used for initializing Token values to indicate that @@ -394,7 +399,7 @@ package Scans is -- We do things this way to minimize the impact on comment scanning. Character_Code : Char_Code; - -- Valid only when Token is Tok_Char_Literal. + -- Valid only when Token is Tok_Char_Literal Real_Literal_Value : Ureal; -- Valid only when Token is Tok_Real_Literal @@ -411,11 +416,17 @@ package Scans is -- Valid only when Token = Tok_String_Literal. Special_Character : Character; - -- Valid only when Token = Tok_Special + -- Valid only when Token = Tok_Special. Returns one of the characters + -- '#', '$', '?', '@', '`', '\', '^', '~', or '_'. + -- + -- Why only this set? What about wide characters??? Comment_Id : Name_Id := No_Name; -- Valid only when Token = Tok_Comment. Store the string that follows - -- the two '-' of a comment. + -- the "--" of a comment when scanning project files. + -- + -- Is it really right for this to be a Name rather than a String, what + -- about the case of Wide_Wide_Characters??? -------------------------------------------------------- -- Procedures for Saving and Restoring the Scan State -- diff --git a/gcc/ada/scng.adb b/gcc/ada/scng.adb index 9d3483e8251..687c32b11d5 100644 --- a/gcc/ada/scng.adb +++ b/gcc/ada/scng.adb @@ -1465,6 +1465,17 @@ package body Scng is else -- Source (Scan_Ptr + 1) = '-' then if Style_Check then Style.Check_Comment; end if; Scan_Ptr := Scan_Ptr + 2; + + -- If we are in preprocessor mode with Replace_In_Comments set, + -- then we return the "--" as a token on its own. + + if Replace_In_Comments then + Token := Tok_Comment; + return; + end if; + + -- Otherwise scan out the comment + Start_Of_Comment := Scan_Ptr; -- Loop to scan comment (this loop runs more than once only if diff --git a/gcc/ada/vms_data.ads b/gcc/ada/vms_data.ads index c3678f46c00..9f37b20683c 100644 --- a/gcc/ada/vms_data.ads +++ b/gcc/ada/vms_data.ads @@ -6,7 +6,7 @@ -- -- -- S p e c -- -- -- --- Copyright (C) 1996-2005 Free Software Foundation, Inc. -- +-- Copyright (C) 1996-2005, 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- -- @@ -3760,6 +3760,14 @@ package VMS_Data is -- /VERBOSE), then error lines start with the full path name of the -- project file, rather than its simple file name. + S_Make_Hi_Verb : aliased constant S := "/HIGH_VERBOSITY " & + "-vh"; + -- /NOHIGH_VERBOSITY (D) + -- /HIGH_VERBOSITY + -- + -- Displays the reason for all recompilations GNAT MAKE decides are + -- necessary, in high verbosity. Equivalent to /VERBOSE. + S_Make_Inplace : aliased constant S := "/IN_PLACE " & "-i"; -- /NOIN_PLACE (D) @@ -3798,6 +3806,15 @@ package VMS_Data is -- /COMPILER_QUALIFIERS, /BINDER_QUALIFIERS and /MAKE_QUALIFIERS will be -- passed to any GNAT LINK commands generated by GNAT LINK. + S_Make_Low_Verb : aliased constant S := "/LOW_VERBOSITY " & + "-vl"; + -- /NOLOW_VERBOSITY (D) + -- /LOW_VERBOSITY + -- + -- Displays the reason for all recompilations GNAT MAKE decides are + -- necessary, in low verbosity, that is with less output than + -- /MEDIUM_VERBOSITY, /HIGH_VERBOSITY or /VERBOSE. + S_Make_Make : aliased constant S := "/MAKE_QUALIFIERS=?" & "-margs MAKE"; -- /MAKE_QUALIFIERS @@ -3822,6 +3839,15 @@ package VMS_Data is -- the mapping file. This will improve the source search during the next -- invocations of the compiler + S_Make_Med_Verb : aliased constant S := "/MEDIUM_VERBOSITY " & + "-vm"; + -- /NOMEDIUM_VERBOSITY (D) + -- /MEDIUM_VERBOSITY + -- + -- Displays the reason for all recompilations GNAT MAKE decides are + -- necessary, in medium verbosity, that is with potentially less output + -- than /HIGH_VERBOSITY or /VERBOSE. + S_Make_Mess : aliased constant S := "/MESSAGES_PROJECT_FILE=" & "DEFAULT " & "-vP0 " & @@ -4017,12 +4043,15 @@ package VMS_Data is S_Make_Ext 'Access, S_Make_Force 'Access, S_Make_Full 'Access, + S_Make_Hi_Verb 'Access, S_Make_Inplace 'Access, S_Make_Index 'Access, S_Make_Library 'Access, S_Make_Link 'Access, + S_Make_Low_Verb'Access, S_Make_Make 'Access, S_Make_Mapping 'Access, + S_Make_Med_Verb'Access, S_Make_Mess 'Access, S_Make_Minimal 'Access, S_Make_Nolink 'Access, @@ -4452,6 +4481,14 @@ package VMS_Data is -- Preprocessor lines and deleted lines are completely removed from the -- output. + S_Prep_Replace : aliased constant S := "/REPLACE_IN_COMMENTS " & + "-C"; + -- /NOREPLACE_IN_COMMENTS (D) + -- /REPLACE_IN_COMMENTS + -- + -- Causes preprocessor to scan comments and perform replacements on + -- any $symbol occurrences within the comment text. + S_Prep_Symbols : aliased constant S := "/SYMBOLS " & "-s"; -- /NOSYMBOLS (D) @@ -4471,6 +4508,7 @@ package VMS_Data is S_Prep_Com 'Access, S_Prep_Ref 'Access, S_Prep_Remove 'Access, + S_Prep_Replace 'Access, S_Prep_Symbols 'Access, S_Prep_Undef 'Access);