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.

269 lines
9.9 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-1999 Microsoft Corporation
  3. Module Name:
  4. iid.cxx
  5. Abstract:
  6. Generate a file containing UUIDs of [object] interfaces.
  7. Notes:
  8. History:
  9. ----------------------------------------------------------------------------*/
  10. /****************************************************************************
  11. * include files
  12. ***************************************************************************/
  13. #include "becls.hxx"
  14. #pragma hdrstop
  15. CG_STATUS
  16. CG_IID_FILE::GenCode(
  17. CCB * pCCB)
  18. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  19. Routine Description:
  20. Generate the IID file.
  21. Arguments:
  22. pCCB - The code gen controller block.
  23. Return Value:
  24. CG_OK if all is well.
  25. Notes:
  26. ----------------------------------------------------------------------------*/
  27. {
  28. ISTREAM Stream( GetFileName(), 4 );
  29. ISTREAM * pStream = pCCB->SetStream( &Stream, this );
  30. CG_INTERFACE * pIntf;
  31. EmitFileHeadingBlock( pCCB,
  32. "the IIDs and CLSIDs",
  33. "link this file in with the server and any clients" );
  34. // Write out the cplusplus guard.
  35. pStream->NewLine( 2 );
  36. pStream->Write( "#ifdef __cplusplus\nextern \"C\"{\n#endif " );
  37. pStream->NewLine( 2 );
  38. // Print out the declarations of the types and the procedures.
  39. const char * DefinitionBlock[] =
  40. {
  41. "#include <rpc.h>"
  42. ,"#include <rpcndr.h>"
  43. ,""
  44. ,"#ifdef _MIDL_USE_GUIDDEF_"
  45. ,""
  46. ,"#ifndef INITGUID"
  47. ,"#define INITGUID"
  48. ,"#include <guiddef.h>"
  49. ,"#undef INITGUID"
  50. ,"#else"
  51. ,"#include <guiddef.h>"
  52. ,"#endif"
  53. ,""
  54. ,"#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\"
  55. ," DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8)"
  56. ,""
  57. ,"#else // !_MIDL_USE_GUIDDEF_"
  58. ,""
  59. ,"#ifndef __IID_DEFINED__"
  60. ,"#define __IID_DEFINED__"
  61. ,""
  62. ,"typedef struct _IID"
  63. ,"{"
  64. ," unsigned long x;"
  65. ," unsigned short s1;"
  66. ," unsigned short s2;"
  67. ," unsigned char c[8];"
  68. ,"} IID;"
  69. ,""
  70. ,"#endif // __IID_DEFINED__"
  71. ,""
  72. ,"#ifndef CLSID_DEFINED"
  73. ,"#define CLSID_DEFINED"
  74. ,"typedef IID CLSID;"
  75. ,"#endif // CLSID_DEFINED"
  76. ,""
  77. ,"#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \\"
  78. ," const type name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}}"
  79. ,""
  80. ,"#endif !_MIDL_USE_GUIDDEF_"
  81. ,""
  82. ,NULL
  83. };
  84. pStream->WriteBlock(DefinitionBlock);
  85. pIntf = (CG_INTERFACE*) GetChild();
  86. while ( pIntf )
  87. {
  88. node_interface * pIntfNode = (node_interface *) pIntf->GetType();
  89. if (!pIntfNode->PrintedIID())
  90. {
  91. switch ( pIntf->GetCGID() )
  92. {
  93. case ID_CG_DISPINTERFACE:
  94. {
  95. CG_DISPINTERFACE * pDI = (CG_DISPINTERFACE *)pIntf;
  96. node_dispinterface * pType = (node_dispinterface *) pDI->GetType();
  97. node_guid * pGuid = (node_guid *) pType->GetAttribute( ATTR_GUID );
  98. pStream->NewLine();
  99. pStream->Write("MIDL_DEFINE_GUID(IID, DIID_");
  100. pStream->Write(pDI->GetSymName());
  101. pStream->Write(',');
  102. Out_Guid(pCCB, pGuid->GetStrs(), GUIDFORMAT_RAW);
  103. pStream->Write(");");
  104. pStream->NewLine(2);
  105. pIntfNode->SetPrintedIID();
  106. break;
  107. }
  108. case ID_CG_COCLASS:
  109. {
  110. CG_COCLASS * pCoclass = (CG_COCLASS *)pIntf;
  111. node_coclass * pType = (node_coclass *) pCoclass->GetType();
  112. node_guid * pGuid = (node_guid *) pType->GetAttribute( ATTR_GUID );
  113. pStream->NewLine();
  114. pStream->Write("MIDL_DEFINE_GUID(CLSID, CLSID_");
  115. pStream->Write(pCoclass->GetSymName());
  116. pStream->Write(',');
  117. Out_Guid(pCCB, pGuid->GetStrs(), GUIDFORMAT_RAW);
  118. pStream->Write(");");
  119. pStream->NewLine(2);
  120. pIntfNode->SetPrintedIID();
  121. break;
  122. }
  123. case ID_CG_OBJECT_INTERFACE:
  124. {
  125. pStream->NewLine();
  126. pStream->Write("MIDL_DEFINE_GUID(IID, IID_");
  127. pStream->Write(pIntf->GetSymName());
  128. pStream->Write(',');
  129. Out_Guid(pCCB, pIntf->GetGuidStrs(), GUIDFORMAT_RAW);
  130. pStream->Write(");");
  131. pStream->NewLine(2);
  132. pIntfNode->SetPrintedIID();
  133. break;
  134. }
  135. case ID_CG_LIBRARY:
  136. {
  137. CG_LIBRARY * pLib = (CG_LIBRARY *)pIntf;
  138. node_library * pType = (node_library *) pLib->GetType();
  139. node_guid * pGuid = (node_guid *) pType->GetAttribute( ATTR_GUID );
  140. pStream->NewLine();
  141. pStream->Write("MIDL_DEFINE_GUID(IID, LIBID_");
  142. pStream->Write(pLib->GetSymName());
  143. pStream->Write(',');
  144. Out_Guid(pCCB, pGuid->GetStrs(), GUIDFORMAT_RAW);
  145. pStream->Write(");");
  146. pStream->NewLine(2);
  147. CG_NDR * pChild = (CG_NDR*) pLib->GetChild();
  148. pIntfNode->SetPrintedIID();
  149. while ( pChild )
  150. {
  151. node_interface * pChildType = (node_interface *) pChild->GetType();
  152. if (!pChildType->PrintedIID())
  153. {
  154. switch ( pChild->GetCGID() )
  155. {
  156. case ID_CG_OBJECT_INTERFACE:
  157. {
  158. if (!pChildType->PrintedIID())
  159. {
  160. pStream->NewLine();
  161. pStream->Write("MIDL_DEFINE_GUID(IID, IID_");
  162. pStream->Write(pChild->GetSymName());
  163. pStream->Write(',');
  164. Out_Guid(pCCB, ((CG_INTERFACE*)pChild)->GetGuidStrs(), GUIDFORMAT_RAW );
  165. pStream->Write(");");
  166. pStream->NewLine(2);
  167. pChildType->SetPrintedIID();
  168. }
  169. break;
  170. }
  171. case ID_CG_DISPINTERFACE:
  172. {
  173. CG_DISPINTERFACE * pDI = (CG_DISPINTERFACE *)pChild;
  174. node_dispinterface * pIntfType = (node_dispinterface *) pDI->GetType();
  175. node_guid * pIntfGuid = (node_guid *) pIntfType->GetAttribute( ATTR_GUID );
  176. pStream->NewLine();
  177. pStream->Write("MIDL_DEFINE_GUID(IID, DIID_");
  178. pStream->Write(pDI->GetSymName());
  179. pStream->Write(',');
  180. Out_Guid(pCCB, pIntfGuid->GetStrs(), GUIDFORMAT_RAW);
  181. pStream->Write(");");
  182. pStream->NewLine(2);
  183. pChildType->SetPrintedIID();
  184. break;
  185. }
  186. case ID_CG_COCLASS:
  187. {
  188. CG_COCLASS * pCoclass = (CG_COCLASS *)pChild;
  189. node_coclass * pClassType = (node_coclass *) pCoclass->GetType();
  190. node_guid * pClassfGuid = (node_guid *) pClassType->GetAttribute( ATTR_GUID );
  191. pStream->NewLine();
  192. pStream->Write("MIDL_DEFINE_GUID(CLSID, CLSID_");
  193. pStream->Write(pCoclass->GetSymName());
  194. pStream->Write(',');
  195. Out_Guid(pCCB, pClassfGuid->GetStrs(), GUIDFORMAT_RAW);
  196. pStream->Write(");");
  197. pStream->NewLine(2);
  198. pChildType->SetPrintedIID();
  199. break;
  200. }
  201. case ID_CG_INTERFACE:
  202. case ID_CG_INHERITED_OBJECT_INTERFACE:
  203. default:
  204. break;
  205. }
  206. }
  207. pChild = (CG_INTERFACE *) pChild->GetSibling();
  208. }
  209. }
  210. case ID_CG_INTERFACE:
  211. case ID_CG_INHERITED_OBJECT_INTERFACE:
  212. default:
  213. break;
  214. }
  215. } // if pIntfNode not printed
  216. pIntf = (CG_INTERFACE *) pIntf->GetSibling();
  217. } // while
  218. // print out the closing endifs.
  219. // the MIDL_DEFINE_GUID stuff.
  220. pStream->Write( "#undef MIDL_DEFINE_GUID" );
  221. pStream->NewLine();
  222. // the cplusplus stuff.
  223. pStream->NewLine();
  224. pStream->Write( "#ifdef __cplusplus\n}\n#endif\n" );
  225. pStream->NewLine();
  226. EmitFileClosingBlock( pCCB );
  227. pStream->Close();
  228. return CG_OK;
  229. }