10.6 Object expressions10.6 Object expressions
10 C++ translator 10 C++ translator
10.8 Value expressions 10.8 Value expressions
10.7 Type expressions

10.7 Type expressions

The translation of a type expression depends on its kind as described below.

10.7.1 Type literals

The type literals are translated as shown below.

RSL C++
Unit not generally accepted
Bool bool
Int int
Nat int
Real double
Text RSL_string
Char RSL_char
Translation of RSL type literals
 

The type Unit is only accepted as complete parameter or result type in a function type expression. As a result type it translates to void.

The types RSL_string and RSL_char are defined in the RSL library. There are constructors RSL_string and RSL_char that convert string and char arguments respectively to RSL_string and RSL_char values, and an overloaded destructor RSL_to_cpp that converts them back to string and char. So we have the following equivalences, for example:

  RSL_to_cpp(RSL_string("abc")) == "abc"
  RSL_to_cpp(RSL_char('a')) == 'a'

These functions make it easy to combine translated RSL with hand-written C++ code.

Note that the function RSL_to_string (section 10.13.1) is not quite the same as RSL_to_cpp. RSL_to_string is intended to generate strings suitable for output (from any type), and produces a string that could be parsed as RSL. For example:

  RSL_to_string(RSL_string("abc")) == "\"abc\""
  RSL_to_string(RSL_char('a')) == "'a'"

10.7.2 Names

A type name that is not an abbreviation translates as a name. A type name that is an abbreviation translates as the abbreviation.

10.7.3 Product type expressions

A product type expression translates as its universal type name (see section 10.12).

10.7.4 Set type expressions

A set type expression translates as its universal type name (see section 10.12).

There is a template RSLSet defined in the RSL library files, and if type T translates to the C++ type Tc, then T-set and T-infset both translate to the universal type name RSL_sTc, which is typedefed to RSLSet<Tc>.

10.7.5 List type expressions

A list type expression translates as its universal type name (see section 10.12).

There is a template RSLList defined in the RSL library files, and (except for Char) if type T translates to the C++ type Tc, then T* and Tω both translate to the universal type name RSL_lTc, which is typedefed to RSLList<Tc>.

Text, Char*, and Charω translate to RSL_string. Standard RSL list operators like hd are defined for RSL_string in an RSL library file. RSL_string values are easily converted to and from string values using the functions RSL_to_cpp and RSL_string respectively: see section 10.7.1.

10.7.6 Map type expressions

A map type expression translates as its universal type name (see section 10.12).

There is a template RSLMap defined in the RSL library files, and if types T and U translate to the C++ types Tc and Uc, then T -m-> U and T -~-> U both translate to the universal type name RSL_TcmTu, which is typedefed to RSLMap<Tc,Uc>.

10.7.7 Function type expressions

A function type expression translates as its universal type name (see section 10.12).

10.7.8 Subtype expressions

A subtype expression translates as its maximal type.

10.7.9 Bracketed type expressions

A bracketed type expression translates as its constituent type expression.
Chris George, April 17, 2008

10.7 Type expressions
10.6 Object expressions10.6 Object expressions
10 C++ translator 10 C++ translator
10.8 Value expressions 10.8 Value expressions