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.

515 lines
13 KiB

4 years ago
  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. bindcls.hxx
  5. Abstract:
  6. Contains definitions for binding related code generation class definitions.
  7. Notes:
  8. History:
  9. VibhasC Sep-18-1993 Created.
  10. ----------------------------------------------------------------------------*/
  11. #ifndef __BINDCLS_HXX__
  12. #define __BINDCLS_HXX__
  13. #include "nulldefs.h"
  14. extern "C"
  15. {
  16. #include <stdio.h>
  17. #include <assert.h>
  18. }
  19. #include "ndrcls.hxx"
  20. #if 0
  21. Although not apparent, a large occurence of binding handle parameters need
  22. the parameter be shipped on the wire. Generic handles get shipped as
  23. ordinary data and context handles as a special representation. The only
  24. class that does not ship anything is primitive handles. Their usage is
  25. rare. Since most binding handle usage WILL result in shipped data, it
  26. warrants a special code generation class of its own.
  27. The usage of the handles is either explicit or implicit. Therefore, the
  28. binding handle class will appear as an explicit child of a param
  29. cg class if there is an explicit handle. The proc cg class always keeps
  30. a ptr to a binding handle class on its own anyway. So in case of explicit
  31. handles, the binding handle class pointer points to another cg class which
  32. is in the param list. In case of implicit handles, there is a new binding
  33. class instance created which is local only to the proc cg class. Therefore,
  34. in both cases, after the IL translation is done, an explicit or implicit
  35. handle looks the same to the analyser and code generation.
  36. If any handle is part of the parameter list, then the handle will get
  37. the GenCode and other related messages. An implicit handle will not be in
  38. the normal parameter list and therefore will never get the code generation
  39. messages. Therefore we dont really need to define implicit or explicit
  40. classes deriving out of the basic handle classes. Handle classes will
  41. implement the code generation methods appropriately and therefore the
  42. differentiation between explicit and implicit will be based purely on
  43. whether an instance of a class gets the code generation message or not.
  44. Only the proc node needs to know if the handle is explicit or implicit,
  45. and that it can do with a flag.
  46. #endif // 0
  47. /////////////////////////////////////////////////////////////////////////////
  48. // The general binding handle class.
  49. /////////////////////////////////////////////////////////////////////////////
  50. class CG_HANDLE : public CG_NDR
  51. {
  52. private:
  53. //
  54. // The type represented in this field is the type of the actual handle.
  55. // Therefore, in case of a generic handle, this field will get the typedef
  56. // node on which the [handle] attribute was applied. In case of a
  57. // context_handle, this is either the typedef node on which [context_handle]
  58. // was applied or the basic type of the parameter node on which the
  59. // [context_handle] was applied. Therefore this field keeps the actual
  60. // handle type.
  61. // Remember this class derives from an ndr code gen class, so that has a
  62. // type node pointer of its own. That is actually the pointer to the param
  63. // node which is the binding handle. In case of implicit handles, that
  64. // field is not relevant and can be 0.
  65. //
  66. node_skl * pHandleType;
  67. //
  68. // The actual param param or id node.
  69. //
  70. node_skl * pHandleIDOrParam;
  71. //
  72. // Offset to binding format string description.
  73. //
  74. long NdrBindDescriptionOffset;
  75. public:
  76. //
  77. // The constructor. Note again that 2 params are required in most cases,
  78. // the first representing the actual type of the handle, and the seconf
  79. // param which is the node_skl of the actual parameter node which is the
  80. // handle. In case of implicit handles, this can be 0.
  81. //
  82. CG_HANDLE( node_skl * pHT, // handle type.
  83. node_skl * pHP, // handle param or 0.
  84. XLAT_SIZE_INFO & Info // memory size
  85. ) : CG_NDR(pHP, Info )
  86. {
  87. pHandleType = pHT;
  88. pHandleIDOrParam = pHP;
  89. NdrBindDescriptionOffset = -1;
  90. }
  91. //
  92. // Get and set methods.
  93. //
  94. node_skl * SetHandleType( node_skl * pHT )
  95. {
  96. return (pHandleType = pHT);
  97. }
  98. node_skl * GetHandleType()
  99. {
  100. return pHandleType;
  101. }
  102. node_skl * GetHandleIDOrParam()
  103. {
  104. return pHandleIDOrParam;
  105. }
  106. void SetNdrBindDescriptionOffset( long Offset )
  107. {
  108. NdrBindDescriptionOffset = Offset;
  109. }
  110. long GetNdrBindDescriptionOffset()
  111. {
  112. return NdrBindDescriptionOffset;
  113. }
  114. //
  115. // Queries.
  116. //
  117. //
  118. // Queries here should generally return a false, since the derived classes
  119. // should implement the methods and return the correct result.
  120. //
  121. virtual
  122. BOOL IsPrimitiveHandle()
  123. {
  124. return FALSE;
  125. }
  126. virtual
  127. BOOL IsGenericHandle()
  128. {
  129. return FALSE;
  130. }
  131. virtual
  132. BOOL IsContextHandle()
  133. {
  134. return FALSE;
  135. }
  136. virtual
  137. BOOL IsAHandle()
  138. {
  139. return TRUE;
  140. }
  141. //
  142. // Format string generation for the bind handle description in a
  143. // procedure's description.
  144. //
  145. virtual
  146. void GenNdrHandleFormat( CCB * pCCB )
  147. {
  148. // Should be redefined by inheriting classes.
  149. assert(0);
  150. }
  151. virtual
  152. void GenNdrParamDescription( CCB * pCCB );
  153. virtual
  154. void GenNdrParamDescriptionOld( CCB * pCCB );
  155. virtual
  156. long FixedBufferSize( CCB * pCCB )
  157. {
  158. return - 1;
  159. }
  160. };
  161. //////////////////////////////////////////////////////////////////////////////
  162. // The auto handle class.
  163. //////////////////////////////////////////////////////////////////////////////
  164. class CG_PRIMITIVE_HANDLE : public CG_HANDLE
  165. {
  166. private:
  167. public:
  168. //
  169. // The constructors.
  170. //
  171. CG_PRIMITIVE_HANDLE( node_skl * pHT,
  172. node_skl * pHP,
  173. XLAT_SIZE_INFO & Info // memory size
  174. ):
  175. CG_HANDLE( pHT, pHP, Info )
  176. {
  177. }
  178. virtual
  179. ID_CG GetCGID()
  180. {
  181. return ID_CG_PRIMITIVE_HDL;
  182. }
  183. //
  184. // Queries. An auto handle is treated as an implicit primitive handle.
  185. //
  186. virtual
  187. BOOL IsPrimitiveHandle()
  188. {
  189. return TRUE;
  190. }
  191. //
  192. // Generate the format string for a handle.
  193. //
  194. virtual
  195. void GenNdrFormat( CCB * pCCB );
  196. //
  197. // This method is called to generate offline portions of a type's
  198. // format string.
  199. //
  200. virtual
  201. void GenNdrParamOffline( CCB * pCCB );
  202. virtual
  203. void GenNdrParamDescription( CCB * pCCB );
  204. virtual
  205. void GenNdrParamDescriptionOld( CCB * pCCB );
  206. virtual
  207. void GenNdrHandleFormat( CCB * pCCB );
  208. virtual
  209. long FixedBufferSize( CCB * pCCB )
  210. {
  211. return 0;
  212. }
  213. virtual
  214. void SetNextNdrAlignment( CCB * pCCB )
  215. {
  216. // Has no effect.
  217. }
  218. virtual
  219. CG_STATUS MarshallAnalysis( ANALYSIS_INFO * pAna )
  220. {
  221. UNUSED( pAna );
  222. return CG_OK;
  223. }
  224. };
  225. ////////////////////////////////////////////////////////////////////////////
  226. // The generic handle class.
  227. ////////////////////////////////////////////////////////////////////////////
  228. //
  229. // The generic handle drives off the name of the type which was defined as
  230. // a handle. The typedef node, which is the handle type serves as the
  231. // placeholder for the name of the handle.
  232. //
  233. class CG_GENERIC_HANDLE : public CG_HANDLE
  234. {
  235. private:
  236. public:
  237. //
  238. // The constructor. The generic handle class needs info about the type
  239. // of the handle. The typedef node on which the [handle] was applied,
  240. // can serve as a placeholder for the name too. The second need is the
  241. // parameter node which is the handle param in case the handle was an
  242. // explicit parameter, or the id node of the implicit handle.
  243. //
  244. CG_GENERIC_HANDLE( node_skl * pHT,
  245. node_skl * pHP,
  246. XLAT_SIZE_INFO & Info // memory size
  247. ) :
  248. CG_HANDLE( pHT, pHP, Info )
  249. {
  250. }
  251. virtual
  252. ID_CG GetCGID()
  253. {
  254. return ID_CG_GENERIC_HDL;
  255. }
  256. //
  257. // Get and set methods.
  258. //
  259. PNAME GetHandleTypeName()
  260. {
  261. return GetHandleType()->GetSymName();
  262. }
  263. long GetImplicitSize()
  264. {
  265. return 4;
  266. }
  267. //
  268. // Queries.
  269. //
  270. virtual
  271. BOOL IsGenericHandle()
  272. {
  273. return TRUE;
  274. }
  275. virtual
  276. BOOL HasAFixedBufferSize()
  277. {
  278. return GetChild()->HasAFixedBufferSize();
  279. }
  280. virtual
  281. CG_STATUS MarshallAnalysis( ANALYSIS_INFO * pAna )
  282. {
  283. return ((CG_NDR *)GetChild())->MarshallAnalysis( pAna );
  284. }
  285. virtual
  286. CG_STATUS UnMarshallAnalysis( ANALYSIS_INFO * pAna )
  287. {
  288. return ((CG_NDR *)GetChild())->UnMarshallAnalysis( pAna );
  289. }
  290. virtual
  291. CG_STATUS S_OutLocalAnalysis( ANALYSIS_INFO * pAna )
  292. {
  293. return ((CG_NDR *)GetChild())->S_OutLocalAnalysis( pAna );
  294. }
  295. virtual
  296. CG_STATUS GenMarshall( CCB * pCCB )
  297. {
  298. return ((CG_NDR *)GetChild())->GenMarshall( pCCB );
  299. }
  300. virtual
  301. CG_STATUS GenUnMarshall( CCB * pCCB )
  302. {
  303. return ((CG_NDR *)GetChild())->GenUnMarshall( pCCB );
  304. }
  305. virtual
  306. CG_STATUS GenSizing( CCB * pCCB )
  307. {
  308. return ((CG_NDR *)GetChild())->GenSizing( pCCB );
  309. }
  310. virtual
  311. CG_STATUS S_GenInitOutLocals( CCB * pCCB )
  312. {
  313. return ((CG_NDR *)GetChild())->S_GenInitOutLocals( pCCB );
  314. }
  315. //
  316. // Generate the format string for a handle.
  317. //
  318. virtual
  319. void GenNdrFormat( CCB * pCCB );
  320. //
  321. // This method is called to generate offline portions of a type's
  322. // format string.
  323. //
  324. virtual
  325. void GenNdrParamOffline( CCB * pCCB );
  326. virtual
  327. void GenNdrParamDescription( CCB * pCCB );
  328. virtual
  329. void GenNdrParamDescriptionOld( CCB * pCCB );
  330. virtual
  331. void GenNdrHandleFormat( CCB * pCCB );
  332. virtual
  333. BOOL ShouldFreeOffline()
  334. {
  335. return ((CG_NDR *)GetChild())->
  336. ShouldFreeOffline();
  337. }
  338. virtual
  339. void GenFreeInline( CCB * pCCB )
  340. {
  341. ((CG_NDR *)GetChild())->GenFreeInline( pCCB );
  342. }
  343. virtual
  344. void SetNextNdrAlignment( CCB * pCCB )
  345. {
  346. ((CG_NDR *)GetChild())->
  347. SetNextNdrAlignment( pCCB );
  348. }
  349. virtual
  350. long FixedBufferSize( CCB * pCCB )
  351. {
  352. return
  353. ((CG_NDR *)GetChild())->FixedBufferSize( pCCB );
  354. }
  355. };
  356. ////////////////////////////////////////////////////////////////////////////
  357. // The context handle class.
  358. ////////////////////////////////////////////////////////////////////////////
  359. class CG_CONTEXT_HANDLE : public CG_HANDLE
  360. {
  361. private:
  362. char * pRundownRoutineName;
  363. public:
  364. CG_CONTEXT_HANDLE( node_skl * pHT,
  365. node_skl * pHP,
  366. XLAT_SIZE_INFO & Info // memory size, etc
  367. ):
  368. CG_HANDLE( pHT, pHP, Info)
  369. {
  370. pRundownRoutineName = NULL;
  371. }
  372. virtual
  373. ID_CG GetCGID()
  374. {
  375. return ID_CG_CONTEXT_HDL;
  376. }
  377. virtual
  378. BOOL IsContextHandle()
  379. {
  380. return TRUE;
  381. }
  382. PNAME GetRundownRtnName();
  383. virtual
  384. CG_STATUS MarshallAnalysis( ANALYSIS_INFO * pAna );
  385. virtual
  386. CG_STATUS UnMarshallAnalysis( ANALYSIS_INFO * pAna );
  387. virtual
  388. CG_STATUS S_GenInitOutLocals( CCB * pCCB );
  389. virtual
  390. CG_STATUS GenMarshall( CCB * pCCB );
  391. virtual
  392. CG_STATUS GenUnMarshall( CCB * pCCB );
  393. //
  394. // Generate the format string for a handle.
  395. //
  396. virtual
  397. void GenNdrFormat( CCB * pCCB );
  398. //
  399. // This method is called to generate offline portions of a type's
  400. // format string.
  401. //
  402. virtual
  403. void GenNdrParamOffline( CCB * pCCB );
  404. virtual
  405. void GenNdrParamDescription( CCB * pCCB );
  406. virtual
  407. void GenNdrParamDescriptionOld( CCB * pCCB );
  408. virtual
  409. void GenNdrHandleFormat( CCB * pCCB );
  410. virtual
  411. void SetNextNdrAlignment( CCB * pCCB )
  412. {
  413. pCCB->SetNextNdrAlignment( 20 );
  414. }
  415. virtual
  416. long FixedBufferSize( CCB * pCCB )
  417. {
  418. return 24;
  419. }
  420. };
  421. #endif // __BINDCLS_HXX__