Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<!-- Crown Copyright (c) 1998 -->
<HTML>
<HEAD>
<TITLE>C Checker Reference Manual: Specifying conversions using the
token syntax</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#400080" ALINK="#FF0000">
<A NAME=S173>
<H1>C Checker Reference Manual</H1>
<H3>January 1998</H3>
<IMG SRC="../images/no_next.gif" ALT="next section">
<A HREF="tdfc21.html"><IMG SRC="../images/prev.gif" ALT="previous section"></A>
<A HREF="tdfc1.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>
<DL>
<DT><A HREF="#S174"><B>H.1 </B> - Introduction</A><DD>
<DT><A HREF="#S175"><B>H.2 </B> - User-defined conversions</A>
<DD>
<DT><A HREF="#S176"><B>H.3 </B> - Specifying integer promotions</A><DD>
</DL>

<HR>
<H1>H  Specifying conversions using the token syntax</H1>
<A NAME=S174>
<HR><H2>H.1  Introduction</H2>
The token syntax described in Annex F can be used to fine-tune the
conversion analysis and integer range checks described in section
3.2.2 and chapter 4 respectively.<P>
<A NAME=S175>
<HR><H2>H.2  <A NAME=2>User-defined conversions</H2>
In the example: <P>
<PRE>
        #pragma token TYPE IP#
        #pragma no_def IP
        #pragma token PROC{ TYPE t ,EXP rvalue : t* : e | EXP e}EXP rvalue:IP:p_to_ip#
        #pragma TenDRA conversion p_to_ip allow
        void f(void){
                IP i, *pip;
                i=pip;
        }
</PRE>
the conversion from type pointer to IP to IP would normally result
in an error. However the pragma: <P>
<PRE>
        #pragma TenDRA conversion <EM>conv_list</EM> allow
</PRE>
allows users to define their own conversions between types that would
otherwise be incompatible. Each identifier in the <EM>conv_list</EM>
must be a local identifier for a PROC token (see <A HREF="tdfc20.html#21">F.9
Procedure tokens</A>), taking exactly one argument which must be an
expression. The procedure must also deliver an expression and both
the parameter and the result must be rvalues. When attempting the
conversion of a value from one type to another, either by assignment
or casting, if that conversion would not normally be permitted, then,
for each token introduced as a conversion token by the pragma above:
<P>
An attempt is made to resolve the type of the token result to the
type to which the value is being converted. <P>
If the result is resolved and the value to be converted is a suitable
argument for the token procedure, the token procedure is applied to
implement the conversion. <P>
If no suitable conversion token can be found, an error will be raised.
<P>
<A NAME=S176>
<HR><H2>H.3  <A NAME=4>Specifying integer promotions</H2>
Whenever an integral type is used, e.g. in a call to a traditionally
defined function, its promotion must be computed. If no promotion
type has been specified, the compiler will raise an error. Although
programs will generally use the default rules provided in the built-in
compilation modes, the TenDRA compiler also allows programmers to
specify their own set of integer promotion rules. Such promotions
can be split into two categories: literal promotions and computed
promotions. <P>
<B>Literal promotions</B>. The promoted type is supplied directly
using the pragma:<P>
<PRE>
        #pragma promote <EM>type-name</EM> : <EM>type-name</EM>
</PRE>
The second type-name specifies the promoted type of the first type-name.
Both types must be integral types.<P>
<B>Computed promotions</B>. The pragma:<P>
<PRE>
        #pragma compute promote <EM>proc-token</EM>
</PRE>
allows the programmer to provide the identification of a procedure
token (see <A HREF="tdfc20.html#21">F.9 Procedure tokens</A>) for
computing the promotion type of any integral type. This token is then
called whenever the promotion of a type without a literal promotion
is required. The procedure token <EM>proc-token</EM> must be declared
as:<P>
<PRE>
        #pragma token PROC ( VARIETY ) VARIETY proc-token #
</PRE>
The TenDRA technology provides two pre-defined procedure tokens, identified
by <CODE>~promote</CODE> and <CODE>~sign-promote</CODE>. These procedures
perform integer promotions according to the ISO/ANSI promotion rules
or according to the traditional signed promotion rules respectively.
The built-in compilation environments (see chapter 2) use these tokens
to specify the appropriate set of integer promotion rules.<P>
<!-- FM pgf ignored -->
<HR>
<P><I>Part of the <A HREF="../index.html">TenDRA Web</A>.<BR>Crown
Copyright &copy; 1998.</I></P>
</BODY>
</HTML>