Skip to content

Commit ce541b6

Browse files
author
nathan
committed
[3/7] Preprocessor macro loc
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@265688 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent 0f1cbe3 commit ce541b6

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

libcpp/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
2018-10-31 Nathan Sidwell <[email protected]>
22

3+
* include/cpplib.h (cpp_macro_definition_location): Make inline.
4+
* macro.c (warn_of_redefinition): Fix comments, examine macro
5+
type, use C++ for.
6+
(cpp_macro_definition_location): Don't define here.
7+
38
* include/cpplib.h (HT_NODE): Don't cast NODE.
49
(NODE_LEN, NODE_NAME): Use HT_NODE.
510

libcpp/include/cpplib.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,10 @@ inline bool cpp_fun_like_macro_p (cpp_hashnode *node)
10171017

10181018
extern const unsigned char *cpp_macro_definition (cpp_reader *,
10191019
cpp_hashnode *);
1020-
extern source_location cpp_macro_definition_location (cpp_hashnode *);
1020+
inline source_location cpp_macro_definition_location (cpp_hashnode *node)
1021+
{
1022+
return node->value.macro->line;
1023+
}
10211024
extern void _cpp_backup_tokens (cpp_reader *, unsigned int);
10221025
extern const cpp_token *cpp_peek_token (cpp_reader *, int);
10231026

libcpp/macro.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,13 +2980,11 @@ _cpp_backup_tokens (cpp_reader *pfile, unsigned int count)
29802980

29812981
/* #define directive parsing and handling. */
29822982

2983-
/* Returns nonzero if a macro redefinition warning is required. */
2983+
/* Returns true if a macro redefinition warning is required. */
29842984
static bool
29852985
warn_of_redefinition (cpp_reader *pfile, cpp_hashnode *node,
29862986
const cpp_macro *macro2)
29872987
{
2988-
unsigned int i;
2989-
29902988
/* Some redefinitions need to be warned about regardless. */
29912989
if (node->flags & NODE_WARN)
29922990
return true;
@@ -3021,18 +3019,18 @@ warn_of_redefinition (cpp_reader *pfile, cpp_hashnode *node,
30213019
return true;
30223020

30233021
/* Check parameter spellings. */
3024-
for (i = 0; i < macro1->paramc; i++)
3022+
for (unsigned i = macro1->paramc; i--; )
30253023
if (macro1->parm.params[i] != macro2->parm.params[i])
30263024
return true;
30273025

30283026
/* Check the replacement text or tokens. */
3029-
if (CPP_OPTION (pfile, traditional))
3027+
if (macro1->kind == cmk_traditional)
30303028
return _cpp_expansions_different_trad (macro1, macro2);
30313029

30323030
if (macro1->count != macro2->count)
30333031
return true;
30343032

3035-
for (i = 0; i < macro1->count; i++)
3033+
for (unsigned i= macro1->count; i--; )
30363034
if (!_cpp_equiv_tokens (&macro1->exp.tokens[i], &macro2->exp.tokens[i]))
30373035
return true;
30383036

@@ -3439,7 +3437,7 @@ create_iso_definition (cpp_reader *pfile)
34393437
(pfile, sizeof (cpp_macro) - sizeof (cpp_token)
34403438
+ sizeof (cpp_token) * macro->count);
34413439

3442-
/* Clear whitespace on first token for warn_of_redefinition(). */
3440+
/* Clear whitespace on first token. */
34433441
if (macro->count)
34443442
macro->exp.tokens[0].flags &= ~PREV_WHITE;
34453443

@@ -3767,11 +3765,3 @@ cpp_macro_definition (cpp_reader *pfile, cpp_hashnode *node)
37673765
*buffer = '\0';
37683766
return pfile->macro_buffer;
37693767
}
3770-
3771-
/* Get the line at which the macro was defined. */
3772-
3773-
source_location
3774-
cpp_macro_definition_location (cpp_hashnode *node)
3775-
{
3776-
return node->value.macro->line;
3777-
}

0 commit comments

Comments
 (0)