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.

785 lines
26 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-1999 Microsoft Corporation
  3. Module Name:
  4. ndrcls.hxx
  5. Abstract:
  6. Contains definitions for ndr related code generation class definitions.
  7. Notes:
  8. History:
  9. VibhasC Jul-29-1993 Created.
  10. ----------------------------------------------------------------------------*/
  11. #ifndef __NDRCLS_HXX__
  12. #define __NDRCLS_HXX__
  13. #include "nulldefs.h"
  14. extern "C"
  15. {
  16. #include <stdio.h>
  17. }
  18. #include "uact.hxx"
  19. #include "cgcls.hxx"
  20. #include "fldattr.hxx"
  21. class CG_STRUCT;
  22. /////////////////////////////////////////////////////////////////////////////
  23. // The base ndr related code generation class.
  24. /////////////////////////////////////////////////////////////////////////////
  25. #if COMMENT
  26. The ndr code generation class corresponds to an entity that actually goes
  27. over the wire. This class therefore corresponds to an actual type or proc
  28. that was specified in the idl file. This class can be contrasted with
  29. the auxillary code generation classes that correspond to stuff like binding,
  30. declarations in the stub, and other housekeeping functions. Note that while
  31. the ndr class actually keeps a pointer to the type declarations in the idl
  32. file, it makes no assumptions about the information kept in the type graph
  33. and hence can only make specific queries about the type, ask the type to
  34. print itself out and so on.
  35. #endif // COMMENT
  36. class CG_NDR : public CG_CLASS
  37. {
  38. private:
  39. unsigned short WireAlignment;
  40. unsigned short MemoryAlignment;
  41. unsigned long MemorySize;
  42. unsigned long WireSize;
  43. //
  44. // These fields specify the allocation stuff for server side parameters.
  45. //
  46. S_STUB_ALLOC_LOCATION AllocLocation : 2;
  47. S_STUB_ALLOC_TYPE AllocType : 2;
  48. S_STUB_INIT_NEED InitNeed : 2;
  49. // Keep an indication of where this is allocated;
  50. unsigned long fAllocatedOnStack : 1;
  51. unsigned long FixUpLock : 1;
  52. unsigned long InFixedBufferSize : 1;
  53. unsigned long ComplexFixupLock : 1;
  54. //
  55. // Keep a link to the actual specification of the type.
  56. //
  57. node_skl * pTypeNode;
  58. // the string name (if any) for the actual type
  59. char * pNodeName;
  60. // Keep track of the resource allocated for this node.
  61. RESOURCE * pResource;
  62. //
  63. // This is the offset from the beginning of the Ndr format string
  64. // where an Ndr entity's description is. This is only used when
  65. // optimization options equal OPTIMIZE_SIZE.
  66. //
  67. long FormatStringOffset;
  68. long FormatStringEndOffset;
  69. // This is used only for fixing offsets for recursive embedded objects.
  70. long InitialFormatStringOffset;
  71. TREGISTRY * pEmbeddedComplexFixupRegistry;
  72. // UnMarshalling action recommendations
  73. U_ACTION UAction;
  74. protected:
  75. node_range_attr* pRangeAttr;
  76. public:
  77. CG_NDR( const CG_NDR & Node )
  78. {
  79. *this = Node;
  80. if ( Node.pResource )
  81. pResource = (RESOURCE*)Node.pResource->Clone();
  82. }
  83. CG_NDR( node_skl * pT, XLAT_SIZE_INFO & Info ) :
  84. pRangeAttr( 0 )
  85. {
  86. pTypeNode = pT;
  87. FormatStringOffset = -1;
  88. FormatStringEndOffset = -1;
  89. SetSizesAndAlignments( Info );
  90. SetUAction(AN_NONE, RA_NONE, UA_NONE, PR_NONE);
  91. SetResource( 0 );
  92. SetAllocatedOnStack( 0 );
  93. SetFixUpLock( 0 );
  94. SetInFixedBufferSize( FALSE );
  95. pNodeName = (pT) ? pT->GetSymName() : "";
  96. SetComplexFixupLock( 0 );
  97. InitialFormatStringOffset = -1;
  98. pEmbeddedComplexFixupRegistry = NULL;
  99. SetSStubAllocLocation(
  100. S_STUB_ALLOC_LOCATION_UNKNOWN );
  101. SetSStubAllocType( S_STUB_ALLOC_TYPE_NONE );
  102. SetSStubInitNeed( S_STUB_INIT_NOT_NEEDED );
  103. }
  104. virtual
  105. void * CheckImportLib();
  106. //
  107. // Get and set routines.
  108. //
  109. virtual void
  110. SetRangeAttribute (
  111. node_range_attr* pRange
  112. )
  113. {
  114. pRangeAttr = pRange;
  115. }
  116. virtual node_range_attr*
  117. GetRangeAttribute ()
  118. {
  119. return pRangeAttr;
  120. }
  121. virtual
  122. void SetSizesAndAlignments( XLAT_SIZE_INFO & Info )
  123. {
  124. SetWireAlignment( Info.GetWireAlign() );
  125. SetWireSize( Info.GetWireSize() );
  126. SetMemoryAlignment( Info.GetMemAlign() );
  127. SetMemorySize( Info.GetMemSize() );
  128. }
  129. void SetAllocatedOnStack( unsigned long Flag )
  130. {
  131. fAllocatedOnStack = Flag;
  132. }
  133. BOOL IsAllocatedOnStack()
  134. {
  135. return (BOOL)( fAllocatedOnStack == 1 );
  136. }
  137. // Set the unmarshalling action recommendation stuff.
  138. unsigned short SetAllocNeed( unsigned short A )
  139. {
  140. return UAction.SetAllocNeed( A );
  141. }
  142. unsigned short GetAllocNeed()
  143. {
  144. return UAction.GetAllocNeed();
  145. }
  146. unsigned short SetRefAction( unsigned short R )
  147. {
  148. return UAction.SetRefAction( R );
  149. }
  150. unsigned short GetRefAction()
  151. {
  152. return UAction.GetRefAction();
  153. }
  154. unsigned short SetUnMarAction( unsigned short U )
  155. {
  156. return UAction.SetUnMarAction( U );
  157. }
  158. unsigned short GetUnMarAction()
  159. {
  160. return UAction.GetUnMarAction();
  161. }
  162. unsigned short SetPresentedExprAction( unsigned short P )
  163. {
  164. return UAction.SetPresentedExprAction( P );
  165. }
  166. unsigned short GetPresentedExprAction()
  167. {
  168. return UAction.GetPresentedExprAction();
  169. }
  170. void SetUAction( unsigned short A,
  171. unsigned short R,
  172. unsigned short U,
  173. unsigned short P
  174. )
  175. {
  176. UAction.SetUAction( A, R, U, P );
  177. }
  178. U_ACTION SetUAction( U_ACTION UA )
  179. {
  180. return UAction.SetUAction( UA );
  181. }
  182. unsigned short GetMemoryAlignment()
  183. {
  184. return MemoryAlignment;
  185. }
  186. unsigned short SetMemoryAlignment( unsigned short MA )
  187. {
  188. return (MemoryAlignment = MA);
  189. }
  190. unsigned short SetWireAlignment( unsigned short WA )
  191. {
  192. return (WireAlignment = WA);
  193. }
  194. unsigned short GetWireAlignment()
  195. {
  196. return WireAlignment;
  197. }
  198. unsigned long SetWireSize( unsigned long WS )
  199. {
  200. return (WireSize = WS);
  201. }
  202. unsigned long GetWireSize()
  203. {
  204. return WireSize;
  205. }
  206. unsigned long SetMemorySize( unsigned long WS )
  207. {
  208. return (MemorySize = WS);
  209. }
  210. unsigned long GetMemorySize()
  211. {
  212. return MemorySize;
  213. }
  214. node_skl * GetType()
  215. {
  216. return pTypeNode;
  217. }
  218. node_skl * SetType( node_skl * pT )
  219. {
  220. return pTypeNode = pT;
  221. }
  222. char * GetSymName()
  223. {
  224. return pNodeName;
  225. }
  226. // skip over any place-holders the current node points to
  227. // does NOT progress if GetType() is a non-place holder
  228. node_skl * GetBasicType();
  229. RESOURCE * SetResource( RESOURCE * pR )
  230. {
  231. return (pResource = pR);
  232. }
  233. RESOURCE * GetResource()
  234. {
  235. return pResource;
  236. }
  237. virtual
  238. RESOURCE * SetSizeResource( RESOURCE * )
  239. {
  240. return 0;
  241. }
  242. virtual
  243. RESOURCE * SetLengthResource( RESOURCE * )
  244. {
  245. return 0;
  246. }
  247. virtual
  248. RESOURCE * GetSizeResource()
  249. {
  250. return 0;
  251. }
  252. virtual
  253. RESOURCE * GetLengthResource()
  254. {
  255. return 0;
  256. }
  257. virtual
  258. RESOURCE * SetFirstResource( RESOURCE * )
  259. {
  260. return 0;
  261. }
  262. virtual
  263. RESOURCE * GetFirstResource()
  264. {
  265. return 0;
  266. }
  267. S_STUB_ALLOC_LOCATION SetSStubAllocLocation( S_STUB_ALLOC_LOCATION L )
  268. {
  269. return (AllocLocation = L);
  270. }
  271. S_STUB_ALLOC_LOCATION GetSStubAllocLocation()
  272. {
  273. return AllocLocation;
  274. }
  275. S_STUB_ALLOC_TYPE SetSStubAllocType( S_STUB_ALLOC_TYPE T )
  276. {
  277. return (AllocType = T);
  278. }
  279. S_STUB_ALLOC_TYPE GetSStubAllocType()
  280. {
  281. return AllocType;
  282. }
  283. S_STUB_INIT_NEED SetSStubInitNeed( S_STUB_INIT_NEED N )
  284. {
  285. return (InitNeed = N );
  286. }
  287. S_STUB_INIT_NEED GetSStubInitNeed()
  288. {
  289. return InitNeed;
  290. }
  291. void SetFixUpLock( int state )
  292. {
  293. FixUpLock = state ? 1 : 0;
  294. }
  295. BOOL IsInFixUp()
  296. {
  297. return FixUpLock == 1;
  298. }
  299. long GetInitialOffset()
  300. {
  301. return( InitialFormatStringOffset );
  302. }
  303. void SetInitialOffset( long offset )
  304. {
  305. InitialFormatStringOffset = offset;
  306. }
  307. void SetComplexFixupLock( int state )
  308. {
  309. ComplexFixupLock = state ? 1 : 0;
  310. }
  311. BOOL IsInComplexFixup()
  312. {
  313. return ComplexFixupLock == 1;
  314. }
  315. TREGISTRY * GetEmbeddedComplexFixupRegistry()
  316. {
  317. return( pEmbeddedComplexFixupRegistry );
  318. }
  319. //
  320. // Queries.
  321. //
  322. virtual
  323. BOOL IsAHandle()
  324. {
  325. return FALSE;
  326. }
  327. virtual
  328. bool IsHomogeneous(FORMAT_CHARACTER)
  329. {
  330. return false;
  331. }
  332. //
  333. // code generation methods.
  334. //
  335. //
  336. // Client side binding analysis.
  337. //
  338. virtual
  339. CG_STATUS C_BindingAnalysis( ANALYSIS_INFO * )
  340. {
  341. return CG_OK;
  342. }
  343. //
  344. // Client side marshalling code generation.
  345. //
  346. virtual
  347. CG_STATUS GenSizing( CCB * )
  348. {
  349. MIDL_ASSERT(0);
  350. return CG_OK;
  351. }
  352. virtual
  353. CG_STATUS GenMarshall( CCB * )
  354. {
  355. MIDL_ASSERT(0);
  356. return CG_OK;
  357. }
  358. virtual
  359. CG_STATUS GenUnMarshall( CCB * )
  360. {
  361. MIDL_ASSERT(0);
  362. return CG_OK;
  363. }
  364. virtual
  365. CG_STATUS GenFree( CCB * )
  366. {
  367. MIDL_ASSERT(0);
  368. return CG_OK;
  369. }
  370. virtual
  371. expr_node * PresentedSizeExpression( CCB * pCCB );
  372. virtual
  373. expr_node * PresentedLengthExpression( CCB * pCCB );
  374. virtual
  375. expr_node * PresentedFirstExpression( CCB * pCCB );
  376. virtual
  377. CG_STATUS S_GenInitOutLocals( CCB* )
  378. {
  379. return CG_OK;
  380. }
  381. virtual
  382. CG_STATUS S_GenInitTopLevelStuff( CCB* )
  383. {
  384. return CG_OK;
  385. }
  386. //
  387. // NDR format string calls.
  388. //
  389. // Generate the format string.
  390. virtual
  391. void GenNdrFormat( CCB * ) /* = 0 */
  392. {
  393. // Should always be redefined.
  394. MIDL_ASSERT(0);
  395. // REVIEW: It turns out that several classes
  396. // don't redefine this. What are the
  397. // ramifications of that?
  398. }
  399. //
  400. // This method is called to generate offline portions of a type's
  401. // format string.
  402. //
  403. virtual
  404. void GenNdrParamOffline( CCB * pCCB )
  405. {
  406. GenNdrFormat( pCCB );
  407. }
  408. //
  409. // Generates a parameter's description.
  410. //
  411. virtual
  412. void GenNdrParamDescription( CCB * pCCB );
  413. virtual
  414. void GetNdrParamAttributes(
  415. CCB *pCCB,
  416. PARAM_ATTRIBUTES *attributes );
  417. //
  418. // Generates the old style NDR 1.1 parameter description.
  419. //
  420. virtual
  421. void GenNdrParamDescriptionOld( CCB * pCCB );
  422. //
  423. // Should an NDR call be made to free all/some of the data.
  424. //
  425. virtual
  426. BOOL ShouldFreeOffline()
  427. {
  428. return FALSE;
  429. }
  430. //
  431. // Generate the inlined portion of the data's freeing.
  432. //
  433. virtual
  434. void GenFreeInline( CCB * )
  435. {
  436. // Doing nothing is ok.
  437. }
  438. //
  439. // In stndr.cxx.
  440. //
  441. virtual
  442. void GenNdrPointerFixUp( CCB * pCCB,
  443. CG_STRUCT * pStruct );
  444. // Recursion may require embedded fixups as well.
  445. void RegisterComplexEmbeddedForFixup(
  446. CG_NDR * pEmbeddedComplex,
  447. long RelativeOffset );
  448. void FixupEmbeddedComplex( CCB * pCCB );
  449. short GetListOfEmbeddedComplex( ITERATOR& I )
  450. {
  451. return pEmbeddedComplexFixupRegistry->
  452. GetListOfTypes( I );
  453. }
  454. //
  455. // Figure out if we have a fixed buffer size.
  456. //
  457. virtual
  458. long FixedBufferSize( CCB * )
  459. {
  460. return - 1;
  461. }
  462. BOOL IsInFixedBufferSize()
  463. {
  464. return InFixedBufferSize;
  465. }
  466. void SetInFixedBufferSize( BOOL fIn )
  467. {
  468. InFixedBufferSize = fIn ? 1 : 0;
  469. }
  470. //
  471. // Figure out if the Interpreter must free this data.
  472. //
  473. virtual
  474. BOOL InterpreterMustFree( CCB * )
  475. {
  476. return TRUE;
  477. }
  478. //
  479. // Only the CG_BASETYPE class should re-define this virtual function
  480. // to return TRUE.
  481. //
  482. virtual
  483. BOOL IsSimpleType()
  484. {
  485. return FALSE;
  486. }
  487. virtual
  488. BOOL IsPointer()
  489. {
  490. return FALSE;
  491. }
  492. virtual
  493. BOOL IsPipeOrPipeReference()
  494. {
  495. return FALSE;
  496. }
  497. virtual
  498. BOOL IsPointerToBaseType()
  499. {
  500. return FALSE;
  501. }
  502. virtual
  503. BOOL IsStruct()
  504. {
  505. return FALSE;
  506. }
  507. virtual
  508. BOOL IsProc()
  509. {
  510. return FALSE;
  511. }
  512. virtual
  513. BOOL IsArray()
  514. {
  515. return FALSE;
  516. }
  517. virtual
  518. BOOL IsVarying()
  519. {
  520. return FALSE;
  521. }
  522. //
  523. // miscellaneous methods.
  524. //
  525. virtual
  526. expr_node * GenBindOrUnBindExpression( CCB * pCCB, BOOL )
  527. {
  528. return pCCB->GetSourceExpression();
  529. }
  530. //
  531. // Set and Get the offset in the format string where this entity's
  532. // description is. CG_UNION redefines these.
  533. //
  534. virtual
  535. void SetFormatStringOffset( long offset )
  536. {
  537. FormatStringOffset = offset;
  538. }
  539. virtual
  540. long GetFormatStringOffset()
  541. {
  542. return FormatStringOffset;
  543. }
  544. virtual
  545. void SetFormatStringEndOffset( long offset )
  546. {
  547. FormatStringEndOffset = offset;
  548. }
  549. virtual
  550. long GetFormatStringEndOffset()
  551. {
  552. return FormatStringEndOffset;
  553. }
  554. virtual
  555. CG_STATUS FollowerMarshallAnalysis( ANALYSIS_INFO * pAna )
  556. {
  557. return ((CG_NDR *)GetChild())->FollowerMarshallAnalysis( pAna );
  558. }
  559. virtual
  560. CG_STATUS MarshallAnalysis( ANALYSIS_INFO * pAna );
  561. virtual
  562. CG_STATUS SizeAnalysis( ANALYSIS_INFO * pAna );
  563. virtual
  564. CG_STATUS FollowerUnMarshallAnalysis( ANALYSIS_INFO * pAna )
  565. {
  566. return ((CG_NDR *)GetChild())->FollowerUnMarshallAnalysis( pAna );
  567. }
  568. virtual
  569. CG_STATUS UnMarshallAnalysis( ANALYSIS_INFO * )
  570. {
  571. return CG_OK;
  572. }
  573. virtual
  574. CG_STATUS S_OutLocalAnalysis( ANALYSIS_INFO * )
  575. {
  576. return CG_OK;
  577. }
  578. virtual
  579. CG_STATUS RefCheckAnalysis( ANALYSIS_INFO * pAna );
  580. virtual
  581. CG_STATUS GenRefChecks( CCB * pCCB );
  582. virtual
  583. CG_STATUS S_FreeAnalysis( ANALYSIS_INFO * )
  584. {
  585. return CG_OK;
  586. }
  587. virtual
  588. U_ACTION RecommendUAction( SIDE CurrentSide,
  589. BOOL fMemoryAllocated,
  590. BOOL fRefAllocated,
  591. BOOL fBufferReUsePossible,
  592. UAFLAGS AdditionalFlags );
  593. virtual
  594. BOOL IsBlockCopyPossible()
  595. {
  596. return TRUE;
  597. }
  598. virtual
  599. BOOL HasPointer()
  600. {
  601. return FALSE;
  602. }
  603. virtual
  604. BOOL HasAFixedBufferSize()
  605. {
  606. return FALSE;
  607. }
  608. virtual
  609. BOOL HasStatuses()
  610. {
  611. return FALSE;
  612. }
  613. virtual
  614. unsigned short GetStatuses()
  615. {
  616. return STATUS_NONE;
  617. }
  618. virtual
  619. CG_STATUS GenAllocateForUnMarshall( CCB * )
  620. {
  621. return CG_OK;
  622. }
  623. virtual
  624. CG_STATUS InLocalAnalysis( ANALYSIS_INFO * pAna );
  625. virtual
  626. CG_STATUS S_GenInitInLocals( CCB * pCCB );
  627. virtual
  628. CG_STATUS GenHeader( CCB * )
  629. {
  630. return CG_OK;
  631. }
  632. };
  633. typedef struct _EMB_COMPLEX_FIXUP
  634. {
  635. CG_NDR * pEmbeddedNdr;
  636. long RelativeOffset;
  637. } EMB_COMPLEX_FIXUP;
  638. typedef struct _POINTER_FIXUP
  639. {
  640. CG_NDR * pNdr;
  641. long AbsoluteOffset;
  642. bool fFixed;
  643. } POINTER_FIXUP;
  644. #endif // __NDRCLS_HXX__