if_diff/src/idfLocation.cxx
//============================================================================
// Create a location which represents the union of the two locations.
// Fail and return false if both are NULL, or if they come from different
// files (by simple name match).
//
// If the two ranges do not overlap, the a location (range) is returned,
// with the gap filled in.
//============================================================================
Create a location which represents the union of the two locations.
Fail and return false if both are NULL, or if they come from different
files (by simple name match).

If the two ranges do not overlap, the a location (range) is returned,
with the gap filled in.
Create a location which represents the union of the two locations . Fail and return false if both are NULL or if they come from different files ( by simple name match ) . If the two ranges do not overlap the a location ( range ) is returned with the gap filled in .
boolean idf_location_union(const locationStruct *loc1,
                           const locationStruct *loc2, locationStruct &loc)
{
  if (loc1 == NULL && loc2 == NULL) {
    return false;
  }
  if (loc1 == NULL) {
    loc = *loc2;
    return true;
  }
  else if (loc2 == NULL) {
    loc = *loc1;
    return true;
  }
  if (!idf_strmatch(loc1->filename, loc2->filename)) {
    return false;
  }
  loc.filename = loc1->filename;
  if ((loc1->start_line == 0) != (loc2->start_line == 0)) {
    return false;
  }
  loc.start_line = loc1->start_line < loc2->start_line ? loc1->start_line
                                                       : loc2->start_line;
  if (loc1->start_line == loc2->start_line) {
    loc.start_column = loc1->start_column < loc2->start_column ? loc1->start_column
                                                               : loc2->start_column;
  }
  else if (loc1->start_line < loc2->start_line) {
    loc.start_column = loc1->start_column;
  }
  else {
    loc.start_column = loc2->start_column;
  }
  int end_line1;
  int end_column1;
  int end_line2;
  int end_column2;
  canonical_end(*loc1, end_line1, end_column1);
  canonical_end(*loc2, end_line2, end_column2);
  if ((end_line1 == 0) != (end_line2 == 0)) {
    return false;
  }
  loc.end_line = end_line1 > end_line2 ? end_line1 : end_line2;
  if (end_line1 == end_line2) {
    loc.end_column = end_column1 > end_column2 ? end_column1 : end_column2;
  }
  else if (end_line1 > end_line2) {
    loc.end_column = end_column1;
  }
  else {
    loc.end_column = end_column2;
  }
  if (loc.end_line == loc.start_line && (loc1->end_line == 0 || loc2->end_line == 0)) {
    loc.end_line = 0;
    loc.end_column -= (loc.start_column - 1);
  }
  return true;
}
boolean idf_location_union ( const locationStruct * loc1 , const locationStruct * loc2 , locationStruct & loc ) { if ( loc1 == NULL && loc2 == NULL ) { return false ; } if ( loc1 == NULL ) { loc = * loc2 ; return true ; } else if ( loc2 == NULL ) { loc = * loc1 ; return true ; } if ( ! idf_strmatch ( loc1 -> filename , loc2 -> filename ) ) { return false ; } loc . filename = loc1 -> filename ; if ( ( loc1 -> start_line == 0 ) != ( loc2 -> start_line == 0 ) ) { return false ; } loc . start_line = loc1 -> start_line < loc2 -> start_line ? loc1 -> start_line : loc2 -> start_line ; if ( loc1 -> start_line == loc2 -> start_line ) { loc . start_column = loc1 -> start_column < loc2 -> start_column ? loc1 -> start_column : loc2 -> start_column ; } else if ( loc1 -> start_line < loc2 -> start_line ) { loc . start_column = loc1 -> start_column ; } else { loc . start_column = loc2 -> start_column ; } int end_line1 ; int end_column1 ; int end_line2 ; int end_column2 ; canonical_end ( * loc1 , end_line1 , end_column1 ) ; canonical_end ( * loc2 , end_line2 , end_column2 ) ; if ( ( end_line1 == 0 ) != ( end_line2 == 0 ) ) { return false ; } loc . end_line = end_line1 > end_line2 ? end_line1 : end_line2 ; if ( end_line1 == end_line2 ) { loc . end_column = end_column1 > end_column2 ? end_column1 : end_column2 ; } else if ( end_line1 > end_line2 ) { loc . end_column = end_column1 ; } else { loc . end_column = end_column2 ; } if ( loc . end_line == loc . start_line && ( loc1 -> end_line == 0 || loc2 -> end_line == 0 ) ) { loc . end_line = 0 ; loc . end_column -= ( loc . start_column - 1 ) ; } return true ; }
Create a location which represents the union of the two locations.
Create a location which represents the union of the two locations .
// Start locations are not comparable since one is byte-based and // the other is row/column based. // Put the end lines and columns into a consistent form for comparison. // End locations are not comparable since one is byte-based and // the other is row/column based. // Find the max end line & column. // Express the end line and column consistently with the input.