This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 01/22] Expose assert_loceq outside of input.c; add ASSERT_LOCEQ


gcc/ChangeLog:
	* input.c: Include "selftest-input.h".
	(selftest::assert_loceq): Remove "static".  Add "report_loc" param
	and update assertions to use it.
	(selftest::test_accessing_ordinary_linemaps): Use ASSERT_LOCEQ
	rather than assert_loceq.
	(selftest::test_builtins): Likewise.
	* selftest-input.h: New file.
---
 gcc/input.c          | 39 +++++++++++++++++++------------------
 gcc/selftest-input.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+), 18 deletions(-)
 create mode 100644 gcc/selftest-input.h

diff --git a/gcc/input.c b/gcc/input.c
index 0480eb2..1aad551 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "intl.h"
 #include "diagnostic-core.h"
 #include "selftest.h"
+#include "selftest-input.h"
 #include "cpplib.h"
 
 #ifndef HAVE_ICONV
@@ -1613,21 +1614,23 @@ test_should_have_column_data_p ()
 }
 
 /* Verify the result of LOCATION_FILE/LOCATION_LINE/LOCATION_COLUMN
-   on LOC.  */
+   on LOC.  Use REPORT_LOC as the effective location when reporting
+   any issues.  */
 
-static void
-assert_loceq (const char *exp_filename, int exp_linenum, int exp_colnum,
+void
+assert_loceq (const location &report_loc,
+	      const char *exp_filename, int exp_linenum, int exp_colnum,
 	      location_t loc)
 {
-  ASSERT_STREQ (exp_filename, LOCATION_FILE (loc));
-  ASSERT_EQ (exp_linenum, LOCATION_LINE (loc));
+  ASSERT_STREQ_AT (report_loc, exp_filename, LOCATION_FILE (loc));
+  ASSERT_EQ_AT (report_loc, exp_linenum, LOCATION_LINE (loc));
   /* If location_t values are sufficiently high, then column numbers
      will be unavailable and LOCATION_COLUMN (loc) will be 0.
      When close to the threshold, column numbers *may* be present: if
      the final linemap before the threshold contains a line that straddles
      the threshold, locations in that line have column information.  */
   if (should_have_column_data_p (loc))
-    ASSERT_EQ (exp_colnum, LOCATION_COLUMN (loc));
+    ASSERT_EQ_AT (report_loc, exp_colnum, LOCATION_COLUMN (loc));
 }
 
 /* Various selftests involve constructing a line table and one or more
@@ -1761,23 +1764,23 @@ test_accessing_ordinary_linemaps (const line_table_case &case_)
   linemap_add (line_table, LC_LEAVE, false, NULL, 0);
 
   /* Verify that we can recover the location info.  */
-  assert_loceq ("foo.c", 1, 1, loc_a);
-  assert_loceq ("foo.c", 1, 23, loc_b);
-  assert_loceq ("foo.c", 2, 1, loc_c);
-  assert_loceq ("foo.c", 2, 17, loc_d);
-  assert_loceq ("foo.c", 3, 700, loc_e);
-  assert_loceq ("foo.c", 4, 100, loc_back_to_short);
+  ASSERT_LOCEQ ("foo.c", 1, 1, loc_a);
+  ASSERT_LOCEQ ("foo.c", 1, 23, loc_b);
+  ASSERT_LOCEQ ("foo.c", 2, 1, loc_c);
+  ASSERT_LOCEQ ("foo.c", 2, 17, loc_d);
+  ASSERT_LOCEQ ("foo.c", 3, 700, loc_e);
+  ASSERT_LOCEQ ("foo.c", 4, 100, loc_back_to_short);
 
   /* In the very wide line, the initial location should be fully tracked.  */
-  assert_loceq ("foo.c", 5, 2000, loc_start_of_very_long_line);
+  ASSERT_LOCEQ ("foo.c", 5, 2000, loc_start_of_very_long_line);
   /* ...but once we exceed LINE_MAP_MAX_COLUMN_NUMBER column-tracking should
      be disabled.  */
-  assert_loceq ("foo.c", 5, 0, loc_too_wide);
-  assert_loceq ("foo.c", 5, 0, loc_too_wide_2);
+  ASSERT_LOCEQ ("foo.c", 5, 0, loc_too_wide);
+  ASSERT_LOCEQ ("foo.c", 5, 0, loc_too_wide_2);
   /*...and column-tracking should be re-enabled for subsequent lines.  */
-  assert_loceq ("foo.c", 6, 10, loc_sane_again);
+  ASSERT_LOCEQ ("foo.c", 6, 10, loc_sane_again);
 
-  assert_loceq ("bar.c", 1, 150, loc_f);
+  ASSERT_LOCEQ ("bar.c", 1, 150, loc_f);
 
   ASSERT_FALSE (is_location_from_builtin_token (loc_a));
   ASSERT_TRUE (pure_location_p (line_table, loc_a));
@@ -1807,7 +1810,7 @@ test_unknown_location ()
 static void
 test_builtins ()
 {
-  assert_loceq (_("<built-in>"), 0, 0, BUILTINS_LOCATION);
+  ASSERT_LOCEQ (_("<built-in>"), 0, 0, BUILTINS_LOCATION);
   ASSERT_PRED1 (is_location_from_builtin_token, BUILTINS_LOCATION);
 }
 
diff --git a/gcc/selftest-input.h b/gcc/selftest-input.h
new file mode 100644
index 0000000..d56af36
--- /dev/null
+++ b/gcc/selftest-input.h
@@ -0,0 +1,54 @@
+/* Support for selftests of location handling.
+   Copyright (C) 2016-2017 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#ifndef GCC_SELFTEST_INPUT_H
+#define GCC_SELFTEST_INPUT_H
+
+/* The selftest code should entirely disappear in a production
+   configuration, hence we guard all of it with #if CHECKING_P.  */
+
+#if CHECKING_P
+
+namespace selftest {
+
+/* input.c.  */
+
+/* Verify the result of LOCATION_FILE/LOCATION_LINE/LOCATION_COLUMN
+   on LOC.  Use REPORT_LOC as the effective location when reporting
+   any issues.  */
+
+extern void assert_loceq (const location &report_loc,
+			  const char *exp_filename, int exp_linenum,
+			  int exp_colnum, location_t loc);
+
+/* Evaluate EXP_FILENAME, EXP_LINENUM, EXP_COLNUM, and LOC.
+   Verify the result of LOCATION_FILE/LOCATION_LINE/LOCATION_COLUMN
+   on LOC.  */
+
+#define ASSERT_LOCEQ(EXP_FILENAME, EXP_LINENUM, EXP_COLNUM, LOC)	\
+  SELFTEST_BEGIN_STMT							\
+    ::selftest::assert_loceq (SELFTEST_LOCATION, (EXP_FILENAME),	\
+			      (EXP_LINENUM), (EXP_COLNUM), (LOC));	\
+  SELFTEST_END_STMT
+
+} /* end of namespace selftest.  */
+
+#endif /* #if CHECKING_P */
+
+#endif /* GCC_SELFTEST_INPUT_H */
-- 
1.8.5.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]