Leaked source code of windows server 2003
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.

276 lines
6.5 KiB

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