Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
4.8 KiB

4 years ago
  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. unioncls.hxx
  5. Abstract:
  6. Contains definitions for base type related code generation class
  7. definitions.
  8. Notes:
  9. History:
  10. GregJen Sep-30-1993 Created.
  11. ----------------------------------------------------------------------------*/
  12. #ifndef __UNIONCLS_HXX__
  13. #define __UNIONCLS_HXX__
  14. #include "nulldefs.h"
  15. extern "C"
  16. {
  17. #include <stdio.h>
  18. #include <assert.h>
  19. }
  20. #include "ndrcls.hxx"
  21. #include "fldcls.hxx"
  22. /////////////////////////////////////////////////////////////////////////////
  23. // the structure code generation class.
  24. /////////////////////////////////////////////////////////////////////////////
  25. //
  26. // This class corresponds to a non-encapsulated union type.
  27. //
  28. #define UNION_UNKNOWN 0x0
  29. #define UNION_ENCAP 0x1
  30. #define UNION_NONENCAP_DCE 0x2
  31. #define UNION_NONENCAP_MS 0x3
  32. class CG_UNION : public CG_COMP
  33. {
  34. private:
  35. //
  36. // Used for Ndr format string generation so that non-switch_is union
  37. // info is shared.
  38. //
  39. long NdrSizeAndArmDescriptionOffset;
  40. //
  41. // Store the CCB in the union so that we can fix CG_UNION
  42. // node sharing problem with format string offsets.
  43. //
  44. CCB * pCCB;
  45. //
  46. // store a CG node for the switch type ( NULL for encap unions (?) )
  47. //
  48. CG_NDR * pCGSwitchType;
  49. //
  50. // the kind of union ( encap, nonencap dce/ms )
  51. //
  52. unsigned short UnionFlavor : 2;
  53. void * _pCTI;
  54. public:
  55. //
  56. // The constructor.
  57. //
  58. CG_UNION(
  59. node_skl * pBT, // base type
  60. XLAT_SIZE_INFO & Info, // memory size
  61. unsigned short HP // Has pointer
  62. ) :
  63. CG_COMP( pBT, Info, HP )
  64. {
  65. SetUnionFlavor( UNION_UNKNOWN );
  66. SetNdrSizeAndArmDescriptionOffset(-1);
  67. SetCCB(0);
  68. SetSwitchType( NULL );
  69. _pCTI = NULL;
  70. }
  71. virtual
  72. ID_CG GetCGID()
  73. {
  74. return ID_CG_UNION;
  75. }
  76. BOOL IsVarying()
  77. {
  78. return TRUE;
  79. }
  80. //
  81. // Generate typeinfo
  82. //
  83. virtual
  84. CG_STATUS GenTypeInfo( CCB * pCCB);
  85. //
  86. // Get and set methods.
  87. //
  88. unsigned short SetUnionFlavor( unsigned short UN )
  89. {
  90. return (UnionFlavor = UN);
  91. }
  92. unsigned short GetUnionFlavor()
  93. {
  94. return UnionFlavor;
  95. }
  96. CG_NDR * SetSwitchType( CG_NDR * pCG )
  97. {
  98. return (pCGSwitchType = pCG);
  99. }
  100. CG_NDR * GetSwitchType()
  101. {
  102. return pCGSwitchType;
  103. }
  104. long GetNumberOfArms()
  105. {
  106. CG_ITERATOR Iterator;
  107. CG_CASE * pCase;
  108. long Arms;
  109. GetMembers(Iterator);
  110. Arms = 0;
  111. while ( ITERATOR_GETNEXT(Iterator,pCase) )
  112. {
  113. if ( pCase->GetCGID() ==
  114. ID_CG_DEFAULT_CASE )
  115. continue;
  116. Arms++;
  117. }
  118. return Arms;
  119. }
  120. BOOL IsEncapsulatedUnion()
  121. {
  122. return (UnionFlavor == UNION_ENCAP);
  123. }
  124. BOOL IsUnion()
  125. {
  126. return TRUE;
  127. }
  128. //
  129. // Redefinitions of get and set format string offsets.
  130. //
  131. void SetFormatStringOffset( long Offset );
  132. long GetFormatStringOffset();
  133. void SetCCB( CCB * pNewCCB )
  134. {
  135. pCCB = pNewCCB;
  136. }
  137. CCB * GetCCB()
  138. {
  139. return pCCB;
  140. }
  141. //
  142. // Ndr format string generation. Used only by non-encapsulated unions.
  143. //
  144. virtual
  145. void GenNdrFormat( CCB * pCCB );
  146. //
  147. // Generate the format strings for the union arms.
  148. //
  149. void GenNdrFormatArms( CCB * pCCB );
  150. //
  151. // Generate the format string for memory size and arm descriptions.
  152. //
  153. void GenNdrSizeAndArmDescriptions( CCB * pCCB );
  154. //
  155. // Generate the switch is description.
  156. //
  157. void GenNdrSwitchIsDescription( CCB * pCCB );
  158. //
  159. // Set and Get the arm description offset.
  160. //
  161. void SetNdrSizeAndArmDescriptionOffset( long offset )
  162. {
  163. NdrSizeAndArmDescriptionOffset = offset;
  164. }
  165. long GetNdrSizeAndArmDescriptionOffset()
  166. {
  167. return NdrSizeAndArmDescriptionOffset;
  168. }
  169. virtual
  170. BOOL ShouldFreeOffline()
  171. {
  172. return HasPointer();
  173. }
  174. virtual
  175. void GenFreeInline( CCB * pCCB )
  176. {
  177. }
  178. virtual
  179. void GenNdrPointerFixUp( CCB * pCCB,
  180. CG_STRUCT * pStruct );
  181. //
  182. // This method tells us if we can use the rpc message buffer to hold
  183. // the union.
  184. //
  185. BOOL CanUseBuffer();
  186. virtual
  187. short GetPointerMembers( ITERATOR& I );
  188. virtual
  189. CG_STATUS S_GenInitOutLocals( CCB * pCCB );
  190. };
  191. #endif // __UNIONCLS_HXX__