Example #1
0
////////////////////////////////////////////////////////////////
//
// CompressModHdr()
//
//		compressing module header array (m_rgModHdr) and do
//		a consistency check. 
//		If the header has a 0 reference, it will remove the stream
//		NOTE:
//		  It is STRONGLY recommended to do a CompressTarget (for
//		  all targets) before calling this function, since
//		  it can substantially speed up the function
/////////////////////////////////////////////////////////////////
BOOL Ncb::CompressModHdr(PDB * pdb)
{
	BOOL * rgModRef;
	USHORT * rgMap;
	unsigned i,j;
	unsigned cModHdr = m_rgModHdr.size();
	unsigned cNewModHdr;
	unsigned cTarget;
	unsigned cMod;
	Stream * pstmMod;

	rgModRef = new BOOL [cModHdr];
	rgMap = new USHORT [cModHdr];

	if (!rgModRef)
		return FALSE;
	
	if (!rgMap)
		return FALSE;

	for (i = 0; i < cModHdr; i++)
		rgModRef[i] = FALSE; // initialize values to FALSE

	// iterate every target array to count the
	// total number of reference of each module
	cTarget = m_rgTargetInfo.size();
	for (i = 0; i < cTarget; i++)
	{
		cMod = m_rgTargetInfo[i].m_rgModInfo.size();
		// check every module in a target
		for (j = 0; j < cMod; j++)
			rgModRef[m_rgTargetInfo[i].m_rgModInfo[j].m_iModHdr] = TRUE;
	}
	
	// now build the map from old index to new index
	cNewModHdr = 0;
	for (i = 0; i < cModHdr; i++)
	{
		if (rgModRef[i] == FALSE)
		{
			// remove the info from the stream
			char buf[512];
			SZ szMod = szFrNi (m_rgModHdr[i].m_ni);
			strcpy (buf, SZ_NCB_MODULE_PREFIX);
			strcat (buf, szMod);
			// REVIEW: is this how to delete a stream??
			if (pdb->OpenStream (buf, &pstmMod))
			{
				pstmMod->Delete();
				pstmMod->Release();
				pstmMod = NULL;
			}
			// mark the map as invalid
			rgMap[i] = (USHORT)-1;
		}
		else // ref. count is greater than 0
		{
			// set a new map to use
			rgMap[i] = cNewModHdr;
			// copy the information to the new position
			if (i != cNewModHdr)
				m_rgModHdr[cNewModHdr] = m_rgModHdr[i];
			// increment the counter
			cNewModHdr++;
		}
	}
	// set the new size for module header:
	m_rgModHdr.setSize (cNewModHdr+1);
	// now fix up the module list for each target
	for (i = 0; i < cTarget; i++)
	{
		cMod = m_rgTargetInfo[i].m_rgModInfo.size();
		// check every module in a target
		for (j = 0; j < cMod; j++)
		{
			_ASSERT (rgMap[m_rgTargetInfo[i].m_rgModInfo[j].m_iModHdr] != (USHORT)-1);
			m_rgTargetInfo[i].m_rgModInfo[j].m_iModHdr =
				rgMap[m_rgTargetInfo[i].m_rgModInfo[j].m_iModHdr];
		}
	}
	return TRUE;
};
Example #2
0
BOOL
MRE::FCloseCompiland ( PMREFile pmrefile, BOOL fCommit ) {
	assert ( m_pmrefRoot );
	assert ( pmrefile == m_pmrefRoot );

	_TCHAR		szStreamName[ ctchMrePathMax ];
	Stream *	pstream;
	BOOL		fRet = fFalse;

	if ( m_mrelog.FLogging() ) {
		m_mrelog.LogNote ( 
			"Note: '%s' deps will %sbe committed.\n",
			SzFromNi ( m_pmrefRoot->Ni() ),
			fCommit ? "" : "not "
			);
		m_mrelog.LogSep();
		}

	if ( fCommit ) {
		_sntprintf (
			szStreamName,
			countof(szStreamName),
			c_szMreFileFmt,
			m_pmrefRoot->Ni()
			);
		// if we haven't hit all the classes that were noted as mr detectable,
		// we need to rude out those classes.
		Array<NI> &	rgni = m_pmrefRoot->RgNiClassesChanged();
		unsigned	iniMax = rgni.size();
		for ( unsigned ini = 0; ini < iniMax; ini++ ) {
			if ( rgni[ ini ] != niNil ) {
				// a class we didn't see a different type id for...
				PCI	pci;
				if ( FClassInfoFromNi ( rgni[ ini ], &pci ) ) {
					// we have to promote all nested types to rude.
					NoteRudeNestedClasses ( pci->Ti() );
					}
				}
			}

		if ( m_ppdb->OpenStream ( szStreamName, &pstream ) ) {
			// if we need to merge the class dependency data, we need
			// to read in the old stream first...
			if ( !m_pmrefRoot->FAllCodeCompiled() ) {
				MRFIBuf	mrfibufT;
				mrfibufT.SetPmre ( this );
				if ( mrfibufT.FInitFromStream ( pstream ) ) {
					assert ( mrfibufT.Pmrfi()->niFile == m_pmrefRoot->Ni() );

					m_mrfibufRoot.FmergeClassDeps ( mrfibufT );
					}
				}
			if ( m_mrfibufRoot.FReplaceStream ( pstream ) ) {
				fRet = fTrue;
				}
			else {
				pstream->Delete();
				}
			pstream->Release();
			}
		if ( fRet ) {
			// if everything is ok for the gen'ed dependencies, we
			// need to update the build # in the file info stream
			PFI	pfi = NULL;
			verify ( m_mpnifi.map ( m_pmrefRoot->Ni(), &pfi ) );
			if ( pfi ) {
				pfi->SetBuildId ( BuildId() );
				verify ( m_mpnifi.map ( pfi->NiRelated(), &pfi ) );
				if ( pfi ) {
					pfi->SetBuildId ( BuildId() );
					}
				}
			}
		}
	else {
		fRet = fTrue;
		}
	delete m_pmrefRoot;
	m_pmrefRoot = NULL;
	return fRet;
	}