if_diff/src/idfMatchAst.cxx
//============================================================================
// idf_match_ast
//----------------------------------------------------------------------------
// Match nodes between AST tree lists.
//============================================================================
idf_match_ast
Match nodes between AST tree lists.
idf_match_ast Match nodes between AST tree lists .
void idf_match_ast(const idfModel &model1, const idfModel &model2)
{
#if 0
  while (ast1 != NULL && ast2 != NULL) {
    match_ast(ast1, ast2, model1, model2);
    ast1 = ast1->getNextSib();
    ast2 = ast2->getNextSib();
  }
#elif 0
  while (ast1 != NULL && ast1->getNextSib() != NULL) {
    ast1 = ast1->getNextSib();
  }
  while (ast2 != NULL && ast2->getNextSib() != NULL) {
    ast2 = ast2->getNextSib();
  }
  while (ast1 != NULL && ast2 != NULL) {
    match_ast(ast1, ast2, model1, model2);
    ast1 = ast1->getPrevSib();
    ast2 = ast2->getPrevSib();
  }
#elif 0
  idfAstSiblings *children1 = model1.getAst();
  idfAstSiblings *children2 = model2.getAst();
  if (children1 != NULL && children2 != NULL) {
    match_children(*children1, *children2, model1, model2);
  }
#else
  idfAstDictionary *asts1 = model1.getAst();
  idfAstDictionary *asts2 = model2.getAst();
  int n1 = asts1->count();
  int n2 = asts2->count();
  while (n1 > 0 && n2 > 0) {
    n1 -= 1;
    n2 -= 1;
    idfAstSiblings *children1 = asts1->lookup(n1);
    idfAstSiblings *children2 = asts2->lookup(n2);
    if (children1 != NULL && children2 != NULL) {
      match_children(*children1, *children2, model1, model2);
    }
  }
  if (n1 != n2 && (asts1->count() > 1 || asts2->count() > 1)) {
    if (!idf_configuration.contains(
	  "AST records, other than the final ASTs, do not match.")) {
      genString s;
      if (n1 > n2) {
	  s.printf("%s: Multiple AST records. Ignoring the first %d of %d.", model1.getFilename(), n1, asts1->count());
      }
      if (n2 > n1) {
	  s.printf("%s: Multiple AST records. Ignoring the first %d of %d.", model2.getFilename(), n2, asts2->count());
      }
      idf_report(s, difference_note);
    }
  }
  else if (n1 != n2) {
      genString s;
      if (n1 > n2) {
	  s.printf("%s: AST missing.", model2.getFilename());
      }
      if (n2 > n1) {
	  s.printf("%s: AST missing.", model1.getFilename());
      }
      idf_report(s, difference_note);
  }
#endif
}
void idf_match_ast ( const idfModel & model1 , const idfModel & model2 ) { #if 0 while ( ast1 != NULL && ast2 != NULL ) { match_ast ( ast1 , ast2 , model1 , model2 ) ; ast1 = ast1 -> getNextSib ( ) ; ast2 = ast2 -> getNextSib ( ) ; } #elif 0 while ( ast1 != NULL && ast1 -> getNextSib ( ) != NULL ) { ast1 = ast1 -> getNextSib ( ) ; } while ( ast2 != NULL && ast2 -> getNextSib ( ) != NULL ) { ast2 = ast2 -> getNextSib ( ) ; } while ( ast1 != NULL && ast2 != NULL ) { match_ast ( ast1 , ast2 , model1 , model2 ) ; ast1 = ast1 -> getPrevSib ( ) ; ast2 = ast2 -> getPrevSib ( ) ; } #elif 0 idfAstSiblings * children1 = model1 . getAst ( ) ; idfAstSiblings * children2 = model2 . getAst ( ) ; if ( children1 != NULL && children2 != NULL ) { match_children ( * children1 , * children2 , model1 , model2 ) ; } #else idfAstDictionary * asts1 = model1 . getAst ( ) ; idfAstDictionary * asts2 = model2 . getAst ( ) ; int n1 = asts1 -> count ( ) ; int n2 = asts2 -> count ( ) ; while ( n1 > 0 && n2 > 0 ) { n1 -= 1 ; n2 -= 1 ; idfAstSiblings * children1 = asts1 -> lookup ( n1 ) ; idfAstSiblings * children2 = asts2 -> lookup ( n2 ) ; if ( children1 != NULL && children2 != NULL ) { match_children ( * children1 , * children2 , model1 , model2 ) ; } } if ( n1 != n2 && ( asts1 -> count ( ) > 1 || asts2 -> count ( ) > 1 ) ) { if ( ! idf_configuration . contains ( " " ) ) { genString s ; if ( n1 > n2 ) { s . printf ( " " , model1 . getFilename ( ) , n1 , asts1 -> count ( ) ) ; } if ( n2 > n1 ) { s . printf ( " " , model2 . getFilename ( ) , n2 , asts2 -> count ( ) ) ; } idf_report ( s , difference_note ) ; } } else if ( n1 != n2 ) { genString s ; if ( n1 > n2 ) { s . printf ( " " , model2 . getFilename ( ) ) ; } if ( n2 > n1 ) { s . printf ( " " , model1 . getFilename ( ) ) ; } idf_report ( s , difference_note ) ; } #endif }
idf_match_ast
Match nodes between AST tree lists.
idf_match_ast Match nodes between AST tree lists .
// init_kind_matches(); // Match in reverse.