Source code of Windows XP (NT5)
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.

802 lines
18 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-1999 Microsoft Corporation
  3. Module Name:
  4. stcls.hxx
  5. Abstract:
  6. Contains definitions for base type related code generation class
  7. definitions.
  8. Notes:
  9. History:
  10. GregJen Sep-30-1993 Created.
  11. ----------------------------------------------------------------------------*/
  12. #ifndef __STCLS_HXX__
  13. #define __STCLS_HXX__
  14. #pragma warning ( disable : 4238 4239 )
  15. #include "nulldefs.h"
  16. extern "C"
  17. {
  18. #include <stdio.h>
  19. }
  20. #include "ndrcls.hxx"
  21. class CG_ARRAY;
  22. class ANALYSIS_INFO;
  23. class CG_FIELD;
  24. //
  25. // This class is the base type for compound things like
  26. // structures, unions, and fields
  27. //
  28. class CG_COMP : public CG_NDR
  29. {
  30. private:
  31. unsigned short Zp;
  32. BOOL fHasPointer : 1;
  33. //
  34. // this flag is set if there are fields with different mem and wire offsets
  35. //
  36. BOOL fHasMovedFields : 1;
  37. expr_node * pSizeExpression;
  38. public:
  39. //
  40. // The constructor.
  41. //
  42. CG_COMP(
  43. node_skl * pBT, // base type
  44. XLAT_SIZE_INFO & Info, // packing and size info
  45. unsigned short HP
  46. ) :
  47. CG_NDR( pBT, Info )
  48. {
  49. SetZp( Info.GetZeePee() );
  50. SetHasPointer(HP);
  51. ResetHasMovedFields();
  52. SetSizeExpression( 0 );
  53. }
  54. virtual
  55. void Visit( CG_VISITOR *pVisitor ) = 0;
  56. //
  57. // Get and set methods.
  58. //
  59. // make sure the ZP gets set along the way
  60. virtual
  61. void SetSizesAndAlignments( XLAT_SIZE_INFO & Info )
  62. {
  63. CG_NDR::SetSizesAndAlignments( Info );
  64. SetZp( Info.GetZeePee() );
  65. }
  66. expr_node * SetSizeExpression( expr_node * pE )
  67. {
  68. return (pSizeExpression = pE);
  69. }
  70. expr_node * GetSizeExpression()
  71. {
  72. return pSizeExpression;
  73. }
  74. unsigned short SetZp( unsigned short ZP )
  75. {
  76. return (Zp = ZP);
  77. }
  78. unsigned short GetZp()
  79. {
  80. return Zp;
  81. }
  82. BOOL SetHasMovedFields()
  83. {
  84. return (fHasMovedFields = TRUE);
  85. }
  86. BOOL ResetHasMovedFields()
  87. {
  88. return (fHasMovedFields = FALSE);
  89. }
  90. BOOL HasMovedFields()
  91. {
  92. return fHasMovedFields;
  93. }
  94. BOOL SetHasPointer( BOOL HP )
  95. {
  96. return (fHasPointer = HP);
  97. }
  98. BOOL HasPointer()
  99. {
  100. return fHasPointer;
  101. }
  102. virtual
  103. CG_STATUS S_GenInitOutLocals( CCB * pCCB );
  104. virtual
  105. CG_STATUS S_OutLocalAnalysis( ANALYSIS_INFO * pAna );
  106. virtual
  107. short GetPointerMembers( ITERATOR& I );
  108. virtual
  109. CG_STATUS RefCheckAnalysis( ANALYSIS_INFO * )
  110. {
  111. return CG_OK;
  112. }
  113. virtual
  114. CG_STATUS InLocalAnalysis( ANALYSIS_INFO * )
  115. {
  116. return CG_OK;
  117. }
  118. virtual
  119. CG_STATUS S_GenInitInLocals( CCB * )
  120. {
  121. return CG_OK;
  122. }
  123. virtual
  124. CG_STATUS GenRefChecks( CCB * )
  125. {
  126. return CG_OK;
  127. }
  128. };
  129. /////////////////////////////////////////////////////////////////////////////
  130. // the structure code generation classes.
  131. /////////////////////////////////////////////////////////////////////////////
  132. class CG_COMPLEX_STRUCT;
  133. //
  134. // This class corresponds to a vanilla structure type.
  135. //
  136. class CG_STRUCT : public CG_COMP, public CG_CLONEABLE
  137. {
  138. private:
  139. void * _pCTI;
  140. // This is needed for recursive embedded complex fixups.
  141. CG_COMPLEX_STRUCT * pDuplicatingComplex;
  142. public:
  143. //
  144. // The constructor.
  145. //
  146. CG_STRUCT(
  147. node_skl * pBT, // base type
  148. XLAT_SIZE_INFO & Info, // memory size, etc
  149. unsigned short HP // Has pointer
  150. ) :
  151. CG_COMP( pBT, Info, HP )
  152. {
  153. _pCTI = NULL;
  154. pDuplicatingComplex = NULL;
  155. }
  156. CG_STRUCT( CG_STRUCT * pStruct ) :
  157. CG_COMP( pStruct->GetType(),
  158. XLAT_SIZE_INFO(), // overwritten by copy below
  159. ( unsigned short )pStruct->HasPointer() )
  160. {
  161. // Make sure we copy everything.
  162. *this = *pStruct;
  163. }
  164. //
  165. // Generate typeinfo
  166. //
  167. virtual
  168. CG_STATUS GenTypeInfo( CCB * pCCB);
  169. virtual
  170. ID_CG GetCGID()
  171. {
  172. return ID_CG_STRUCT;
  173. }
  174. virtual
  175. void Visit( CG_VISITOR *pVisitor )
  176. {
  177. pVisitor->Visit( this );
  178. }
  179. virtual
  180. CG_CLASS* Clone()
  181. {
  182. return new CG_STRUCT( *this );
  183. }
  184. // Unroll imbeded structure members.
  185. void Unroll();
  186. BOOL HasSizedPointer();
  187. //
  188. // Get and set methods.
  189. //
  190. virtual
  191. BOOL IsStruct()
  192. {
  193. return TRUE;
  194. }
  195. BOOL IsComplexStruct();
  196. CG_COMPLEX_STRUCT * GetDuplicatingComplex()
  197. {
  198. return( pDuplicatingComplex );
  199. }
  200. void SetDuplicatingComplex( CG_COMPLEX_STRUCT * pC )
  201. {
  202. pDuplicatingComplex = pC;
  203. }
  204. BOOL IsHardStruct();
  205. BOOL IsHardStructOld();
  206. virtual
  207. bool IsHomogeneous(FORMAT_CHARACTER format);
  208. long GetNumberOfPointers();
  209. long GetNumberOfEnum16s();
  210. long GetNumberOfUnions();
  211. CG_FIELD * GetFinalField();
  212. CG_FIELD * GetArrayField( CG_ARRAY * pArray );
  213. long GetEnum16Offset();
  214. //
  215. // Generate the Ndr format string for the type.
  216. //
  217. virtual
  218. void GenNdrFormat( CCB * pCCB );
  219. //
  220. // Generate the description for a "hard" structure.
  221. //
  222. void GenNdrFormatHard( CCB * pCCB );
  223. //
  224. // Generate the description for a "complex" structure.
  225. //
  226. void GenNdrFormatComplex( CCB * pCCB );
  227. //
  228. // Ndr format string generation methods shared by all structure classes
  229. // except CG_COMPLEX_STRUCT, which redefines both of these methods.
  230. //
  231. virtual
  232. void GenNdrStructurePointerLayout( CCB * pCCB,
  233. BOOL fNoPP,
  234. BOOL fNoType );
  235. void GenStructureMemPad( CCB * pCCB, unsigned long MemPad );
  236. virtual
  237. void GenNdrStructureLayout( CCB * pCCB );
  238. virtual
  239. BOOL ShouldFreeOffline();
  240. virtual
  241. void GenFreeInline( CCB * pCCB );
  242. //
  243. // One more Ndr format string generation method. This time shared by all
  244. // structure classes, so it's not a virtual.
  245. //
  246. void GenNdrStructurePointees( CCB * pCCB );
  247. virtual
  248. long FixedBufferSize( CCB * pCCB );
  249. BOOL InterpreterMustFree( CCB * ) { return TRUE; }
  250. CG_FIELD * GetPreviousField( CG_FIELD * pField );
  251. virtual
  252. CG_STATUS MarshallAnalysis( ANALYSIS_INFO * pAna );
  253. virtual
  254. CG_STATUS UnMarshallAnalysis( ANALYSIS_INFO * pAna );
  255. virtual
  256. BOOL HasAFixedBufferSize();
  257. };
  258. //
  259. // This class corresponds to a encapsulated structure type.
  260. //
  261. class CG_ENCAPSULATED_STRUCT : public CG_STRUCT
  262. {
  263. private:
  264. public:
  265. //
  266. // The constructor.
  267. //
  268. CG_ENCAPSULATED_STRUCT(
  269. node_skl * pBT, // base type
  270. XLAT_SIZE_INFO & Info, // memory size, etc
  271. unsigned short HP // Has pointer
  272. ) :
  273. CG_STRUCT( pBT, Info, HP )
  274. {
  275. }
  276. virtual
  277. ID_CG GetCGID()
  278. {
  279. return ID_CG_ENCAP_STRUCT;
  280. }
  281. virtual
  282. void Visit( CG_VISITOR *pVisitor )
  283. {
  284. pVisitor->Visit( this );
  285. }
  286. virtual
  287. CG_CLASS* Clone()
  288. {
  289. return new CG_ENCAPSULATED_STRUCT( *this );
  290. }
  291. BOOL IsVarying()
  292. {
  293. return TRUE;
  294. }
  295. //
  296. // Redefine this method, which CG_STRUCT defines.
  297. //
  298. virtual
  299. BOOL IsStruct()
  300. {
  301. return FALSE;
  302. }
  303. //
  304. // This is, for all intents and purposes, a union.
  305. //
  306. virtual
  307. BOOL IsUnion()
  308. {
  309. return TRUE;
  310. }
  311. //
  312. // Get and set methods.
  313. //
  314. //
  315. // Generate the Ndr format string for the type.
  316. //
  317. virtual
  318. void GenNdrFormat( CCB * pCCB );
  319. virtual
  320. BOOL ShouldFreeOffline();
  321. virtual
  322. void GenFreeInline( CCB * )
  323. {
  324. }
  325. virtual
  326. void GenNdrPointerFixUp( CCB * pCCB,
  327. CG_STRUCT * pStruct );
  328. long FixedBufferSize( CCB * )
  329. {
  330. return -1;
  331. }
  332. virtual
  333. BOOL HasAFixedBufferSize()
  334. {
  335. return FALSE;
  336. }
  337. };
  338. //
  339. // This class corresponds to a conformant structure type.
  340. //
  341. // The pConfFld entry points to the CG_FIELD of this structure that describes
  342. // the conformance. If the conformance is due to an embedded struct, then
  343. // it points to the CG_FIELD above the embedded conformant structure
  344. //
  345. // The actual conformance is described by a CG_xxx_ARRAY somewhere below the
  346. // CG_FIELD.
  347. //
  348. class CG_CONFORMANT_STRUCT : public CG_STRUCT
  349. {
  350. private:
  351. CG_CLASS * pConfFld;
  352. public:
  353. //
  354. // The constructor.
  355. //
  356. CG_CONFORMANT_STRUCT(
  357. node_skl * pBT, // base type
  358. XLAT_SIZE_INFO & Info, // memory size
  359. unsigned short HP, // Has pointer
  360. CG_CLASS * pCF // conformant field
  361. ) :
  362. CG_STRUCT( pBT, Info, HP )
  363. {
  364. SetConformantField( pCF );
  365. }
  366. CG_CONFORMANT_STRUCT(
  367. CG_STRUCT * pStruct,
  368. CG_CLASS * pCF
  369. ) :
  370. CG_STRUCT( pStruct )
  371. {
  372. SetConformantField( pCF );
  373. }
  374. virtual
  375. ID_CG GetCGID()
  376. {
  377. return ID_CG_CONF_STRUCT;
  378. }
  379. virtual
  380. CG_CLASS* Clone()
  381. {
  382. return new CG_CONFORMANT_STRUCT( *this );
  383. }
  384. virtual
  385. void Visit( CG_VISITOR *pVisitor )
  386. {
  387. pVisitor->Visit( this );
  388. }
  389. //
  390. // Get and set methods.
  391. //
  392. CG_CLASS * SetConformantField( CG_CLASS * pCF )
  393. {
  394. return (pConfFld = pCF);
  395. }
  396. CG_CLASS * GetConformantField()
  397. {
  398. return pConfFld;
  399. }
  400. //
  401. // Dig down into the bowels of the CG class graph and get my
  402. // conformant array class.
  403. // Return a CG_ARRAY pointer since both conformant and conformant
  404. // varying arrays inherit this.
  405. //
  406. CG_ARRAY * GetConformantArray();
  407. };
  408. //
  409. // This class corresponds to a vanilla structure type.
  410. //
  411. class CG_CONFORMANT_VARYING_STRUCT : public CG_CONFORMANT_STRUCT
  412. {
  413. private:
  414. public:
  415. //
  416. // The constructor.
  417. //
  418. CG_CONFORMANT_VARYING_STRUCT(
  419. node_skl * pBT, // base type
  420. XLAT_SIZE_INFO & Info, // memory size, etc
  421. unsigned short HP, // Has pointer
  422. CG_CLASS * pCF // conformant field
  423. ) :
  424. CG_CONFORMANT_STRUCT( pBT, Info, HP, pCF )
  425. {
  426. }
  427. virtual
  428. ID_CG GetCGID()
  429. {
  430. return ID_CG_CONF_VAR_STRUCT;
  431. }
  432. virtual
  433. CG_CLASS* Clone()
  434. {
  435. return new CG_CONFORMANT_VARYING_STRUCT( *this );
  436. }
  437. virtual
  438. void Visit( CG_VISITOR *pVisitor )
  439. {
  440. pVisitor->Visit( this );
  441. }
  442. virtual
  443. BOOL HasAFixedBufferSize()
  444. {
  445. return FALSE;
  446. }
  447. };
  448. //
  449. // This class corresponds to a vanilla structure type.
  450. //
  451. class CG_COMPLEX_STRUCT : public CG_CONFORMANT_STRUCT
  452. {
  453. private:
  454. //
  455. // Struct from which we were duplicated, if any. This is used for
  456. // handling packed structures.
  457. //
  458. CG_STRUCT * pDuplicatedStruct;
  459. public:
  460. //
  461. // The constructor.
  462. //
  463. CG_COMPLEX_STRUCT(
  464. node_skl * pBT, // base type
  465. XLAT_SIZE_INFO & Info, // memory size, etc
  466. unsigned short HP, // Has pointer
  467. CG_CLASS * pCF // conformant field
  468. ) :
  469. CG_CONFORMANT_STRUCT( pBT, Info, HP, pCF )
  470. {
  471. pDuplicatedStruct = 0;
  472. }
  473. CG_COMPLEX_STRUCT(
  474. CG_STRUCT * pStruct,
  475. CG_CLASS * pCF
  476. ) :
  477. CG_CONFORMANT_STRUCT( pStruct, pCF )
  478. {
  479. pDuplicatedStruct = pStruct;
  480. }
  481. virtual
  482. ID_CG GetCGID()
  483. {
  484. return ID_CG_COMPLEX_STRUCT;
  485. }
  486. virtual
  487. CG_CLASS* Clone()
  488. {
  489. return new CG_COMPLEX_STRUCT( *this );
  490. }
  491. virtual
  492. void Visit( CG_VISITOR *pVisitor )
  493. {
  494. pVisitor->Visit( this );
  495. }
  496. BOOL IsVarying()
  497. {
  498. return TRUE;
  499. }
  500. //
  501. // Get and set methods.
  502. //
  503. CG_STRUCT * GetDuplicatedStruct()
  504. {
  505. return pDuplicatedStruct;
  506. }
  507. //
  508. // Generate the Ndr format string for the type.
  509. //
  510. virtual
  511. void GenNdrFormat( CCB * pCCB );
  512. virtual
  513. void GenNdrStructurePointerLayout( CCB * pCCB );
  514. BOOL WarnAboutEmbeddedComplexStruct();
  515. };
  516. //
  517. // New Class for 64bit NDR
  518. //
  519. #define DECLARE_STRUCT_CG_CLASS( NEWTYPE, BASETYPE ) \
  520. class NEWTYPE : public BASETYPE \
  521. { \
  522. protected: \
  523. NEWTYPE( const NEWTYPE & Node ) : \
  524. BASETYPE( Node ) {} \
  525. public: \
  526. NEWTYPE(node_skl *pType, \
  527. XLAT_SIZE_INFO & Info, \
  528. BOOL HP ) : \
  529. BASETYPE( pType, \
  530. Info, \
  531. (unsigned short)HP, \
  532. NULL ) {} \
  533. \
  534. virtual CG_CLASS* Clone() { return new NEWTYPE(*this); } \
  535. virtual void Visit( CG_VISITOR *pVisitor ) { pVisitor->Visit( this ); } \
  536. }; \
  537. DECLARE_STRUCT_CG_CLASS( CG_FULL_COMPLEX_STRUCT, CG_COMPLEX_STRUCT )
  538. DECLARE_STRUCT_CG_CLASS( CG_FORCED_COMPLEX_STRUCT, CG_COMPLEX_STRUCT )
  539. DECLARE_STRUCT_CG_CLASS( CG_CONFORMANT_FULL_COMPLEX_STRUCT, CG_COMPLEX_STRUCT )
  540. DECLARE_STRUCT_CG_CLASS( CG_CONFORMANT_FORCED_COMPLEX_STRUCT, CG_COMPLEX_STRUCT )
  541. //
  542. // Block copyable regions for 64bit NDR
  543. //
  544. // Do not instantiate CG_REGION directly since it is a base class.
  545. class CG_REGION : public CG_STRUCT
  546. {
  547. protected:
  548. CG_REGION( const CG_REGION & Node ) :
  549. CG_STRUCT( Node )
  550. {}
  551. CG_REGION(CG_COMPLEX_STRUCT *pComplexStruct,
  552. XLAT_SIZE_INFO & Info,
  553. BOOL HP) :
  554. CG_STRUCT(pComplexStruct->GetType(),
  555. Info,
  556. (unsigned short)HP)
  557. {
  558. }
  559. public:
  560. virtual CG_CLASS* Clone() = 0;
  561. virtual void Visit( CG_VISITOR *pVisitor ) = 0;
  562. };
  563. // Small region without any pointers
  564. class CG_SIMPLE_REGION : public CG_REGION
  565. {
  566. protected:
  567. CG_SIMPLE_REGION( const CG_REGION & Node ) :
  568. CG_REGION( Node )
  569. {}
  570. public:
  571. CG_SIMPLE_REGION( CG_COMPLEX_STRUCT *pComplexStruct,
  572. XLAT_SIZE_INFO & Info ) :
  573. CG_REGION( pComplexStruct,
  574. Info,
  575. FALSE )
  576. {}
  577. virtual CG_CLASS* Clone() { return new CG_SIMPLE_REGION(*this); }
  578. virtual void Visit( CG_VISITOR *pVisitor ) { pVisitor->Visit( this ); }
  579. };
  580. // Larger region or region with pointers
  581. class CG_COMPLEX_REGION : public CG_REGION
  582. {
  583. protected:
  584. CG_COMPLEX_REGION( const CG_REGION & Node ) :
  585. CG_REGION( Node )
  586. {}
  587. public:
  588. CG_COMPLEX_REGION( CG_COMPLEX_STRUCT *pComplexStruct,
  589. XLAT_SIZE_INFO & Info,
  590. BOOL HP ) :
  591. CG_REGION( pComplexStruct,
  592. Info,
  593. HP )
  594. {}
  595. virtual CG_CLASS* Clone() { return new CG_COMPLEX_REGION(*this); }
  596. virtual void Visit( CG_VISITOR *pVisitor ) { pVisitor->Visit( this ); }
  597. };
  598. // Represents a buffer pad.
  599. class CG_PAD : public CG_NDR
  600. {
  601. private:
  602. public:
  603. //
  604. // The constructor.
  605. //
  606. CG_PAD( node_skl *pType,
  607. XLAT_SIZE_INFO & Info ) :
  608. CG_NDR( pType, Info )
  609. {
  610. }
  611. virtual
  612. CG_CLASS * Clone()
  613. {
  614. return new CG_PAD( *this );
  615. }
  616. virtual
  617. ID_CG GetCGID()
  618. {
  619. return ID_CG_PAD;
  620. }
  621. virtual
  622. void Visit( CG_VISITOR *pVisitor )
  623. {
  624. pVisitor->Visit( this );
  625. }
  626. //
  627. // Ndr format string generation method.
  628. //
  629. virtual
  630. void GenNdrFormat( CCB * pCCB )
  631. {
  632. FORMAT_STRING * pFormat = pCCB->GetFormatString();
  633. pFormat->PushFormatChar( FC_BUFFER_ALIGN );
  634. pFormat->PushByte( GetWireAlignment() - 1 );
  635. }
  636. };
  637. #endif // __STCLS_HXX__