Subversion Repositories tendra.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
<!-- Crown Copyright (c) 1998 -->
2
<HTML>
3
<HEAD>
4
<TITLE>C Checker Reference Manual: Specifying conversions using the
5
token syntax</TITLE>
6
</HEAD>
7
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#400080" ALINK="#FF0000">
8
<A NAME=S173>
9
<H1>C Checker Reference Manual</H1>
10
<H3>January 1998</H3>
11
<IMG SRC="../images/no_next.gif" ALT="next section">
12
<A HREF="tdfc21.html"><IMG SRC="../images/prev.gif" ALT="previous section"></A>
13
<A HREF="tdfc1.html"><IMG SRC="../images/top.gif" ALT="current document"></A>
14
<A HREF="../index.html"><IMG SRC="../images/home.gif" ALT="TenDRA home page">
15
</A>
16
<IMG SRC="../images/no_index.gif" ALT="document index"><P>
17
<HR>
18
<DL>
19
<DT><A HREF="#S174"><B>H.1 </B> - Introduction</A><DD>
20
<DT><A HREF="#S175"><B>H.2 </B> - User-defined conversions</A>
21
<DD>
22
<DT><A HREF="#S176"><B>H.3 </B> - Specifying integer promotions</A><DD>
23
</DL>
24
 
25
<HR>
26
<H1>H  Specifying conversions using the token syntax</H1>
27
<A NAME=S174>
28
<HR><H2>H.1  Introduction</H2>
29
The token syntax described in Annex F can be used to fine-tune the
30
conversion analysis and integer range checks described in section
31
3.2.2 and chapter 4 respectively.<P>
32
<A NAME=S175>
33
<HR><H2>H.2  <A NAME=2>User-defined conversions</H2>
34
In the example: <P>
35
<PRE>
36
	#pragma token TYPE IP#
37
	#pragma no_def IP
38
	#pragma token PROC{ TYPE t ,EXP rvalue : t* : e | EXP e}EXP rvalue:IP:p_to_ip#
39
	#pragma TenDRA conversion p_to_ip allow
40
	void f(void){
41
		IP i, *pip;
42
		i=pip;
43
	}
44
</PRE>
45
the conversion from type pointer to IP to IP would normally result
46
in an error. However the pragma: <P>
47
<PRE>
48
	#pragma TenDRA conversion <EM>conv_list</EM> allow
49
</PRE>
50
allows users to define their own conversions between types that would
51
otherwise be incompatible. Each identifier in the <EM>conv_list</EM>
52
must be a local identifier for a PROC token (see <A HREF="tdfc20.html#21">F.9
53
Procedure tokens</A>), taking exactly one argument which must be an
54
expression. The procedure must also deliver an expression and both
55
the parameter and the result must be rvalues. When attempting the
56
conversion of a value from one type to another, either by assignment
57
or casting, if that conversion would not normally be permitted, then,
58
for each token introduced as a conversion token by the pragma above:
59
<P>
60
An attempt is made to resolve the type of the token result to the
61
type to which the value is being converted. <P>
62
If the result is resolved and the value to be converted is a suitable
63
argument for the token procedure, the token procedure is applied to
64
implement the conversion. <P>
65
If no suitable conversion token can be found, an error will be raised.
66
<P>
67
<A NAME=S176>
68
<HR><H2>H.3  <A NAME=4>Specifying integer promotions</H2>
69
Whenever an integral type is used, e.g. in a call to a traditionally
70
defined function, its promotion must be computed. If no promotion
71
type has been specified, the compiler will raise an error. Although
72
programs will generally use the default rules provided in the built-in
73
compilation modes, the TenDRA compiler also allows programmers to
74
specify their own set of integer promotion rules. Such promotions
75
can be split into two categories: literal promotions and computed
76
promotions. <P>
77
<B>Literal promotions</B>. The promoted type is supplied directly
78
using the pragma:<P>
79
<PRE>
80
	#pragma promote <EM>type-name</EM> : <EM>type-name</EM>
81
</PRE>
82
The second type-name specifies the promoted type of the first type-name.
83
Both types must be integral types.<P>
84
<B>Computed promotions</B>. The pragma:<P>
85
<PRE>
86
	#pragma compute promote <EM>proc-token</EM>
87
</PRE>
88
allows the programmer to provide the identification of a procedure
89
token (see <A HREF="tdfc20.html#21">F.9 Procedure tokens</A>) for
90
computing the promotion type of any integral type. This token is then
91
called whenever the promotion of a type without a literal promotion
92
is required. The procedure token <EM>proc-token</EM> must be declared
93
as:<P>
94
<PRE>
95
	#pragma token PROC ( VARIETY ) VARIETY proc-token #
96
</PRE>
97
The TenDRA technology provides two pre-defined procedure tokens, identified
98
by <CODE>~promote</CODE> and <CODE>~sign-promote</CODE>. These procedures
99
perform integer promotions according to the ISO/ANSI promotion rules
100
or according to the traditional signed promotion rules respectively.
101
The built-in compilation environments (see chapter 2) use these tokens
102
to specify the appropriate set of integer promotion rules.<P>
103
<!-- FM pgf ignored -->
104
<HR>
105
<P><I>Part of the <A HREF="../index.html">TenDRA Web</A>.<BR>Crown
106
Copyright &copy; 1998.</I></P>
107
</BODY>
108
</HTML>