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.

786 lines
26 KiB

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