aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2017-12-06 19:56:11 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2017-12-06 19:56:11 +0000
commit613bc14fcd3f6b58289aca9a2980cacfc2e75299 (patch)
treeadf0978b4aae44dff2d6b8e753023d32a03d9960
parent06f9708454a5e644b1fb5ed17a863cd624985e17 (diff)
downloadgcc-613bc14fcd3f6b58289aca9a2980cacfc2e75299.zip
gcc-613bc14fcd3f6b58289aca9a2980cacfc2e75299.tar.gz
gcc-613bc14fcd3f6b58289aca9a2980cacfc2e75299.tar.bz2
Move macro-spellchecking code from "gcc" to new files in c-family
The code for spellchecking macros really belongs in c-family, rather than in gcc/spellcheck-tree.c, so this patch moves it there. gcc/ChangeLog: * Makefile.in (C_COMMON_OBJS): Add c-family/c-spellcheck.o. * spellcheck-tree.c (find_closest_macro_cpp_cb): Move to c-family/c-spellcheck.cc. (best_macro_match::best_macro_match): Likewise. * spellcheck-tree.h (struct edit_distance_traits<cpp_hashnode *>): Move to c-family/c-spellcheck.h. (class best_macro_match): Likewise. gcc/c-family/ChangeLog: * c-spellcheck.cc: New file, taken from macro-handling code in spellcheck-tree.c. * c-spellcheck.h: New file, taken from macro-handling code in spellcheck-tree.h. gcc/c/ChangeLog: * c-decl.c: Include "c-family/c-spellcheck.h". gcc/cp/ChangeLog: * name-lookup.c: Include "c-family/c-spellcheck.h". From-SVN: r255452
-rw-r--r--gcc/ChangeLog11
-rw-r--r--gcc/Makefile.in2
-rw-r--r--gcc/c-family/ChangeLog7
-rw-r--r--gcc/c-family/c-spellcheck.cc57
-rw-r--r--gcc/c-family/c-spellcheck.h51
-rw-r--r--gcc/c/ChangeLog4
-rw-r--r--gcc/c/c-decl.c1
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/name-lookup.c1
-rw-r--r--gcc/spellcheck-tree.c30
-rw-r--r--gcc/spellcheck-tree.h26
11 files changed, 137 insertions, 57 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 0310a52..3661e97 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@
+2017-12-06 David Malcolm <dmalcolm@redhat.com>
+
+ * Makefile.in (C_COMMON_OBJS): Add c-family/c-spellcheck.o.
+ * spellcheck-tree.c (find_closest_macro_cpp_cb): Move to
+ c-family/c-spellcheck.cc.
+ (best_macro_match::best_macro_match): Likewise.
+ * spellcheck-tree.h
+ (struct edit_distance_traits<cpp_hashnode *>): Move to
+ c-family/c-spellcheck.h.
+ (class best_macro_match): Likewise.
+
2017-12-06 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/83293
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index db43fc1..6874f94 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1196,7 +1196,7 @@ C_COMMON_OBJS = c-family/c-common.o c-family/c-cppbuiltin.o c-family/c-dump.o \
c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-pretty-print.o \
c-family/c-semantics.o c-family/c-ada-spec.o \
c-family/c-ubsan.o c-family/known-headers.o \
- c-family/c-attribs.o c-family/c-warn.o
+ c-family/c-attribs.o c-family/c-warn.o c-family/c-spellcheck.o
# Language-independent object files.
# We put the *-match.o and insn-*.o files first so that a parallel make
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 8b619ad..ee590ed 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,10 @@
+2017-12-06 David Malcolm <dmalcolm@redhat.com>
+
+ * c-spellcheck.cc: New file, taken from macro-handling code in
+ spellcheck-tree.c.
+ * c-spellcheck.h: New file, taken from macro-handling code in
+ spellcheck-tree.h.
+
2017-12-01 Jakub Jelinek <jakub@redhat.com>
* c-attribs.c (c_common_attribute_table): Remove "cilk simd function"
diff --git a/gcc/c-family/c-spellcheck.cc b/gcc/c-family/c-spellcheck.cc
new file mode 100644
index 0000000..db70a64
--- /dev/null
+++ b/gcc/c-family/c-spellcheck.cc
@@ -0,0 +1,57 @@
+/* Find near-matches for macros.
+ 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/>. */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "tree.h"
+#include "cpplib.h"
+#include "spellcheck-tree.h"
+#include "c-family/c-spellcheck.h"
+
+/* A callback for cpp_forall_identifiers, for use by best_macro_match's ctor.
+ Process HASHNODE and update the best_macro_match instance pointed to be
+ USER_DATA. */
+
+static int
+find_closest_macro_cpp_cb (cpp_reader *, cpp_hashnode *hashnode,
+ void *user_data)
+{
+ if (hashnode->type != NT_MACRO)
+ return 1;
+
+ best_macro_match *bmm = (best_macro_match *)user_data;
+ bmm->consider (hashnode);
+
+ /* Keep iterating. */
+ return 1;
+}
+
+/* Constructor for best_macro_match.
+ Use find_closest_macro_cpp_cb to find the closest matching macro to
+ NAME within distance < best_distance_so_far. */
+
+best_macro_match::best_macro_match (tree goal,
+ edit_distance_t best_distance_so_far,
+ cpp_reader *reader)
+: best_match <goal_t, candidate_t> (goal, best_distance_so_far)
+{
+ cpp_forall_identifiers (reader, find_closest_macro_cpp_cb, this);
+}
diff --git a/gcc/c-family/c-spellcheck.h b/gcc/c-family/c-spellcheck.h
new file mode 100644
index 0000000..adc539a
--- /dev/null
+++ b/gcc/c-family/c-spellcheck.h
@@ -0,0 +1,51 @@
+/* Find near-matches for macros.
+ 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 C_SPELLCHECK_H
+#define C_SPELLCHECK_H
+
+#include "spellcheck.h"
+
+/* Specialization of edit_distance_traits for preprocessor macros. */
+
+template <>
+struct edit_distance_traits<cpp_hashnode *>
+{
+ static size_t get_length (cpp_hashnode *hashnode)
+ {
+ return hashnode->ident.len;
+ }
+
+ static const char *get_string (cpp_hashnode *hashnode)
+ {
+ return (const char *)hashnode->ident.str;
+ }
+};
+
+/* Specialization of best_match<> for finding the closest preprocessor
+ macro to a given identifier. */
+
+class best_macro_match : public best_match<tree, cpp_hashnode *>
+{
+ public:
+ best_macro_match (tree goal, edit_distance_t best_distance_so_far,
+ cpp_reader *reader);
+};
+
+#endif /* C_SPELLCHECK_H */
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index 8fea426..b89939e 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,7 @@
+2017-12-06 David Malcolm <dmalcolm@redhat.com>
+
+ * c-decl.c: Include "c-family/c-spellcheck.h".
+
2017-12-05 Martin Liska <mliska@suse.cz>
Jakub Jelinek <jakub@redhat.com>
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 56c63d8..d7dad1a 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -56,6 +56,7 @@ along with GCC; see the file COPYING3. If not see
#include "asan.h"
#include "c-family/name-hint.h"
#include "c-family/known-headers.h"
+#include "c-family/c-spellcheck.h"
/* In grokdeclarator, distinguish syntactic contexts of declarators. */
enum decl_context
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 122045b..4cd3917 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,7 @@
+2017-12-06 David Malcolm <dmalcolm@redhat.com>
+
+ * name-lookup.c: Include "c-family/c-spellcheck.h".
+
2017-12-05 Jason Merrill <jason@redhat.com>
PR c++/82331 - ICE with variadic partial specialization of auto
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 62ea564..482ddcc 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see
#include "parser.h"
#include "c-family/name-hint.h"
#include "c-family/known-headers.h"
+#include "c-family/c-spellcheck.h"
static cxx_binding *cxx_binding_make (tree value, tree type);
static cp_binding_level *innermost_nonclass_level (void);
diff --git a/gcc/spellcheck-tree.c b/gcc/spellcheck-tree.c
index b819980..99878d5 100644
--- a/gcc/spellcheck-tree.c
+++ b/gcc/spellcheck-tree.c
@@ -66,36 +66,6 @@ find_closest_identifier (tree target, const auto_vec<tree> *candidates)
return bm.get_best_meaningful_candidate ();
}
-/* A callback for cpp_forall_identifiers, for use by best_macro_match's ctor.
- Process HASHNODE and update the best_macro_match instance pointed to be
- USER_DATA. */
-
-static int
-find_closest_macro_cpp_cb (cpp_reader *, cpp_hashnode *hashnode,
- void *user_data)
-{
- if (hashnode->type != NT_MACRO)
- return 1;
-
- best_macro_match *bmm = (best_macro_match *)user_data;
- bmm->consider (hashnode);
-
- /* Keep iterating. */
- return 1;
-}
-
-/* Constructor for best_macro_match.
- Use find_closest_macro_cpp_cb to find the closest matching macro to
- NAME within distance < best_distance_so_far. */
-
-best_macro_match::best_macro_match (tree goal,
- edit_distance_t best_distance_so_far,
- cpp_reader *reader)
-: best_match <goal_t, candidate_t> (goal, best_distance_so_far)
-{
- cpp_forall_identifiers (reader, find_closest_macro_cpp_cb, this);
-}
-
#if CHECKING_P
namespace selftest {
diff --git a/gcc/spellcheck-tree.h b/gcc/spellcheck-tree.h
index eecfd1a..84b76e0 100644
--- a/gcc/spellcheck-tree.h
+++ b/gcc/spellcheck-tree.h
@@ -48,30 +48,4 @@ struct edit_distance_traits<tree>
}
};
-/* Specialization of edit_distance_traits for preprocessor macros. */
-
-template <>
-struct edit_distance_traits<cpp_hashnode *>
-{
- static size_t get_length (cpp_hashnode *hashnode)
- {
- return hashnode->ident.len;
- }
-
- static const char *get_string (cpp_hashnode *hashnode)
- {
- return (const char *)hashnode->ident.str;
- }
-};
-
-/* Specialization of best_match<> for finding the closest preprocessor
- macro to a given identifier. */
-
-class best_macro_match : public best_match<tree, cpp_hashnode *>
-{
- public:
- best_macro_match (tree goal, edit_distance_t best_distance_so_far,
- cpp_reader *reader);
-};
-
#endif /* GCC_SPELLCHECK_TREE_H */