Download 15 The CPP2SDL Tool

Transcript
Chapter
15
The CPP2SDL Tool
NEWTYPE ptr_Y2 Ref( Y2);
OPERATORS
ptr_Y2 : -> ptr_Y2;
ptr_Y2 : ptr_Y2 -> ptr_Y2;
ENDNEWTYPE ptr_Y2;EXTERNAL ’C++’;
NEWTYPE Y2
OPERATORS
Y2 : -> Y2;
Y2 : Y2 -> Y2;
ENDNEWTYPE Y2;EXTERNAL ’C++’;
NEWTYPE ptr_Y3 Ref( Y3);
OPERATORS
ptr_Y3 : -> ptr_Y3;
ptr_Y3 : ptr_Y3 -> ptr_Y3;
ENDNEWTYPE ptr_Y3;EXTERNAL ’C++’;
NEWTYPE Y3
OPERATORS
Y3 : -> Y3;
Y3 : Y3 -> Y3;
ENDNEWTYPE Y3;EXTERNAL ’C++’;
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
The inheritance access specifier also affects how casting from the derived type to the base type can be done. This is described in “Type Compatibility between Inherited Classes” on page 816 and in “Type Compatibility between Pointers to Inherited Classes” on page 817.
Type Compatibility between Inherited Classes
Rule: An object of a derived class may be assigned to an object of a
base class by using an explicit cast operator in SDL.
The above assignment (known as slicing) is type-compatible in C++
without the use of a cast operator. Since only the common members are
copied in the assignment, this operation is somewhat dangerous and is
not generally recommended. Therefore, the cast operators that are needed in SDL to do slicing between objects, are only generated when the
-slicing option is set.
Example 121: Generation of operators for slicing –––––––––––––––––
C++:
class C {};
class D {};
class CD : public C, public D {};
SDL:
NEWTYPE ptr_C Ref( C);
OPERATORS
816
,um-st1
Telelogic Tau 4.5 User’s Manual
July 2003