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.

596 lines
20 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-1999 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. }
  18. #include "ndrcls.hxx"
  19. #include "ilxlat.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. virtual
  92. void Visit( CG_VISITOR *pVisitor ) = 0;
  93. //
  94. // Get and set methods.
  95. //
  96. node_skl * SetHandleType( node_skl * pHT )
  97. {
  98. return (pHandleType = pHT);
  99. }
  100. node_skl * GetHandleType()
  101. {
  102. return pHandleType;
  103. }
  104. node_skl * GetHandleIDOrParam()
  105. {
  106. return pHandleIDOrParam;
  107. }
  108. void SetNdrBindDescriptionOffset( long Offset )
  109. {
  110. NdrBindDescriptionOffset = Offset;
  111. }
  112. long GetNdrBindDescriptionOffset()
  113. {
  114. return NdrBindDescriptionOffset;
  115. }
  116. //
  117. // Queries.
  118. //
  119. //
  120. // Queries here should generally return a false, since the derived classes
  121. // should implement the methods and return the correct result.
  122. //
  123. virtual
  124. BOOL IsPrimitiveHandle()
  125. {
  126. return FALSE;
  127. }
  128. virtual
  129. BOOL IsGenericHandle()
  130. {
  131. return FALSE;
  132. }
  133. virtual
  134. BOOL IsContextHandle()
  135. {
  136. return FALSE;
  137. }
  138. virtual
  139. BOOL IsAHandle()
  140. {
  141. return TRUE;
  142. }
  143. //
  144. // Format string generation for the bind handle description in a
  145. // procedure's description.
  146. //
  147. virtual
  148. unsigned char MakeExplicitHandleFlag(
  149. CG_PARAM * pHandleParam );
  150. virtual
  151. void GetNdrHandleInfo( CCB *, NDR64_BINDINGS * )
  152. {
  153. // Should be redefined by inheriting classes.
  154. MIDL_ASSERT(0);
  155. }
  156. virtual
  157. void GenNdrHandleFormat( CCB * )
  158. {
  159. // Should be redefined by inheriting classes.
  160. MIDL_ASSERT(0);
  161. }
  162. virtual
  163. void GenNdrParamDescription( CCB * pCCB );
  164. virtual
  165. void GenNdrParamDescriptionOld( CCB * pCCB );
  166. virtual
  167. long FixedBufferSize( CCB * )
  168. {
  169. return - 1;
  170. }
  171. };
  172. //////////////////////////////////////////////////////////////////////////////
  173. // The auto handle class.
  174. //////////////////////////////////////////////////////////////////////////////
  175. class CG_PRIMITIVE_HANDLE : public CG_HANDLE
  176. {
  177. private:
  178. public:
  179. //
  180. // The constructors.
  181. //
  182. CG_PRIMITIVE_HANDLE( node_skl * pHT,
  183. node_skl * pHP,
  184. XLAT_SIZE_INFO & Info // memory size
  185. ):
  186. CG_HANDLE( pHT, pHP, Info )
  187. {
  188. }
  189. virtual
  190. ID_CG GetCGID()
  191. {
  192. return ID_CG_PRIMITIVE_HDL;
  193. }
  194. virtual
  195. void Visit( CG_VISITOR *pVisitor )
  196. {
  197. pVisitor->Visit( this );
  198. }
  199. //
  200. // Queries. An auto handle is treated as an implicit primitive handle.
  201. //
  202. virtual
  203. BOOL IsPrimitiveHandle()
  204. {
  205. return TRUE;
  206. }
  207. //
  208. // Generate the format string for a handle.
  209. //
  210. virtual
  211. void GenNdrFormat( CCB * pCCB );
  212. //
  213. // This method is called to generate offline portions of a type's
  214. // format string.
  215. //
  216. virtual
  217. void GenNdrParamOffline( CCB * pCCB );
  218. virtual
  219. void GenNdrParamDescription( CCB * pCCB );
  220. virtual
  221. void GenNdrParamDescriptionOld( CCB * pCCB );
  222. virtual
  223. void GetNdrHandleInfo( CCB *, NDR64_BINDINGS * );
  224. virtual
  225. void GenNdrHandleFormat( CCB * pCCB );
  226. virtual
  227. long FixedBufferSize( CCB * )
  228. {
  229. return 0;
  230. }
  231. virtual
  232. CG_STATUS MarshallAnalysis( ANALYSIS_INFO * )
  233. {
  234. return CG_OK;
  235. }
  236. };
  237. ////////////////////////////////////////////////////////////////////////////
  238. // The generic handle class.
  239. ////////////////////////////////////////////////////////////////////////////
  240. //
  241. // The generic handle drives off the name of the type which was defined as
  242. // a handle. The typedef node, which is the handle type serves as the
  243. // placeholder for the name of the handle.
  244. //
  245. class CG_GENERIC_HANDLE : public CG_HANDLE
  246. {
  247. private:
  248. public:
  249. //
  250. // The constructor. The generic handle class needs info about the type
  251. // of the handle. The typedef node on which the [handle] was applied,
  252. // can serve as a placeholder for the name too. The second need is the
  253. // parameter node which is the handle param in case the handle was an
  254. // explicit parameter, or the id node of the implicit handle.
  255. //
  256. CG_GENERIC_HANDLE( node_skl * pHT,
  257. node_skl * pHP,
  258. XLAT_SIZE_INFO & Info // memory size
  259. ) :
  260. CG_HANDLE( pHT, pHP, Info )
  261. {
  262. }
  263. virtual
  264. ID_CG GetCGID()
  265. {
  266. return ID_CG_GENERIC_HDL;
  267. }
  268. virtual
  269. void Visit( CG_VISITOR *pVisitor )
  270. {
  271. pVisitor->Visit( this );
  272. }
  273. //
  274. // Get and set methods.
  275. //
  276. PNAME GetHandleTypeName()
  277. {
  278. return GetHandleType()->GetSymName();
  279. }
  280. long GetImplicitSize()
  281. {
  282. return 4;
  283. }
  284. //
  285. // Queries.
  286. //
  287. virtual
  288. BOOL IsGenericHandle()
  289. {
  290. return TRUE;
  291. }
  292. virtual
  293. BOOL HasAFixedBufferSize()
  294. {
  295. return GetChild()->HasAFixedBufferSize();
  296. }
  297. virtual
  298. CG_STATUS MarshallAnalysis( ANALYSIS_INFO * pAna )
  299. {
  300. return ((CG_NDR *)GetChild())->MarshallAnalysis( pAna );
  301. }
  302. virtual
  303. CG_STATUS UnMarshallAnalysis( ANALYSIS_INFO * pAna )
  304. {
  305. return ((CG_NDR *)GetChild())->UnMarshallAnalysis( pAna );
  306. }
  307. virtual
  308. CG_STATUS S_OutLocalAnalysis( ANALYSIS_INFO * pAna )
  309. {
  310. return ((CG_NDR *)GetChild())->S_OutLocalAnalysis( pAna );
  311. }
  312. virtual
  313. CG_STATUS S_GenInitOutLocals( CCB * pCCB )
  314. {
  315. return ((CG_NDR *)GetChild())->S_GenInitOutLocals( pCCB );
  316. }
  317. //
  318. // Generate the format string for a handle.
  319. //
  320. virtual
  321. void GenNdrFormat( CCB * pCCB );
  322. //
  323. // This method is called to generate offline portions of a type's
  324. // format string.
  325. //
  326. virtual
  327. void GenNdrParamOffline( CCB * pCCB );
  328. virtual
  329. void GenNdrParamDescription( CCB * pCCB );
  330. virtual
  331. void GetNdrParamAttributes(
  332. CCB * pCCB,
  333. PARAM_ATTRIBUTES *attributes );
  334. virtual
  335. void GenNdrParamDescriptionOld( CCB * pCCB );
  336. virtual
  337. void GetNdrHandleInfo( CCB *, NDR64_BINDINGS * );
  338. virtual
  339. void GenNdrHandleFormat( CCB * pCCB );
  340. virtual
  341. BOOL ShouldFreeOffline()
  342. {
  343. return ((CG_NDR *)GetChild())->
  344. ShouldFreeOffline();
  345. }
  346. virtual
  347. void GenFreeInline( CCB * pCCB )
  348. {
  349. ((CG_NDR *)GetChild())->GenFreeInline( pCCB );
  350. }
  351. virtual
  352. long FixedBufferSize( CCB * pCCB )
  353. {
  354. return
  355. ((CG_NDR *)GetChild())->FixedBufferSize( pCCB );
  356. }
  357. };
  358. ////////////////////////////////////////////////////////////////////////////
  359. // The context handle class.
  360. ////////////////////////////////////////////////////////////////////////////
  361. class CG_CONTEXT_HANDLE : public CG_HANDLE
  362. {
  363. private:
  364. bool fStrictContext;
  365. bool fNoSerialize;
  366. bool fSerialize;
  367. bool fCannotBeNull;
  368. char* pRundownRoutineName;
  369. public:
  370. CG_CONTEXT_HANDLE (
  371. node_skl * pHT,
  372. node_skl * pHP,
  373. XLAT_CTXT& Info
  374. ) :
  375. CG_HANDLE( pHT, pHP, ( XLAT_SIZE_INFO& ) Info),
  376. pRundownRoutineName( 0 )
  377. {
  378. fStrictContext = Info.GetInterfaceContext()
  379. ->GetAttribute( ATTR_STRICT_CONTEXT_HANDLE ) != 0;
  380. fNoSerialize = Info.ExtractAttribute( ATTR_NOSERIALIZE ) != 0;
  381. fSerialize = Info.ExtractAttribute( ATTR_SERIALIZE ) != 0;
  382. fCannotBeNull = false;
  383. }
  384. virtual
  385. ID_CG GetCGID()
  386. {
  387. return ID_CG_CONTEXT_HDL;
  388. }
  389. virtual
  390. void Visit( CG_VISITOR *pVisitor )
  391. {
  392. pVisitor->Visit( this );
  393. }
  394. virtual
  395. BOOL IsContextHandle()
  396. {
  397. return TRUE;
  398. }
  399. bool GetCannotBeNull()
  400. {
  401. return fCannotBeNull;
  402. }
  403. void SetCannotBeNull()
  404. {
  405. fCannotBeNull = true;
  406. }
  407. BOOL HasNewContextFlavor()
  408. {
  409. return fStrictContext || fNoSerialize || fSerialize;
  410. }
  411. BOOL HasSerialize()
  412. {
  413. return fSerialize;
  414. }
  415. BOOL HasNoSerialize()
  416. {
  417. return fNoSerialize;
  418. }
  419. BOOL HasStrict()
  420. {
  421. return fStrictContext;
  422. }
  423. PNAME GetRundownRtnName();
  424. virtual
  425. CG_STATUS MarshallAnalysis( ANALYSIS_INFO * pAna );
  426. virtual
  427. CG_STATUS UnMarshallAnalysis( ANALYSIS_INFO * pAna );
  428. virtual
  429. CG_STATUS S_GenInitOutLocals( CCB * pCCB );
  430. //
  431. // Generate the format string for a handle.
  432. //
  433. virtual
  434. void GenNdrFormat( CCB * pCCB );
  435. //
  436. // This method is called to generate offline portions of a type's
  437. // format string.
  438. //
  439. virtual
  440. void GenNdrParamOffline( CCB * pCCB );
  441. virtual
  442. void GenNdrParamDescription( CCB * pCCB );
  443. virtual
  444. void GetNdrParamAttributes(
  445. CCB * pCCB,
  446. PARAM_ATTRIBUTES *attributes );
  447. virtual
  448. void GenNdrParamDescriptionOld( CCB * pCCB );
  449. virtual
  450. unsigned char MakeExplicitHandleFlag(
  451. CG_PARAM * pHandleParam );
  452. virtual
  453. void GetNdrHandleInfo( CCB *, NDR64_BINDINGS * );
  454. virtual
  455. void GenNdrHandleFormat( CCB * pCCB );
  456. virtual
  457. long FixedBufferSize( CCB * )
  458. {
  459. return MAX_WIRE_ALIGNMENT + 20;
  460. }
  461. };
  462. class CG_ASYNC_HANDLE : public CG_NDR
  463. {
  464. private:
  465. public:
  466. CG_ASYNC_HANDLE(node_skl* pType,
  467. XLAT_SIZE_INFO& Info) : CG_NDR( pType, Info )
  468. {
  469. SetSStubAllocLocation( S_STUB_ALLOC_LOCATION_UNKNOWN );
  470. SetSStubAllocType( S_STUB_ALLOC_TYPE_NONE );
  471. SetSStubInitNeed( S_STUB_INIT_NOT_NEEDED );
  472. }
  473. virtual
  474. void Visit( CG_VISITOR *pVisitor )
  475. {
  476. pVisitor->Visit( this );
  477. }
  478. ID_CG GetCGID()
  479. {
  480. return ID_CG_ASYNC_HANDLE;
  481. }
  482. };
  483. #endif // __BINDCLS_HXX__