BinClone/CloneSearcherLib/CSController.cpp
//
// Find all the clones from the DB
//
Find all the clones from the DB
Find all the clones from the DB
bool CCSController::findFileClones(LPCTSTR targetAssemblyFilePath, 
                                   const CCSParam& param,
                                   bool bFindExactClones, 
                                   bool bFindInexactClones, 
                                   double minCoOccThreshold, 
                                   const CCSClones*& pClones)
{
	if (bFindInexactClones) {
		m_dbMgr.setMinCoOccThreshold(minCoOccThreshold);
		m_dbMgr.setInitialVariables(param);
		m_dbMgr.setTotalNCombination(param);
	}
    long startProgTime = getTime();
    pClones = NULL;
    delete m_pTargetAssemblyFile;
    m_pTargetAssemblyFile = new CCSAssemblyFile(targetAssemblyFilePath, &m_assemblyFileMgr);
    if (!m_pTargetAssemblyFile->parseFile(param, false))
        return false;
    if (!m_pTargetAssemblyFile->normalizeCode(param))
        return false;
    long endPreprocessTime = getTime();
    long startCloneTime = getTime();
    if (!m_pTargetAssemblyFile->extractFunctions(&m_dbMgr, param, false))
        return false;
    tcout << _T("Number of functions: ") << m_pTargetAssemblyFile->getNumFunctions() << " in " << targetAssemblyFilePath << endl;
    if (!m_pTargetAssemblyFile->extractRegions(&m_dbMgr, param, bFindExactClones, bFindInexactClones, false, false, NULL))
        return false;
    tcout << _T("Number of regions: ") << m_pTargetAssemblyFile->getNumRegions() << _T(" in ") << targetAssemblyFilePath << endl;
    long startUnificationTime = getTime();
    tcout << _T("Number of clones before unification: ") << m_pTargetAssemblyFile->getClones()->GetSize() << endl;
	if (!m_pTargetAssemblyFile->getClones()->unifyToLargestClones(param.m_windowSize, minCoOccThreshold)) {
        tcout << _T("Error: failed to unify clones.") << endl;
        return false;
    }
    tcout << _T("Number of clones after unification: ") << m_pTargetAssemblyFile->getClones()->GetSize() << endl;
    CCSClone* pClone = NULL;
    for (int c = 0; c < m_pTargetAssemblyFile->getClones()->GetSize(); ++c) {
        pClone = m_pTargetAssemblyFile->getClones()->GetAt(c);
        if (!m_dbMgr.fetchFilePath(pClone->m_srcFileID, pClone->m_srcFilePath))
            return false;
    }
    if (!m_pTargetAssemblyFile->getClones()->sortByTarRawStart()) {
        tcout << _T("Error: failed to sort clones.") << endl;
        return false;
    }
    pClones = m_pTargetAssemblyFile->getClones();
    long endProgTime = getTime();    
    tcout << _T("Spent: ") << endPreprocessTime - startProgTime << _T("s on reading and preprocessing the target assembly file.") << endl;    
    tcout << _T("Spent: ") << startUnificationTime - startCloneTime << _T("s on finding clones.") << endl;
    tcout << _T("Spent: ") << endProgTime - startUnificationTime << _T("s on unifying and sorting clones.") << endl;
    tcout << _T("Spent: ") << endProgTime - startProgTime << _T("s in total.") << std::endl; 	
	return true;
}
bool CCSController :: findFileClones ( LPCTSTR targetAssemblyFilePath , const CCSParam & param , bool bFindExactClones , bool bFindInexactClones , double minCoOccThreshold , const CCSClones * & pClones ) { if ( bFindInexactClones ) { m_dbMgr . setMinCoOccThreshold ( minCoOccThreshold ) ; m_dbMgr . setInitialVariables ( param ) ; m_dbMgr . setTotalNCombination ( param ) ; } long startProgTime = getTime ( ) ; pClones = NULL ; delete m_pTargetAssemblyFile ; m_pTargetAssemblyFile = new CCSAssemblyFile ( targetAssemblyFilePath , & m_assemblyFileMgr ) ; if ( ! m_pTargetAssemblyFile -> parseFile ( param , false ) ) return false ; if ( ! m_pTargetAssemblyFile -> normalizeCode ( param ) ) return false ; long endPreprocessTime = getTime ( ) ; long startCloneTime = getTime ( ) ; if ( ! m_pTargetAssemblyFile -> extractFunctions ( & m_dbMgr , param , false ) ) return false ; tcout << _T ( " " ) << m_pTargetAssemblyFile -> getNumFunctions ( ) << " " << targetAssemblyFilePath << endl ; if ( ! m_pTargetAssemblyFile -> extractRegions ( & m_dbMgr , param , bFindExactClones , bFindInexactClones , false , false , NULL ) ) return false ; tcout << _T ( " " ) << m_pTargetAssemblyFile -> getNumRegions ( ) << _T ( " " ) << targetAssemblyFilePath << endl ; long startUnificationTime = getTime ( ) ; tcout << _T ( " " ) << m_pTargetAssemblyFile -> getClones ( ) -> GetSize ( ) << endl ; if ( ! m_pTargetAssemblyFile -> getClones ( ) -> unifyToLargestClones ( param . m_windowSize , minCoOccThreshold ) ) { tcout << _T ( " " ) << endl ; return false ; } tcout << _T ( " " ) << m_pTargetAssemblyFile -> getClones ( ) -> GetSize ( ) << endl ; CCSClone * pClone = NULL ; for ( int c = 0 ; c < m_pTargetAssemblyFile -> getClones ( ) -> GetSize ( ) ; ++ c ) { pClone = m_pTargetAssemblyFile -> getClones ( ) -> GetAt ( c ) ; if ( ! m_dbMgr . fetchFilePath ( pClone -> m_srcFileID , pClone -> m_srcFilePath ) ) return false ; } if ( ! m_pTargetAssemblyFile -> getClones ( ) -> sortByTarRawStart ( ) ) { tcout << _T ( " " ) << endl ; return false ; } pClones = m_pTargetAssemblyFile -> getClones ( ) ; long endProgTime = getTime ( ) ; tcout << _T ( " " ) << endPreprocessTime - startProgTime << _T ( " " ) << endl ; tcout << _T ( " " ) << startUnificationTime - startCloneTime << _T ( " " ) << endl ; tcout << _T ( " " ) << endProgTime - startUnificationTime << _T ( " " ) << endl ; tcout << _T ( " " ) << endProgTime - startProgTime << _T ( " " ) << std :: endl ; return true ; }
Find all the clones from the DB
Find all the clones from the DB
// initialze the inexact detection minCoOccThreshold and score vector // calculate the total number of combinations/clusters // Parse the target assembly file. // normalize code // create functions in memory. // create regions. // unify the clones // fetch the file paths     // Sort the clones by the target raw start number // Get all the clones //pClones->printClones();