Download 15 The CPP2SDL Tool
Transcript
Chapter
15
The CPP2SDL Tool
Anonymous Unions
Rule: An anonymous union is translated by making its members become fields of the newtype that represents the enclosing scope unit.
This translation rule is natural since an anonymous union is no scope
unit.
Example 107: Translation of Anonymous Unions –––––––––––––––––
C++:
struct S {
int i;
union {
int j;
int k;
};
};
SDL:
NEWTYPE ptr_S Ref( S);
OPERATORS
ptr_S : -> ptr_S;
ptr_S : ptr_S -> ptr_S;
ENDNEWTYPE ptr_S;EXTERNAL ’C++’;
NEWTYPE S
STRUCT
j int;/* member of anonymous union */
k int;/* member of anonymous union */
i int;
OPERATORS
S : -> S;/* implicit parameter-less constructor
*/
S : S -> S;/* implicit copy constructor */
ENDNEWTYPE S;EXTERNAL ’C++’;
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
Note that an anonymous union is not an incomplete type declaration, although the syntax is similar. An anonymous union is not used to declare
a type nor a variable, and does not define a type at all. Consequently, the
translation rules for anonymous unions and incomplete types differ significantly. Compare with “Incomplete Types” on page 823.
Constructors
Rule: A constructor for a class is translated to an operator with the same
name as the newtype that represents the class.
798
,um-st1
Telelogic Tau 4.5 User’s Manual
July 2003