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.

464 lines
18 KiB

4 years ago
  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. cgcls.hxx
  5. Abstract:
  6. class definitions for code generation entities for midl.
  7. Notes:
  8. A code generation entity is a transformed form of the type graph. This
  9. form is a much closer representation of what goes on the wire.
  10. History:
  11. VibhasC Jul-29-1993 Created.
  12. ----------------------------------------------------------------------------*/
  13. #ifndef __CGCLS_HXX__
  14. #define __CGCLS_HXX__
  15. /****************************************************************************
  16. * include files
  17. ***************************************************************************/
  18. #include "nulldefs.h"
  19. extern "C"
  20. {
  21. #include <stdio.h>
  22. #include <assert.h>
  23. }
  24. #include "allnodes.hxx"
  25. #include "cgcommon.hxx"
  26. // #include "analysis.hxx"
  27. #include "ccb.hxx"
  28. class ANALYSIS_INFO;
  29. /////////////////////////////////////////////////////////////////////////////
  30. // define a type which returns the code generation status.
  31. /////////////////////////////////////////////////////////////////////////////
  32. typedef enum _cg_status
  33. {
  34. CG_OK
  35. // everything was hunky dory.
  36. ,CG_NOT_LAYED_OUT
  37. // I got an HREFTYPE to an incomplete ITypeInfo.
  38. // I will not be able to call LayOut.
  39. ,CG_REF_NOT_LAYED_OUT
  40. // I got an HREFTYPE to a reference (ptr) to an incomplete ITypeInfo
  41. // I will be able to call LayOut but I must then try to get my
  42. // dependencies to call LayOut.
  43. } CG_STATUS;
  44. //
  45. // Enumerate the different cg classes. This is purely for dump purposes. If
  46. // we add a new CG class, we add the enumerator here.
  47. //
  48. typedef enum _idcg
  49. {
  50. ID_CG_ERROR
  51. ,ID_CG_SOURCE
  52. ,ID_CG_FILE
  53. ,ID_CG_BT
  54. ,ID_CG_ENUM
  55. ,ID_CG_ERROR_STATUS_T
  56. ,ID_CG_PROC
  57. ,ID_CG_CALLBACK_PROC
  58. ,ID_CG_OBJECT_PROC
  59. ,ID_CG_INHERITED_OBJECT_PROC
  60. ,ID_CG_LOCAL_OBJECT_PROC
  61. ,ID_CG_TYPE_ENCODE
  62. ,ID_CG_TYPE_ENCODE_PROC
  63. ,ID_CG_ENCODE_PROC
  64. ,ID_CG_PARAM
  65. ,ID_CG_RETURN
  66. ,ID_CG_PTR
  67. ,ID_CG_IGN_PTR
  68. ,ID_CG_BC_PTR
  69. ,ID_CG_STRING_PTR
  70. ,ID_CG_STRUCT_STRING_PTR
  71. ,ID_CG_SIZE_STRING_PTR
  72. ,ID_CG_SIZE_PTR
  73. ,ID_CG_LENGTH_PTR
  74. ,ID_CG_SIZE_LENGTH_PTR
  75. ,ID_CG_INTERFACE_PTR
  76. ,ID_CG_STRUCT
  77. ,ID_CG_VAR_STRUCT
  78. ,ID_CG_CONF_STRUCT
  79. ,ID_CG_CONF_VAR_STRUCT
  80. ,ID_CG_COMPLEX_STRUCT
  81. ,ID_CG_ENCAP_STRUCT
  82. ,ID_CG_FIELD
  83. ,ID_CG_UNION
  84. ,ID_CG_UNION_FIELD
  85. ,ID_CG_CASE
  86. ,ID_CG_DEFAULT_CASE
  87. ,ID_CG_ARRAY
  88. ,ID_CG_CONF_ARRAY
  89. ,ID_CG_VAR_ARRAY
  90. ,ID_CG_CONF_VAR_ARRAY
  91. ,ID_CG_STRING_ARRAY
  92. ,ID_CG_CONF_STRING_ARRAY
  93. ,ID_CG_PRIMITIVE_HDL
  94. ,ID_CG_GENERIC_HDL
  95. ,ID_CG_CONTEXT_HDL
  96. ,ID_CG_TRANSMIT_AS
  97. ,ID_CG_REPRESENT_AS
  98. ,ID_CG_USER_MARSHAL
  99. ,ID_CG_INTERFACE
  100. ,ID_CG_OBJECT_INTERFACE
  101. ,ID_CG_INHERITED_OBJECT_INTERFACE
  102. ,ID_CG_COM_CLASS
  103. ,ID_CG_COM_SERVER_DLL
  104. ,ID_CG_COM_SERVER_EXE
  105. ,ID_CG_HRESULT
  106. ,ID_CG_TYPELIBRARY_FILE
  107. ,ID_CG_INTERFACE_REFERENCE
  108. ,ID_CG_MODULE
  109. ,ID_CG_DISPINTERFACE
  110. ,ID_CG_COCLASS
  111. ,ID_CG_LIBRARY
  112. ,ID_CG_SAFEARRAY
  113. ,ID_CG_TYPEDEF
  114. ,ID_CG_ID
  115. ,ID_CG_PIPE
  116. } ID_CG;
  117. ////////////////////////////////////////////////////////////////////////////
  118. // The general code generation class object.
  119. ////////////////////////////////////////////////////////////////////////////
  120. class CG_CLASS;
  121. class CG_ITERATOR;
  122. class CG_CLASS
  123. {
  124. private:
  125. class CG_CLASS * pChild;
  126. class CG_CLASS * pSibling;
  127. BOOL fLayedOut;
  128. BOOL fReadyForLayOut;
  129. BOOL fDepsLayedOut;
  130. #ifdef MIDL_INTERNAL
  131. //
  132. // This field used only in the debug dump mode.
  133. //
  134. unsigned short DumpNumber;
  135. void SetDumpNumber( unsigned short D )
  136. {
  137. DumpNumber = D;
  138. }
  139. unsigned short GetDumpNumber()
  140. {
  141. return DumpNumber;
  142. }
  143. #endif // MIDL_INTERNAL
  144. public:
  145. CG_CLASS()
  146. {
  147. SetSibling( (CG_CLASS *)0 );
  148. SetChild( (CG_CLASS *)0 );
  149. fLayedOut = FALSE;
  150. fReadyForLayOut = FALSE;
  151. fDepsLayedOut = FALSE;
  152. #ifdef MIDL_INTERNAL
  153. SetDumpNumber(0);
  154. #endif // MIDL_INTERNAL
  155. }
  156. CG_CLASS( CG_CLASS *pC, CG_CLASS *pS )
  157. {
  158. SetSibling( pS );
  159. SetChild( pC );
  160. fLayedOut = FALSE;
  161. fReadyForLayOut = FALSE;
  162. fDepsLayedOut = FALSE;
  163. #ifdef MIDL_INTERNAL
  164. SetDumpNumber(0);
  165. #endif // MIDL_INTERNAL
  166. }
  167. //
  168. // Get and set child and sibling.
  169. //
  170. CG_CLASS * GetChild()
  171. {
  172. return pChild;
  173. }
  174. CG_CLASS * GetNonGenericHandleChild()
  175. {
  176. CG_CLASS * pC = GetChild();
  177. if( pC->GetCGID() == ID_CG_GENERIC_HDL )
  178. {
  179. pC = pC->GetChild();
  180. }
  181. return pC;
  182. }
  183. CG_CLASS * SetChild( CG_CLASS *p )
  184. {
  185. return (pChild = p );
  186. }
  187. CG_CLASS * GetSibling()
  188. {
  189. return pSibling;
  190. }
  191. CG_CLASS * SetSibling( CG_CLASS * p )
  192. {
  193. return (pSibling = p);
  194. }
  195. short GetMembers( ITERATOR& I );
  196. short GetMembers( CG_ITERATOR& I );
  197. BOOL HasMembers()
  198. {
  199. return (BOOL) GetChild();
  200. }
  201. CG_CLASS * GetLastSibling();
  202. PNAME GetName()
  203. {
  204. return (PNAME)( GetType()->GetSymName() );
  205. }
  206. #ifdef MIDL_INTERNAL
  207. //
  208. // debug methods.
  209. //
  210. unsigned short Dump( unsigned short );
  211. #endif // MIDL_INTERNAL
  212. virtual
  213. CG_STATUS GenCode( CCB * pCCB )
  214. {
  215. UNUSED( pCCB );
  216. return CG_OK;
  217. }
  218. virtual
  219. CG_STATUS GenTypeInfo( CCB * pCCB )
  220. {
  221. UNUSED( pCCB );
  222. return CG_OK;
  223. }
  224. virtual
  225. CG_STATUS GetTypeDesc(TYPEDESC * &ptd, CCB * pCCB);
  226. virtual
  227. void * CheckImportLib()
  228. {
  229. return NULL;
  230. }
  231. BOOL IsLayedOut()
  232. {
  233. return fLayedOut;
  234. }
  235. void LayedOut()
  236. {
  237. fLayedOut = TRUE;
  238. }
  239. BOOL AreDepsLayedOut()
  240. {
  241. return fDepsLayedOut;
  242. }
  243. void DepsLayedOut()
  244. {
  245. fDepsLayedOut = TRUE;
  246. }
  247. void ClearDepsLayedOut()
  248. {
  249. fDepsLayedOut = FALSE;
  250. }
  251. BOOL IsReadyForLayOut()
  252. {
  253. return fReadyForLayOut;
  254. }
  255. void ReadyForLayOut()
  256. {
  257. fReadyForLayOut = TRUE;
  258. }
  259. //
  260. // miscellaneous methods.
  261. //
  262. virtual
  263. ID_CG GetCGID()
  264. {
  265. return ID_CG_ERROR;
  266. }
  267. virtual
  268. node_skl * GetType()
  269. {
  270. return (node_skl *)0;
  271. }
  272. //
  273. // IsXXX methods
  274. //
  275. virtual
  276. BOOL IsArray()
  277. {
  278. return FALSE;
  279. }
  280. virtual
  281. BOOL IsPointer()
  282. {
  283. return FALSE;
  284. }
  285. virtual
  286. BOOL IsStruct()
  287. {
  288. return FALSE;
  289. }
  290. virtual
  291. BOOL IsUnion()
  292. {
  293. return FALSE;
  294. }
  295. virtual
  296. BOOL IsXmitRepOrUserMarshal()
  297. {
  298. return FALSE;
  299. }
  300. virtual
  301. BOOL IsObject()
  302. {
  303. return FALSE;
  304. }
  305. virtual
  306. BOOL HasAFixedBufferSize()
  307. {
  308. return FALSE;
  309. }
  310. void * operator new ( size_t size )
  311. {
  312. return AllocateOnceNew( size );
  313. }
  314. void operator delete( void * ptr )
  315. {
  316. AllocateOnceDelete( ptr );
  317. }
  318. };
  319. class CG_ITERATOR
  320. {
  321. private:
  322. CG_CLASS * pFirst;
  323. CG_CLASS * pCurrent;
  324. public:
  325. CG_ITERATOR( CG_CLASS * pStart = NULL )
  326. {
  327. SetList( pStart );
  328. }
  329. void SetList( CG_CLASS * pStart )
  330. {
  331. pFirst = pStart;
  332. pCurrent = pStart;
  333. }
  334. STATUS_T Init( void )
  335. {
  336. pCurrent = pFirst;
  337. return STATUS_OK;
  338. }
  339. STATUS_T GetNext( void ** ppReturn )
  340. {
  341. if( pCurrent)
  342. {
  343. (*ppReturn) = pCurrent;
  344. pCurrent = pCurrent->GetSibling();
  345. return STATUS_OK;
  346. }
  347. // null out the return if the list was empty
  348. if ( !pFirst )
  349. (*ppReturn) = NULL;
  350. return I_ERR_NO_PEER;
  351. }
  352. void * PeekThis()
  353. {
  354. if( pCurrent )
  355. {
  356. return pCurrent;
  357. }
  358. else
  359. return (void *)0;
  360. }
  361. short GetCount( void )
  362. {
  363. CG_CLASS * pTmp = pFirst;
  364. short count = 0;
  365. while ( pTmp )
  366. {
  367. count++;
  368. pTmp = pTmp->GetSibling();
  369. }
  370. return count;
  371. }
  372. STATUS_T Discard()
  373. {
  374. SetList( NULL );
  375. return STATUS_OK;
  376. }
  377. };
  378. // tuck this away here, so that it goes blazingly fast
  379. inline
  380. short
  381. CG_CLASS::GetMembers(
  382. CG_ITERATOR& I )
  383. {
  384. I.SetList( GetChild() );
  385. return I.GetCount();
  386. }
  387. #endif // __CGCLS_HXX__