home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gnat-2.06-src.tgz / tar.out / fsf / gnat / ada / errout.ads < prev    next >
Text File  |  1996-09-28  |  21KB  |  417 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT COMPILER COMPONENTS                         --
  4. --                                                                          --
  5. --                               E R R O U T                                --
  6. --                                                                          --
  7. --                                 S p e c                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.47 $                             --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. --
  22. --                                                                          --
  23. ------------------------------------------------------------------------------
  24.  
  25. --  This package contains the routines to output error messages. They
  26. --  are basically system independent, however in some environments, e.g.
  27. --  when the parser is embedded into an editor, it may be appropriate
  28. --  to replace the implementation of this package.
  29.  
  30. with Table;
  31. with Types; use Types;
  32. with Uintp; use Uintp;
  33.  
  34. package Errout is
  35.  
  36.    Errors_Detected : Int;
  37.    --  Number of errors detected so far
  38.  
  39.    Warnings_Detected : Int;
  40.    --  Number of warnings detected
  41.  
  42.    type Compiler_State_Type is (Parsing, Analyzing);
  43.    Compiler_State : Compiler_State_Type;
  44.    --  Indicates current state of compilation. This is put in the Errout
  45.    --  spec because it affects the action of the error message handling.
  46.    --  In particular, an attempt is made by Errout to suppress cascaded
  47.    --  error messages in Parsing mode, but not in the other modes.
  48.  
  49.    Error_Monitoring_On : Boolean;
  50.    --  Indicates whether error monitoring mode is currently on or not
  51.  
  52.    Monitored_Errors : Natural;
  53.    --  Incremented if an error occurs in an error monitored region
  54.  
  55.    Monitored_Message : Name_Id;
  56.    --  This is relevant only if Error_Monitoring_On is true. If it is set
  57.    --  to No_Name, then no special action is required. Otherwise, Errout
  58.    --  checks that the first error message issued matches the given name,
  59.    --  and resets Monitored_Message to No_Name if it does match, and to
  60.    --  Error_Name if it does not match.
  61.  
  62.    -----------------------------------
  63.    -- Suppression of Error Messages --
  64.    -----------------------------------
  65.  
  66.    --  In an effort to reduce the impact of redundant error messages, the
  67.    --  error output routines in this package normally suppress certain
  68.    --  classes of messages as follows:
  69.  
  70.    --    1.  Identical messages placed at the same point in the text. Such
  71.    --        duplicate error message result for example from rescanning
  72.    --        sections of the text that contain lexical errors. Only one of
  73.    --        such a set of duplicate messages is output, and the rest are
  74.    --        suppressed.
  75.  
  76.    --    2.  If more than one parser message is generated for a single source
  77.    --        line, then only the first message is output, the remaining
  78.    --        messages on the same line are suppressed.
  79.  
  80.    --    3.  If a message is posted on a node for which a message has been
  81.    --        previously posted, then only the first message is retained. The
  82.    --        Error_Posted flag is used to detect such multiple postings. Note
  83.    --        that this only applies to semantic messages, since otherwise
  84.    --        for parser messages, this would be a special case of case 2.
  85.  
  86.    --    4.  If a message is posted on a node whose Etype or Entity
  87.    --        fields reference entities on which an error message has
  88.    --        already been placed, as indicated by the Error_Posted flag
  89.    --        being set on these entities, then the message is suppressed.
  90.  
  91.    --    5.  If a message attempts to insert an Error node, or a direct
  92.    --        reference to the Any_Type node, then the message is suppressed.
  93.  
  94.    --  This normal suppression action may be overridden in cases 2-5 (but not
  95.    --  in case 1) by setting All_Errors mode, or by setting the special
  96.    --  unconditional message insertion character (!) at the end of the message
  97.    --  text as described below.
  98.  
  99.    ---------------------------------------------------------
  100.    -- Error Message Text and Message Insertion Characters --
  101.    ---------------------------------------------------------
  102.  
  103.    --  Error message text strings are composed of lower case letters, digits
  104.    --  and the special characters space, comma, period, colon and semicolon,
  105.    --  apostrophe and parentheses. Special insertion characters can also
  106.    --  appear which cause the error message circuit to modify the given
  107.    --  string as follows:
  108.  
  109.    --    Insertion character % (Percent: insert name from Names table)
  110.    --      The character % is replaced by the text for the name specified by
  111.    --      the Name_Id value stored in Error_Msg_Name_1. A blank precedes
  112.    --      the name if it is preceded by a non-blank character other than a
  113.    --      left parenthesis. The name is enclosed in quotes unless manual
  114.    --      quotation mode is set. If the Name_Id is set to No_Name, then
  115.    --      no insertion occurs; if the Name_Id is set to Error_Name, then
  116.    --      the string <error> is inserted. A second and third % may appear
  117.    --      in a single message, similarly replaced by the names which are
  118.    --      specified by the Name_Id values stored in Error_Msg_Name_2 and
  119.    --      Error_Msg_Name_3. The names are cased according to the current
  120.    --      identifier casing mode.
  121.  
  122.    --    Insertion character $ (Dollar: insert unit name from Names table)
  123.    --      The character $ is treated similarly to %, except that the name
  124.    --      is obtained from the Unit_Name_Type value in Error_Msg_Unit_1
  125.    --      and Error_Msg_Unit_2, as provided by Get_Unit_Name_String in
  126.    --      package Uname.
  127.  
  128.    --    Insertion character { (Left brace: insert file name from names table)
  129.    --      The character { is treated similarly to %, except that the
  130.    --      name is output literally as stored in the names table without
  131.    --      adjusting the casing.
  132.  
  133.    --    Insertion character * (Asterisk, insert reserved word name)
  134.    --      The insertion character * is treated exactly like % except that
  135.    --      the resulting name is cased according to the default conventions
  136.    --      for reserved words (see package Scans).
  137.  
  138.    --    Insertion character & (Ampersand: insert name from node)
  139.    --      The insertion character & is treated similarly to %, except that
  140.    --      the name is taken from the Chars field of the given node, and may
  141.    --      refer to a child unit name, or a selected component. The casing
  142.    --      is, if possible, taken from the original source reference, which
  143.    --      is obtained from the Sloc field of the given node or nodes. If no
  144.    --      Sloc is available (happens e.g. for nodes in package Standard),
  145.    --      then the default case (see Scans spec) is used. The nodes to be
  146.    --      used are stored in Error_Msg_Node_1, Error_Msg_Node_2. No insertion
  147.    --      occurs for the Empty node, and the Error node results in the
  148.    --      insertion of the characters <error>.
  149.  
  150.    --    Insertion character # (Pound: insert line number reference)
  151.    --      The character # is replaced by the string indicating the source
  152.    --      position stored in Error_Msg_Sloc. There are three cases:
  153.    --
  154.    --        for package Standard:           in package Standard
  155.    --        for locations in current file:  at line nnn:ccc
  156.    --        for locations in other files:   at filename:nnn:ccc
  157.    --
  158.    --      By convention, the # insertion character is only used at the end
  159.    --      of an error message, so the above strings only appear as the last
  160.    --      characters of an error message.
  161.  
  162.    --    Insertion character } (Right brace: insert type reference)
  163.    --      The character } is replaced by a string describing the type
  164.    --      referenced by the entity whose Id is stored in Error_Msg_Node_1.
  165.    --      the string gives the name or description of the type, and also
  166.    --      where appropriate the location of its declaration. Special
  167.    --      cases like "some integer type" are handled appropriately. Only
  168.    --      one } is allowed in a message, since there is not enough room
  169.    --      for two (the insertion can be quite long, including a file name)
  170.  
  171.    --    Insertion character @ (At: insert column number reference)
  172.    --      The character @ is replaced by null if the RM_Column_Check mode is
  173.    --      off (False). If the switch is on (True), then @ is replaced by the
  174.    --      text string " in column nnn" where nnn is the decimal representation
  175.    --      of the column number stored in Error_Msg_Col plus one (the plus one
  176.    --      is because the number is stored 0-origin and displayed 1-origin).
  177.  
  178.    --    Insertion character ^ (Carret: insert integer value)
  179.    --      The character ^ is replaced by the decimal conversion of the Uint
  180.    --      value stored in Error_Msg_Uint_1, with a possible leading minus.
  181.    --      A second ^ may occur in the message, in which case it is replaced
  182.    --      by the decimal conversion of the Uint value in Error_Msg_Uint_2.
  183.  
  184.    --    Insertion character ! (Exclamation: unconditional message)
  185.    --      The character ! appearing as the last character of a message makes
  186.    --      the message unconditional which means that it is output even if it
  187.    --      would normally be suppressed. See section above for a description
  188.    --      of the cases in which messages are normally suppressed.
  189.  
  190.    --    Insertion character ? (Question: warning message)
  191.    --      The character ? appearing anywhere in a message makes the message
  192.    --      a warning instead of a normal error message, and the text of the
  193.    --      message will be preceded by "Warning:" instead of "Error:" The
  194.    --      handling of warnings if further controlled by the Warning_Mode
  195.    --      option (-w switch), see package Opt for further details.
  196.  
  197.    --    Insertion character A-Z (Upper case letter: Ada reserved word)
  198.    --      If two or more upper case letters appear in the message, they are
  199.    --      taken as an Ada reserved word, and are converted to the default
  200.    --      case for reserved words (see Scans package spec). Surrounding
  201.    --      quotes are added unless manual quotation mode is currently set.
  202.  
  203.    --    Insertion character ` (Backquote: set manual quotation mode)
  204.    --      The backquote character always appears in pairs. Each backquote
  205.    --      of the pair is replaced by a double quote character. In addition,
  206.    --      Any reserved keywords, or name insertions between these backquotes
  207.    --      are not surrounded by the usual automatic double quotes. See the
  208.    --      section below on manual quotation mode for further details.
  209.  
  210.    --    Insertion character ' (Quote: literal character)
  211.    --      Precedes a character which is placed literally into the message.
  212.    --      Used to insert characters into messages that are one of the
  213.    --      insertion characters defined here.
  214.  
  215.    -----------------------------------------------------
  216.    -- Global Values Used for Error Message Insertions --
  217.    -----------------------------------------------------
  218.  
  219.    --  The following global variables are essentially additional parameters
  220.    --  passed to the error message routine for insertion sequences described
  221.    --  above. The reason these are passed globally is that the insertion
  222.    --  mechanism is essentially an untyped one in which the appropriate
  223.    --  variables are set dependingon the specific insertion characters used.
  224.  
  225.    Error_Msg_Col : Column_Number;
  226.    --  Column for @ insertion character in message
  227.  
  228.    Error_Msg_Uint_1 : Uint;
  229.    Error_Msg_Uint_2 : Uint;
  230.    --  Uint values for ^ insertion characters in message
  231.  
  232.    Error_Msg_Sloc : Source_Ptr;
  233.    --  Source location for # insertion character in message
  234.  
  235.    Error_Msg_Name_1 : Name_Id;
  236.    Error_Msg_Name_2 : Name_Id;
  237.    Error_Msg_Name_3 : Name_Id;
  238.    --  Name_Id values for % insertion characters in message
  239.  
  240.    Error_Msg_Unit_1 : Name_Id;
  241.    Error_Msg_Unit_2 : Name_Id;
  242.    --  Name_Id values for $ insertion characters in message
  243.  
  244.    Error_Msg_Node_1 : Node_Id;
  245.    Error_Msg_Node_2 : Node_Id;
  246.    --  Node_Id values for & insertion characters in message
  247.  
  248.    -----------------------------------------------------
  249.    -- Format of Messages and Manual Quotation Control --
  250.    -----------------------------------------------------
  251.  
  252.    --  Messages are generally all in lower case, except for inserted names
  253.    --  and appear in one of the following three forms:
  254.  
  255.    --    error: text
  256.    --    warning: text
  257.  
  258.    --  The prefixes error and warning are supplied automatically (depending
  259.    --  on the use of the ? insertion character), and the call to the error
  260.    --  message routine supplies the text. The "error: " prefix is omitted
  261.    --  in brief error message formats.
  262.  
  263.    --  Reserved Ada keywords in the message are in the default keyword case
  264.    --  (determined from the given source program), surrounded by quotation
  265.    --  marks. This is achieved by spelling the reserved word in upper case
  266.    --  letters, which is recognized as a request for insertion of quotation
  267.    --  marks by the error text processor. Thus for example:
  268.  
  269.    --    Error_Msg_AP ("IS expected");
  270.  
  271.    --  would result in the output of one of the following:
  272.  
  273.    --    error: "is" expected
  274.    --    error: "IS" expected
  275.    --    error: "Is" expected
  276.  
  277.    --  the choice between these being made by looking at the casing convention
  278.    --  used for keywords (actually the first compilation unit keyword) in the
  279.    --  source file.
  280.  
  281.    --  In the case of names, the default mode for the error text processor
  282.    --  is to surround the name by quotation marks automatically. The case
  283.    --  used for the identifier names is taken from the source program where
  284.    --  possible, and otherwise is the default casing convention taken from
  285.    --  the source file usage.
  286.  
  287.    --  In some cases, better control over the placement of quote marks is
  288.    --  required. This is achieved using manual quotation mode. In this mode,
  289.    --  one or more insertion sequences is surrounded by backquote characters.
  290.    --  The backquote characters are output as double quote marks, and normal
  291.    --  automatic insertion of quotes is suppressed between the double quotes.
  292.    --  For example:
  293.  
  294.    --    Error_Msg_AP ("`END&;` expected");
  295.  
  296.    --  generates a message like
  297.  
  298.    --    error: "end Open_Scope;" expected
  299.  
  300.    --  where the node specifying the name Open_Scope has been stored in
  301.    --  Error_Msg_Node_1 prior to the call. The great majority of error
  302.    --  messages operates in normal quotation mode.
  303.  
  304.    ----------------------------
  305.    -- Message ID Definitions --
  306.    ----------------------------
  307.  
  308.    type Error_Msg_Id is new Int;
  309.    --  A type used to represent specific error messages. Used by the clients
  310.    --  of this package only in the context of the Get_Error_Id and
  311.    --  Change_Error_Text subprograms.
  312.  
  313.    No_Error_Msg : constant Error_Msg_Id := 0;
  314.    --  A constant which is different from any value returned by Get_Error_Id.
  315.    --  Typically used by a client to indicate absense of a saved Id value.
  316.  
  317.    function Get_Msg_Id return Error_Msg_Id;
  318.    --  Returns the Id of the message most recently posted using one of the
  319.    --  Error_Msg routines.
  320.  
  321.    ------------------------
  322.    -- List Pragmas Table --
  323.    ------------------------
  324.  
  325.    --  When a pragma Page or pragma List is encountered by the parser, an
  326.    --  entry is made in the following table. This table is then used to
  327.    --  control the full listing if one is being generated. Note that the
  328.    --  reason we do the processing in the parser is so that we get proper
  329.    --  listing control even in syntax check only mode.
  330.  
  331.    type List_Pragma_Type is (List_On, List_Off, Page);
  332.  
  333.    type List_Pragma_Record is record
  334.       Ptyp : List_Pragma_Type;
  335.       Ploc : Source_Ptr;
  336.    end record;
  337.  
  338.    --  Note: Ploc points to the terminating semicolon in the List_Off and
  339.    --  Page cases, and to the pragma keyword for List_On. In the case of
  340.    --  a pragma List_Off, a List_On entry is also made in the table,
  341.    --  pointing to the pragma keyword. This ensures that, as required,
  342.    --  a List (Off) pragma is listed even in list off mode.
  343.  
  344.    package List_Pragmas is new Table (
  345.      Table_Component_Type => List_Pragma_Record,
  346.      Table_Index_Type     => Int,
  347.      Table_Low_Bound      => 1,
  348.      Table_Initial        => 50,
  349.      Table_Increment      => 200,
  350.      Table_Name           => "List_Pragmas");
  351.  
  352.    ------------------------------
  353.    -- Error Output Subprograms --
  354.    ------------------------------
  355.  
  356.    procedure Initialize;
  357.    --  Initializes for output of error messages. Must be called for each
  358.    --  source file before using any of the other routines in the package.
  359.  
  360.    procedure Finalize;
  361.    --  Finalize processing of error messages for one file and output message
  362.    --  indicating the number of detected errors.
  363.  
  364.    procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr);
  365.    --  Output a message at specified location. Can be called from the parser
  366.    --  or the semantic analyzer.
  367.  
  368.    procedure Error_Msg_S (Msg : String);
  369.    --  Output a message at current scan pointer location. This routine can be
  370.    --  called only from the parser, since it references Scan_Ptr.
  371.  
  372.    procedure Error_Msg_AP (Msg : String);
  373.    --  Output a message just after the previous token. This routine can be
  374.    --  called only from the parser, since it references Prev_Token_Ptr.
  375.  
  376.    procedure Error_Msg_BC (Msg : String);
  377.    --  Output a message just before the current token. Note that the important
  378.    --  difference between this and the previous routine is that the BC case
  379.    --  posts a flag on the current line, whereas AP can post a flag at the
  380.    --  end of the preceding line. This routine can be called only from the
  381.    --  parser, since it references Token_Ptr.
  382.  
  383.    procedure Error_Msg_SC (Msg : String);
  384.    --  Output a message at the start of the current token, unless we are at
  385.    --  the end of file, in which case we always output the message after the
  386.    --  last real token in the file. This routine can be called only from the
  387.    --  parser, since it references Token_Ptr.
  388.  
  389.    procedure Error_Msg_SP (Msg : String);
  390.    --  Output a message at the start of the previous token. This routine can
  391.    --  be called only from the parser, since it references Prev_Token_Ptr.
  392.  
  393.    procedure Error_Msg_N (Msg : String; N : Node_Id);
  394.    --  Output a message at the Sloc of the given node. This routine can be
  395.    --  called from the parser or the semantic analyzer, although the call
  396.    --  from the latter is much more common (and is the most usual way of
  397.    --  generating error messages from the analyzer). The message text may
  398.    --  contain a single & insertion, which will reference the given node.
  399.  
  400.    procedure Error_Msg_NE (Msg : String; N : Node_Id; E : Entity_Id);
  401.    --  Output a message at the Sloc of the given node, with an insertion of
  402.    --  the name from the given entity node. This is used by the semantic
  403.    --  routines, where this is a common error message situation. The Msg
  404.    --  text will contain a & or } as usual to mark the insertion point.
  405.    --  This routine can be called from the parser or the analyzer.
  406.  
  407.    procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String);
  408.    --  The error message text of the message identified by Id is replaced by
  409.    --  the given text. This text may contain insertion characters in the
  410.    --  usual manner, and need not be the same length as the original text.
  411.  
  412.    procedure Temporary_Msg_N (Msg : String; N : Node_Id);
  413.    --  Same functionality as Error_Msg_N but used as a reminder in source
  414.    --  when issuing temporary messages for specific versions of GNAT which
  415.    --  may be eliminated in successive versions of the system.
  416. end Errout;
  417.