]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[3/7] Preprocessor macro loc
authorNathan Sidwell <nathan@acm.org>
Wed, 31 Oct 2018 14:51:54 +0000 (14:51 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Wed, 31 Oct 2018 14:51:54 +0000 (14:51 +0000)
https://gcc.gnu.org/ml/gcc-patches/2018-10/msg02039.html
* include/cpplib.h (cpp_macro_definition_location): Make inline.
* macro.c (warn_of_redefinition): Fix comments, examine macro
type, use C++ for.
(cpp_macro_definition_location): Don't define here.

From-SVN: r265688

libcpp/ChangeLog
libcpp/include/cpplib.h
libcpp/macro.c

index bcbfa97a2be7d20e1f1d21aee406092af7dce368..a02a335eae9a50d92471944aaee4996a90a67e03 100644 (file)
@@ -1,5 +1,10 @@
 2018-10-31  Nathan Sidwell  <nathan@acm.org>
 
+       * include/cpplib.h (cpp_macro_definition_location): Make inline.
+       * macro.c (warn_of_redefinition): Fix comments, examine macro
+       type, use C++ for.
+       (cpp_macro_definition_location): Don't define here.
+
        * include/cpplib.h (HT_NODE): Don't cast NODE.
        (NODE_LEN, NODE_NAME): Use HT_NODE.
 
index 345155b210a83b2b90c2648714882de71bd78d35..a2dab5237dd07c450ce7778d09bbb0e1451ee122 100644 (file)
@@ -1017,7 +1017,10 @@ inline bool cpp_fun_like_macro_p (cpp_hashnode *node)
 
 extern const unsigned char *cpp_macro_definition (cpp_reader *,
                                                  cpp_hashnode *);
-extern source_location cpp_macro_definition_location (cpp_hashnode *);
+inline source_location cpp_macro_definition_location (cpp_hashnode *node)
+{
+  return node->value.macro->line;
+}
 extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
 extern const cpp_token *cpp_peek_token (cpp_reader *, int);
 
index aacaf8c302061f8e7d45394c985a6f4d3c6816ce..bb3d95899d3a616dfc031fd31137a5922ff3f085 100644 (file)
@@ -2980,13 +2980,11 @@ _cpp_backup_tokens (cpp_reader *pfile, unsigned int count)
 
 /* #define directive parsing and handling.  */
 
-/* Returns nonzero if a macro redefinition warning is required.  */
+/* Returns true if a macro redefinition warning is required.  */
 static bool
 warn_of_redefinition (cpp_reader *pfile, cpp_hashnode *node,
                      const cpp_macro *macro2)
 {
-  unsigned int i;
-
   /* Some redefinitions need to be warned about regardless.  */
   if (node->flags & NODE_WARN)
     return true;
@@ -3021,18 +3019,18 @@ warn_of_redefinition (cpp_reader *pfile, cpp_hashnode *node,
     return true;
 
   /* Check parameter spellings.  */
-  for (i = 0; i < macro1->paramc; i++)
+  for (unsigned i = macro1->paramc; i--; )
     if (macro1->parm.params[i] != macro2->parm.params[i])
       return true;
 
   /* Check the replacement text or tokens.  */
-  if (CPP_OPTION (pfile, traditional))
+  if (macro1->kind == cmk_traditional)
     return _cpp_expansions_different_trad (macro1, macro2);
 
   if (macro1->count != macro2->count)
     return true;
 
-  for (i = 0; i < macro1->count; i++)
+  for (unsigned i= macro1->count; i--; )
     if (!_cpp_equiv_tokens (&macro1->exp.tokens[i], &macro2->exp.tokens[i]))
       return true;
 
@@ -3439,7 +3437,7 @@ create_iso_definition (cpp_reader *pfile)
     (pfile, sizeof (cpp_macro) - sizeof (cpp_token)
      + sizeof (cpp_token) * macro->count);
 
-  /* Clear whitespace on first token for warn_of_redefinition().  */
+  /* Clear whitespace on first token.  */
   if (macro->count)
     macro->exp.tokens[0].flags &= ~PREV_WHITE;
 
@@ -3767,11 +3765,3 @@ cpp_macro_definition (cpp_reader *pfile, cpp_hashnode *node)
   *buffer = '\0';
   return pfile->macro_buffer;
 }
-
-/* Get the line at which the macro was defined.  */
-
-source_location
-cpp_macro_definition_location (cpp_hashnode *node)
-{
-  return node->value.macro->line;
-}