Rev 2 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<!-- Crown Copyright (c) 1998 -->
<HTML>
<HEAD>
<TITLE>
C++ Producer Guide: Error catalogue
</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#400080" ALINK="#FF0000">
<H1>C++ Producer Guide</H1>
<H3>March 1998</H3>
<A HREF="parse.html"><IMG SRC="../images/next.gif" ALT="next section"></A>
<A HREF="alg.html"><IMG SRC="../images/prev.gif" ALT="previous section"></A>
<A HREF="index.html"><IMG SRC="../images/top.gif" ALT="current document"></A>
<A HREF="../index.html"><IMG SRC="../images/home.gif" ALT="TenDRA home page">
</A>
<IMG SRC="../images/no_index.gif" ALT="document index"><P>
<HR>
<H2>3.3. Error catalogue</H2>
<P>
This section describes the error catalogue which lies at the heart
of the C++ producer's error reporting routines. The full
<A HREF="error1.html">error catalogue syntax</A> is given as an annex.
A typical entry in the catalogue is as follows:
<PRE>
class_union_deriv ( CLASS_TYPE: ct )
{
USAGE: serious
PROPERTIES: ansi
KEY (ISO) "9.5"
KEY (STANDARD) "The union '"ct"' can't have base classes"
}
</PRE>
This defines an error, <CODE>class_union_deriv</CODE>, which takes
a single parameter <CODE>ct</CODE> of type <CODE>CLASS_TYPE</CODE>.
The severity of this error is <CODE>serious</CODE>; that is to say,
a constraint error. The error property <CODE>ansi</CODE> indicates
that the error arises from the ISO C++ standard, the associated
<CODE>ISO</CODE> key indicating section 9.5. Finally the text to
be printed for this error, including a reference to <CODE>ct</CODE>,
is given. Looking up section 9.5 in the ISO C++ standard reveals
the corresponding constraint in paragraph 1:
<BLOCKQUOTE>
<I>A union shall not have base classes.</I>
</BLOCKQUOTE>
Each constraint within the ISO C++ standard has a corresponding error
in this way. The errors are named in a systematic fashion using the
section names used in the draft standard. For example, section 9.5
is called <CODE>class.union</CODE>, so all the constraint errors arising
from this section have names of the form <CODE>class_union_*</CODE>.
These error names can be used in the <A HREF="pragma.html#low">low
level directives</A> such as:
<PRE>
#pragma TenDRA++ error "class_union_deriv" <I>allow</I>
</PRE>
to modify the error severity. The effect of reducing the severity
of a constraint error in this way is undefined.
</P>
<P>
In addition to the obvious error severity levels, <CODE>serious</CODE>,
<CODE>warning</CODE> and <CODE>none</CODE>, the error catalogue specifies
a list of optional severity levels along with their default values.
For example, the entry:
<PRE>
link_incompat = serious
</PRE>
sets up an option named <CODE>link_incompat</CODE> which is a constraint
error by default. Errors with this severity, such as:
<PRE>
dcl_stc_external ( LONG_ID: id, PTR_LOC: loc )
{
USAGE: link_incompat
PROPERTIES: ansi
KEY (ISO) "7.1.1"
KEY (STANDARD) "'"id"' previously declared with external
linkage (at "loc")"
}
</PRE>
are therefore constraint errors. The severity associated with
<CODE>link_incompat</CODE> can be modified either
<A HREF="pragma.html#low">directly</A>, using the directive:
<PRE>
#pragma TenDRA++ option "link_incompat" <I>allow</I>
</PRE>
or <A HREF="pragma.html#linkage">indirectly</A> using the directive:
<PRE>
#pragma TenDRA incompatible linkage <I>allow</I>
</PRE>
the effect being to modify the severity of the associated error messages.
</P>
<P>
The error catalogue is processed by a simple tool,
<CODE>make_err</CODE>, which generates C code which is compiled into
the C++ producer. Each error in the catalogue is assigned a number
(there are currently 873 errors in the catalogue) which gives an index
into an automatically generated table of error information. It is
this error number, together with a list of error arguments, which
forms the associated <A HREF="alg.html#err"><CODE>ERROR</CODE> object</A>.
<CODE>make_err</CODE> generates a macro for each error in the catalogue
which takes arguments of the appropriate types (which may be statically
checked) and creates an <CODE>ERROR</CODE> object. For example, for
the entry above this macro takes the form:
<PRE>
ERROR ERR_class_union_deriv ( CLASS_TYPE ) ;
</PRE>
These macros hide the error catalogue numbers from the rest of the
C++ producer.
</P>
<P>
It is also possible to join a number of simple <CODE>ERROR</CODE>
objects to form a single composite <CODE>ERROR</CODE>. The severity
of the composite error is the maximum of the severities of the component
errors. To this purpose a dummy error severity level <CODE>whatever</CODE>
is introduced which is less severe than any other level. This is
intended for use with error messages which are only ever used to add
information to existing errors, and which inherit their severity level
from the main error.
</P>
<P>
The text of a simple error message can be found in the table of error
information. The text contains certain escape sequences indicating
where the error arguments are to be printed. For example,
<CODE>%1</CODE> indicates the second argument. The error argument
sorts - what is referred to as the error signature - is also stored
in the table of error information as an array of characters, each
corresponding to an <CODE>ERR_KEY_</CODE><I>type</I> macro. The producer
defines printing routines for each of the types given by these values,
and calls the appropriate routine to print the argument.
</P>
<P>
There are several command-line options which can be used to modify
the form in which the error message is printed. The default format
is as follows:
<PRE>
"file.C", line 42: Error:
[ISO 9.5]: The union 'U' can't have base classes.
</PRE>
The ISO section number can be suppressed using <CODE>-m-s</CODE>.
The <CODE>-mc</CODE> option causes the source code line giving rise
to the error to be printed as part of the message, with <CODE>!!!!</CODE>
marking the position of the error within the line. The <CODE>-me</CODE>
option causes the error name, <CODE>class_union_deriv</CODE>, to be
printed as part of the message. The <CODE>-ml</CODE> option causes
the full file location, including the list of <CODE>#include</CODE>
directives used in reaching the file, to be printed. The <CODE>-mt</CODE>
option causes <CODE>typedef</CODE> names to be used when printing
types, rather than expanding to the type definition.
</P>
<HR>
<P><I>Part of the <A HREF="../index.html">TenDRA Web</A>.<BR>Crown
Copyright © 1998.</I></P>
</BODY>
</HTML>