if_diff/src/idfMatchSmt.cxx
//============================================================================
// make_one_match(idfSmt *, idfSmt *, idfSmt *&, idfSmt *&,
//     	      	  idfSymbolDictionary &, idfSymbolDictionary &)
//----------------------------------------------------------------------------
// Given two SMT lists that "ought to match", match the individual nodes
// as much as possible. Previous nodes in the SMT are already matched;
// only subsequent nodes are operated on.
//============================================================================


Given two SMT lists that "ought to match", match the individual nodes
as much as possible. Previous nodes in the SMT are already matched;
only subsequent nodes are operated on.
Given two SMT lists that " ought to match " match the individual nodes as much as possible . Previous nodes in the SMT are already matched ; only subsequent nodes are operated on .
static boolean make_one_match(idfSmt *smt1, idfSmt *smt2,
      	      	      	      idfSmt *&match1, idfSmt *&match2,
      	      	      	      const idfModel &model1, const idfModel &model2)
{
  if (smt1 == NULL || smt2 == NULL) {
    return false;
  }
  boolean found = false;
  const int how_far = 4;
  int outer_count = 0;
  idfSmt *outer_try1 = smt1;
  idfSmt *outer_try2 = smt2;
  while (outer_count < how_far && !found) {
    int inner_count = 0;
    idfSmt *try1 = smt1;
    idfSmt *try2 = smt2;
    while (inner_count <= outer_count) {
      if (is_match(outer_try1, try2, model1, model2)) {
      	found = true;
      	match1 = outer_try1;
      	match2 = try2;
      }
      if (is_match(try1, outer_try2, model1, model2)) {
	found = true;
	match1 = try1;
	match2 = outer_try2;
      }
      if (try1 != NULL) {
        try1 = try1->getNext();
      }
      if (try2 != NULL) {
        try2 = try2->getNext();
      }
      inner_count += 1;
    }
    if (outer_try1 != NULL) {
      outer_try1 = outer_try1->getNext();
    }
    if (outer_try2 != NULL) {
      outer_try2 = outer_try2->getNext();
    }
    outer_count += 1;
  }
  int extent1 = 0;
  int extent2 = 0;
  while (!found && smt1 != NULL && smt2 != NULL) {
    locationStruct *loc1 = comparable(smt1);
    locationStruct *loc2 = comparable(smt2);
#if 0
    {
      genString sr1;
      idf_location_str(loc1, sr1);
      genString sr2;
      idf_location_str(loc2, sr2);
      cout << "comparing at " << sr1.str() << " & " << sr2.str() << endl;
    }
#endif
    int starts_smt1_vs_smt2;
    boolean starts_compared = idf_compare_locations(loc1, loc2, true, starts_smt1_vs_smt2);
    int smt1_vs_smt2;
    boolean compared = idf_compare_locations(loc1, loc2, false, smt1_vs_smt2);
    if (   (starts_compared && starts_smt1_vs_smt2 == 0 && is_match(smt1, smt2, model1, model2))
      	|| (compared && smt1_vs_smt2 == 0)) {
      found = true;
      match1 = smt1;
      match2 = smt2;
    }
    else if (compared) {
      if (smt1_vs_smt2 <= 0) {
        smt1 = smt1->getNext();
      	extent1 += 1;
      }
      if (smt1_vs_smt2 >= 0) {
      	smt2 = smt2->getNext();
      	extent2 += 1;
      }
    }
    else if (loc1 != NULL && idf_filename_match(idf_interesting_filename, loc1->filename)) {
      smt2 = smt2->getNext();
      extent2 += 1;
    }
    else if (loc2 != NULL && idf_filename_match(idf_interesting_filename, loc2->filename)) {
      smt1 = smt1->getNext();
      extent1 += 1;
    }
    else {      
      if (extent1 <= extent2) {
        smt1 = smt1->getNext();
      	extent1 += 1;
      }
      if (extent1 > extent2) {
      	smt2 = smt2->getNext();
      	extent2 += 1;
      }
    }
  }
  if (found) {
    match1->setMatch(match2);
    match2->setMatch(match1);
  }
  return found;
}
static boolean make_one_match ( idfSmt * smt1 , idfSmt * smt2 , idfSmt * & match1 , idfSmt * & match2 , const idfModel & model1 , const idfModel & model2 ) { if ( smt1 == NULL || smt2 == NULL ) { return false ; } boolean found = false ; const int how_far = 4 ; int outer_count = 0 ; idfSmt * outer_try1 = smt1 ; idfSmt * outer_try2 = smt2 ; while ( outer_count < how_far && ! found ) { int inner_count = 0 ; idfSmt * try1 = smt1 ; idfSmt * try2 = smt2 ; while ( inner_count <= outer_count ) { if ( is_match ( outer_try1 , try2 , model1 , model2 ) ) { found = true ; match1 = outer_try1 ; match2 = try2 ; } if ( is_match ( try1 , outer_try2 , model1 , model2 ) ) { found = true ; match1 = try1 ; match2 = outer_try2 ; } if ( try1 != NULL ) { try1 = try1 -> getNext ( ) ; } if ( try2 != NULL ) { try2 = try2 -> getNext ( ) ; } inner_count += 1 ; } if ( outer_try1 != NULL ) { outer_try1 = outer_try1 -> getNext ( ) ; } if ( outer_try2 != NULL ) { outer_try2 = outer_try2 -> getNext ( ) ; } outer_count += 1 ; } int extent1 = 0 ; int extent2 = 0 ; while ( ! found && smt1 != NULL && smt2 != NULL ) { locationStruct * loc1 = comparable ( smt1 ) ; locationStruct * loc2 = comparable ( smt2 ) ; #if 0 { genString sr1 ; idf_location_str ( loc1 , sr1 ) ; genString sr2 ; idf_location_str ( loc2 , sr2 ) ; cout << " " << sr1 . str ( ) << " " << sr2 . str ( ) << endl ; } #endif int starts_smt1_vs_smt2 ; boolean starts_compared = idf_compare_locations ( loc1 , loc2 , true , starts_smt1_vs_smt2 ) ; int smt1_vs_smt2 ; boolean compared = idf_compare_locations ( loc1 , loc2 , false , smt1_vs_smt2 ) ; if ( ( starts_compared && starts_smt1_vs_smt2 == 0 && is_match ( smt1 , smt2 , model1 , model2 ) ) || ( compared && smt1_vs_smt2 == 0 ) ) { found = true ; match1 = smt1 ; match2 = smt2 ; } else if ( compared ) { if ( smt1_vs_smt2 <= 0 ) { smt1 = smt1 -> getNext ( ) ; extent1 += 1 ; } if ( smt1_vs_smt2 >= 0 ) { smt2 = smt2 -> getNext ( ) ; extent2 += 1 ; } } else if ( loc1 != NULL && idf_filename_match ( idf_interesting_filename , loc1 -> filename ) ) { smt2 = smt2 -> getNext ( ) ; extent2 += 1 ; } else if ( loc2 != NULL && idf_filename_match ( idf_interesting_filename , loc2 -> filename ) ) { smt1 = smt1 -> getNext ( ) ; extent1 += 1 ; } else { if ( extent1 <= extent2 ) { smt1 = smt1 -> getNext ( ) ; extent1 += 1 ; } if ( extent1 > extent2 ) { smt2 = smt2 -> getNext ( ) ; extent2 += 1 ; } } } if ( found ) { match1 -> setMatch ( match2 ) ; match2 -> setMatch ( match1 ) ; } return found ; }
make_one_match(idfSmt *, idfSmt *, idfSmt *&, idfSmt *&,
idfSymbolDictionary &, idfSymbolDictionary &)
make_one_match ( idfSmt * idfSmt * idfSmt * & idfSmt * & idfSymbolDictionary & idfSymbolDictionary & )
// Look for a good match in the next few nodes. // Search this pair of nodes and up to 3 nodes beyond, // searching nearer first, and giving preference to pairs that // are equally far along from this point. // If that didn't succeed, try a long-distance strategy. // Push ahead through the SMT lists. // A match! // Advance smt1. // Advance smt2. // Advance smt2. // Advance smt1. // Advance smt1. // Advance smt2. // One or both pointers have been advanced. // Got one! Set the match.