Patchwork [c-family] Small fix for -fdump-ada-spec

login
register
mail settings
Submitter Eric Botcazou
Date Oct. 18, 2012, 6:44 p.m.
Message ID <4759815.ojHB7dFO0n@polaris>
Download mbox | patch
Permalink /patch/192402/
State New
Headers show

Comments

Eric Botcazou - Oct. 18, 2012, 6:44 p.m.
The recent introduction of virtual locations revealed a weak spot in the 
implementation of -fdump-ada-spec.

Tested on x86_64-suse-linux, applied on the mainline as obvious.


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.

Patch

Index: c-ada-spec.c
===================================================================
--- c-ada-spec.c	(revision 192526)
+++ c-ada-spec.c	(working copy)
@@ -67,8 +67,6 @@  static void dump_ads (const char *, void
 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
   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 v
   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;