if_diff/src/idfAst.cxx
//============================================================================
// Determine a location for the siblings.
//============================================================================
Determine a location for the siblings.
Determine a location for the siblings .
void idfAstSiblings::determineSubtreeLocation()
{
  boolean have_start = false;
  int num_children = getNumber();
  int num_inspected = 0;
  while (!have_start && num_inspected < num_children) {
    idfAst *child = getSibling(num_inspected);
    locationStruct child_loc;
    if (child->getSubtreeLocation(child_loc)) {
      have_start = true;
      subtreeLocation.filename = child_loc.filename;
      subtreeLocation.start_line = child_loc.start_line;
      subtreeLocation.start_column = child_loc.start_column;
    }
    num_inspected += 1;
  }
  if (!have_start) {
    hasSubtreeLocation = false;
    return;
  }
  num_inspected = 0;
  boolean have_end = false;
  subtreeLocation.end_line = 0;
  subtreeLocation.end_column = 0;
  while (!have_end && num_inspected < num_children) {
    idfAst *child = getSibling(num_children - num_inspected - 1);
    locationStruct child_loc;
    if (child->getSubtreeLocation(child_loc) && !idf_endless(child_loc)) {
      if (!idf_strmatch(subtreeLocation.filename, child_loc.filename)) {
        hasSubtreeLocation = false;
      	return;
      }
      have_end = true;
      if (child_loc.end_line != 0) {
      	subtreeLocation.end_line = child_loc.end_line;
      	subtreeLocation.end_column = child_loc.end_column;
      }
      else if (subtreeLocation.start_line == child_loc.start_line) {
      	subtreeLocation.end_line = 0;
      	subtreeLocation.end_column = child_loc.end_column + (child_loc.start_column - subtreeLocation.start_column);
      }
      else {
      	subtreeLocation.end_line = child_loc.start_line;
      	subtreeLocation.end_column = child_loc.start_column + child_loc.end_column - 1;
      }
    }
    num_inspected += 1;
  }
  hasSubtreeLocation = true;
}
void idfAstSiblings :: determineSubtreeLocation ( ) { boolean have_start = false ; int num_children = getNumber ( ) ; int num_inspected = 0 ; while ( ! have_start && num_inspected < num_children ) { idfAst * child = getSibling ( num_inspected ) ; locationStruct child_loc ; if ( child -> getSubtreeLocation ( child_loc ) ) { have_start = true ; subtreeLocation . filename = child_loc . filename ; subtreeLocation . start_line = child_loc . start_line ; subtreeLocation . start_column = child_loc . start_column ; } num_inspected += 1 ; } if ( ! have_start ) { hasSubtreeLocation = false ; return ; } num_inspected = 0 ; boolean have_end = false ; subtreeLocation . end_line = 0 ; subtreeLocation . end_column = 0 ; while ( ! have_end && num_inspected < num_children ) { idfAst * child = getSibling ( num_children - num_inspected - 1 ) ; locationStruct child_loc ; if ( child -> getSubtreeLocation ( child_loc ) && ! idf_endless ( child_loc ) ) { if ( ! idf_strmatch ( subtreeLocation . filename , child_loc . filename ) ) { hasSubtreeLocation = false ; return ; } have_end = true ; if ( child_loc . end_line != 0 ) { subtreeLocation . end_line = child_loc . end_line ; subtreeLocation . end_column = child_loc . end_column ; } else if ( subtreeLocation . start_line == child_loc . start_line ) { subtreeLocation . end_line = 0 ; subtreeLocation . end_column = child_loc . end_column + ( child_loc . start_column - subtreeLocation . start_column ) ; } else { subtreeLocation . end_line = child_loc . start_line ; subtreeLocation . end_column = child_loc . start_column + child_loc . end_column - 1 ; } } num_inspected += 1 ; } hasSubtreeLocation = true ; }
Determine a location for the siblings.
Determine a location for the siblings .
// Find end line, if possible. // can continue to use a byte length // translate end byte length to line/column