C Checker Reference Manual

January 1998

next section
previous section current document TenDRA home page document index

H.1 - Introduction
H.2 - User-defined conversions
H.3 - Specifying integer promotions

H Specifying conversions using the token syntax

H.1 Introduction

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.

H.2 User-defined conversions

In the example:

	#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;
the conversion from type pointer to IP to IP would normally result in an error. However the pragma:

	#pragma TenDRA conversion conv_list allow
allows users to define their own conversions between types that would otherwise be incompatible. Each identifier in the conv_list must be a local identifier for a PROC token (see
F.9 Procedure tokens), 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:

An attempt is made to resolve the type of the token result to the type to which the value is being converted.

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.

If no suitable conversion token can be found, an error will be raised.

H.3 Specifying integer promotions

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.

Literal promotions. The promoted type is supplied directly using the pragma:

	#pragma promote type-name : type-name
The second type-name specifies the promoted type of the first type-name. Both types must be integral types.

Computed promotions. The pragma:

	#pragma compute promote proc-token
allows the programmer to provide the identification of a procedure token (see
F.9 Procedure tokens) 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 proc-token must be declared as:

	#pragma token PROC ( VARIETY ) VARIETY proc-token #
The TenDRA technology provides two pre-defined procedure tokens, identified by ~promote and ~sign-promote. 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.

Part of the TenDRA Web.
Crown Copyright © 1998.