}
}
+static int
+msg_point_compare_3way (const struct msg_point *a, const struct msg_point *b)
+{
+ return (!a->line ? 1
+ : !b->line ? -1
+ : a->line > b->line ? 1
+ : a->line < b->line ? -1
+ : !a->column ? 1
+ : !b->column ? -1
+ : a->column > b->column ? 1
+ : a->column < b->column ? -1
+ : 0);
+}
+
+void
+msg_location_merge (struct msg_location **dstp, const struct msg_location *src)
+{
+ if (dst->file_name != src->file_name)
+ {
+ /* Failure. */
+ return;
+ }
+
+ if (msg_point_compare_3way (&dst->p[0], &src->p[0]) > 0)
+ dst->p[0] = src->p[0];
+ if (msg_point_compare_3way (&dst->p[1], &src->p[1]) < 0)
+ dst->p[1] = src->p[1];
+}
+
struct msg_location *
msg_location_dup (const struct msg_location *src)
{
struct msg_location *dst = xmalloc (sizeof *dst);
*dst = (struct msg_location) {
.file_name = intern_new_if_nonnull (src->file_name),
- .first_line = src->first_line,
- .last_line = src->last_line,
- .first_column = src->first_column,
- .last_column = src->last_column,
+ .p[0] = src->p[0],
+ .p[1] = src->p[1],
};
return dst;
}
msg_location_is_empty (const struct msg_location *loc)
{
return !loc || (!loc->file_name
- && loc->first_line <= 0
- && loc->first_column <= 0);
+ && loc->p[0].line <= 0
+ && loc->p[0].column <= 0);
}
void
if (loc->file_name)
ds_put_cstr (s, loc->file_name);
- int l1 = loc->first_line;
- int l2 = MAX (loc->first_line, loc->last_line - 1);
- int c1 = loc->first_column;
- int c2 = MAX (loc->first_column, loc->last_column - 1);
+ int l1 = loc->p[0].line;
+ int l2 = MAX (l1, loc->p[1].line);
+ int c1 = loc->p[0].column;
+ int c2 = MAX (c1, loc->p[1].column);
if (l1 > 0)
{