c-ada-spec.c (LOCATION_COL): Delete.
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 18 Oct 2012 18:47:23 +0000 (18:47 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Thu, 18 Oct 2012 18:47:23 +0000 (18:47 +0000)
* c-ada-spec.c (LOCATION_COL): Delete.
(compare_location): New function.
(compare_node): Use it.
(compare_comment): Likewise.

From-SVN: r192574

gcc/c-family/ChangeLog
gcc/c-family/c-ada-spec.c

index e2499fb8dbe5036079d04d9868f722c123511cd9..454196fb6326e961efbbaf90c8360a157ca43f44 100644 (file)
@@ -1,3 +1,10 @@
+2012-10-18  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * c-ada-spec.c (LOCATION_COL): Delete.
+       (compare_location): New function.
+       (compare_node): Use it.
+       (compare_comment): Likewise.
+
 2012-10-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
        PR c/53063
index 792fee26e19b53c94e4e0bb3b7628a3c867e801e..4c47ed44a549b244ffc9ac4f0ae13bb420aacf1a 100644 (file)
@@ -67,8 +67,6 @@ static void dump_ads (const char *, void (*)(const char *),
 static char *to_ada_name (const char *, int *);
 static bool separate_class_package (tree);
 
-#define LOCATION_COL(LOC) ((expand_location (LOC)).column)
-
 #define INDENT(SPACE) do { \
   int i; for (i = 0; i<SPACE; i++) pp_space (buffer); } while (0)
 
@@ -553,6 +551,26 @@ decl_sloc (const_tree decl, bool last)
   return decl_sloc_common (decl, last, false);
 }
 
+/* Compare two locations LHS and RHS.  */
+
+static int
+compare_location (location_t lhs, location_t rhs)
+{
+  expanded_location xlhs = expand_location (lhs);
+  expanded_location xrhs = expand_location (rhs);
+
+  if (xlhs.file != xrhs.file)
+    return filename_cmp (xlhs.file, xrhs.file);
+
+  if (xlhs.line != xrhs.line)
+    return xlhs.line - xrhs.line;
+
+  if (xlhs.column != xrhs.column)
+    return xlhs.column - xrhs.column;
+
+  return 0;
+}
+
 /* Compare two declarations (LP and RP) by their source location.  */
 
 static int
@@ -561,7 +579,7 @@ compare_node (const void *lp, const void *rp)
   const_tree lhs = *((const tree *) lp);
   const_tree rhs = *((const tree *) rp);
 
-  return decl_sloc (lhs, true) - decl_sloc (rhs, true);
+  return compare_location (decl_sloc (lhs, true), decl_sloc (rhs, true));
 }
 
 /* Compare two comments (LP and RP) by their source location.  */
@@ -572,17 +590,7 @@ compare_comment (const void *lp, const void *rp)
   const cpp_comment *lhs = (const cpp_comment *) lp;
   const cpp_comment *rhs = (const cpp_comment *) rp;
 
-  if (LOCATION_FILE (lhs->sloc) != LOCATION_FILE (rhs->sloc))
-    return filename_cmp (LOCATION_FILE (lhs->sloc),
-                        LOCATION_FILE (rhs->sloc));
-
-  if (LOCATION_LINE (lhs->sloc) != LOCATION_LINE (rhs->sloc))
-    return LOCATION_LINE (lhs->sloc) - LOCATION_LINE (rhs->sloc);
-
-  if (LOCATION_COL (lhs->sloc) != LOCATION_COL (rhs->sloc))
-    return LOCATION_COL (lhs->sloc) - LOCATION_COL (rhs->sloc);
-
-  return 0;
+  return compare_location (lhs->sloc, rhs->sloc);
 }
 
 static tree *to_dump = NULL;