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.

628 lines
16 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-1999 Microsoft Corporation
  3. Module Name:
  4. filecls.hxx
  5. Abstract:
  6. cg classes for file nodes.
  7. Notes:
  8. History:
  9. ----------------------------------------------------------------------------*/
  10. #ifndef __FILECLS_HXX__
  11. #define __FILECLS_HXX__
  12. #include "ndrcls.hxx"
  13. #include "auxcls.hxx"
  14. #include "bindcls.hxx"
  15. class node_file;
  16. class node_interface;
  17. class node_source;
  18. // Ids for tables that we need remember file position of for ANSI.
  19. // Note that following tables don't need this, as they are tables of functions,
  20. // not structs:
  21. // ContextRundownSizePosition,
  22. // ExprEvaluationSizePosition,
  23. // NotifySizePosition,
  24. //
  25. typedef enum
  26. {
  27. TypeFormatStringSizePosition,
  28. ProcFormatStringSizePosition,
  29. GenericHandleSizePosition,
  30. TransmitAsSizePosition,
  31. WireMarshalSizePosition,
  32. TABLE_ID_MAX
  33. } TABLE_ID;
  34. class CG_FILE : public CG_AUX
  35. {
  36. private:
  37. PFILENAME pFileName;
  38. //
  39. // The header file name could be different from the default name
  40. // based off the stub name. The ilxlat will supply this info.
  41. //
  42. char * pHeaderFileName;
  43. node_file * pNode;
  44. long OptionalTableSizePositions[ TABLE_ID_MAX ];
  45. FORMAT_STRING * pLocalFormatString;
  46. FORMAT_STRING * pLocalProcFormatString;
  47. NdrVersionControl VersionControl;
  48. // REVIEW: some of the flags are specific to certain types of files. We may
  49. // want to create approriate intermediate classes for them
  50. // Has the memory stuff for [enable_allocated] been emitted?
  51. unsigned long fMallocAndFreeStructExternEmitted : 1;
  52. public:
  53. //
  54. // constructor.
  55. //
  56. CG_FILE(
  57. node_file * pN,
  58. PFILENAME pFName,
  59. PFILENAME pHdrFName = NULL
  60. )
  61. {
  62. SetFileName( pFName );
  63. SetFileNode( pN );
  64. pHeaderFileName = pHdrFName;
  65. for ( int i=0; i < TABLE_ID_MAX; i++ )
  66. OptionalTableSizePositions[ i ] = 0;
  67. fMallocAndFreeStructExternEmitted = 0;
  68. }
  69. virtual
  70. void Visit( CG_VISITOR *pVisitor )
  71. {
  72. pVisitor->Visit( this );
  73. }
  74. //
  75. // get and set methods.
  76. //
  77. PFILENAME SetFileName( PFILENAME p )
  78. {
  79. return (pFileName = p);
  80. }
  81. PFILENAME GetFileName()
  82. {
  83. return pFileName;
  84. }
  85. node_file * SetFileNode( node_file * pN )
  86. {
  87. return (pNode = pN);
  88. }
  89. node_file * GetFileNode()
  90. {
  91. return pNode;
  92. }
  93. PFILENAME GetHeaderFileName()
  94. {
  95. return pHeaderFileName;
  96. }
  97. NdrVersionControl & GetNdrVersionControl()
  98. {
  99. return( VersionControl );
  100. }
  101. long GetOptionalTableSizePosition( TABLE_ID TableId )
  102. {
  103. return OptionalTableSizePositions[ TableId ];
  104. }
  105. void SetOptionalTableSizePosition( TABLE_ID TableId,
  106. long PositionInFile )
  107. {
  108. OptionalTableSizePositions[ TableId ] = PositionInFile;
  109. }
  110. BOOL GetMallocAndFreeStructExternEmitted()
  111. {
  112. return fMallocAndFreeStructExternEmitted;
  113. }
  114. void SetMallocAndFreeStructExternEmitted()
  115. {
  116. fMallocAndFreeStructExternEmitted = 1;
  117. }
  118. //
  119. // code generation methods.
  120. //
  121. virtual
  122. ID_CG GetCGID()
  123. {
  124. return ID_CG_FILE;
  125. }
  126. virtual
  127. CG_STATUS GenCode( CCB * )
  128. {
  129. return CG_OK;
  130. }
  131. void EmitFileHeadingBlock( CCB * pCCB,
  132. char * CommentStr,
  133. char * CommentStr2 = 0,
  134. bool fDualFile = true );
  135. void EmitFileClosingBlock( CCB * pCCB,
  136. bool fDualFile = true );
  137. void EmitStandardHeadingBlock( CCB * pCCB );
  138. void CheckForHeadingToken( CCB * pCCB );
  139. void Out_TransferSyntaxDefs( CCB * pCCB);
  140. void EmitFormatStringTypedefs( CCB * pCCB );
  141. void EmitFixupToFormatStringTypedefs( CCB * pCCB );
  142. void EmitOptionalClientTableSizeTypedefs( CCB * pCCB );
  143. void EmitFixupToOptionalClientTableSizeTypedefs( CCB * pCCB );
  144. void EvaluateVersionControl();
  145. };
  146. class CG_CSTUB_FILE : public CG_FILE
  147. {
  148. private:
  149. public:
  150. //
  151. // The constructor.
  152. //
  153. CG_CSTUB_FILE(
  154. node_file * pN,
  155. PFILENAME pFName,
  156. PFILENAME pHdrName
  157. )
  158. : CG_FILE( pN, pFName, pHdrName )
  159. {
  160. }
  161. virtual
  162. void Visit( CG_VISITOR *pVisitor )
  163. {
  164. pVisitor->Visit( this );
  165. }
  166. //
  167. // Code generation methods.
  168. //
  169. virtual
  170. CG_STATUS GenCode( CCB * pCCB );
  171. void OutputTypePicklingTables( CCB * pCCB );
  172. };
  173. class CG_SSTUB_FILE : public CG_FILE
  174. {
  175. private:
  176. public:
  177. //
  178. // The constructor.
  179. //
  180. CG_SSTUB_FILE(
  181. node_file * pN,
  182. PFILENAME pFName,
  183. PFILENAME pHdrName
  184. )
  185. : CG_FILE( pN, pFName, pHdrName )
  186. {
  187. }
  188. virtual
  189. void Visit( CG_VISITOR *pVisitor )
  190. {
  191. pVisitor->Visit( this );
  192. }
  193. //
  194. // Code generation methods.
  195. //
  196. virtual
  197. CG_STATUS GenCode( CCB * pCCB );
  198. };
  199. //
  200. // Header file generation class
  201. //
  202. // This includes a pointer to an iterator over the import level 1
  203. // node_file nodes
  204. //
  205. class CG_HDR_FILE : public CG_FILE
  206. {
  207. private:
  208. ITERATOR * pImportList; // ptr to list of level 1 imports
  209. public:
  210. CG_HDR_FILE(
  211. node_file * pN,
  212. PFILENAME pFName,
  213. ITERATOR * pIList,
  214. PFILENAME pOtherHdr = NULL
  215. )
  216. : CG_FILE(pN, pFName, pOtherHdr)
  217. {
  218. pImportList = pIList;
  219. }
  220. virtual
  221. void Visit( CG_VISITOR *pVisitor )
  222. {
  223. pVisitor->Visit( this );
  224. }
  225. ITERATOR * GetImportList()
  226. {
  227. return pImportList;
  228. }
  229. //
  230. // Code generation methods.
  231. //
  232. virtual
  233. CG_STATUS GenCode( CCB * pCCB );
  234. virtual
  235. void OutputImportIncludes( CCB * pCCB );
  236. void OutputMultipleInterfacePrototypes( CCB * pCCB );
  237. };
  238. class CG_IID_FILE : public CG_FILE
  239. {
  240. private:
  241. public:
  242. //
  243. // The constructor.
  244. //
  245. CG_IID_FILE(
  246. node_file * pN,
  247. PFILENAME pFName
  248. )
  249. : CG_FILE( pN, pFName )
  250. {
  251. }
  252. virtual
  253. void Visit( CG_VISITOR *pVisitor )
  254. {
  255. pVisitor->Visit( this );
  256. }
  257. //
  258. // Code generation methods.
  259. //
  260. virtual
  261. CG_STATUS GenCode( CCB * pCCB );
  262. };
  263. class CG_PROXY_FILE : public CG_FILE
  264. {
  265. private:
  266. //
  267. // this is a list of all the interfaces supported by this proxy file
  268. // (non-inherited, and non-local )
  269. // This list may be sorted by IID in the future.
  270. //
  271. ITERATOR ImplementedInterfaces;
  272. public:
  273. //
  274. // The constructor.
  275. //
  276. CG_PROXY_FILE(
  277. node_file * pN,
  278. PFILENAME pFName,
  279. PFILENAME pHdrName
  280. )
  281. : CG_FILE( pN, pFName, pHdrName )
  282. {
  283. }
  284. virtual
  285. void Visit( CG_VISITOR *pVisitor )
  286. {
  287. pVisitor->Visit( this );
  288. }
  289. //
  290. // Code generation methods.
  291. //
  292. virtual
  293. CG_STATUS GenCode( CCB * pCCB );
  294. //
  295. // Output methods
  296. //
  297. void MakeImplementedInterfacesList( CCB * pCCB );
  298. ITERATOR & GetImplementedInterfacesList()
  299. {
  300. ITERATOR_INIT( ImplementedInterfaces );
  301. return ImplementedInterfaces;
  302. }
  303. void Out_ProxyBuffer( CCB *pCCB, char * pFName );
  304. void Out_StubBuffer( CCB *pCCB, char * pFName );
  305. void Out_InterfaceNamesList( CCB *pCCB, char * pFName );
  306. void Out_BaseIntfsList( CCB * pCCB, char * pFName );
  307. void Out_InfoSearchRoutine( CCB * pCCB, char * pFName );
  308. void Out_AsyncInterfaceTable( CCB* pCCB, char* pFName );
  309. void Out_ProxyFileInfo( CCB *pCCB );
  310. void UpdateDLLDataFile( CCB * pCCB );
  311. };
  312. class CG_TYPELIBRARY_FILE: public CG_FILE
  313. {
  314. private:
  315. public:
  316. CG_TYPELIBRARY_FILE(
  317. node_file * pN,
  318. PFILENAME pFName
  319. )
  320. : CG_FILE(pN, pFName)
  321. {
  322. }
  323. virtual
  324. void Visit( CG_VISITOR *pVisitor )
  325. {
  326. pVisitor->Visit( this );
  327. }
  328. //
  329. // Code generation methods.
  330. //
  331. virtual
  332. CG_STATUS GenCode( CCB * pCCB );
  333. };
  334. // These are classes used by CG_NETMONSTUB_FILE to implement a hashtable class.
  335. // CG_NETMONSTUB_FILE uses hashtables to store interface information for quick
  336. // lookups. The CG_INTERFACE class could have been modified with some Get/Set flags
  337. // to do the same thing, but the philosophy behind the CG_NETMONSTUB_FILE class was to
  338. // modify as little of the main code base as possible.
  339. class NetmonStubFileInterfaceNode {
  340. protected:
  341. char* m_pszInterface;
  342. long m_lNumProcs;
  343. NetmonStubFileInterfaceNode* m_pNext;
  344. public:
  345. NetmonStubFileInterfaceNode (char* pszInterface);
  346. ~NetmonStubFileInterfaceNode();
  347. NetmonStubFileInterfaceNode* GetNext();
  348. void SetNext (NetmonStubFileInterfaceNode* pNext);
  349. char* GetInterface();
  350. void SetNumProcedures (long lNumProcs);
  351. long GetNumProcedures();
  352. };
  353. class NetmonStubFileInterfaceList {
  354. protected:
  355. NetmonStubFileInterfaceNode* m_pHead;
  356. NetmonStubFileInterfaceNode* m_pTail;
  357. public:
  358. NetmonStubFileInterfaceList();
  359. ~NetmonStubFileInterfaceList();
  360. void AddInterface (char* pszInterface);
  361. BOOL FindInterface (char* pszInterface);
  362. BOOL SetNumProcedures (char* pszInterface, long lNumProcs);
  363. BOOL GetNumProcedures (char* pszInterface, long* plNumProcs);
  364. };
  365. class NetmonStubFileInterfaceTable {
  366. protected:
  367. NetmonStubFileInterfaceList* m_pTable;
  368. long GetHashValue (char* pszInterface);
  369. public:
  370. NetmonStubFileInterfaceTable();
  371. ~NetmonStubFileInterfaceTable();
  372. void AddInterface (char* pszInterface);
  373. BOOL FindInterface (char* pszInterface);
  374. BOOL SetNumProcedures (char* pszInterface, long lNumProcs);
  375. BOOL GetNumProcedures (char* pszInterface, long* plNumProcs);
  376. };
  377. class CG_NETMONSTUB_FILE: public CG_FILE
  378. {
  379. protected:
  380. CCB* m_pCCB;
  381. ISTREAM* m_pStream;
  382. // Tables used to keep track of interfaces present in the compile and
  383. // mark interfaces that we've processed as used
  384. NetmonStubFileInterfaceTable m_itInterfaceTable;
  385. NetmonStubFileInterfaceTable m_itOutputInterfaceTable;
  386. // TRUE if classic or object interfaces are present in the compile
  387. BOOL m_bClassic;
  388. BOOL m_bObject;
  389. // TRUE if we're doing the object interface pass; false otherwise
  390. BOOL m_bDoObject;
  391. // Interface counters
  392. long m_lNumClassicInterfaces;
  393. long m_lNumObjectInterfaces;
  394. CG_STATUS ScanInterfaces();
  395. CG_STATUS OpenComment();
  396. CG_STATUS EmitComment (char* pszString);
  397. CG_STATUS CloseComment();
  398. CG_STATUS EmitStandardIncludes();
  399. CG_STATUS EmitLocalIncludes();
  400. CG_STATUS EmitDefinitions();
  401. CG_STATUS EmitDebugProcedures();
  402. CG_STATUS EmitServerClientDebugProcedure (CG_PROC* pProc, BOOL bIsObject);
  403. CG_STATUS EmitDataTables();
  404. CG_STATUS EmitProcNameTables();
  405. CG_STATUS EmitServerClientTables();
  406. CG_STATUS EmitGlobalInterfaceData();
  407. // Object interface functions
  408. CG_STATUS EmitObjectInterfaceData();
  409. CG_STATUS EmitRPCServerInterface (CG_INTERFACE* pCG);
  410. public:
  411. CG_NETMONSTUB_FILE(
  412. BOOL bDoObject,
  413. node_file * pN,
  414. PFILENAME pFName
  415. )
  416. : CG_FILE(pN, pFName)
  417. {
  418. m_pCCB = NULL;
  419. m_pStream = NULL;
  420. m_bDoObject = bDoObject;
  421. m_bClassic = m_bObject = FALSE;
  422. m_lNumClassicInterfaces = m_lNumObjectInterfaces = 0;
  423. }
  424. virtual
  425. void Visit( CG_VISITOR *pVisitor )
  426. {
  427. pVisitor->Visit( this );
  428. }
  429. // Codegen
  430. virtual CG_STATUS GenCode( CCB * pCCB);
  431. };
  432. //
  433. // the root of the IL translation tree
  434. //
  435. class CG_SOURCE : public CG_AUX
  436. {
  437. private:
  438. node_source * pSourceNode;
  439. public:
  440. CG_SOURCE( node_source *p )
  441. {
  442. pSourceNode = p;
  443. }
  444. //
  445. // code generation methods.
  446. //
  447. virtual
  448. ID_CG GetCGID()
  449. {
  450. return ID_CG_SOURCE;
  451. }
  452. virtual
  453. void Visit( CG_VISITOR *pVisitor )
  454. {
  455. pVisitor->Visit( this );
  456. }
  457. virtual
  458. CG_STATUS GenCode( CCB * pCCB );
  459. };
  460. //
  461. // Miscellaneous prototypes
  462. //
  463. void NormalizeString(
  464. char* szSrc,
  465. char* szNrm );
  466. void SetNoOutputIn2ndCodegen( CCB * pCCB );
  467. void ResetNoOutputIn2ndCodegen( CCB *pCCB );
  468. #endif // __FILECLS_HXX__