[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 8/9] -npcs: Fix recognition of function pointers
From: |
Tim Hentenaar |
Subject: |
[PATCH 8/9] -npcs: Fix recognition of function pointers |
Date: |
Wed, 17 Jun 2015 20:56:04 +0200 |
Indent reads a function pointer with more than one level of indirection
such as char **(*x) as 'char *' [decl] '*' [unary_op] '(' [lparen] which
was preventing it from being detected as a function pointer since the code
for that was expecting only 'decl' before the lparen.
This patch fixes the detection code to account for this fact, since it
seems that there's other functionality relying on it.
---
ChangeLog | 2 ++
regression/input/fp.c | 1 +
regression/standard/fp.c | 1 +
regression/standard/no-space-after-fp-name.c | 1 +
src/handletoken.c | 6 ++++--
5 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 96bc261..101bcbb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,8 @@
* Added an option (-ntac/--dont-tab-align-comments) which if specified
prevents indent from automagically pushing comments out to the
nearest tabstoo.
+ * Fixed recognition of function pointers with multiple levels of
+ indirection by the -npcs stuff.
2015-06-16 Tim Hentenaar <address@hidden>
* Use want_blank instead of copying a space to e_code to avoid
diff --git a/regression/input/fp.c b/regression/input/fp.c
index 92f6354..dc869f3 100644
--- a/regression/input/fp.c
+++ b/regression/input/fp.c
@@ -1,6 +1,7 @@
int (*fp ())();
register void (*GCForward) () asm ("r16"); /* GC Forwarding code */
+char **(*get_string_array) (const char *s1, const char *s2);
main ()
{
diff --git a/regression/standard/fp.c b/regression/standard/fp.c
index af15ae8..dc775af 100644
--- a/regression/standard/fp.c
+++ b/regression/standard/fp.c
@@ -1,6 +1,7 @@
int (*fp ()) ();
register void (*GCForward) () asm ("r16"); /* GC Forwarding code */
+char **(*get_string_array) (const char *s1, const char *s2);
main ()
{
diff --git a/regression/standard/no-space-after-fp-name.c
b/regression/standard/no-space-after-fp-name.c
index 6bc5885..3b52ef7 100644
--- a/regression/standard/no-space-after-fp-name.c
+++ b/regression/standard/no-space-after-fp-name.c
@@ -1,6 +1,7 @@
int (*fp())();
register void (*GCForward)() asm("r16"); /* GC Forwarding code */
+char **(*get_string_array)(const char *s1, const char *s2);
main()
{
diff --git a/src/handletoken.c b/src/handletoken.c
index b3a807d..60828d5 100644
--- a/src/handletoken.c
+++ b/src/handletoken.c
@@ -353,8 +353,10 @@ static void handle_token_lparen(
}
/* Remember if this looks like a function pointer decl. */
- if (parser_state_tos->want_blank &&
- parser_state_tos->last_token == decl && *(token + 1) == '*')
+ if (*(token + 1) == '*' &&
+ parser_state_tos->last_rw == rw_decl &&
+ (parser_state_tos->last_token == decl ||
+ parser_state_tos->last_token == unary_op))
parser_state_tos->is_func_ptr_decl = true;
if (parser_state_tos->in_decl && !parser_state_tos->block_init)
--
2.3.6
- [PATCH 0/9] More bugfixes, etc., Tim Hentenaar, 2015/06/17
- [PATCH 1/9] Add regressions mising from upstream, Tim Hentenaar, 2015/06/17
- [PATCH 4/9] scan_profile(): Make sure the buffers are initialized, Tim Hentenaar, 2015/06/17
- [PATCH 2/9] comments.c: Fix print_comment reading past the end of the buffer when reading less than a full comment from stdin., Tim Hentenaar, 2015/06/17
- [PATCH 8/9] -npcs: Fix recognition of function pointers,
Tim Hentenaar <=
- [PATCH 6/9] indent.c: Don't force nl between rbrace and comma, Tim Hentenaar, 2015/06/17
- [PATCH 9/9] Add an install target to the regression Makefile, Tim Hentenaar, 2015/06/17
- [PATCH 3/9] Fix several potential memory leaks, Tim Hentenaar, 2015/06/17
- [PATCH 7/9] Don't tab-align comments (-ntac), Tim Hentenaar, 2015/06/17
- [PATCH 5/9] comments.c: Fix heap corruption, Tim Hentenaar, 2015/06/17