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.

154 lines
3.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1998
  6. //
  7. // File: symt.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. // SYMT.CPP
  12. //
  13. #include <basetsd.h>
  14. #include <iostream>
  15. #include <fstream>
  16. #include <string.h>
  17. #include "model.h"
  18. #include "symtmbn.h"
  19. //
  20. // Create a duplicate of the given token array given a source token
  21. // array and the symbol table associated with this token array.
  22. //
  23. void VTKNPD :: Clone ( MPSYMTBL & mpsymtbl, const VTKNPD & vtknpd )
  24. {
  25. ASSERT_THROW( size() == 0,
  26. EC_INVALID_CLONE,
  27. "cannot clone into non-empty structure" );
  28. resize( vtknpd.size() );
  29. for ( int i = 0; i < size(); i++ )
  30. {
  31. TKNPD & tk = self[i];
  32. const TKNPD & tkOther = vtknpd[i];
  33. // Get the token's string pointer or NULL if it's not a string
  34. if ( tkOther.BStr() )
  35. {
  36. SZC szcOther = tkOther.Szc();
  37. assert( szcOther && strlen( szcOther ) > 0 );
  38. tk = mpsymtbl.intern(szcOther);
  39. }
  40. else
  41. {
  42. tk = tkOther.Dtkn();
  43. }
  44. }
  45. }
  46. ZSTR VTKNPD :: ZstrSignature ( int iStart ) const
  47. {
  48. ZSTR zs;
  49. bool bPdSeen = false;
  50. for ( int i = iStart; i < size(); i++ )
  51. {
  52. const TKNPD & tknpd = self[i];
  53. switch ( tknpd.UiTkn() )
  54. {
  55. case DTKN_PD:
  56. zs += _T("p(");
  57. bPdSeen = true;
  58. break;
  59. case DTKN_COND:
  60. zs += _T("|");
  61. break;
  62. case DTKN_AND:
  63. zs += _T(",");
  64. break;
  65. case DTKN_EQ:
  66. zs += _T("=");
  67. break;
  68. case DTKN_DIST:
  69. zs += _T("d(");
  70. bPdSeen = true;
  71. break;
  72. case DTKN_QUAL:
  73. zs += _T(":");
  74. break;
  75. case DTKN_STRING:
  76. {
  77. // It's the name of a node
  78. SZC szcName = tknpd.Szc();
  79. assert( szcName );
  80. bool bLegal = MODEL::BSzLegal( szcName );
  81. if ( ! bLegal )
  82. zs += _T("\"") ;
  83. zs += szcName;
  84. if ( ! bLegal )
  85. zs += _T("\"") ;
  86. break;
  87. }
  88. default:
  89. {
  90. if ( tknpd.UiTkn() >= DTKN_STATE_BASE && tknpd.UiTkn() < DTKN_TOKEN_MIN )
  91. // It's a discrete state index
  92. zs.FormatAppend(_T("%d"), tknpd.UiTkn() - DTKN_STATE_BASE);
  93. else
  94. // Huh?
  95. zs += _T("?ERR?");
  96. break;
  97. }
  98. }
  99. }
  100. if ( bPdSeen )
  101. zs += ")";
  102. return zs;
  103. }
  104. void MPPD :: Clone ( MPSYMTBL & mpsymtbl, const MPPD & mppd )
  105. {
  106. for ( const_iterator it = mppd.begin(); it != mppd.end(); it++ )
  107. {
  108. // Access the key and value from the old map
  109. const VTKNPD & vtknpdOld = (*it).first;
  110. const BNDIST * pbndistOld = (*it).second.Pobj();
  111. assert( pbndistOld );
  112. // Construct the new key using the new symbol table
  113. VTKNPD vtknpd;
  114. vtknpd.Clone( mpsymtbl, vtknpdOld );
  115. // Add to the current map
  116. self[vtknpd] = new BNDIST;
  117. // Duplicate the old distribution
  118. self[vtknpd]->Clone( *pbndistOld );
  119. }
  120. }
  121. void MPPD :: Dump ()
  122. {
  123. cout << "\n=======================================\nDump of distribution table map \n";
  124. UINT ipd = 0;
  125. for ( iterator it = begin(); it != end(); it++, ipd++ )
  126. {
  127. const VTKNPD & vtknpd = (*it).first;
  128. ZSTR zs = vtknpd.ZstrSignature();
  129. bool bCI = (*it).second->Edist() > BNDIST::ED_SPARSE;
  130. REFBNDIST & refbndist = (*it).second;
  131. cout << "\tPD ["
  132. << ipd
  133. << "]: "
  134. << zs.Szc()
  135. << (bCI ? " (CI max/plus)" : "" )
  136. << ", (refs="
  137. << refbndist->CRef()
  138. << ")"
  139. << "\n" ;
  140. refbndist->Dump();
  141. }
  142. }