|
|
| ||||||
| 10.7 Type expressions | ||||||||
The translation of a type expression depends on its kind as described below.
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 |
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'"
A type name that is not an abbreviation translates as a name. A type name that is an abbreviation translates as the abbreviation.
A product type expression translates as its universal type name (see section 10.12).
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>.
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 definedfor 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.
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>.
A function type expression translates as its universal type name (see section 10.12).
A subtype expression translates as its maximal type.
A bracketed type expression translates as its constituent type expression.
| 10.7 Type expressions | ||||||||
|
|
| ||||||