Download 15 The CPP2SDL Tool

Transcript
Chapter
15
The CPP2SDL Tool
NEWTYPE ptr_s Ref( s);
OPERATORS
ptr_s : -> ptr_s;
ptr_s : ptr_s -> ptr_s;
ENDNEWTYPE ptr_s;EXTERNAL ’C++’;
NEWTYPE s
STRUCT
f1 int : 12;
OPERATORS
s : -> s;
s : s -> s;
ENDNEWTYPE s;EXTERNAL ’C++’;
NEWTYPE arr_2_int CArray( 2, int);
ENDNEWTYPE arr_2_int;EXTERNAL ’C++’;
SYNTYPE intarr = arr_2_int
ENDSYNTYPE intarr;EXTERNAL ’C++’;
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Note that not all the constant expressions in this example are visible in
the SDL translation, and thus need not be evaluated by CPP2SDL.
Most constant expressions can be evaluated by CPP2SDL, but not all.
In particular, expressions containing the sizeof() operator are difficult to evaluate since CPP2SDL has no information about what compiler that will be used to compile the generated C/C++ code. Some standard assumptions are therefore used when a sizeof() operator is encountered, and a warning will be issued to encourage manual inspection
of the translation.
Classes, Structs and Unions
Rule: A class, struct or union is translated to an SDL newtype.
This rule follows from the fact that classes, structs and unions are scope
units (see “Scope Units” on page 790).
This section mainly uses classes in the discussions and examples, but
since the translation rules make no difference between classes, structs
and unions, the same is valid for structs and unions. Example 106 shows
the translation of an empty class, struct and union.
Example 106: Translation of classes, structs and unions ––––––––––
C++:
class C {};
struct S {};
union U {};
796
,um-st1
Telelogic Tau 4.5 User’s Manual
July 2003