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.

475 lines
19 KiB

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