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.

240 lines
4.9 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-1999 Microsoft Corporation
  3. Module Name:
  4. ilreg.cxx
  5. Abstract:
  6. This file implements the type registry for structure/union reuse.
  7. Notes:
  8. History:
  9. Oct-25-1993 GregJen Created.
  10. ----------------------------------------------------------------------------*/
  11. /****************************************************************************
  12. * include files
  13. ***************************************************************************/
  14. #include "becls.hxx"
  15. #pragma hdrstop
  16. #include "ilreg.hxx"
  17. /***********************************************************************
  18. * global data
  19. **********************************************************************/
  20. // #define trace_reuse
  21. REUSE_DICT * pReUseDict;
  22. REUSE_DICT::REUSE_DICT()
  23. : Dictionary()
  24. {
  25. }
  26. SSIZE_T
  27. REUSE_DICT::Compare( pUserType pL, pUserType pR )
  28. {
  29. SSIZE_T l1 = (SSIZE_T) ((REUSE_INFO *)pL)->pType;
  30. SSIZE_T l2 = (SSIZE_T) ((REUSE_INFO *)pR)->pType;
  31. return l1 - l2;
  32. }
  33. REUSE_INFO *
  34. REUSE_DICT::IsRegistered(
  35. REUSE_INFO * pInfo )
  36. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  37. Routine Description:
  38. Search for a type with the reuse registry.
  39. Arguments:
  40. pInfo - A pointer to the type being registered.
  41. Return Value:
  42. The node that gets registered.
  43. Notes:
  44. ----------------------------------------------------------------------------*/
  45. {
  46. #ifdef trace_reuse
  47. printf(". . .Reuse: finding %08x\n", pInfo->pType );
  48. fflush(stdout);
  49. #endif
  50. Dict_Status Status = Dict_Find( pInfo );
  51. switch( Status )
  52. {
  53. case EMPTY_DICTIONARY:
  54. case ITEM_NOT_FOUND:
  55. return (REUSE_INFO *)0;
  56. default:
  57. return (REUSE_INFO *)Dict_Curr_Item();
  58. }
  59. }
  60. REUSE_INFO *
  61. REUSE_DICT::Register(
  62. REUSE_INFO * pInfo )
  63. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  64. Routine Description:
  65. Register a type with the dictionary.
  66. Arguments:
  67. pType - A pointer to the type node.
  68. Return Value:
  69. The final inserted type.
  70. Notes:
  71. ----------------------------------------------------------------------------*/
  72. {
  73. #ifdef trace_reuse
  74. printf(". . .Reuse: inserting %08x\n", pInfo->pType );
  75. fflush(stdout);
  76. #endif
  77. Dict_Insert( (pUserType) pInfo );
  78. return pInfo;
  79. }
  80. BOOL
  81. REUSE_DICT::GetReUseEntry(
  82. REUSE_INFO * & pRI,
  83. node_skl * pNode )
  84. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  85. Routine Description:
  86. Register a type with the dictionary.
  87. Arguments:
  88. pRI - A pointer to the returned REUSE_INFO block
  89. pNode - A pointer to the type node.
  90. Return Value:
  91. True if the entry was already in the table,
  92. False if the entry is new.
  93. Notes:
  94. ----------------------------------------------------------------------------*/
  95. {
  96. REUSE_INFO TempEntry(pNode);
  97. REUSE_INFO * pRealEntry;
  98. #ifdef trace_reuse
  99. printf(". . .Reuse: searching for %08x\n", pNode );
  100. fflush(stdout);
  101. #endif
  102. if ( (pRealEntry = IsRegistered( &TempEntry ) ) == 0 )
  103. {
  104. pRealEntry = new REUSE_INFO( pNode );
  105. Register( pRealEntry );
  106. pRI = pRealEntry;
  107. #ifdef trace_reuse
  108. printf(". . .Reuse: new node %08x\n", pRI );
  109. fflush(stdout);
  110. #endif
  111. return FALSE;
  112. }
  113. pRI = pRealEntry;
  114. #ifdef trace_reuse
  115. printf(". . .Reuse: found %08x\n", pRI );
  116. fflush(stdout);
  117. #endif
  118. return TRUE;
  119. }
  120. void
  121. REUSE_DICT::MakeIterator(
  122. ITERATOR& ListIter )
  123. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  124. Routine Description:
  125. Get a list of structs and unions into the specified iterator.
  126. Arguments:
  127. ListIter - A reference to the iterator class where the list is
  128. accumulated.
  129. Return Value:
  130. A count of the number of resources.
  131. Notes:
  132. ----------------------------------------------------------------------------*/
  133. {
  134. REUSE_INFO * pR;
  135. Dict_Status Status;
  136. //
  137. // Get to the top of the dictionary.
  138. //
  139. Status = Dict_Next( (pUserType) 0 );
  140. //
  141. // Iterate till the entire dictionary is done.
  142. //
  143. while( SUCCESS == Status )
  144. {
  145. pR = (REUSE_INFO *)Dict_Curr_Item();
  146. ITERATOR_INSERT( ListIter, pR->pSavedCG );
  147. Status = Dict_Next( pR );
  148. }
  149. return;
  150. }
  151. /****************************************************************************
  152. utility functions.
  153. ****************************************************************************/
  154. SSIZE_T
  155. CompareReUseKey( void * p1, void *p2 )
  156. {
  157. #ifdef trace_reuse
  158. printf(". . .Reuse: comparing %08x to %08x (in)\n", p1, p2 );
  159. fflush(stdout);
  160. #endif
  161. SSIZE_T l1 = (SSIZE_T)
  162. ((REUSE_INFO *)p1)->pType;
  163. SSIZE_T l2 = (SSIZE_T)
  164. ((REUSE_INFO *)p2)->pType;
  165. #ifdef trace_reuse
  166. printf(". . .Reuse: comparing %08x to %08x\n", l1, l2 );
  167. fflush(stdout);
  168. #endif
  169. if( l1 < l2 ) return -1;
  170. else if( l1 > l2 ) return 1;
  171. return 0;
  172. }
  173. void
  174. PrintReUseKey( void* ) { }