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.

431 lines
10 KiB

4 years ago
  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. header.cxx
  5. Abstract:
  6. Generates header file.
  7. Notes:
  8. History:
  9. ----------------------------------------------------------------------------*/
  10. /****************************************************************************
  11. * include files
  12. ***************************************************************************/
  13. #include "becls.hxx"
  14. #pragma hdrstop
  15. #include "buffer.hxx"
  16. /****************************************************************************
  17. * local definitions
  18. ***************************************************************************/
  19. /****************************************************************************
  20. * externs
  21. ***************************************************************************/
  22. extern CMD_ARG * pCommand;
  23. CG_STATUS
  24. CG_OBJECT_INTERFACE::GenHeader(
  25. CCB * pCCB )
  26. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  27. Routine Description:
  28. Generate interface header file.
  29. Arguments:
  30. pCCB - a pointer to the code generation control block.
  31. Return Value:
  32. CG_OK if all is well, error otherwise.
  33. Notes: The interface header file has the following structure:
  34. Forward declaration
  35. TypeDeclarations
  36. #if defined(__cplusplus) && !defined(CINTERFACE)
  37. CPlusPlusLanguageBinding
  38. #else
  39. CLanguageBinding
  40. #endif
  41. ----------------------------------------------------------------------------*/
  42. {
  43. node_interface * pInterface = (node_interface *) GetType();
  44. ISTREAM * pStream = pCCB->GetStream();
  45. char * pName = pInterface->GetSymName();
  46. if (!pInterface->PrintedDef())
  47. {
  48. //Initialize the CCB for this interface.
  49. InitializeCCB(pCCB);
  50. // put out the interface guards
  51. pStream->Write("\n#ifndef __");
  52. pStream->Write( pName );
  53. pStream->Write( "_INTERFACE_DEFINED__\n" );
  54. pStream->Write( "#define __");
  55. pStream->Write( pName );
  56. pStream->Write( "_INTERFACE_DEFINED__\n" );
  57. // Print out the declarations of the types
  58. pStream->NewLine();
  59. pInterface->PrintType( PRT_INTERFACE | PRT_OMIT_PROTOTYPE, pStream, 0);
  60. Out_IID(pCCB);
  61. // print out the vtable/class definitions
  62. pStream->NewLine();
  63. pStream->Write("#if defined(__cplusplus) && !defined(CINTERFACE)");
  64. pStream->IndentInc();
  65. CPlusPlusLanguageBinding(pCCB);
  66. pStream->IndentDec();
  67. pStream->NewLine();
  68. pStream->Write("#else \t/* C style interface */");
  69. pStream->IndentInc();
  70. CLanguageBinding(pCCB);
  71. pStream->IndentDec();
  72. // print out the C Macros
  73. CLanguageMacros( pCCB );
  74. pStream->NewLine( 2 );
  75. pStream->Write("#endif \t/* C style interface */");
  76. pStream->NewLine( 2 );
  77. // print out the prototypes for the proxy and stub routines
  78. ProxyPrototypes(pCCB);
  79. pStream->NewLine();
  80. // put out the trailing interface guard
  81. pStream->Write( "\n#endif \t/* __");
  82. pStream->Write( pName );
  83. pStream->Write( "_INTERFACE_DEFINED__ */\n" );
  84. pStream->NewLine();
  85. pInterface->SetPrintedDef();
  86. }
  87. return CG_OK;
  88. }
  89. CG_STATUS
  90. CG_OBJECT_INTERFACE::CPlusPlusLanguageBinding(CCB *pCCB)
  91. {
  92. ISTREAM *pStream = pCCB->GetStream();
  93. char *pName;
  94. pStream->NewLine();
  95. pName = GetType()->GetSymName();
  96. assert (pName != (char *)0);
  97. pStream->NewLine();
  98. pStream->Write("interface ");
  99. pStream->Write(pName);
  100. //Check if this interface was derived from a base interface.
  101. if(pBaseCG)
  102. {
  103. pStream->Write(" : public ");
  104. pStream->Write(pBaseCG->GetType()->GetSymName());
  105. }
  106. pStream->NewLine();
  107. pStream->Write('{');
  108. pStream->NewLine();
  109. pStream->Write("public:");
  110. pStream->IndentInc();
  111. if( ! pBaseCG )
  112. {
  113. // For IUnknown only and only on PowerMac the following macro
  114. // would add a dummy entry, otherwise it's empty.
  115. pStream->NewLine();
  116. pStream->Write("BEGIN_INTERFACE");
  117. }
  118. PrintMemberFunctions( pStream, TRUE );
  119. if( ! pBaseCG )
  120. {
  121. pStream->NewLine();
  122. pStream->Write("END_INTERFACE");
  123. }
  124. pStream->IndentDec();
  125. pStream->NewLine();
  126. pStream->Write("};");
  127. pStream->NewLine();
  128. return CG_OK;
  129. }
  130. STATUS_T
  131. CG_OBJECT_INTERFACE::PrintMemberFunctions(
  132. ISTREAM * pStream,
  133. BOOL fAbstract)
  134. /*++
  135. Routine Description:
  136. This routine prints C++ function prototypes for the interface member functions.
  137. We assume that all of the procedure nodes are pure virtual functions.
  138. Arguments:
  139. pStream - Specifies the output stream.
  140. fAbstract - Specifies whether the methods should be abstract ( = 0 ).
  141. --*/
  142. {
  143. CG_OBJECT_PROC * pProc;
  144. char * pszName;
  145. node_skl * pN;
  146. PRTFLAGS ChildFlags = PRT_OMIT_PRAGMA_PACK;
  147. pszName = GetType()->GetSymName();
  148. assert (pszName != (char *)0);
  149. pProc = (CG_OBJECT_PROC *) GetChild();
  150. while( pProc )
  151. {
  152. if ( !pProc->SupressHeader())
  153. {
  154. pN = pProc->GetType();
  155. //Assume this is a pure virtual function.
  156. // use the call_as form, if any
  157. pStream->NewLine();
  158. pStream->Write("virtual ");
  159. pN->PrintType( PRT_PROTOTYPE | PRT_CALL_AS | PRT_FORCE_CALL_CONV, pStream, 0 );
  160. if ( fAbstract)
  161. pStream->Write(" = 0;");
  162. else
  163. pStream->Write(";");
  164. pStream->NewLine();
  165. }
  166. pProc = (CG_OBJECT_PROC *) pProc->GetSibling();
  167. }
  168. return STATUS_OK;
  169. }
  170. CG_STATUS
  171. CG_OBJECT_PROC::PrintVtableEntry(
  172. CCB * pCCB)
  173. {
  174. ISTREAM * pStream = pCCB->GetStream();
  175. node_id * pTempID;
  176. char * pName = GetType()->GetSymName();
  177. if (SupressHeader())
  178. {
  179. return CG_OK;
  180. }
  181. if ( GetCallAsName() )
  182. {
  183. pName = GetCallAsName();
  184. }
  185. pTempID = MakePtrIDNode( pName, GetType() );
  186. pStream->NewLine();
  187. pTempID->PrintType( PRT_PROC_PTR_PROTOTYPE | PRT_THIS_POINTER | PRT_CALL_AS | PRT_FORCE_CALL_CONV,
  188. pStream,
  189. NULL ,
  190. pCCB->GetInterfaceCG()->GetType() );
  191. return CG_OK;
  192. }
  193. CG_STATUS
  194. CG_OBJECT_INTERFACE::CLanguageBinding(CCB *pCCB)
  195. {
  196. #ifndef DISABLE_C_OUTPUT
  197. ISTREAM * pStream = pCCB->GetStream();
  198. char * pName = pCCB->GetInterfaceName();
  199. pStream->NewLine( 2 );
  200. pStream->Write("typedef struct ");
  201. pStream->Write(pName);
  202. pStream->Write("Vtbl");
  203. pStream->NewLine();
  204. pStream->Write('{');
  205. pStream->IndentInc();
  206. pStream->NewLine();
  207. // We need to emit a macro that creates a dummy entry on PowerMac.
  208. // On Win32 the macro is defined as empty.
  209. pStream->Write("BEGIN_INTERFACE");
  210. pStream->NewLine();
  211. // Now the regular entries.
  212. PrintVtableEntries( pCCB );
  213. // This is a match for the other macro.
  214. pStream->NewLine();
  215. pStream->Write("END_INTERFACE");
  216. pStream->IndentDec();
  217. pStream->NewLine();
  218. pStream->Write("} ");
  219. pStream->Write(pName);
  220. pStream->Write("Vtbl;");
  221. pStream->NewLine( 2 );
  222. pStream->Write("interface ");
  223. pStream->Write(pName);
  224. pStream->NewLine();
  225. pStream->Write('{');
  226. pStream->IndentInc();
  227. pStream->NewLine();
  228. pStream->Write("CONST_VTBL struct ");
  229. pStream->Write(pName);
  230. pStream->Write("Vtbl __RPC_FAR *lpVtbl;");
  231. pStream->IndentDec();
  232. pStream->NewLine();
  233. pStream->Write("};");
  234. pStream->NewLine( 2 );
  235. #endif
  236. return CG_OK;
  237. }
  238. CG_STATUS
  239. CG_OBJECT_INTERFACE::ProxyPrototypes(CCB *pCCB)
  240. /*++
  241. Routine Description:
  242. This routine generates function prototypes for the interface proxy.
  243. For each procedure, we generate a proxy prototype and a
  244. stub prototype.
  245. Arguments:
  246. pCCB - a pointer to the code generation control block.
  247. Return Value:
  248. CG_OK if all is well, error otherwise.
  249. --*/
  250. {
  251. ISTREAM * pStream = pCCB->GetStream();
  252. CG_OBJECT_PROC * pProcCG;
  253. char * pszName;
  254. CG_ITERATOR I;
  255. pszName = GetType()->GetSymName();
  256. assert (pszName != (char *)0);
  257. GetMembers( I );
  258. while( ITERATOR_GETNEXT( I, pProcCG ) )
  259. {
  260. if (!pProcCG->SupressHeader())
  261. {
  262. //print proxy function prototype
  263. pStream->NewLine();
  264. pProcCG->Out_ProxyFunctionPrototype(pCCB,
  265. PRT_TRAILING_SEMI );
  266. //print stub function prototype
  267. pStream->NewLine();
  268. pProcCG->Out_StubFunctionPrototype( pCCB );
  269. pStream->Write(';');
  270. pStream->NewLine();
  271. }
  272. }
  273. pStream->NewLine();
  274. return CG_OK;
  275. }
  276. CG_STATUS
  277. CG_OBJECT_INTERFACE::PrintCMacros(CCB *pCCB)
  278. /*++
  279. Routine Description:
  280. This routine generates C macros for an interface
  281. Arguments:
  282. pCCB - a pointer to the code generation control block.
  283. Return Value:
  284. CG_OK if all is well, error otherwise.
  285. --*/
  286. {
  287. #ifndef DISABLE_C_OUTPUT
  288. ISTREAM * pStream = pCCB->GetStream();
  289. CG_OBJECT_PROC * pProcCG;
  290. CG_ITERATOR I;
  291. // print inherited methods ( with our current ccb intf name )
  292. if ( GetBaseInterfaceCG() )
  293. GetBaseInterfaceCG()->PrintCMacros( pCCB );
  294. GetMembers( I );
  295. while( ITERATOR_GETNEXT( I, pProcCG ) )
  296. {
  297. //print proxy function prototype
  298. pStream->NewLine();
  299. pProcCG->GenCMacro(pCCB);
  300. }
  301. pStream->NewLine();
  302. #endif
  303. return CG_OK;
  304. }
  305. CG_STATUS
  306. CG_OBJECT_INTERFACE::CLanguageMacros(CCB *pCCB)
  307. {
  308. #ifndef DISABLE_C_OUTPUT
  309. ISTREAM * pStream = pCCB->GetStream();
  310. pStream->NewLine( 2 );
  311. pStream->Write("#ifdef COBJMACROS");
  312. pStream->NewLine();
  313. PrintCMacros( pCCB );
  314. pStream->NewLine();
  315. pStream->Write("#endif /* COBJMACROS */");
  316. pStream->NewLine();
  317. #endif
  318. return CG_OK;
  319. }